Ubuntu: Cannot connect to postgresql on port 5432
Question: I installed the http://bitnami.org/stack/djangostack which included PostgreSQL
8.4.
When I run psql -U postgres I get 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"?
PG is definitely running and the pg_hba.conf file looks like this:
TYPE DATABASE USER CIDR-ADDRESS METHOD
"local" is for Unix domain socket connections only
local all all md5
IPv4 local connections:
host all all 127.0.0.1/32 md5
IPv6 local connections:
host all all ::1/128 md5
What gives?
"Proof" that pg is running:
root@assaf-desktop:/home/assaf# ps axf | grep postgres
14338 ? S 0:00 /opt/djangostack-1.3-0/postgresql/bin/postgres -D /
opt/djangostack-1.3-0/postgresql/data -p 5432
14347 ? Ss 0:00 \_ postgres: writer process
14348 ? Ss 0:00 \_ postgres: wal writer process
14349 ? Ss 0:00 \_ postgres: autovacuum launcher process
14350 ? Ss 0:00 \_ postgres: stats collector process
15139 pts/1 S+ 0:00 \_ grep --color=auto postgres
root@assaf-desktop:/home/assaf# netstat -nltp | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
14338/postgres
tcp6 0 0 ::1:5432 :::* LISTEN
14338/postgres
root@assaf-desktop:/home/assaf#
Solutions Sample (Please watch the whole video to see all solutions, in order of how many people found them helpful):
== This solution helped 15 people ==
Just create a softlink like this :
ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
== This solution helped 17 people ==
You can use psql -U postgres -h localhost to force the connection to happen
over TCP instead of UNIX domain sockets; your netstat output shows that the
PostgreSQL server is listening on localhost's port 5432.
You can find out which local UNIX socket is used by the PostgrSQL server by
using a different invocavtion of http://manpages.ubuntu.com/netstat:
netstat -lp --protocol=unix | grep postgres
At any rate, the interfaces on which the PostgreSQL server listens to are
configured in postgresql.conf.
== This solution helped 17 people ==
This works for me:
Edit: postgresql.conf
sudo nano /etc/postgresql/9.3/main/postgresql.conf
Enable or add:
listen_addresses = '*'
Restart the database engine:
sudo service postgresql restart
Also, you can check the file pg_hba.conf
sudo nano /etc/postgresql/9.3/main/pg_hba.conf
And add your network or host address:
host all all 192.168.1.0/24 md5
== This solution helped 1 person ==
I found uninstalling Postgres sounds unconvincing. This helps to solve my
problem:
1. Start the postgres server:
sudo systemctl start postgresql
2. Make sure that the server starts on boot:
sudo systemctl enable postgresql
Detail information can be found on DigitalOcean site https://
www.digitalocean.com/community/questions/is-the-server-running-locally-and-
accepting-connections-on-unix-domain-socket-var-run-postgresql-s-pgsql-5432
With thanks & praise to God! With thanks to all the many who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music & music license: https://www.bensound.com/royalty-free-music | Images & images license: https://stocksnap.io/license and others | With thanks to user Zanna (https://askubuntu.com/users/527764), user Uriel (https://askubuntu.com/users/75885), user Stewart (https://askubuntu.com/users/185585), user Riccardo Murri (https://askubuntu.com/users/325), user Peter Eisentraut (https://askubuntu.com/users/1156), user Peachy (https://askubuntu.com/users/74307), user parlad neupane (https://askubuntu.com/users/340419), user Noushad PP (https://askubuntu.com/users/574905), user Nj Subedi (https://askubuntu.com/users/279492), user mymusise (https://askubuntu.com/users/594086), user Mehdi Nellen (https://askubuntu.com/users/624875), user jurban1997 (https://askubuntu.com/users/644015), user Joe (https://askubuntu.com/users/105851), user David Foerster (https://askubuntu.com/users/175814), user bogdanvlviv (https://askubuntu.com/users/435906), user Assaf Lavie (https://askubuntu.com/users/6674), user angelous (https://askubuntu.com/users/208319), and the Stack Exchange Network (http://stackoverflow.com/questions/50621). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything should be amiss at Roel D.OT VandePaar A.T gmail.com.
7 Comments