postgresql - Postgres - How to use psql to create a database with the -c command and password authentication? -


if run following:

psql -h localhost -u admin -c "create database sales owner admin;" 

it returns:

psql fatal: database "admin" not exist

i need use password authentication , have setup .pgpass follows:

localhost:*:*:admin:admin 

any ideas?

by default, when connect user, database connected db of same name user.

if want connect different db, must specify in psql command line. since in case you're trying create db, can't connect yet, must connect db (like template1 or postgres) exists.

e.g.

psql -h localhost -u admin template1 -c "create database sales owner admin;"                            ^^^^^^^^^ 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -