{"kind": "storage", "major": "18", "item": {"slug": "wal-internals", "name": "WAL Internals", "name_zh": "", "category": "Physical structures", "summary": "WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see Section 28.5 ).", "aliases": [], "content_hash": "b4c1bf3f3df56edb5a2887edb2951954e9a7a700ca9e455fa49af5c29b889e22", "versions": {"10": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/relopts/?v=10", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "label": "10.23", "major": "10", "channel": "stable", "revision": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9"}, "sources": [{"url": "/docs/10/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 10 English manual", "sha256": "a58d322b79c31902a0e013fefad736cad9452f36a4491f897d7d795023ec5f39"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see Section 30.4 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">30.5.\u00a0WAL Internals</h2>\n</div>\n</div>\n</div>\n\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/10/wal-configuration.html\" title=\"30.4.\u00a0WAL Configuration\">Section\u00a030.4</a>).</p>\n<p>WAL records are appended to the WAL logs as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the logs, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/10/datatype-pg-lsn.html\" title=\"8.19.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL logs are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--with-wal-segsize</code> configure option when building the server). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The log record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the log is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL log files do not make such false reports. (See <a class=\"xref\" href=\"/docs/10/wal-reliability.html\" title=\"30.1.\u00a0Reliability\">Section\u00a030.1</a>.)</p>\n<p>After a checkpoint has been made and the log flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the log location indicated in the checkpoint record. Because the entire content of data pages is saved in the log on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/10/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing log segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/10/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "11": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/relopts/?v=11", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "label": "11.22", "major": "11", "channel": "stable", "revision": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0"}, "sources": [{"url": "/docs/11/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 11 English manual", "sha256": "56efdd32415762c4ce1acbc3a04ab33f03e8bcab7ce26106d4baa4ea4f3d092d"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see Section 30.4 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">30.5.\u00a0WAL Internals</h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/11/wal-configuration.html\" title=\"30.4.\u00a0WAL Configuration\">Section\u00a030.4</a>).</p>\n<p>WAL records are appended to the WAL logs as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the logs, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/11/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL logs are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> initdb option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The log record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the log is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL log files do not make such false reports. (See <a class=\"xref\" href=\"/docs/11/wal-reliability.html\" title=\"30.1.\u00a0Reliability\">Section\u00a030.1</a>.)</p>\n<p>After a checkpoint has been made and the log flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the log location indicated in the checkpoint record. Because the entire content of data pages is saved in the log on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/11/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing log segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/11/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "12": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=12", "label": "Table AM"}, {"url": "/wiki/relopts/?v=12", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "label": "12.22", "major": "12", "channel": "stable", "revision": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b"}, "sources": [{"url": "/docs/12/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 12 English manual", "sha256": "56a61ae576c15c7069a7e9af572aa95b3fbc83df5953dbfb6678c5424c24d281"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see Section 29.4 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">29.5.\u00a0WAL Internals</h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/12/wal-configuration.html\" title=\"29.4.\u00a0WAL Configuration\">Section\u00a029.4</a>).</p>\n<p>WAL records are appended to the WAL logs as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the logs, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/12/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL logs are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> initdb option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The log record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the log is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL log files do not make such false reports. (See <a class=\"xref\" href=\"/docs/12/wal-reliability.html\" title=\"29.1.\u00a0Reliability\">Section\u00a029.1</a>.)</p>\n<p>After a checkpoint has been made and the log flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the log location indicated in the checkpoint record. Because the entire content of data pages is saved in the log on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/12/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing log segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/12/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "13": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=13", "label": "Table AM"}, {"url": "/wiki/relopts/?v=13", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "label": "13.23", "major": "13", "channel": "stable", "revision": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6"}, "sources": [{"url": "/docs/13/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 13 English manual", "sha256": "8a5b29e6b99c671811f4c25131bf47d2ea33ad5b9a8ed67a1c4ce7828ed9d3cc"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see Section 29.4 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">29.5.\u00a0WAL Internals</h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/13/wal-configuration.html\" title=\"29.4.\u00a0WAL Configuration\">Section\u00a029.4</a>).</p>\n<p>WAL records are appended to the WAL logs as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the logs, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/13/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL logs are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> initdb option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The log record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the log is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL log files do not make such false reports. (See <a class=\"xref\" href=\"/docs/13/wal-reliability.html\" title=\"29.1.\u00a0Reliability\">Section\u00a029.1</a>.)</p>\n<p>After a checkpoint has been made and the log flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the log location indicated in the checkpoint record. Because the entire content of data pages is saved in the log on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/13/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing log segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/13/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "14": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=14", "label": "Table AM"}, {"url": "/wiki/relopts/?v=14", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "label": "14.24", "major": "14", "channel": "stable", "revision": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897"}, "sources": [{"url": "/docs/14/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 14 English manual", "sha256": "c9448655bebb6b1ad021979093d3bf6ebad48d7e6730d69b9564aa45f0c22f8e"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see Section 30.5 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">30.6.\u00a0WAL Internals</h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/14/wal-configuration.html\" title=\"30.5.\u00a0WAL Configuration\">Section\u00a030.5</a>).</p>\n<p>WAL records are appended to the WAL logs as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the logs, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/14/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL logs are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> <span class=\"application\">initdb</span> option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The log record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the log is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL log files do not make such false reports. (See <a class=\"xref\" href=\"/docs/14/wal-reliability.html\" title=\"30.1.\u00a0Reliability\">Section\u00a030.1</a>.)</p>\n<p>After a checkpoint has been made and the log flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the log location indicated in the checkpoint record. Because the entire content of data pages is saved in the log on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/14/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing log segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/14/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "15": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=15", "label": "Table AM"}, {"url": "/wiki/relopts/?v=15", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "label": "15.19", "major": "15", "channel": "stable", "revision": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89"}, "sources": [{"url": "/docs/15/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 15 English manual", "sha256": "2b9ad5a55a65e8a2d3cf0bd3f75a64245dcf81c6055cfdf89e09bfda66f5453c"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see Section 30.5 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">30.6.\u00a0WAL Internals</h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL logs are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/15/wal-configuration.html\" title=\"30.5.\u00a0WAL Configuration\">Section\u00a030.5</a>).</p>\n<p>WAL records are appended to the WAL logs as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the logs, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/15/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL logs are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> <span class=\"application\">initdb</span> option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The log record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the log is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL log files do not make such false reports. (See <a class=\"xref\" href=\"/docs/15/wal-reliability.html\" title=\"30.1.\u00a0Reliability\">Section\u00a030.1</a>.)</p>\n<p>After a checkpoint has been made and the log flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the log location indicated in the checkpoint record. Because the entire content of data pages is saved in the log on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/15/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing log segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/15/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "16": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=16", "label": "Table AM"}, {"url": "/wiki/relopts/?v=16", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "label": "16.15", "major": "16", "channel": "stable", "revision": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed"}, "sources": [{"url": "/docs/16/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 16 English manual", "sha256": "965ad174d6e86754ba6d95a80a46d7415a5f4d8205629df4924017cb31d6d046"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see Section 30.5 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">30.6.\u00a0WAL Internals </h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/16/wal-configuration.html\" title=\"30.5.\u00a0WAL Configuration\">Section\u00a030.5</a>).</p>\n<p>WAL records are appended to the WAL files as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the WAL, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/16/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL files are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> <span class=\"application\">initdb</span> option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The WAL record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the WAL is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL files do not make such false reports. (See <a class=\"xref\" href=\"/docs/16/wal-reliability.html\" title=\"30.1.\u00a0Reliability\">Section\u00a030.1</a>.)</p>\n<p>After a checkpoint has been made and the WAL flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the WAL location indicated in the checkpoint record. Because the entire content of data pages is saved in the WAL on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/16/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing WAL segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/16/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "17": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=17", "label": "Table AM"}, {"url": "/wiki/relopts/?v=17", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "label": "17.11", "major": "17", "channel": "stable", "revision": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}, "sources": [{"url": "/docs/17/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 17 English manual", "sha256": "2d5e9788085ba33889e36ae6648163dcf4757c95d2c3c4c9c96e5a4d8e5d1440"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see Section 28.5 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">28.6.\u00a0WAL Internals </h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/17/wal-configuration.html\" title=\"28.5.\u00a0WAL Configuration\">Section\u00a028.5</a>).</p>\n<p>WAL records are appended to the WAL files as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the WAL, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/17/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL files are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> <span class=\"application\">initdb</span> option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The WAL record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the WAL is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL files do not make such false reports. (See <a class=\"xref\" href=\"/docs/17/wal-reliability.html\" title=\"28.1.\u00a0Reliability\">Section\u00a028.1</a>.)</p>\n<p>After a checkpoint has been made and the WAL flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the WAL location indicated in the checkpoint record. Because the entire content of data pages is saved in the WAL on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/17/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing WAL segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/17/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "18": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=18", "label": "Table AM"}, {"url": "/wiki/relopts/?v=18", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "label": "18.6", "major": "18", "channel": "stable", "revision": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "sources": [{"url": "/docs/18/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 18 English manual", "sha256": "81c125b1657049ba0b146e15b1decb82aa524ac54df1add0b07e154d95f3f300"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see Section 28.5 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">28.6.\u00a0WAL Internals </h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/18/wal-configuration.html\" title=\"28.5.\u00a0WAL Configuration\">Section\u00a028.5</a>).</p>\n<p>WAL records are appended to the WAL files as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the WAL, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/18/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL files are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> <span class=\"application\">initdb</span> option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The WAL record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the WAL is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL files do not make such false reports. (See <a class=\"xref\" href=\"/docs/18/wal-reliability.html\" title=\"28.1.\u00a0Reliability\">Section\u00a028.1</a>.)</p>\n<p>After a checkpoint has been made and the WAL flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the WAL location indicated in the checkpoint record. Because the entire content of data pages is saved in the WAL on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing WAL segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/18/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "19": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=19", "label": "Table AM"}, {"url": "/wiki/relopts/?v=19", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "label": "19beta4", "major": "19", "channel": "preview", "revision": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}, "sources": [{"url": "/docs/19/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 19 English manual", "sha256": "cc12b0c0e02ad5c1ff3d05151533086748e60b45740f0dac956397e0f3278899"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see Section 28.5 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">28.6.\u00a0WAL Internals </h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/19/wal-configuration.html\" title=\"28.5.\u00a0WAL Configuration\">Section\u00a028.5</a>).</p>\n<p>WAL records are appended to the WAL files as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the WAL, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/19/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL files are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> <span class=\"application\">initdb</span> option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The WAL record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the WAL is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL files do not make such false reports. (See <a class=\"xref\" href=\"/docs/19/wal-reliability.html\" title=\"28.1.\u00a0Reliability\">Section\u00a028.1</a>.)</p>\n<p>After a checkpoint has been made and the WAL flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the WAL location indicated in the checkpoint record. Because the entire content of data pages is saved in the WAL on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/19/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing WAL segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/19/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "20": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=20", "label": "Table AM"}, {"url": "/wiki/relopts/?v=20", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "label": "20devel", "major": "20", "channel": "devel", "revision": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41"}, "sources": [{"url": "/docs/devel/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 20 English manual", "sha256": "5c83fe08d41b7aca8bc1fa250c8b8e9b1363108d2e4516df43c29e948a896f5f"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see Section 28.5 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">28.6.\u00a0WAL Internals </h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/devel/wal-configuration.html\" title=\"28.5.\u00a0WAL Configuration\">Section\u00a028.5</a>).</p>\n<p>WAL records are appended to the WAL files as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the WAL, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/devel/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL files are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> <span class=\"application\">initdb</span> option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The WAL record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the WAL is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL files do not make such false reports. (See <a class=\"xref\" href=\"/docs/devel/wal-reliability.html\" title=\"28.1.\u00a0Reliability\">Section\u00a028.1</a>.)</p>\n<p>After a checkpoint has been made and the WAL flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the WAL location indicated in the checkpoint record. Because the entire content of data pages is saved in the WAL on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/devel/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing WAL segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/devel/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}}}, "snapshot": {"facts": [{"label": "Definition scope", "value": "Same-version core physical storage documentation"}], "tables": [], "related": [{"url": "/wiki/tableam/?v=18", "label": "Table AM"}, {"url": "/wiki/relopts/?v=18", "label": "Storage Parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "label": "18.6", "major": "18", "channel": "stable", "revision": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "sources": [{"url": "/docs/18/wal-internals.html", "path": "wal-internals.html", "label": "PostgreSQL 18 English manual", "sha256": "81c125b1657049ba0b146e15b1decb82aa524ac54df1add0b07e154d95f3f300"}], "sections": [], "signature": "", "description": ["WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see Section 28.5 )."], "manual_html": "<div class=\"sect1\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">28.6.\u00a0WAL Internals </h2>\n</div>\n</div>\n</div>\n<p>WAL is automatically enabled; no action is required from the administrator except ensuring that the disk-space requirements for the WAL files are met, and that any necessary tuning is done (see <a class=\"xref\" href=\"/docs/18/wal-configuration.html\" title=\"28.5.\u00a0WAL Configuration\">Section\u00a028.5</a>).</p>\n<p>WAL records are appended to the WAL files as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the WAL, increasing monotonically with each new record. LSN values are returned as the datatype <a class=\"link\" href=\"/docs/18/datatype-pg-lsn.html\" title=\"8.20.\u00a0pg_lsn Type\"><code class=\"type\">pg_lsn</code></a>. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.</p>\n<p>WAL files are stored in the directory <code class=\"filename\">pg_wal</code> under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the <code class=\"option\">--wal-segsize</code> <span class=\"application\">initdb</span> option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the <code class=\"option\">--with-wal-blocksize</code> configure option). The WAL record headers are described in <code class=\"filename\">access/xlogrecord.h</code>; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at <code class=\"filename\">000000010000000000000001</code>. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.</p>\n<p>It is advantageous if the WAL is located on a different disk from the main database files. This can be achieved by moving the <code class=\"filename\">pg_wal</code> directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.</p>\n<p>The aim of WAL is to ensure that the log is written before database records are altered, but this can be subverted by disk drives that falsely report a successful write to the kernel, when in fact they have only cached the data and not yet stored it on the disk. A power failure in such a situation might lead to irrecoverable data corruption. Administrators should try to ensure that disks holding <span class=\"productname\">PostgreSQL</span>'s WAL files do not make such false reports. (See <a class=\"xref\" href=\"/docs/18/wal-reliability.html\" title=\"28.1.\u00a0Reliability\">Section\u00a028.1</a>.)</p>\n<p>After a checkpoint has been made and the WAL flushed, the checkpoint's position is saved in the file <code class=\"filename\">pg_control</code>. Therefore, at the start of recovery, the server first reads <code class=\"filename\">pg_control</code> and then the checkpoint record; then it performs the REDO operation by scanning forward from the WAL location indicated in the checkpoint record. Because the entire content of data pages is saved in the WAL on the first page modification after a checkpoint (assuming <a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> is not disabled), all pages changed since the checkpoint will be restored to a consistent state.</p>\n<p>To deal with the case where <code class=\"filename\">pg_control</code> is corrupt, we should support the possibility of scanning existing WAL segments in reverse order \u2014 newest to oldest \u2014 in order to find the latest checkpoint. This has not been implemented yet. <code class=\"filename\">pg_control</code> is small enough (less than one disk page) that it is not subject to partial-write problems, and as of this writing there have been no reports of database failures due solely to the inability to read <code class=\"filename\">pg_control</code> itself. So while it is theoretically a weak spot, <code class=\"filename\">pg_control</code> does not seem to be a problem in practice.</p>\n</div>", "manual_path": "/docs/18/wal-internals.html", "comparison_data": {"layouts": []}, "comparison_hash": "27341929154bfb55531f03501322b65af719c5561f3c4ddc9528a14aa4df69b5"}, "comparison": {"left": "17", "right": "18", "status": "unchanged", "diff": ""}}