psql: could not connect to server [ubuntu] - postgresql

Under the postgres user, I tried the psql command and I'm getting this error:
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"
But when I run /usr/local/pgsql/bin/psql, it is working.
Is there anything wrong with my configuration?

the above issue seems related to PostgreSQL default port no,
Change the port no in postgresql.conf file and restart the DB server. if u have changed the port while installing.
(OR)
instead of psql type full command like
"psql -p 5432 -h localhost"

You could include the database user too:
psql -U postgres -p 5432 -h localhost

Did you reinstall the postgresql-9.6.3 ?
You need to uninstall postgresql completely
sudo apt-get --purge autoremove postgresql*
sudo apt install postgresql-9.6

Related

I couldn't run psql command in my ubuntu server (version 22.04)

I couldn't run psql commad in my ubuntu server (version 22.04)
1.I installed postgres with the command sudo apy install postgresql-13
Than I run sudo -i -u postgres to connect as user "postgres" and get this in terminal:. postgres#IdeaPad:~$. It's OK.
Next i try to run psql / psql -h localhost -p 5432 and get an error message
I made sure the postgres server is up
I deleted file postmaster.pid and than restated the server
This don't solve the problem.
Changed file /etc/postgresql/13/main/pg_hba.conf to make it look like this
This don't solve the problem too.
I really don't understand what is problem and hope you could help me
UPD: I run psql -U postgres -h localhost and get this:

could not connect to database postgres

createuser: could not connect to database postgres: 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"?
I am trying to install dspace 6.3 on ubuntu server 18.04 but after installing postgresql when I run the command createuser -U postgres -d -A -P dspace I am getting the above error help please
Did you start the server? Try sudo service postgresql restart or sudo systemctl restart postgresql

Error while connecting to remote Postgres on centos

When I'm trying to connect to Postgres on remote cloud . It is showing :
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Local system -- Postgres 9.3 (windows)
Remote System is on Azure -- Postgres 9.2(centos)
Command I'm using: psql -h "abc.cloudapp.net" -p 5432
I've set the end-point as 5432 in azure
changed the postgresql.conf to "*" to allow connection
and changed the pg_hba to (host all all ip/24 md5)
Please help me out on this.
Endpoint is OK, and you need to set up the network security group as well.
Try to define not just 5432, but the range of ports (1024-65536 for example).
UPD: I was able to create the CentOs 7.0 + PostgreSQL and connected to that instance:
sudo yum install postgresql-server postgresql-contribs
sudo postgresql-setup initdb
sudo vi /var/lib/pgsql/data/pg_hba.conf
Edit 127.0.0.1/32 to 0.0.0.0/0
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo vim /var/lib/pgsql/data/postgresql.conf
sudo service postgresql restart
sudo service postgresql restart
sudo -u postgres createuser --superuser azureuser -P
Then i downloaded pgAdmin and connected to that. (see screenshot) (do not pay attention to the test1 database, just change it to postgres).

Postgresql (pgsql) client expecting sockets in different location from postgrsql-server

While trying to connect to postgres running locally on my workstation, I get:
$ sudo -u postgres psql -c "create role ..."
could not change directory to "/home/esauer/workspace/cfme"
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
My postgres-server install creates sockets in /var/run/postgresql.
How do I get the client to look in the proper location?
Check the --host option with psql --help.
Then you can make it permanent by setting it in your .psqlrc user file.
In your case try:
psql -h /var/run/postgresql -d your_database

Unable to connect to postgres in ubuntu

I am trying to install postgresql on ubuntu.
I followed the steps from http://hocuspokus.net/2008/05/install-postgresql-on-ubuntu-804/.
And on typing the command :
psql template1
I am getting the following error:
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"?
The problem for me was that I had previously installed version 9.1, and 9.1 was still hogging the default port 5432. I was able to find this with the command:
root#labs:/home/caleb# /etc/init.d/postgresql status
9.1/main (port 5432): down
9.2/main (port 5433): online
So I was able to see that my 9.2 database was running on port 5433. So to connect, I had to explicitly specify port 5433:
psql -p 5433
try the following
psql template0
what resolved this error for me was deleting a file called postmaster.pid in the postgres directory. please see my question/answer using the following link for step by step instructions. my issue was not related to file permissions:
psql: could not connect to server: No such file or directory (Mac OS X)
You can also get in the CLI via this command:
psql -U postgres -p 5432 -h localhost
This should solve the error,
make a symbolic link to the /tmp/.s.PGSQL.5432:
sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
Thanks to this post