【发布时间】:2020-08-26 16:44:43
【问题描述】:
在 9.6->12.3 pg_upgrade 之后,我们标记了一些严重的选择,给出了缺失的结果! REINDEX 或 drop / create 解决了问题。
升级要点
- 停止 9.6
- rsync 9.6 数据和 bin 文件从 Centos7 到 Centos8(预装12)
- pg_upgrade
- ./analyze_new_cluster.sh
- ./delete_old_cluster.sh
每个数据库我们发现 1-3 个唯一损坏的索引。每个索引缺少大约 20 个值。
我们发现了一个非常有用的工具 amcheck! https://www.postgresql.org/docs/10/amcheck.html
SELECT bt_index_check(c.oid), c.relname, c.relpages
FROM pg_index i
JOIN pg_opclass op ON i.indclass[0] = op.oid
JOIN pg_am am ON op.opcmethod = am.oid
JOIN pg_class c ON i.indexrelid = c.oid
JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE am.amname = 'btree' AND n.nspname = 'pg_catalog'
-- Don't check temp tables, which may be from another session:
AND c.relpersistence != 't'
-- Function may throw an error when this is omitted:
AND i.indisready AND i.indisvalid
ORDER BY c.relpages DESC LIMIT 10;
非常重要:通过验证注释掉 (AND n.nspname = 'pg_catalog' + LIMIT 10) 限制,以便对您的索引也运行 bt_index_check 函数!
是的,如果找到损坏的索引,该函数会抛出异常。
为什么索引会出错? 我们如何确定我们的新数据库是一致的并且升级成功了?
【问题讨论】:
-
索引列是什么数据类型?如果它们是
text或varchar这可能是由 CentOS 7 和 8 之间的 glibc 更改引起的。 -
Varchar(255)!非常感谢!那么英国不仅仅是 varchar 索引!
标签: postgresql upgrade postgresql-9.6 postgresql-12