0

From http://suite.opengeo.org/docs/latest/dataadmin/pgGettingStarted/firstconnect.html, it says:

Run the psql command from the postgres user account:

sudo -u postgres psql postgres

Does the first postgres mean that psql will be run by user postgres?

What does the second postgres mean?

The manpage of psql gives

SYNOPSIS
       psql [option...] [dbname [username]]

Is the second postgres a dbname?

Does postgresql by default have a database named postgres, as well as a user named postgres?

Thanks.

1
  • Yes... and yes... and yes... Try this command: sudo -u postgres psql -c "\l" Commented Dec 6, 2017 at 22:28

1 Answer 1

0

From sudo documentation:

-u user, --user=user
Run the command as a user other than the default target user (usually root).

From (PostgreSQL) initdb documentation:

Creating a database cluster consists of creating the directories in which the database data will live, generating the shared catalog tables (tables that belong to the whole cluster rather than to any particular database), and creating the template1 and postgres databases.

and

-U username --username=username

Selects the user name of the database superuser. This defaults to the name of the effective user running initdb. It is really not important what the superuser's name is, but one might choose to keep the customary name postgres, even if the operating system user's name is different.

From psql documentation you quote you can see that, besides options, you call it with either a database name, or a database name and user name

If you do not provide a database name it tries to connect to the database name being the name of the user currently running psql, as explained in documentation:

The default user name is your operating-system user name, as is the default database name.

2
  • Thanks. Can you point out where it says " if you do not provide a database name it tries to connect to the database name being the name of the user currently running psql"?
    – user167166
    Commented Dec 7, 2017 at 0:54
  • I have edited the end of my answer to add the relevant line from psql manual Commented Dec 7, 2017 at 1:23

You must log in to answer this question.