psql: could not connect to server: No such file or directory
SOLUTION 已验证- 已更新三月27日19:52-
English
环境
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.Raw
bash-4.3$ psqlpsql: could not connect to server: No such file or directoryIs the server running locally and acceptingconnections on Unix domain socket "/tmp/.s.PGSQL.5432"?
决议
The error message indicates thatpostgresql
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 :Raw
# ps -ef | grep postgrespostgres 60431 0 16:20 ? 00:00:00 /usr/bin/postgres -D /var/lib/pgsql/data -p 5454postgres 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=>
根源
Thepostgresql
service was running on port 5454 instead of default port 5432.诊断步骤
Collect the following commands output and check tcp port used bypostgresql
serviceRaw
# ps -ef | grep postgres# netstat -tulnp | grep postgres