1

When I perform sudo -u zorgan postgres psql to start my postgres session it returns:

postgres: invalid argument: "psql"

if I remove psql it returns:

postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

Any idea what the problem is?

7
  • 1
    depends on what you try to do... what you expect from sudo -u zorgan postgres psql?... Commented May 14, 2018 at 12:42
  • I'm simply trying to start a postgres session so I can create my database, similar to here: digitalocean.com/community/tutorials/… (however I'm doing this on my local server not a remote server) Commented May 14, 2018 at 12:43
  • 1
    sudo -u zorgan postgres will run a program named postgres as the Linux user zorgan - I doubt that this is what you want. If you already have a user zorgan then why not just supply the username directly using: psql -U zorgan Commented May 14, 2018 at 12:46
  • 1
    You probably shouldn't run the postgres binary with psql as the argument, but the psql binary. Drop postgres out of that command line. Commented May 14, 2018 at 12:48
  • 1
    sudo -u zorgan psql postgres?.. Commented May 14, 2018 at 12:53

2 Answers 2

2

sudo -u postgres psql

The postgres above is a user.

Sign up to request clarification or add additional context in comments.

Comments

1

https://www.sudo.ws/man/1.8.18/sudo.man.html

[-u user] [command]

so in your case:

sudo -u zorgan postgres psql

tries to start postgres process with argument psql and thankfully fails. if you want to connect to postgres cluster using psql client, use psql. so if you wish to run it with sudo:

sudo -u zorgan psql postgres

here postgres is argumentfor psql, which is dbname...

https://www.postgresql.org/docs/current/static/app-psql.html

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.