无法在目录“/var/run/postgresql”中创建 Unix 域套接字

could not create Unix-domain socket in directory "/var/run/postgresql"

我尝试在 postgresql.conf.

中取消注释 'unix_socket_directories = '/var/run/postgresql'

但是在这样做之后,当我尝试重新启动 postgresql 时,我收到

  Job for postgresql.service failed because the control process exited with error code. See 
  "systemctl status postgresql.service" and "journalctl -xe" for details.

正在寻找 journalctl,我看到:

LOG:  could not bind Unix socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, remove socket file 
"/var/run/postgresql/.s.PGSQL...and retry.
: WARNING:  could not create Unix-domain socket in directory "/var/run/postgresql"

全栈:

 Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; 
 vendor preset: disabled)
  Active: failed (Result: exit-code) since Ср 2020-01-29 13:39:52 MSK; 
 27s ago
  Process: 2937 ExecStop=/usr/bin/pg_ctl stop -D ${PGDATA} -s -m fast 
 (code=exited, status=1/FAILURE)
  Process: 2550 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p 
 ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
  Process: 2544 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} 
 (code=exited, status=0/SUCCESS)
 Main PID: 2554 (code=killed, signal=KILL)

   plesk.iline.pro systemd[1]: Starting PostgreSQL database server...
   plesk.iline.pro pg_ctl[2550]: LOG:  could not bind Unix socket: 
   Address already in use
   plesk.iline.pro pg_ctl[2550]: HINT:  Is another postmaster already 
   running on port 5432? If not, remove socket file 
   "/var/run/postgresql/.s.PGSQL...and retry.
    plesk.iline.pro pg_ctl[2550]: WARNING:  could not create Unix- 
    domain socket in directory "/var/run/postgresql"
    plesk.iline.pro systemd[1]: Started PostgreSQL database server.
    2 plesk.iline.pro systemd[1]: postgresql.service: main process 
    exited, code=killed, status=9/KILL
    plesk.iline.pro pg_ctl[2937]: pg_ctl: could not send stop signal 
    (PID: 2554): No such process
    plesk.iline.pro systemd[1]: postgresql.service: control process 
    exited, code=exited status=1
    plesk.iline.pro systemd[1]: Unit postgresql.service entered failed 
    state.
    plesk.iline.pro systemd[1]: postgresql.service failed.
    Hint: Some lines were ellipsized, use -l to show in full.

同一个端口上可能还有另一个 PostgreSQL 服务器 运行。

您应该按照 PostgreSQL 的建议进行操作:

ls -l /var/run/postgresql/.s.PGSQL.5432

应该存在套接字文件。

然后,作为用户root,查看是否有PostgreSQL进程监听端口:

sudo fuser /var/run/postgresql/.s.PGSQL.5432

如果有结果,则端口 5432 上确实有另一个 PostgreSQL 服务器 运行。要么停止该服务器,要么为您的集群选择一个不同的端口。

如果没有结果,socket可能会遗留。删除它并重试。