5

When I am running this command below:

sudo -u postgres psq

I get this error message below:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

How can I start postgreSql and fix this error?

3
  • Have you tried sudo systemctl start postgresql and sudo -u postgres -i ? And what systemctl status postgresql says?
    – Gryu
    Jan 28 '20 at 18:25
  • After i have done that it hangs ?
    – Jonte YH
    Jan 28 '20 at 18:29
  • Open new terminal tab and check postgresql daemon status.
    – Gryu
    Jan 28 '20 at 18:30
2

To start the PostgreSQL database (on Ubuntu Server, no GUI), normally you would use the pg_ctl command. Become the admin user that PostgreSQL was installed with. You probably will need to set the environment variables for PGDATA and PGPORT.

When the database is up, you should see something like this:

# pg_ctl status
pg_ctl: server is running (PID: 23890)

To start the database:

# pg_ctl start

To run psql and supply the parameters:

# psql -d {dbname} -p {pgport} -U {username} -W {password} 

Ignore the # symbols as these are just representing the command line.

2
  • Do you have an link about info how to set up pg_ctl ?
    – Jonte YH
    Jan 28 '20 at 18:50
  • If you have set up your environment variables to access PostgreSQL, such as $PGDATA and $POSTGRESQL_HOME, there should be no need to do any setup. $POSTGRESQL_HOME is where the PostgreSQL engine is installed. $PGDATA is the folder/directory where your instance is located and where the postgresql.conf file is located. Use pg_ctl --help to see what flags are available. You can find out more at the official online documentation. postgresql.org/docs/current/app-pg-ctl.html
    – S. Nixon
    Jan 29 '20 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.