PostgreSQL常见报错分析

PostgreSQL常见报错分析

1.进入数据库报错

连接拒绝Connection refused

[root@hg bin]# psql
psql: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

解决办法
查看PG数据库端口起来没有

# ss -nuplt |grep:5432

2.启动PG数据库报错

# service postgresql-11 start
Redirecting to /bin/systemctl start postgresql-11.service
Job for postgresql-11.service failed because the control process exited with error code. See "systemctl status postgresql-11.service" and "journalctl -xe" for details.
# journalctl -xe
May 26 16:22:39 hg postgresql-check-db-dir[30320]: "/var/lib/pgsql/data" is missing or empty.
May 26 16:22:39 hg postgresql-check-db-dir[30320]: Use "postgresql-setup initdb" to initialize the database cluster.
May 26 16:22:39 hg postgresql-check-db-dir[30320]: See /usr/share/doc/postgresql-9.2.24/README.rpm-dist for more information.

解决办法
可以看到根本原因就是没有db,所以需要先初始化db。

# chmod 754 /usr/bin/postgres-setup 
# /usr/bin/postgresql-setup initdb

#chmod 754 /usr/lib/systemd/system/postgresql.service
启动PG数据库
#systemctl  start  postgresql.service
原文地址:https://www.cnblogs.com/Alicebat/p/12966619.html