Postgresql 数据库错误修复v0.1

PS. 查询\nebula_boh\logs\BOHInterfaceLog.log 日志,
一般数据库文件损坏的日志 有 “UncategorizedSQLException” 或 “zero page at block”  或 “invalid page header” 关键字ERROR

说明postgresql数据库文件存在损坏,根据日志建议的修复方法 ,
修复损坏的表或者索引,如果修复失败 则考虑重装数据库了

1、表损坏修复(分开一个一个的执行)
set zero_damaged_pages = on; --当这个参数为on的时候,会忽略所有数据有损坏的页面
vacuum full 损坏数据表表名;
reindex table 损坏数据表表名;

2、索引损坏修复
REINDEX INDEX 索引名称 ; --修复损坏的表索引

产生原因:
--------------------------------------------
索引崩溃,并且不再包含有效的数据。尽管理论上这是不可能发生的,但实际上索引会因为软件毛病或者硬件问题而崩溃。REINDEX 提供了一个恢复方法。
索引变得"臃肿",包含大量的空页或接近空页。这个问题在某些罕见访问模式时会发生在 B-tree 索引上。REINDEX 通过写一个不带无用索引页的新索引提供了缩小索引空间消耗的途径。

样例:
2019-01-29 10:03:46.145 [pool-8-thread-1] - [ERROR] com.tzx.service.impl.CCOrder2BOHServiceImpl(:389) 门店接收订单异常:org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQLException for SQL [...]; SQL state [XX002]; error code [0]; ERROR: index "index_yddxm2_destineid" contains unexpected zero page at block 0
建议:Please REINDEX it.; nested exception is org.postgresql.util.PSQLException: ERROR: index "index_yddxm2_destineid" contains unexpected zero page at block 0
建议:Please REINDEX it.

修复:
REINDEX INDEX index_yddxm2_destineid;

3、表索引查询
select * from pg_indexes where tablename='表名';
或 select * from pg_statio_all_indexes where relname='表名';

猜你喜欢

转载自www.cnblogs.com/hebingprogramming/p/10333821.html