I installed the Bitnami Django stack 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#
This issue comes from installing the
postgres
package without a version number. Althoughpostgres
will be installed and it will be the correct version, the script to setup the cluster will not run correctly; it's a packaging issue.If you're comfortable with
postgres
there is a script you can run to create this cluster and getpostgres
running. However, there's an easier way.First purge the old postgres install, which will remove everything of the old installation, including databases, so back up your databases first.. The issue currently lies with 9.1 so I will assume that's what you have installed
Now simply reinstall
Note the package name with the version number. HTH.
The error message refers to a Unix-domain socket, so you need to tweak your
netstat
invocation to not exclude them. So try it without the option-t
:I would guess that the server is actually listening on the socket
/tmp/.s.PGSQL.5432
rather than the/var/run/postgresql/.s.PGSQL.5432
that your client is attempting to connect to. This is a typical problem when using hand-compiled or third-party PostgreSQL packages on Debian or Ubuntu, because the source default for the Unix-domain socket directory is/tmp
but the Debian packaging changes it to/var/run/postgresql
.Possible workarounds:
/opt/djangostack-1.3-0/postgresql/bin/psql
). Possibly uninstall the Ubuntu-supplied packages altogether (might be difficult because of other reverse dependencies).-H localhost
to connect via TCP/IP instead.-h /tmp
or equivalentPGHOST
setting to point to the right directory.This works for me:
Edit: postgresql.conf
Enable or add:
Restart the database engine:
Also, you can check the file
pg_hba.conf
And add your network or host address:
Just create a softlink like this :
You can use
psql -U postgres -h localhost
to force the connection to happen over TCP instead of UNIX domain sockets; yournetstat
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 netstat:
At any rate, the interfaces on which the PostgreSQL server listens to are configured in
postgresql.conf
.I make it work by doing this:
Choose your preferred locales then run
(9.5 is my version of postgresql)
and then it works!
I had to compile PostgreSQL 8.1 on Debian Squeeze because I am using Project Open, which is based on OpenACS and will not run on more recent versions of PostgreSQL.
The default compile configuration puts the
unix_socket
in/tmp
, but Project Open, which relies on PostgreSQL, would not work because it looks for theunix_socket
at/var/run/postgresql
.There is a setting in
postgresql.conf
to set the location of the socket. My problem was that either I could set for/tmp
andpsql
worked, but not project open, or I could set it for/var/run/postgresql
andpsql
would not work but project open did.One resolution to the issue is to set the socket for
/var/run/postgresql
and then runpsql
, based on Peter's suggestion, as:This runs locally using local permissions. The only drawback is that it is more typing than simply "psql".
The other suggestion that someone made was to create a symbolic link between the two locations. This also worked, but, the link disappeared upon reboot. It maybe easier to just use the -h argument, however, I created the symbolic link from within the PostgreSQL script in
/etc/init.d
. I placed the symbolic link create command in the "start" section. Of course, when I issue a stop and start or restart command, it will try to recreate an existing symbolic link, but other than warning message, there is probably no harm in that.In my case, instead of:
I have
and have explicitly set the unix_socket to
/var/run/postgresql/.s.PGSQL.5432
inpostgresql.conf
.If your Postgres service is up and running without any error or there is no error in starting the Postgres service and still you are getting the mentioned error, follow these steps
Step1: Running
pg_lsclusters
will list all the postgres clusters running on your deviceeg:
most probably the status will be down in your case and postgres service
Step 2: Restart the pg_ctlcluster
Step 3: Step 2 failed and threw error
If this process is not successful it will throw an error. You can see the error log on
/var/log/postgresql/postgresql-9.6-main.log
My error was:
Step 4: check ownership of postgres
Make sure that
postgres
is the owner of/var/lib/postgresql/version_no/main
If not, run
Step 5: Check postgres user belongs to ssl-cert user group
It turned out that I had erroneously removed the Postgres user from the
ssl-cert
group. Run the below code to fix the user group issue and fix the permissionsI found uninstalling Postgres sounds unconvincing. This helps to solve my problem:
Start the postgres server:
Make sure that the server starts on boot:
Detail information can be found on DigitalOcean site Here.
Solution:
Do this
and this. (9.3 is my current PostgreSQL version. Write your version!)