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?
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:
To start the database:
To run psql and supply the parameters:
Ignore the # symbols as these are just representing the command line.
The situation described in the question can happen after a reboot in systems with Postgres installed. The service may fail to start or not start properly.
Since 16.04 services are managed with the
systemctl
tool. In most circumstances you only need to restart the service:sudo systemctl restart postgresql.service
You can also check the current status of the service:
sudo systemctl status postgresql.service
And start it if it is down:
sudo systemctl start postgresql.service