PostgreSQL 10.0 preview 功能增强 - 增加access method CHECK接口amcheck

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

标签

PostgreSQL , 10.0 , amcheck , 逻辑一致性检测 , 物理存储检测


背景

一些高端存储、包括ZFS文件系统,在使用了RAID后,有块检测和异常块的修复功能。

对于数据库来说,数据的可靠性是非常重要的指标,例如:

1. 写进入是什么,读出来就应该是什么。

2. 当操作系统的collate发生变化时,索引的顺序可能与实际的collate顺序不匹配。造成不稳定现象。

3. 数据块partial write,可能导致数据损坏。

4. 内存页异常,使用到某些异常页时,可能带来问题。

PostgreSQL通过full page write来避免3的问题。另外在数据页上面有checksum提供检测。

PostgreSQL 10.0 提供了一个check接口,可以对数据进行检测,发现以上问题。

amcheck接口

amcheck是一个框架,用于检测数据的一致性。例如PG有heap存储,b-tree,gist,gin,sp-gist,brin索引存储。amcheck可以用于检测各种接口对应数据存储的一致性。

命名为amcheck, am指的是access method,检测的自然是access method相关的。

src/backend/access  
  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 brin  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 common  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 gin  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 gist  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 hash  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:38 heap  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 index  
-rw-r--r-- 1 digoal digoal  321 Apr 14 12:17 Makefile  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 nbtree  
-rw-rw-r-- 1 digoal digoal 4759 Apr 14 23:38 objfiles.txt  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 rmgrdesc  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 spgist  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:37 tablesample  
drwxrwxr-x 2 digoal digoal 4096 Apr 14 23:38 transam  

目前amcheck已经做到可以检测索引的异常(例如前面提到的操作系统collate变化引发的索引的逻辑顺序异常)。未来会扩展更多的检测接口。

10.0也推出了对ICU的支持,从根源上避免了collate的问题。

《PostgreSQL 10.0 preview 功能增强 - 国际化功能增强,支持ICU(International Components for Unicode)》

amcheck 可检测的异常

1. Structural inconsistencies caused by incorrect operator class implementations.

问题可能来自操作系统collate的变化,导致collate变化前后,QUERY输出不一致(顺序)的结果.

检测方法,参考每种access method的一致性校验function

https://www.postgresql.org/docs/devel/static/xindex.html#xindex-support

2. Corruption caused by hypothetical undiscovered bugs in the underlying PostgreSQL access method code or sort code.

3. Filesystem or storage subsystem faults where checksums happen to simply not be enabled.

4. Corruption caused by faulty RAM, and the broader memory subsystem and operating system.

amcheck 检测到的异常修复

不同的异常,修复的方法不一样,通常能直接修复的是REINDEX。(但并不是所有的异常都有方法修复。)

但是社区给出了一个建议,如果是代码的BUG,REINDEX可能是无法修复的,但是通过pageinspect插件,可以帮助进行问题诊断。

amcheck patch介绍

Add amcheck extension to contrib.  
  
author	Andres Freund <andres@anarazel.de>	  
Fri, 10 Mar 2017 07:50:40 +0800 (15:50 -0800)  
committer	Andres Freund <andres@anarazel.de>	  
Fri, 10 Mar 2017 08:33:02 +0800 (16:33 -0800)  
  
This is the beginning of a collection of SQL-callable functions to  
verify the integrity of data files.  For now it only contains code to  
verify B-Tree indexes.  
  
This adds two SQL-callable functions, validating B-Tree consistency to  
a varying degree.  Check the, extensive, docs for details.  
  
The goal is to later extend the coverage of the module to further  
access methods, possibly including the heap.  Once checks for  
additional access methods exist, we'll likely add some "dispatch"  
functions that cover multiple access methods.  
  
Author: Peter Geoghegan, editorialized by Andres Freund  
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,  
   Anastasia Lubennikova, Robert Haas, Amit Langote  
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com  

amcheck b-tree数据检测接口

对于b-tree索引数据,通过这两个接口可以进行检测。

1. bt_index_check(index regclass) returns void

加select一样的accessshared锁。基本无影响。注意,如果被检测的索引页在shared buffer中时,不会扫磁盘。

返回空表示正常。

test=# 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;  
 bt_index_check |             relname             | relpages   
