バージョンごとのドキュメント一覧

F.2. amcheck — テーブルとインデックスの一貫性を検査するツール #

<title>amcheck &mdash; tools to verify table and index consistency</title>

The <filename>amcheck</filename> module provides functions that allow you to verify the logical consistency of the structure of relations. amcheckモジュールは、リレーションの構造の論理的な一貫性を検査する機能を提供します。

The B-Tree checking functions verify various <emphasis>invariants</emphasis> in the structure of the representation of particular relations. The correctness of the access method functions behind index scans and other important operations relies on these invariants always holding. For example, certain functions verify, among other things, that all B-Tree pages have items in <quote>logical</quote> order (e.g., for B-Tree indexes on <type>text</type>, index tuples should be in collated lexical order). If that particular invariant somehow fails to hold, we can expect binary searches on the affected page to incorrectly guide index scans, resulting in wrong answers to SQL queries. If the structure appears to be valid, no error is raised. B-Tree検査関数は、特定のリレーションの構造表現における様々な不変量を検査します。 インデックスの走査や、その他の重要な操作を担うアクセスメソッド関数の正しさは、これらの不変量を常に保つことに依存しています。 たとえば、ある関数は、とりわけすべてのB-Treeページの中の項目が論理的な順序になっていることを検査します。(たとえばtextのB-Treeインデックスでは、インデックスタプルは語句の照合順になっていなければなりません。) その特定の不変量が何らかの理由で保たれなければ、該当するページで二分探索が不正なインデックス走査をもたらし、SQL問い合わせに誤った答えを返すことになるでしょう。 構造が適正であると見なされれば、エラーは報告されません。

Verification is performed using the same procedures as those used by index scans themselves, which may be user-defined operator class code. For example, B-Tree index verification relies on comparisons made with one or more B-Tree support function 1 routines. See <xref linkend="xindex-support"/> for details of operator class support functions. 検証は、インデックス走査自身で使われるのと同じ手続きを用いて行われます。 その手続きは、ユーザ定義演算子クラスのコードかもしれません。 たとえば、B-Treeインデックスの検査は、一つ以上のB-Treeサポート関数1ルーチンを用いる比較に依存しています。 演算子クラスサポート関数の詳細については38.16.3をご覧ください。

Unlike the B-Tree checking functions which report corruption by raising errors, the heap checking function <function>verify_heapam</function> checks a table and attempts to return a set of rows, one row per corruption detected. Despite this, if facilities that <function>verify_heapam</function> relies upon are themselves corrupted, the function may be unable to continue and may instead raise an error. エラーを起こすことによって破損を報告するB-Tree検査関数とは違って、ヒープ検査関数verify_heapamはテーブルを検査し、破損の検出ごとに1行が対応する行の集合を返そうとします。 にも関わらず、verify_heapamが依存する機能自体が破損していれば、この関数は続行することができず、代わりにエラーを引き起こすかもしれません。

Permission to execute <filename>amcheck</filename> functions may be granted to non-superusers, but before granting such permissions careful consideration should be given to data security and privacy concerns. Although the corruption reports generated by these functions do not focus on the contents of the corrupted data so much as on the structure of that data and the nature of the corruptions found, an attacker who gains permission to execute these functions, particularly if the attacker can also induce corruption, might be able to infer something of the data itself from such messages. 非スーパーユーザにamcheck関数の実行許可を与えることができますが、そのような権限を許可する前に、データのセキュリティとプライバシー上の懸念を注意深く考慮すべきです。 これらの関数が生成する破損報告は、データの構造と見つかった破損の性質ほどには、破損データの内容に焦点を当てるわけではありませんが、とりわけ攻撃者が破損を引き起こすこともできるのであれば、これらの関数の実行権限を与えられた攻撃者はそうしたメッセージからデータ自身を推測できるかもしれません。

F.2.1. 関数 #

<title>Functions</title>
bt_index_check(index regclass, heapallindexed boolean) returns void

