Ho installato lo stack Bitnami Django che include PostgreSQL 8.4.
Quando eseguo psql -U postgres
ottengo il seguente errore:
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 è sicuramente in esecuzione e il file pg_hba.conf
è così:
# 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
Cosa c'è?
Prova" che il pg sta funzionando:
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#
Il messaggio di errore si riferisce a un socket di dominio Unix, quindi dovete modificare la vostra invocazione netstat
per non escluderli. Quindi provate senza l'opzione -t
:
netstat -nlp | grep 5432
Immagino che il server sia effettivamente in ascolto sul socket /tmp/.s.PGSQL.5432
piuttosto che sul /var/run/postgresql/.s.PGSQL.5432
a cui il tuo client sta cercando di connettersi. Questo è un problema tipico quando si usano pacchetti PostgreSQL compilati a mano o di terze parti su Debian o Ubuntu, perché il sorgente predefinito per la directory socket del dominio Unix è /tmp
ma il pacchetto Debian lo cambia in /var/run/postgresql
.
Possibili soluzioni:
/opt/djangostack-1.3-0/postgresql/bin/psql
). Possibilmente disinstallare del tutto i pacchetti forniti da Ubuntu (potrebbe essere difficile a causa di altre dipendenze inverse).-H localhost
per connettersi via TCP/IP.-h /tmp
o un'impostazione PGHOST
equivalente per puntare alla giusta directory.Puoi usare psql -U postgres -h localhost
per forzare la connessione su TCP invece che sui socket di dominio UNIX; il tuo output netstat
mostra che il server PostgreSQL è in ascolto sulla porta 5432 di localhost.
Puoi scoprire quale socket UNIX locale è usato dal server PostgreSQL usando un'altra invocazione di netstat:
netstat -lp --protocol=unix | grep postgres
In ogni caso, le interfacce su cui il server PostgreSQL ascolta sono configurate in postgresql.conf
.