postgresql 报错 FATAL: the database system is shutting down 解决方法

服务器在同一个数据目录上启动了两个Postgresql实例(它已经删除postmaster.pid并使用了新的端口号,因此绕过了这种行为的正常保护措施被绕过),导致Postgresql的误操作

postgresql 报错 FATAL: the database system is shutting down 解决方法

查看主机进程

[root@localhost ~]# ps -ef
[root@localhost ~]# su - postgres

执行命令可以看出,Postgresql 进程还在,但是psql查看端口发现没有端口:

查看端口命令:netstat -a | grep PGsql

尝试链接提示端口未启动.

连接psql

# psql -h 127.0.0.1 -d postgres -U postgres
psqlCould not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
# psql -p 1921
psql: FATAL: the database system is shutting down

数据库连接不上,报 “the database system is shutting down” , 意思是数据库正在关闭, 而 Postgresql 进程明明都还在,再仔细观察了上面步骤的进程,发现有十几个“ 127.0.0.1(40181) idle in transaction” 难道是这些进程发生了异常.

关闭数据库

[postgre@localhost data]$ pg_ctl stop -m fast
pg_ctl: PID file "/opt/postgresql-9.0.1/data/postmaster.pid" does not exist
Is server running?

数据库无法关闭, 文件 postmaster.pid 不存在

创建 postmaster.pid 文件

参照其它库的 postmaster,pid 文件,构造了一个创建文件 /opt/postgresql-9.0.1/data/postmaster.pid , 并增加以下内容:

27639
/opt/postgresql-9.0.1/data

备注: 第一行: “27639” 表示 Postgresql 的父进程,根据步骤一的红色标识可以看到;

第二行: “/opt/postgresql-9.0.1/data” 表示数据目录;

第三行:正常情况下,第三行还有两个字段,但具体信息不详,无法构造。

再次尝试关闭数据库

[postgre@localhost data]$ pg_ctl stop -m fast -D $PGDATA
waiting for server to shut down.... done 
server stopped

启动数据库

[postgre@localhost data]$ pg_ctl start -D $PGDATA
server starting

再次检查端口,并尝试链接

查看端口命令:netstat -a | grep PGsql

链接psql:psql -h 127.0.0.1 -d postgres -U postgres

一切都正常了,搞定!

总结

至今 postmaster.pid 文件丢失原因尚不明确,但这次通过构造 postmaster.pid 文件从而将数据库成功恢复!

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...