<function>bt_index_check</function> tests that its target, a B-Tree index, respects a variety of invariants. Example usage: bt_index_checkは対象となるB-Treeインデックスが、様々な不変量を維持していることをテストします。 例を示します。

test=# SELECT bt_index_check(index => c.oid, heapallindexed => i.indisunique),
               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 c.relkind = 'i' 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)

This example shows a session that performs verification of the 10 largest catalog indexes in the database <quote>test</quote>. Verification of the presence of heap tuples as index tuples is requested for the subset that are unique indexes. Since no error is raised, all indexes tested appear to be logically consistent. Naturally, this query could easily be changed to call <function>bt_index_check</function> for every index in the database where verification is supported. この例では、データベースtest中のもっとも大きな10個のカタログインデックスの検証を行うセッションを示しています。 インデックスタプルに対応するヒープタプルの存在の検証が、ユニークインデックスであるインデックスの一部に対して要求されています。 エラーは出ていないので、テストしたすべてのインデックスは論理的に一貫していることがわかります。 当然のことながら、この問い合わせは、検証可能なデータベース中のすべてのインデックスに対してbt_index_checkを呼び出すように変更できます。

<function>bt_index_check</function> acquires an <literal>AccessShareLock</literal> on the target index and the heap relation it belongs to. This lock mode is the same lock mode acquired on relations by simple <literal>SELECT</literal> statements. <function>bt_index_check</function> does not verify invariants that span child/parent relationships, but will verify the presence of all heap tuples as index tuples within the index when <parameter>heapallindexed</parameter> is <literal>true</literal>. When a routine, lightweight test for corruption is required in a live production environment, using <function>bt_index_check</function> often provides the best trade-off between thoroughness of verification and limiting the impact on application performance and availability. bt_index_checkは、ターゲットとなるインデックスと、それが所属するヒープリレーションに対してAccessShareLockを獲得します。 このロックモードは、単純なSELECT文がリレーションに対して獲得するのと同じものです。 bt_index_checkは、子/親関係に渡る不変量を検査しませんが、heapallindexedtrueの場合には、インデックス中のインデックスタプルに対応するすべてのヒープタプルの存在が検証されます。 実行中の運用環境で定期的、軽量なデータ破損検査が必要な場合、bt_index_checkを使うのが、検査の完全性と、アプリケーションの性能と稼働への影響を限定することとの間の最良のトレードオフになることがしばしばあります。

bt_index_parent_check(index regclass, heapallindexed boolean, rootdescend boolean) returns void

<function>bt_index_parent_check</function> tests that its target, a B-Tree index, respects a variety of invariants. Optionally, when the <parameter>heapallindexed</parameter> argument is <literal>true</literal>, the function verifies the presence of all heap tuples that should be found within the index. When the optional <parameter>rootdescend</parameter> argument is <literal>true</literal>, verification re-finds tuples on the leaf level by performing a new search from the root page for each tuple. The checks that can be performed by <function>bt_index_parent_check</function> are a superset of the checks that can be performed by <function>bt_index_check</function>. <function>bt_index_parent_check</function> can be thought of as a more thorough variant of <function>bt_index_check</function>: unlike <function>bt_index_check</function>, <function>bt_index_parent_check</function> also checks invariants that span parent/child relationships, including checking that there are no missing downlinks in the index structure. <function>bt_index_parent_check</function> follows the general convention of raising an error if it finds a logical inconsistency or other problem. bt_index_parent_checkは、ターゲットとなるB-Treeインデックスが様々な不変量を保っていることを検査します。 オプションとして、heapallindexed引数がtrueの場合、インデックスに対応して存在すべきすべてのヒープタプルの存在を検証します。 省略可能な引数rootdescendtrueであれば、各タプルに対するルートページから新しく探索することで、検証はリーフレベルのタプルを再び見つけます。 bt_index_parent_checkにより実施される検査は、bt_index_checkにより実施される検査のスーパーセットになっています。 bt_index_parent_checkは、bt_index_checkの更なる完璧版であると考えることができます。 つまり、bt_index_checkと違ってbt_index_parent_checkは、インデックス構造中のダウンリンクに漏れがないことを含め、親/子関係に渡る不変量も検査します。 bt_index_parent_checkは、論理的な非一貫性やその他の問題を発見した場合、一般的な習慣に従ってエラーを報告します。

