SQL Error: ERROR: database is not accepting commands&nb

标签:
数据库itpostgresqldb |
数据库管理和维护的经验重要是从实践中得来的,如果平常数据库出现的问题不多,解决问题的能力就会得不到提升。最近管理的一个数据库出现了下面的报错,查看一下是由于transaction
id 满了造成的,默认情况下postgresql的transantion id
是40亿,而且开启autovacuum的话DB会自动进行历史记录的清理,但是这次是里面的数据太多而且更新太快,DB还没来得及清理就出现了这个情况:
SQL Error: ERROR: database
is not accepting commands to avoid wraparound data loss in database
"ispdb_stmsg"
HINT: Stop the postmaster and use a
standalone backend to vacuum that database.
You might also need to commit or roll back old prepared
transactions.
不多说了,直接找解决办法吧:
网上很多黏贴复制的方法,很不实用,有的甚至连自己测试也没有测试就直接发布解决办法,误导问题解决者,非常不负责任。
考虑到我们的数据库有15T这么大,执行vacuum
full会花费很长时间(实际上用了8天时间),决定开一个screen在后台运行。
具体操作步骤:
1. 开一个screen 进程,后面的操作只需要在screen中进行就可以了:
screen -S pg_vacuum:
2. 切换到postgres超级用户
su postgres
3. 停止数据库,其中-m 后面是i(immediate),大家可以用/usr/pgsql-9.2/bin/pg_ctl
-h查看具体解释:
/usr/pgsql-9.2/bin/pg_ctl -m i stop -D
/var/lib/pgsql/9.2/data
http://s5/mw690/002InA8tgy6Qhg69smU54&690Error: ERROR: database is not accepting commands&nb" TITLE="SQL Error: ERROR: database is not accepting commands&nb" />
4. 开一个backend ,这个是针对具体的数据库进行的:
/usr/pgsql-9.2/bin/postgres --single ispdb_stmsg -D
/var/lib/pgsql/9.2/data
http://s11/mw690/002InA8tgy6Qhga8xJg1a&690Error: ERROR: database is not accepting commands&nb" TITLE="SQL Error: ERROR: database is not accepting commands&nb" />
5. 执行命令,这个命令执行了8天,这要是数据库太大的原因:
vacuum full
6. 等查看这个vacuum full执行完之后退出 single backend:
Control+D 退出single backend
7. 最后把数据库重启即可:
/usr/pgsql-9.2/bin/pg_ctl start -D
/var/lib/pgsql/9.2/data