0

I've installed postgresql on Ubuntu 21.04.

when I want to use it with psql command I got this error:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?

update 1

I had postgres before. today I tried to use it and I got this error, so I remove everything about postgres using sudo apt remove postgresql-13 postgresql-client-13 postgresql-client-common postgresql-14 postgresql-client-14 postgresql-common and installed postgres by sudo apt install postgresql .

in tutorials, they install postgres and start using it without any configurations but I can't do that.


update 2

output of pg_lsclusters command:

Ver Cluster Port Status                Owner    Data directory              Log file
13  main    5432 down,binaries_missing postgres /var/lib/postgresql/13/main /var/log/postgresql/postgresql-13-main.log
14  main    5433 online                postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log

6
  • 1
    The error message is specific: ' Is the server running locally and accepting connections on that socket?. So did you start the server? In postgresql.conf` is port set to 5432? Further information: How did you install Postgres? Do you have more then one instance of Postgres running? Add answers as update to your question. Commented Oct 18, 2021 at 18:28
  • What does pg_lsclusters show? Add as update to your question. Commented Oct 19, 2021 at 23:56
  • @AdrianKlaver Updated. Commented Oct 22, 2021 at 19:40
  • The output is pretty clear, the Postgres server that is up is listening on port 5433. The one that is set up for port 5432 does not have binaries installed. Your choices are psql -p 5433, install the Postgres 14 binaries or change the Postgres 13 server to listen on port 5432. Commented Oct 22, 2021 at 20:06
  • @AdrianKlaver When I run psql -p 5433 command I got this error: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5433" failed: FATAL: role "smjt2000" does not exist . how I can change the Postgres 13 port to 5432 ? Commented Oct 22, 2021 at 20:17

2 Answers 2

3

Edit this files for solve port problem:

/etc/postgresql/14/main/postgresql.conf :

port = 5433 -> port = 5432

/etc/postgresql/13/main/postgresql.conf :

port = 5432 -> port = 5433


Open /etc/postgresql/14/main/pg_hba.conf with your preferred editor and change the following line:

local     all     postgres               peer

to this:

local     all     postgres               trust

then run sudo service postgresql restart

run psql -U postgres and run this command:

ALTER USER postgres WITH ENCRYPTED PASSWORD "#your-password" ;
CRETE USER smjt2000 WITH ENCRYPTED PASSWORD "#your-password" ;
CREATE DATABASE smjt2000 OWNER smjt2000 ;

exit the postgresql shell by entering exit

change /etc/postgresql/14/main/pg_hba.conf to this:

local     all     postgres          md5

finally run sudo service postgresql restart

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

2 Comments

It's good but when I run psql it doesn't ask my password.
@mohammadjavad open /etc/postgresql/14/main/pg_hba.conf and change this line local all all peer to local all all md5
0

You can also check if postrgresql service is running. It could be in an inactive state.

○ postgresql.service - PostgreSQL RDBMS
 Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
 Active: **inactive (dead)**

To check the status of the service:

$sudo service postrgresql status

Your error is as a result of the service being inactive, hence not part of the local connection. To restart the service:

$sudo service postrgresql restart

Confirm if it is active:

$sudo service postrgresql status

● postgresql.service - PostgreSQL RDBMS
 Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
 Active: active (exited) since Tue 2022-01-18 02:13:35 EST; 2min 16s ago
Process: 167135 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 167135 (code=exited, status=0/SUCCESS)
    CPU: 3ms

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.