A <literal>ShareLock</literal> is required on the target index by <function>bt_index_parent_check</function> (a <literal>ShareLock</literal> is also acquired on the heap relation). These locks prevent concurrent data modification from <command>INSERT</command>, <command>UPDATE</command>, and <command>DELETE</command> commands. The locks also prevent the underlying relation from being concurrently processed by <command>VACUUM</command>, as well as all other utility commands. Note that the function holds locks only while running, not for the entire transaction. bt_index_parent_checkは、ターゲットインデックスにShareLockを獲得することを必要とします。 (ShareLockはヒープリレーションにも獲得されます。) このロックは、INSERTUPDATEDELETEが並行してデータ更新することを防ぎます。 また、このロックはVACUUMその他のユーティリティコマンドによって、背後にあるリレーションが同時に処理されることを防ぎます。 この関数は実行中のみロックを保持し、トランザクション全体に保持するのではないことに注意してください。

<function>bt_index_parent_check</function>'s additional verification is more likely to detect various pathological cases. These cases may involve an incorrectly implemented B-Tree operator class used by the index that is checked, or, hypothetically, undiscovered bugs in the underlying B-Tree index access method code. Note that <function>bt_index_parent_check</function> cannot be used when hot standby mode is enabled (i.e., on read-only physical replicas), unlike <function>bt_index_check</function>. bt_index_parent_checkによる追加の検査では、様々な病的な事象を検出する可能性があります。 これらの現象は、チェック対象のインデックスが使用している間違った実装がされたB-Tree演算子クラスによるものや、もしかしたら関連するB-Treeインデックスアクセスメソッドのコード中のまだ見つかっていないバグによるものなのかもしれません。 bt_index_checkと違って、bt_index_parent_checkは、ホットスタンバイモードが有効な場合(すなわち、読み出し専用物理レプリカ)では使用できません。

ヒント

<function>bt_index_check</function> and <function>bt_index_parent_check</function> both output log messages about the verification process at <literal>DEBUG1</literal> and <literal>DEBUG2</literal> severity levels. These messages provide detailed information about the verification process that may be of interest to <productname>PostgreSQL</productname> developers. Advanced users may also find this information helpful, since it provides additional context should verification actually detect an inconsistency. Running: bt_index_checkbt_index_parent_checkは両方とも、DEBUG1DEBUG2の深刻度レベルで検証プロセスに関するログメッセージを出力します。 このメッセージは、PostgreSQL開発者にとって興味のあるかもしれない検証プロセスに関する詳細な情報を提供します。 検証が実際に非一貫性を検出する追加の状況を提供しますので、上級ユーザにもこの情報は役立つかもしれません。 以下を実行すると、

SET client_min_messages = DEBUG1;

in an interactive <application>psql</application> session before running a verification query will display messages about the progress of verification with a manageable level of detail. 検証問い合わせを実行する前に対話式のpsqlセッションで扱いやすい程度の詳細で検証の進行状況に関するメッセージを表示します。

verify_heapam(relation regclass, on_error_stop boolean, check_toast boolean, skip text, startblock bigint, endblock bigint, blkno OUT bigint, offnum OUT integer, attnum OUT integer, msg OUT text) returns setof record

Checks a table, sequence, or materialized view for structural corruption, where pages in the relation contain data that is invalidly formatted, and for logical corruption, where pages are structurally valid but inconsistent with the rest of the database cluster. リレーションのページが不正なフォーマットのデータを含む構造上の破損と、ページは構造的に正しいものの、データベースクラスタの他の部分と一貫していない論理上の破損に関してテーブル、シーケンス、またはマテリアライズドビューを検査します。

The following optional arguments are recognized: 次のようなオプションの引数を認識します。

on_error_stop

