postgresql流日志误删处理(xlog)

postgresql流日志误删处理(xlog)

今天同事误删postgresql库数据文件下的pg_xlog文件夹,导致所有流日志丢失,数据库无法启动,观察警告日志:

2018-03-12 18:45:54 CST LOG:  database system shutdown was interrupted; last known up at 2018-03-12 17:48:27 CST
2018-03-12 18:45:54 CST LOG:  could not open file "pg_xlog/000000010000001400000060" (log file 20, segment 96): No such file or directory
2018-03-12 18:45:54 CST LOG:  invalid primary checkpoint record
2018-03-12 18:45:54 CST LOG:  could not open file "pg_xlog/000000010000001400000060" (log file 20, segment 96): No such file or directory
2018-03-12 18:45:54 CST LOG:  invalid secondary checkpoint record
2018-03-12 18:45:54 CST PANIC:  could not locate a valid checkpoint record
2018-03-12 18:45:54 CST LOG:  startup process (PID 32680) was terminated by signal 6: Aborted
2018-03-12 18:45:54 CST LOG:  aborting startup due to startup process failure

用postgresql自带的pg_resetxlog工具可以跳过对WAL log的恢复。不过会丢失一些事务。恢复命令也很简单如下:

pg_resetxlog -f /var/lib/pgsql/9.6/data

然后启动postgrsql ,数据库就可正常进入

参考:pg_resetxlog官方文档

你可能感兴趣的:(PostgreSQL)