Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Query regarding psql command

10 views
Skip to first unread message

ajat.pr...@gmail.com

unread,
May 25, 2018, 2:34:24 AM5/25/18
to
Hi there,
I'm an undergrad student and very new to postgresql. I have a question to which I haven't been able to find an answer yet.
I installed postgresql and ran the command `psql -U postgres` and as expected it failed because the role doesn't exist.

But when I tried to run `psql postgres`, it worked! My question is why is this command working? I've not been able to find this command anywhere in the documentation.

Now, I also created the role postgres and both commands are working.

Note: when I run `psql postgres` the logged-in user is the superuser to OS. I'm doing this on High Sierra.

Laurenz Albe

unread,
May 25, 2018, 7:05:59 AM5/25/18
to
It must be that your installation process named the default superuser
differently when it ran "initdb" to create the cluster.

You can use this query to find the name of the default superuser:

SELECT usename FROM pg_user WHERE usesysid = 10;

Your attempt with "psql postgres" succeeded because the default superuser
happened to have the same name as your operating system user, and that's
the default that psql uses if you don't specify the -U option.

You can rename a user with

ALTER USER ... RENAME TO ...;

But you shouldn't forget that renaming a user clears the password, so you
have to set it again with \password.

ajat.pr...@gmail.com

unread,
May 25, 2018, 8:25:11 AM5/25/18
to
Thank you Laurenz for the help 🙂
0 new messages