[postgres@zhaopin-200-43 ~]$ pg_resetxlog -f /data/postgresql/rdrc_94/data/
Transaction log reset
[postgres@zhaopin-200-43 ~]$ pg_ctl -D /data/postgresql/rdrc_94/data/ start
server starting
[postgres@zhaopin-200-43 ~]$ [ 2015-11-27 01:45:44.185 UTC 74963 5657b5c8.124d3 1 0]LOG: redirecting log output to logging collector process
[ 2015-11-27 01:45:44.185 UTC 74963 5657b5c8.124d3 2 0]HINT: Future log output will appear in directory "pg_log".
[postgres@zhaopin-200-43 ~]$
[postgres@zhaopin-200-43 ~]$
[postgres@zhaopin-200-43 ~]$ psql
psql (9.4.4)
Type "help" for help.
postgres=# \q
[postgres@zhaopin-200-43 ~]$ more /data/postgresql/rdrc_94/data/pg_log/postgresql-2015-11-27_01.log
[ 2015-11-27 01:29:18.436 UTC 74156 5657b1ee.121ac 1 0]LOG: database system shutdown was interrupted; last known up at 2015-11-26 04:58:07 UTC
[ 2015-11-27 01:29:18.581 UTC 74156 5657b1ee.121ac 2 0]LOG: invalid primary checkpoint record
[ 2015-11-27 01:29:18.581 UTC 74156 5657b1ee.121ac 3 0]LOG: invalid secondary checkpoint record
[ 2015-11-27 01:29:18.581 UTC 74156 5657b1ee.121ac 4 0]PANIC: could not locate a valid checkpoint record
[ 2015-11-27 01:29:18.816 UTC 74154 5657b1ee.121aa 3 0]LOG: startup process (PID 74156) was terminated by signal 6: Aborted
[ 2015-11-27 01:29:18.816 UTC 74154 5657b1ee.121aa 4 0]LOG: aborting startup due to startup process failure
[ 2015-11-27 01:32:46.778 UTC 74362 5657b2be.1227a 1 0]LOG: database system shutdown was interrupted; last known up at 2015-11-26 04:58:07 UTC
[ 2015-11-27 01:32:46.923 UTC 74362 5657b2be.1227a 2 0]LOG: invalid primary checkpoint record
[ 2015-11-27 01:32:46.923 UTC 74362 5657b2be.1227a 3 0]LOG: invalid secondary checkpoint record
[ 2015-11-27 01:32:46.923 UTC 74362 5657b2be.1227a 4 0]PANIC: could not locate a valid checkpoint record
[ 2015-11-27 01:32:47.154 UTC 74360 5657b2be.12278 3 0]LOG: startup process (PID 74362) was terminated by signal 6: Aborted
[ 2015-11-27 01:32:47.154 UTC 74360 5657b2be.12278 4 0]LOG: aborting startup due to startup process failure
[ 2015-11-27 01:45:44.188 UTC 74965 5657b5c8.124d5 1 0]LOG: database system was shut down at 2015-11-27 01:43:27 UTC
[ 2015-11-27 01:45:44.192 UTC 74965 5657b5c8.124d5 2 0]LOG: MultiXact member wraparound protections are now enabled
[ 2015-11-27 01:45:44.195 UTC 74963 5657b5c8.124d3 3 0]LOG: database system is ready to accept connections
[ 2015-11-27 01:45:44.195 UTC 74969 5657b5c8.124d9 1 0]LOG: autovacuum launcher started
[[unknown] [unknown] [unknown] 2015-11-27 01:45:46.645 UTC 74972 5657b5ca.124dc 1 0]LOG: connection received: host=[local]
[postgres postgres [unknown] [local] 2015-11-27 01:45:46.647 UTC 74972 5657b5ca.124dc 2 0]LOG: connection authorized: user=postgres database=postgres
[postgres postgres psql [local] 2015-11-27 01:45:48.410 UTC 74972 5657b5ca.124dc 3 0]LOG: disconnection: session time: 0:00:01.765 user=postgres database=postgres host=[local]
[postgres@zhaopin-200-43 ~]$
Postgresql WAL log 误删处理
今天在测试环境,开发人员在处理磁盘100%问题时,删除了postgresql的 pg_xlog目录下的全部WAL日志,导致postgresql崩溃,在启动时出现:
2011-11-02 18:45:54 CST LOG: database system shutdown was interrupted; last known up at 2011-11-02 17:48:27 CST
2011-11-02 18:45:54 CST LOG: could not open file "pg_xlog/000000010000001400000060" (log file 20, segment 96): No such file or directory
2011-11-02 18:45:54 CST LOG: invalid primary checkpoint record
2011-11-02 18:45:54 CST LOG: could not open file "pg_xlog/000000010000001400000060" (log file 20, segment 96): No such file or directory
2011-11-02 18:45:54 CST LOG: invalid secondary checkpoint record
2011-11-02 18:45:54 CST PANIC: could not locate a valid checkpoint record
2011-11-02 18:45:54 CST LOG: startup process (PID 32680) was terminated by signal 6: Aborted
2011-11-02 18:45:54 CST LOG: aborting startup due to startup process failure
用postgresql自带的pg_resetxlog工具可以跳过对WAL log的恢复。不过会丢失一些事务。恢复命令也很简单如下:
pg_resetxlog -f /opt/postgres9-1/data
-- 然后启动postgrsql ,记住要马上做dump再import
贴一个pg_resetxlog的使用:http://www.php100.com/manual/pgsql/app-pgresetxlog.html
pg_resetxlog
Name
pg_resetxlog -- 重置预写日志以及 pg_control 内容
Synopsis
pg_resetxlog [ -f ] [ -n ] [ -o oid ] [ -x xid ] [ -l fileid,seg ] datadir
描述
pg_resetxlog 清理预写日志并且可以选择地 重置在 pg_control 文件中地一些字段。 有时候,如果这些文件崩溃了,我们需要这个功能。 我们一定只把它用作最后的方法,就是说只有因为这样的崩溃导致服务器 无法启动的时候才使用。
在运行这个命令之后,我们可能可以启动服务器了,但是,一定要记住 数据库可能因为部分提交的事务而含有不完整的数据。 你应该马上转储你的数据,运行initdb,然后重新装载。 在重新装载之后,检查不完整的部分然后根据需要进行修复。
这个命令只能由安装服务器的用户运行,因为它需要对 datadir 的 读写权限。出于安全考虑,你必须在命令行上声明数据目录。 pg_resetxlog 不使用环境变量PGDATA。
如果 pg_resetxlog 抱怨说它无法判断用于 pg_control 的有效数据,那么你可以强制它继续处理, 方法是声明 -f (强制)开关。在这种情况下,那些丢失 了的数据的值将用模糊的近似数值代替。大多数字段都可以匹配上, 但是下一个 OID,下一个事务 ID,WAL 开始地址以及数据库区域字段可能需要手工帮助, 前面三个可以用下面讨论的开关设置。pg_resetxlog 自己的环境是猜测区域字段的来源;看看 LANG 等等东西,它们 应该和 initdb 运行的环境相匹配。如果你不能判断所有 这些字段的正确数值,那么还是可以使用 -f,但是这样恢复 过来的数据库更叫要怀疑有问题 --- 立即转储和重置是必须的。 在转储之前不要执行任何修改数据的操作,因为任何这样的 动作都可能把事情搞得更糟糕。
-o,-x,和 -l 开关允许我们 手工设置下一个 OID,下一个事务 ID,以及 WAL 起始位置得数值。 只有在 pg_resetxlog 无法通过读取 pg_control 判断合适的数值的时候才需要它。对于下一个事务 ID 而言,一个安全的数值是看看$PGDATA/pg_clog 里最大的文件名,然后加一,然后再 乘上 1048576。请注意那些文件名是十六进制的。通常我们也以十六进制的形式 声明开关值是最简单得。比如,如果 0011 是 pg_clog 里 最大的记录,-x 0x1200000 就可以了(后面的五个零提供了合适的乘积)。 WAL 的起始位置应该比目前存在于 $PGDATA/pg_xlog里面的任何文件号都大。它也是十六进制的,并且有两部分。比如,如果000000FF0000003A 是 pg_xlog 里最大的条目, 那么-l 0xFF,0x3B 就可以了。我们没有很容易的办法来判断比 数据库中最大的 OID 大一号的下一个 OID,不过很走运的是获取正确的下一个 OID 并非非常关键。
开关 -n (无操作)指示 pg_resetxlog 打印从 pg_control 重新构造的数值然后不修改任何值就退出。 这主要是一个调试工具,但是在 pg_resetxlog 真正处理 前进行的整洁性检查的时候可能会有用。
注意
在 postmaster 运行的时候一定不要运行这个命令。 如果发现在 datadir 目录里有锁文件,那么 pg_resetxlog 将拒绝启动。如果 postmaster 崩溃,那么可能会 剩下一个锁文件;如果这样,你可以删除该锁文件以便允许 pg_resetxlog 运行。但是在你这么做之前,一定要确信没有任何postmaster或者后端服务器仍在运行。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29898569/viewspace-1847657/
,如需转载,请注明出处,否则将追究法律责任。