psql: could not connect to server: No such file or directory
SOLUTION 已验证 - 已更新 2015年三月27日19:52 -
环境
- Red Hat Enterprise Linux 6 (RHEL)
- PostgreSQL database
问题
- We are unable to login the PostgreSQL database of Jon server application using the command psql. Tried to login as postgres and root user, but getting the same error. Please see the error details below and guide us fix this error ASAP.
bash-4.3$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
决议
- The error message indicates that
postgresql
service is not running and listening to default tcp port 5432. Use the below command and confirm tcp port used bypostgresql
service. Then use correct command to connect it. For example :
# ps -ef | grep postgres
postgres 6043 1 0 16:20 ? 00:00:00 /usr/bin/postgres -D /var/lib/pgsql/data -p 5454
postgres 6044 6043 0 16:20 ? 00:00:00 postgres: logger process
postgres 6046 6043 0 16:20 ? 00:00:00 postgres: checkpointer process
postgres 6047 6043 0 16:20 ? 00:00:00 postgres: writer process
postgres 6048 6043 0 16:20 ? 00:00:00 postgres: wal writer process
postgres 6049 6043 0 16:20 ? 00:00:00 postgres: autovacuum launcher process
# bash-4.3$ psql rhq --host=localhost --port=5454 --username=rhqadmin --password
Password for user rhqadmin:
psql (9.2.0)
Type "help" for help.
rhq=>
根源
- The
postgresql
service was running on port 5454 instead of default port 5432.
诊断步骤
- Collect the following commands output and check tcp port used by
postgresql
service
# ps -ef | grep postgres
# netstat -tulnp | grep postgres