Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the server running locally - Postgresql

Tags:

postgresql

tameen@tameen-HP:~/Downloads/$ sudo -u postgres 
tameen@tameen-HP:~/Downloads/$ sudo -u postgres psql
[sudo] password for tameen: 
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.5433"?

tameen@tameen-HP:~/Downloads/$ netstat -an | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:5939          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN  

if its listening the port 5432 and by using export PGPORT=5432 its not working . How to solve this problem?


tameen@tameen-HP:~/Downloads$ sudo su postgres 
postgres@tameen-HP:/home/tameen/Downloads$ createdb template_postgis
could not change directory to "/home/tameen/Downloads": Permission denied
createdb: could not connect to database template1: 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.5433"?
like image 203
Tameen Malik Avatar asked Jan 09 '23 01:01

Tameen Malik


2 Answers

Provide the port and host via -p/-h options:

sudo -u postgres psql -p 5432 -h 127.0.0.1

createdb -p 5432 -h 127.0.0.1 template_postgis
like image 192
catavaran Avatar answered Jan 16 '23 19:01

catavaran


At a guess you're using a PostgreSQL psql client and libpq compiled with a default unix_socket_directories of /var/run/postgresql but your server is compiled with /tmp as the default.

This is common when you have PostgreSQL installed from your distro's packages and also installed by some other means.

Use psql -h /tmp/ to specify the unix socket directory, rather than switching to tcp/ip as @catavaran suggests.

like image 26
Craig Ringer Avatar answered Jan 16 '23 19:01

Craig Ringer