Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

Cannot connect to Postgresql using the terminal in Ubuntu 20

I am using postgresql 13. When I type psql I get this:

psql: error: could not connect to server: Ficheiro ou pasta inexistente
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I installed it using

sudo apt update
sudo apt install postgresql postgresql-contrib

systemctl status gives this

postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Thu 2021-02-04 15:04:55 -03; 6min ago
    Process: 35313 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 35313 (code=exited, status=0/SUCCESS)

fev 04 15:04:55 diego-I42IL1 systemd[1]: Starting PostgreSQL RDBMS...
fev 04 15:04:55 diego-I42IL1 systemd[1]: Finished PostgreSQL RDBMS.

It seems ok.

question from:https://stackoverflow.com/questions/66051343/cannot-connect-to-postgresql-using-the-terminal-in-ubuntu-20

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Before I used the installation commands stated in the question I am "almost" certain that I had used other commands to install postgres. The problem is that I had several versions installed.

I used this command pg_lsclusters

It will show the clusters and the ports the are using

12  main    5432 down,binaries_missing <unknown> /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
13  main    5433 online                postgres  /var/lib/postgresql/13/main /var/log/postgresql/postgresql-13-main.log

I wasn't connecting to postgresql because I supposedly had purged version 12. But the task of removing postgresql is not as easy as installing it. The system was seeing Potgres as installed(even though th libs were missing) and was using the default port.

To use the right port use this command "psql --port 533'3'"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...