문제

If I run the following:

psql -h localhost -U admin -c "CREATE DATABASE sales OWNER admin;"

It returns:

psql FATAL: database "admin" does not exist

I need to use password authentication and have setup .pgpass as follows:

localhost:*:*:admin:admin

Any ideas?

도움이 되었습니까?

해결책

By default, when you connect as a user, the database connected to is the DB of the same name as the user.

If you want to connect to a different DB, you must specify it in the psql command line. Since in this case you're trying to create the DB, you can't connect to it yet, you must connect to another DB (like template1 or postgres) that already exists.

E.g.

psql -h localhost -U admin template1 -c "CREATE DATABASE sales OWNER admin;"
                           ^^^^^^^^^
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top