If true, corruption checking stops at the end of the first block in which any corruptions are found. 真なら、破損が見つかった最初のブロックの終端で破損検査は終了します。

Defaults to false. デフォルトは偽です。

check_toast

If true, toasted values are checked against the target relation's TOAST table. 真なら、TOASTされた値が対象リレーションのTOASTテーブルに対して検査されます。

This option is known to be slow. Also, if the toast table or its index is corrupt, checking it against toast values could conceivably crash the server, although in many cases this would just produce an error. このオプションは遅いことが知られています。 また、TOASTテーブルあるいはそのインデックスが破損していると、それをTOAST値に対して検査することで、おそらくサーバがクラッシュすることもあり得ます。 もっとも、多くの場合には単にエラーが生じるだけでしょう。

Defaults to false. デフォルトは偽です。

skip

If not <literal>none</literal>, corruption checking skips blocks that are marked as all-visible or all-frozen, as specified. Valid options are <literal>all-visible</literal>, <literal>all-frozen</literal> and <literal>none</literal>. noneでなければ、指定されたとおりに破損検査はすべて可視あるいは凍結されていると印が付けられたブロックをスキップします。 可能なオプションはall-visibleall-frozennoneです。

Defaults to <literal>none</literal>. デフォルトはnoneです。

startblock

If specified, corruption checking begins at the specified block, skipping all previous blocks. It is an error to specify a <parameter>startblock</parameter> outside the range of blocks in the target table. 指定すると、破損検査は前のブロックをすべてスキップして指定ブロックから開始されます。 startblockをターゲットテーブルに含まれるブロックの範囲外で指定するとエラーになります。

By default, checking begins at the first block. デフォルトでは最初のブロックから検索が始まります。

endblock

If specified, corruption checking ends at the specified block, skipping all remaining blocks. It is an error to specify an <parameter>endblock</parameter> outside the range of blocks in the target table. 指定すると、残りのすべてのブロックをスキップして指定ブロックで破損検査が終了します。 endblockをターゲットテーブルに含まれるブロックの範囲外で指定するとエラーになります。

By default, all blocks are checked. デフォルトではすべてのブロックが検査されます。

For each corruption detected, <function>verify_heapam</function> returns a row with the following columns: 個々の破損の検出に対してverify_heapamは以下の列を含む行を返します。

blkno

The number of the block containing the corrupt page. 破損ページを含むブロック番号。

offnum

The OffsetNumber of the corrupt tuple. 破損タプルのオフセット番号。

attnum

The attribute number of the corrupt column in the tuple, if the corruption is specific to a column and not the tuple as a whole. タプル全体ではなく、破損が特定の列にのみ起こっているなら、タプル内の破損列の属性番号。

msg

A message describing the problem detected. 検出された問題を記述するメッセージ。

F.2.2. オプションheapallindexed検証 #

<title>Optional <parameter>heapallindexed</parameter> Verification</title>

When the <parameter>heapallindexed</parameter> argument to B-Tree verification functions is <literal>true</literal>, an additional phase of verification is performed against the table associated with the target index relation. This consists of a <quote>dummy</quote> <command>CREATE INDEX</command> operation, which checks for the presence of all hypothetical new index tuples against a temporary, in-memory summarizing structure (this is built when needed during the basic first phase of verification). The summarizing structure <quote>fingerprints</quote> every tuple found within the target index. The high level principle behind <parameter>heapallindexed</parameter> verification is that a new index that is equivalent to the existing, target index must only have entries that can be found in the existing structure. B-Tree検証関数のheapallindexed引数がtrueならば、ターゲットのインデックスリレーションと関連付けられたテーブルに対して追加の検証フェーズが実施されます。 これはダミーCREATE INDEX操作から構成され、インメモリ上の一時的なサマリー構造(これは必要に応じて基礎的な最初の検証フェーズで構築されます)に対する仮想的な新しいインデックスタプルがすべて存在することをチェックします。 サマリー構造はターゲットのインデックスで見つかったすべてのタプルに対して指紋採取(fingerprint)を行います。 heapallindexed検証の背後にある高レベルの原理は、新しいインデックスが既存のインデックスと等しいこと、ターゲットインデックスが既存の構造中に見つかったエントリーのみを含むことです。

