Home Explore Blog CI



postgresql

4th chunk of `doc/src/sgml/wal.sgml`
a0a3fbb5133e7369475d936c4b2ea4f775034dbc04e97dd90000000100000fa3
 against some kinds of data corruption
   on storage devices that may occur because of hardware errors or media failure over time,
   such as reading/writing garbage data.
   <itemizedlist>
    <listitem>
     <para>
      Each individual record in a WAL file is protected by a CRC-32C (32-bit) check
      that allows us to tell if record contents are correct. The CRC value
      is set when we write each WAL record and checked during crash recovery,
      archive recovery and replication.
     </para>
    </listitem>
    <listitem>
     <para>
      Data pages are checksummed by default, and full page images
      recorded in WAL records are always checksum protected.
     </para>
    </listitem>
    <listitem>
     <para>
      Internal data structures such as <filename>pg_xact</filename>, <filename>pg_subtrans</filename>, <filename>pg_multixact</filename>,
      <filename>pg_serial</filename>, <filename>pg_notify</filename>, <filename>pg_stat</filename>, <filename>pg_snapshots</filename> are not directly
      checksummed, nor are pages protected by full page writes. However, where
      such data structures are persistent, WAL records are written that allow
      recent changes to be accurately rebuilt at crash recovery and those
      WAL records are protected as discussed above.
     </para>
    </listitem>
    <listitem>
     <para>
      Individual state files in <filename>pg_twophase</filename> are protected by CRC-32C.
     </para>
    </listitem>
    <listitem>
     <para>
      Temporary data files used in larger SQL queries for sorts,
      materializations and intermediate results are not currently checksummed,
      nor will WAL records be written for changes to those files.
     </para>
    </listitem>
   </itemizedlist>
  </para>
  <para>
   <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.
  </para>
 </sect1>

 <sect1 id="checksums">
  <title>Data Checksums</title>
  <indexterm>
   <primary>checksums</primary>
  </indexterm>

  <para>
   By default, data pages are protected by checksums, but this can
   optionally be disabled for a cluster. When enabled, each data page includes
   a checksum that is updated when the page is written and verified each time
   the page is read. Only data pages are protected by checksums; internal data
   structures and temporary files are not.
  </para>

  <para>
   Checksums can be disabled when the cluster is initialized using <link
   linkend="app-initdb-data-checksums"><application>initdb</application></link>.
   They can also be enabled or disabled at a later time as an offline
   operation. Data checksums are enabled or disabled at the full cluster
   level, and cannot be specified individually for databases or tables.
  </para>

  <para>
   The current state of checksums in the cluster can be verified by viewing the
   value of the read-only configuration variable <xref
   linkend="guc-data-checksums" /> by issuing the command <command>SHOW
   data_checksums</command>.
  </para>

  <para>
   When attempting to recover from page corruptions, it may be necessary to
   bypass the checksum protection. To do this, temporarily set the
   configuration parameter <xref linkend="guc-ignore-checksum-failure" />.
  </para>

  <sect2 id="checksums-offline-enable-disable">
   <title>Off-line Enabling of Checksums</title>

   <para>
    The <link linkend="app-pgchecksums"><application>pg_checksums</application></link>
    application can be used to enable or disable data checksums, as well as
    verify checksums, on an offline cluster.
   </para>

  </sect2>
 </sect1>

  <sect1 id="wal-intro">
   <title>Write-Ahead Logging (<acronym>WAL</acronym>)</title>

   <indexterm zone="wal">
    <primary>WAL</primary>
   </indexterm>

   <indexterm>
    <primary>transaction log</primary>
    <see>WAL</see>
   </indexterm>

   <para>

Title: Data Integrity and Checksums in PostgreSQL
Summary
This section discusses how PostgreSQL protects against data corruption through mechanisms such as checksums on data pages and WAL records, and how these checksums can be enabled or disabled, as well as the use of the pg_checksums application to verify and manage checksums on an offline cluster.