----------------+---------------------------------+----------  
                | pg_depend_reference_index       |       43  
                | pg_depend_depender_index        |       40  
                | pg_proc_proname_args_nsp_index  |       31  
                | pg_description_o_c_o_index      |       21  
                | pg_attribute_relid_attnam_index |       14  
                | pg_proc_oid_index               |       10  
                | pg_attribute_relid_attnum_index |        9  
                | pg_amproc_fam_proc_index        |        5  
                | pg_amop_opr_fam_index           |        5  
                | pg_amop_fam_strat_index         |        5  
(10 rows)  

2. bt_index_parent_check(index regclass) returns void

被检测的索引,以及索引对应的表加ShareLock锁。冲突较大,堵塞INSERT, UPDATE, and DELETE,表的VACUUM,以及更大的锁操作。

HOT STNADBY不允许执行 bt_index_parent_check(index regclass) 。

这个patch的讨论,详见邮件组,本文末尾URL。

PostgreSQL社区的作风非常严谨,一个patch可能在邮件组中讨论几个月甚至几年,根据大家的意见反复的修正,patch合并到master已经非常成熟,所以PostgreSQL的稳定性也是远近闻名的。

参考

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=3717dc149ecf44b8be95350a68605ba7299474fd

https://www.postgresql.org/docs/devel/static/amcheck.html

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
18天前
|
关系型数据库 Serverless 分布式数据库
【公测】PolarDB PostgreSQL版Serverless功能免费使用​!
【公测】PolarDB PostgreSQL版Serverless功能免费使用​,公测于2024年3月28日开始,持续三个月,公测期间可以免费使用!
|
3月前
|
存储 关系型数据库 MySQL
PolarDB优势功能
PolarDB优势功能
|
6月前
|
存储 关系型数据库 数据库
深入了解 PostgreSQL:功能、特性和部署
PostgreSQL,通常简称为Postgres,是一款强大且开源的关系型数据库管理系统(RDBMS),它在数据存储和处理方面提供了广泛的功能和灵活性。本文将详细介绍 PostgreSQL 的功能、特性以及如何部署和使用它。
224 1
深入了解 PostgreSQL:功能、特性和部署
|
7月前
|
SQL 关系型数据库 测试技术
PolarDB的Online DDL功能验证实验
本场景带您体验如何在PolarDB-X中进行Online DDL。
951 0
|
1月前
|
关系型数据库 Serverless 分布式数据库
PolarDB PostgreSQL版Serverless功能上线公测啦,公测期间免费使用!
Serverless数据库能够使得数据库集群资源随客户业务负载动态弹性扩缩,将客户从复杂的业务资源评估和运维工作中解放出来。PolarDB PostgreSQL版 Serverless提供了CPU、内存、存储、网络资源的实时弹性能力,构建计算与存储分离架构下的 PolarDB PostgreSQL版产品新形态。
|
2月前
|
SQL 存储 缓存
PostgreSQL函数管理接口
学习PostgreSQL服务端开发必须要对函数管理接口有比较深入的了解
142 0
|
2月前
|
SQL 关系型数据库 分布式数据库
在PolarDB for PostgreSQL中,你可以使用LIKE运算符来实现类似的查询功能,而不是使用IF函数
在PolarDB for PostgreSQL中,你可以使用LIKE运算符来实现类似的查询功能,而不是使用IF函数
42 7
|
2月前
|
关系型数据库 Linux Shell
Centos系统上安装PostgreSQL和常用PostgreSQL功能
Centos系统上安装PostgreSQL和常用PostgreSQL功能
|
3月前
|
关系型数据库 MySQL 分布式数据库
PolarDB MySQL企业版与标准版功能对比:如何选择适合您的版本?
随着数字化时代的到来,企业对于数据处理的需求越来越高,而数据库作为数据处理的核心,其性能和成本成为了企业关注的焦点。阿里云全新推出的PolarDB MySQL企业版和标准版,以全新的架构和优化,为企业提供了高性能、低成本的数据库解决方案。但在功能上,这两个版本有很多差异,我们该如何选择呢?
55 2
|
3月前
|
SQL 关系型数据库 分布式数据库
在PolarDB for PostgreSQL中,你可以使用LIKE运算符来实现类似的查询功能
在PolarDB for PostgreSQL中,你可以使用LIKE运算符来实现类似的查询功能【1月更文挑战第13天】【1月更文挑战第65篇】
30 2

相关产品

  • 云原生数据库 PolarDB