The additional <parameter>heapallindexed</parameter> phase adds significant overhead: verification will typically take several times longer. However, there is no change to the relation-level locks acquired when <parameter>heapallindexed</parameter> verification is performed. 追加のheapallindexedフェーズは大きなオーバーヘッドをもたらします。 典型的には、検証に数倍時間かかるようになります。 しかし、取得されたリレーションレベルのロックに対して、heapallindexed検証が実施されるときに変更はありません。

The summarizing structure is bound in size by <varname>maintenance_work_mem</varname>. In order to ensure that there is no more than a 2% probability of failure to detect an inconsistency for each heap tuple that should be represented in the index, approximately 2 bytes of memory are needed per tuple. As less memory is made available per tuple, the probability of missing an inconsistency slowly increases. This approach limits the overhead of verification significantly, while only slightly reducing the probability of detecting a problem, especially for installations where verification is treated as a routine maintenance task. Any single absent or malformed tuple has a new opportunity to be detected with each new verification attempt. サマライズ構造は、maintenance_work_memによってその大きさが制限されます。 インデックス中に存在すべきヒープタプルの非一貫性の検出失敗の確率が2%を超えないことを保証するために、タプルごとに約2バイトのメモリが必要です。 タプルごとに利用可能なメモリが少ないほど、非一貫性を見逃す可能性が徐々に増えていきます。 この手法によって検証のオーバーヘッドを大幅に減らせる一方、とりわけ検証を日常的な保守作業として行うシステムでは、問題を検出できる確率が少し減少するだけです。 失われた、あるいは不正なタプルは次の検証の機会に検出されます。

F.2.3. amcheckを効果的に使う #

<title>Using <filename>amcheck</filename> Effectively</title>

