更改端口号后,连接到 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”

After changing the port number, connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"

  1. 我完成了 postgresql11 的安装并更改了端口号

  2. 我修改的第一个文件是'/var/lib/pgsql/11/data/postgresql.conf'

#listen_addresses = 'localhost' -> listen_addresses ='*'

#port = 5432 -> port = 9485
  1. 我修改的第二个文件是'/var/lib/pgsql/11/data/pg_hba.conf'

我添加的行是'host all all 0.0.0.0/0 md5'

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
host    all             all             0.0.0.0/0               md5
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            ident
host    replication     all             ::1/128                 ident

  1. 我重新启动了 postgresql 服务器

systemctl restart postgresql-11

  1. 从外部客户端到 dbeaver 的连接工作正常。

  2. 但本地连接不正常

su - postgres

psql

有错误信息

psql: could not connect to server: There is no such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

  1. 我可以在“/var/run/postgresql”中找到两个文件

.s.PGSQL.9485

.s.PGSQL.9485.lock

  1. 如果我把端口恢复到原来的5432号,就可以正常工作了

  2. 请告诉我如何修复它

psql 不知道您的 Postgres 设置,它正在使用默认端口 5432

尝试:psql -p 9485

要完成设置,您必须更改环境变量 PGPORT

PGPORT=9495; export PGPORT;

如果不是,则必须为每个 cde(psql、pg_dump、...)提供端口号 (-p 9495)