服务器 运行 是否在本地 - Postgresql
Is the server running locally - 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"?
通过-p
/-h
选项提供端口和主机:
sudo -u postgres psql -p 5432 -h 127.0.0.1
createdb -p 5432 -h 127.0.0.1 template_postgis
我猜您使用的是 PostgreSQL psql
客户端,并且 libpq
是使用 /var/run/postgresql
的默认 unix_socket_directories
编译的,但是您的服务器是使用 [=14] 编译的=] 作为默认值。
当您从发行版的软件包中安装了 PostgreSQL 并通过其他方式安装时,这很常见。
使用psql -h /tmp/
指定unix套接字目录,而不是像@catavaran建议的那样切换到tcp/ip。
正如您在 unix 套接字 /var/run/postgresql/.s.PGSQL.5433
上看到的那样,您的客户端尝试连接到端口 5433 上服务器 运行 的 unix 套接字。根据您的 netstat
输出,您的服务器在端口 5432.
上 运行
我建议:
- 停止服务器
- 删除
/var/run/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"?
通过-p
/-h
选项提供端口和主机:
sudo -u postgres psql -p 5432 -h 127.0.0.1
createdb -p 5432 -h 127.0.0.1 template_postgis
我猜您使用的是 PostgreSQL psql
客户端,并且 libpq
是使用 /var/run/postgresql
的默认 unix_socket_directories
编译的,但是您的服务器是使用 [=14] 编译的=] 作为默认值。
当您从发行版的软件包中安装了 PostgreSQL 并通过其他方式安装时,这很常见。
使用psql -h /tmp/
指定unix套接字目录,而不是像@catavaran建议的那样切换到tcp/ip。
正如您在 unix 套接字 /var/run/postgresql/.s.PGSQL.5433
上看到的那样,您的客户端尝试连接到端口 5433 上服务器 运行 的 unix 套接字。根据您的 netstat
输出,您的服务器在端口 5432.
我建议:
- 停止服务器
- 删除
/var/run/postgresql/
中所有剩余的套接字文件
- 再次启动服务器