我们的平台DB使用的是postgres的主备结构,主备用的是repmgrd实现的
早上一上班nagios发送警告短信,主数据库由于相应时间太慢自动进行了主备切换
首先查找原因,发现履历查询较慢查看履历表99G数据
psql
\c DBname #切换数据库
\l+ DBname #查看DB存储量
\dt+ tableName # 查看table数据量
之后先分配主数据库
sudo su - postgres
psql
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
f
(1 row)
quite
repmgr primary register -F
删除履历表中数据
然后连接备库先停掉数据库,同步数据,恢复主备
sudo su - postgres
pg_ctl stop -mf
rm -rf /ihdata/platform/yourDBDir/data
cd /ihdata/platform/postgresql/tablespace
rm -rf *
cd /ihdata/platform/yourDBDir/archive
rm -rf *
#同步数据
repmgr -h [primary by server] -p 15487 -U repmgr -d repmgr standby clone -F
#启动备份数据库
pg_ctl start
#注册备份数据库
repmgr standby register -F
最后主备重启守护进程
1ps -ef | grep repmgrd
kill -9 [pid]
repmgrd -d
然后插入必要的履历数据到履历表
最后根本解决表过大的问题需要使用分区表,之后推进分区表使用。