Reputation: 57541
This question is similar to create database using psql in shell script takes username as db name, but since that doesn't have an accepted answer I'm asking it again here. I've created a user with username myuser
and password mypassword
:
> psql
psql (11.5)
Type "help" for help.
kurt=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
kurt | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
myuser | | {}
kurt=#
However, if I do psql --username=myuser
, I get an error that database "myuser" does not exist
:
> psql --username=myuser
psql: FATAL: database "myuser" does not exist
I'm a bit confused by this error message, because according to psql --help
, this is a user name, not a database name:
Connection options:
-h, --host=HOSTNAME database server host or socket directory (default: "local socket")
-p, --port=PORT database server port (default: "5432")
-U, --username=USERNAME database user name (default: "kurt")
-w, --no-password never prompt for password
-W, --password force password prompt (should happen automatically)
Any idea what I'm doing wrong? Here is the version of psql
I'm using:
> psql --version
psql (PostgreSQL) 11.5
Upvotes: 5
Views: 2092
Reputation: 1
After creating your new user, first you have to login using postgres user and create new database similar to your new created user. ex: if my new user is "david", I must create also database called "david" using posgtres user.After this you can now login using your new user created.
Upvotes: 0
Reputation:
The default user name is your operating-system user name, as is the default database name
If you specify a username, that username is then also assumed as the default for the database name.
Upvotes: 2