服务器在同一个数据目录上启动了两个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 psql: could 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 文件从而将数据库成功恢复!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。