服务器是否在本地运行 - Postgresql

时间:2015-01-22 03:09:32

标签: 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  

如果它正在侦听端口5432并使用export PGPORT=5432它不起作用。如何解决这个问题呢?


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"?

3 个答案:

答案 0 :(得分:2)

通过-p / -h选项提供端口和主机:

sudo -u postgres psql -p 5432 -h 127.0.0.1

createdb -p 5432 -h 127.0.0.1 template_postgis

答案 1 :(得分:2)

您猜测您正在使用PostgreSQL psql客户端和libpq使用默认unix_socket_directories /var/run/postgresql编译,但您的服务器编译为{{1}默认情况下。

当您从发行版的软件包中安装PostgreSQL并通过其他方式安装PostgreSQL时,这种情况很常见。

使用/tmp指定unix套接字目录,而不是像@catavaran建议那样切换到tcp / ip。

答案 2 :(得分:0)

正如您在Unix套接字/var/run/postgresql/.s.PGSQL.5433上看到的那样,您的客户端尝试连接到端口 5433 上运行的服务器的Unix套接字。根据{{​​1}}的输出,您的服务器正在端口 5432 上运行。

我建议:

  1. 停止服务器
  2. 删除netstat中所有剩余的套接字文件
  3. 再次启动服务器