我有一个PostgreSQL数据库集群在运行:
postgres@ip-172-31-24-25:~$ ps -ef | grep postgres | grep -v sudo | grep -v grep | grep -v bash | grep -v su
postgres 817943 1 0 Jun25 ? 00:00:20 /home/postgres/pg175/bin/postgres
postgres 817944 817943 0 Jun25 ? 00:00:00 postgres: checkpointer
postgres 817945 817943 0 Jun25 ? 00:00:03 postgres: background writer
postgres 817947 817943 0 Jun25 ? 00:00:03 postgres: walwriter
postgres 817948 817943 0 Jun25 ? 00:00:02 postgres: autovacuum launcher
postgres 817949 817943 0 Jun25 ? 00:00:08 postgres: logical replication launcher
postgres 923261 923177 0 16:31 pts/3 00:00:00 ps -ef
我执行psql连接本地的数据库集群,发现如下入错:
postgres@ip-172-31-24-25:~$ psql
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
我看到了一下我的psql,发现它是16版本的,而服务器是17.5
postgres@ip-172-31-24-25:~$ which psql
/usr/lib/postgresql/16/bin/psql
我们可以看到Unix domain的目录是/tmp
postgres@ip-172-31-24-25:~$ cat /home/postgres/data1/postgresql.conf | grep -i unix_socket_direct
#unix_socket_directories = '/tmp' # comma-separated list of directories
则我们可以使用如下命令登录进数据库:
postgres@ip-172-31-24-25:~$ psql -h /tmp
psql (16.9 (Ubuntu 16.9-0ubuntu0.24.04.1), server 17.5)
WARNING: psql major version 16, server major version 17.
Some psql features might not work.
Type "help" for help.
postgres=#