<filename>amcheck</filename> can be effective at detecting various types of failure modes that <link linkend="app-initdb-data-checksums"><application>data checksums</application></link> will fail to catch. These include: amcheckは、データチェックサムが検知できないような、様々なタイプの障害モードを効果的に検知できます。 以下のようなものがあります。

  • Structural inconsistencies caused by incorrect operator class implementations. 演算子クラスの正しくない実装によって引き起こされる構造の非一貫性。

    This includes issues caused by the comparison rules of operating system collations changing. Comparisons of datums of a collatable type like <type>text</type> must be immutable (just as all comparisons used for B-Tree index scans must be immutable), which implies that operating system collation rules must never change. Though rare, updates to operating system collation rules can cause these issues. More commonly, an inconsistency in the collation order between a primary server and a standby server is implicated, possibly because the <emphasis>major</emphasis> operating system version in use is inconsistent. Such inconsistencies will generally only arise on standby servers, and so can generally only be detected on standby servers. オペレーティングシステムの照合順序の比較ルールの変更による問題も含まれます。 textのような照合可能な型のデータの比較は、不変でなければならず(B-Treeインデックスの走査のための、すべての比較が不変でなければならないのと同じことです)、それはオペレーティングシステムの照合順序が決して変化してはいけないことを意味します。 まれであるとは言え、オペレーティングシステムの照合順序ルールの更新は、これらの問題を引き起こします。 もっと普通に起こることとしては、プライマリサーバとスタンバイサーバの照合順序の違いが関与することです。 これは、使用されているオペレーティングシステムのメジャーバージョンに一貫性がないことによります。 そうした一貫性の欠如は一般的にスタンバイサーバでのみ起こるので、通常スタンバイサーバでのみ検出されます。

    If a problem like this arises, it may not affect each individual index that is ordered using an affected collation, simply because <emphasis>indexed</emphasis> values might happen to have the same absolute ordering regardless of the behavioral inconsistency. See <xref linkend="locale"/> and <xref linkend="collation"/> for further details about how <productname>PostgreSQL</productname> uses operating system locales and collations. そうした問題が起きても、影響を受けた照合順序を使って順序付けられた個々のインデックスには影響ないかもしれません。 これは単純に、振る舞いにおける一貫性のなさにかかわらずインデックスされた値は同じ絶対的な順になるからです。 PostgreSQLがオペレーティングシステムのロケールと照合順序をどう使用するかについての更なる詳細については、24.124.2をご覧ください。

  • Structural inconsistencies between indexes and the heap relations that are indexed (when <parameter>heapallindexed</parameter> verification is performed). インデックスとインデックス付されたヒープリレーションの間の構造的な非一貫性(heapallindexed検証が実施される場合)

    There is no cross-checking of indexes against their heap relation during normal operation. Symptoms of heap corruption can be subtle. 通常の操作においてはインデックスとそのヒープリレーションの間にはクロスチェックはありません。 ヒープの破壊による症状は些細なものかもしれません。

  • Corruption caused by hypothetical undiscovered bugs in the underlying <productname>PostgreSQL</productname> access method code, sort code, or transaction management code. 依拠するPostgreSQLのアクセスメソッド、あるいはソート、トランザクション管理コードにおける、潜在的なまだ見つかっていないバグによる破損。

    Automatic verification of the structural integrity of indexes plays a role in the general testing of new or proposed <productname>PostgreSQL</productname> features that could plausibly allow a logical inconsistency to be introduced. Verification of table structure and associated visibility and transaction status information plays a similar role. One obvious testing strategy is to call <filename>amcheck</filename> functions continuously when running the standard regression tests. See <xref linkend="regress-run"/> for details on running the tests. 新規、あるいは提案中の PostgreSQLの機能が、論理的な非一貫性をもたらしかねないかどうか全般的にテストする際に、インデックスの構造的な一貫性の自動検証が役立ちます。 テーブル構造と、関連する可視性およびトランザクション状態情報の検証も同じような役割を果たします。 わかりやすいテスト戦略の一つは、標準のリグレッションテストを実行中に、amcheck関数を継続的に呼び出すことです。 テストの実行に関する詳細は、33.1をご覧ください。

  • File system or storage subsystem faults where checksums happen to simply not be enabled. 単にチェックサムが有効になっていないファイルシステムあるいはストレージサブシステムの障害。

    Note that <filename>amcheck</filename> examines a page as represented in some shared memory buffer at the time of verification if there is only a shared buffer hit when accessing the block. Consequently, <filename>amcheck</filename> does not necessarily examine data read from the file system at the time of verification. Note that when checksums are enabled, <filename>amcheck</filename> may raise an error due to a checksum failure when a corrupt block is read into a buffer. amcheckは、ブロックをアクセスする際に共有バッファがヒットした場合、検査時に共有メモリバッファ上に表現されたページを調査します。 そのため、amcheckは、検査時にファイルシステムから読み込んだデータを調査するとは限りません。 チェックサムが有効な場合、amcheckは壊れたブロックをバッファに読み込んだ際にチェックサム障害によるエラーを報告するかもしれません。

  • Corruption caused by faulty RAM, or the broader memory subsystem. 欠陥のあるRAMあるいは、広範囲に渡るメモリサブシステムによる破損。

    <productname>PostgreSQL</productname> does not protect against correctable memory errors and it is assumed you will operate using RAM that uses industry standard Error Correcting Codes (ECC) or better protection. However, ECC memory is typically only immune to single-bit errors, and should not be assumed to provide <emphasis>absolute</emphasis> protection against failures that result in memory corruption. PostgreSQLは、訂正可能なメモリーエラーからは身を守らないので、業界標準のエラー訂正コード(ECC)、あるいはもっと優れた保護機構を使ったRAMを使って運用する前提となっています。 しかし、ECCメモリは典型的には単一ビットエラーに対してのみ耐性があり、メモリ破損に起因する障害に対して完全な保護を提供すると考えるべきではありません。

    When <parameter>heapallindexed</parameter> verification is performed, there is generally a greatly increased chance of detecting single-bit errors, since strict binary equality is tested, and the indexed attributes within the heap are tested. heapallindexed検証が実施されると、一般に1ビットエラーを検出する可能性が非常に高くなります。 これは、バイナリ一致を厳密にテストすることと、またヒープ内のインデックス付けされたアトリビュートをテストすることによります。

