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;"
^^^^^^^^^