postgres使用pg_resetxlog命令重置一个数据库集群的预写日志以及其它控制内容

情景:

今天像平常一样连接数据库,出现了一下信息,

[postgres@cqs postgresql-9.5]$ psql
psql: could not connect to server: 拒绝连接
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 5432?

这时候再看看本地的postgres是不是没打开,此环境之前设置了开机自启动pg服务,使用命令“ps -ef | grep postgres”

[postgres@cqs postgresql-9.5]$ ps -ef | grep postgres
root      1640  1630  0 03:30 pts/0    00:00:00 su postgres
postgres  1641  1640  0 03:30 pts/0    00:00:00 bash
postgres  1725  1641  7 03:40 pts/0    00:00:00 ps -ef
postgres  1726  1641  0 03:40 pts/0    00:00:00 grep postgres

发现服务真的没启动起来。。。

启动服务,

[postgres@cqs postgresql-9.5]$ pg_ctl start
server starting
[postgres@cqs postgresql-9.5]$ LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "pg_log".

一直卡在这里,这时候得看一下对应的日志档查看是不是出了问题。

对应的日志档存在pg_log中

[root@cqs pg_log]# cd /home/postgres/data/pg_log

[root@cqs pg_log]# cat postgresql-2016-12-23_035509.csv
2016-12-23 03:55:09.754 CST,,,1765,,585c2f9d.6e5,1,,2016-12-23 03:55:09 CST,,0,LOG,00000,"ending log output to stderr",,"Future log output will go to log destination ""csvlog"".",,,,,,,""
2016-12-23 03:55:09.758 CST,,,1767,,585c2f9d.6e7,1,,2016-12-23 03:55:09 CST,,0,LOG,00000,"database system shutdown was interrupted; last known up at 2016-12-23 03:40:27 CST",,,,,,,,,""
2016-12-23 03:55:09.843 CST,,,1767,,585c2f9d.6e7,2,,2016-12-23 03:55:09 CST,,0,LOG,00000,"database system was not properly shut down; automatic recovery in progress",,,,,,,,,""
2016-12-23 03:55:09.847 CST,,,1767,,585c2f9d.6e7,3,,2016-12-23 03:55:09 CST,,0,LOG,00000,"redo starts at 1/F6005B20",,,,,,,,,""
2016-12-23 03:55:09.847 CST,,,1767,,585c2f9d.6e7,4,,2016-12-23 03:55:09 CST,,0,LOG,00000,"redo done at 1/F6005C00",,,,,,,,,""
2016-12-23 03:55:09.911 CST,,,1767,,585c2f9d.6e7,5,,2016-12-23 03:55:09 CST,,0,PANIC,53100,"could not write to file ""pg_xlog/xlogtemp.1767"": No space left on device",,,,,,,,,""
2016-12-23 03:55:09.911 CST,,,1765,,585c2f9d.6e5,2,,2016-12-23 03:55:09 CST,,0,LOG,00000,"startup process (PID 1767) was terminated by signal 6: Aborted",,,,,,,,,""
2016-12-23 03:55:09.911 CST,,,1765,,585c2f9d.6e5,3,,2016-12-23 03:55:09 CST,,0,LOG,00000,"aborting startup due to startup process failure",,,,,,,,,""

log提示数据库系统关闭时收到干扰,主要原因应该是由于数据库日志档出现问题了。

翻了好多资料,抱着试一试尝试了pg_resetxlog

pg_resetxlog相关用法
名称
pg_resetxlog -- 重置一个数据库集群的预写日志以及其它控制内容
语法
pg_resetxlog [-f] [-n] [-ooid ] [-x xid ] [-e xid_epoch ] [-m mxid ] [-O mxoff ] [-l timelineid, fileid, seg ] datadir
描述
pg_resetxlog 清理预写日志(WAL)并且可以有选择地重置其它一些存储在 pg_control 文件中的控制信息。有时候,如果这些文件崩溃了,就需要这个功能。一定只把它用作最后的方法,就是说只有因为这样的崩溃导致服务器无法启动的时候才使用。

[postgres@cqs bin]$ pg_resetxlog /home/postgres/data/

The database server was not shut down cleanly.
Resetting the transaction log might cause data to be lost.
If you want to proceed anyway, use -f to force reset.

[postgres@cqs bin]$ pg_resetxlog -f /home/postgres/data/
Transaction log reset

好了,完成清理预写日志命令,启动pg数据库服务器

[postgres@cqs bin]$ pg_ctl start
server starting
[postgres@cqs bin]$ LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "pg_log".

[root@cqs pg_log]# ps -ef | grep postgres
root      1640  1630  0 03:30 pts/0    00:00:00 su postgres
postgres  1641  1640  0 03:30 pts/0    00:00:00 bash
postgres  1805     1  0 04:46 pts/0    00:00:00 /usr/local/postgresql-9.5/bin/postgres
postgres  1806  1805  0 04:46 ?        00:00:00 postgres: logger process              
postgres  1808  1805  0 04:46 ?        00:00:00 postgres: checkpointer process        
postgres  1809  1805  0 04:46 ?        00:00:00 postgres: writer process              
postgres  1810  1805  0 04:46 ?        00:00:00 postgres: wal writer process          
postgres  1811  1805  0 04:46 ?        00:00:00 postgres: autovacuum launcher process   
postgres  1812  1805  0 04:46 ?        00:00:00 postgres: archiver process   failed on 000000010000000000000002.00000028.backup
postgres  1813  1805  0 04:46 ?        00:00:00 postgres: stats collector process     
postgres  1819  1641  0 04:47 pts/0    00:00:00 psql
postgres  1820  1805  0 04:47 ?        00:00:00 postgres: postgres postgres 127.0.0.1(33254) idle
root      1952  1666  0 05:15 pts/1    00:00:00 grep postgres

这时候相关的postgres服务正常启动了,连接数据库

[postgres@cqs bin]$ psql
psql (9.5alpha2)
Type "help" for help.


postgres=# 
postgres=# 

成功连上数据库,又可以愉快地操作对应的数据库了。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值