Structural corruption can happen due to faulty storage hardware, or relation files being overwritten or modified by unrelated software. This kind of corruption can also be detected with <link linkend="checksums"><application>data page checksums</application></link>. 構造上の破損は故障したストレージハードウェア、あるいはリレーションファイルが無関係のソフトウェアによって上書きされたり変更されることによって起こることがあります。 この種の破損はデータページチェックサムによっても検出することができます。

Relation pages which are correctly formatted, internally consistent, and correct relative to their own internal checksums may still contain logical corruption. As such, this kind of corruption cannot be detected with <application>checksums</application>. Examples include toasted values in the main table which lack a corresponding entry in the toast table, and tuples in the main table with a Transaction ID that is older than the oldest valid Transaction ID in the database or cluster. 正しくフォーマットされ、内部的に一貫していて、かつ自身の内部チェックサムが正しいリレーションページでも論理的に破損していることがあります。 ですから、この種の破損はチェックサムでは検出できません。 例としては、主テーブルのTOASTされた値に対応するTOASTテーブルのエントリが存在しない、主テーブルのタプルのトランザクションIDがデータベースクラスタ内の有効な最古のトランザクションIDよりも古い、などがあります。

Multiple causes of logical corruption have been observed in production systems, including bugs in the <productname>PostgreSQL</productname> server software, faulty and ill-conceived backup and restore tools, and user error. PostgreSQLサーバソフトウェアのバグ、欠陥があったり、よく考慮されていないバックアップ、リストアツール、ユーザのエラーなど、論理的破損の複数の原因が実運用システム上で観測されています。

Corrupt relations are most concerning in live production environments, precisely the same environments where high risk activities are least welcome. For this reason, <function>verify_heapam</function> has been designed to diagnose corruption without undue risk. It cannot guard against all causes of backend crashes, as even executing the calling query could be unsafe on a badly corrupted system. Access to <link linkend="catalogs-overview">catalog tables</link> is performed and could be problematic if the catalogs themselves are corrupted. 破損したリレーションは、リスクの高い活動がもっとも忌避される環境である、運用中の実システム環境では最大の懸念事項です。 このため、verify_heapamは過度のリスクを伴わずに破損を診断するように設計されています。 ひどく破損したシステムでは問い合わせの呼び出しを実行するだけでも安全ではないため、バックエンドのクラッシュのすべての原因から守ることはできません。 カタログ自身が破損していればカタログテーブルへのアクセスの実行も問題になるでしょう。

In general, <filename>amcheck</filename> can only prove the presence of corruption; it cannot prove its absence. 一般的に、amcheckは破損の存在を証明することはできますが、破損がないことを証明することはできません。

F.2.4. 破損の修復 #

<title>Repairing Corruption</title>

No error concerning corruption raised by <filename>amcheck</filename> should ever be a false positive. <filename>amcheck</filename> raises errors in the event of conditions that, by definition, should never happen, and so careful analysis of <filename>amcheck</filename> errors is often required. amcheckが報告するエラーが関与する破損で、偽陽性のものはありません。 amcheckは、定義により発生してはならないはずの条件下で発生したエラーを報告するので、amcheckの報告するエラーを注意深く解析することがしばしば求められます。

There is no general method of repairing problems that <filename>amcheck</filename> detects. An explanation for the root cause of an invariant violation should be sought. <xref linkend="pageinspect"/> may play a useful role in diagnosing corruption that <filename>amcheck</filename> detects. A <command>REINDEX</command> may not be effective in repairing corruption. amcheckが検出した問題を修復する一般的な方法はありません。 不変条件違反の根本的な原因の説明が求められます。 amcheckが検出した破損の診断には、pageinspectが有用な役割を担うかもしれません。 REINDEXは破損の修復には効果的ではないかもしれません。