From 03e6f42077e25de71ceffeb839c09f4530bc1aa8 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@timescale.com>
Date: Mon, 16 Jan 2023 12:23:30 +0300
Subject: [PATCH v2 1/4] Correct the docs about preventing XID wraparound

Prior to this commit the documentation was somewhat misleading. It stated that
the system will "shutdown" in order to prevent XID wraparound. This is not
what actually happens though.

Actually the system refuses to allocate new XIDs. XIDs are allocated lazily
and not needed for checking the visibility rules. Thus read-only transaction
will continues to execute. Additionally, read-write transactions that are
in progress and have an allocated XID will continue to execute and can be
committed.

Author: Aleksander Alekseev
Reviewed-by: TODO FIXME
Discussion: https://postgr.es/m/CAJ7c6TM2D277U2wH8X78kg8pH3tdUqebV3_JCJqAkYQFHCFzeg@mail.gmail.com
---
 doc/src/sgml/maintenance.sgml | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml
index 759ea5ac9c..2aa072ba89 100644
--- a/doc/src/sgml/maintenance.sgml
+++ b/doc/src/sgml/maintenance.sgml
@@ -662,24 +662,25 @@ HINT:  To avoid a database shutdown, execute a database-wide VACUUM in that data
     hint; but note that the <command>VACUUM</command> must be performed by a
     superuser, else it will fail to process system catalogs and thus not
     be able to advance the database's <structfield>datfrozenxid</structfield>.)
-    If these warnings are
-    ignored, the system will shut down and refuse to start any new
-    transactions once there are fewer than three million transactions left
-    until wraparound:
+    If these warnings are ignored, the system will refuse to allocate new XIDs
+    once there are fewer than three million transactions left until wraparound:
 
 <programlisting>
 ERROR:  database is not accepting commands to avoid wraparound data loss in database "mydb"
 HINT:  Stop the postmaster and vacuum that database in single-user mode.
 </programlisting>
 
+    In this condition the system can still execute read-only transactions.
+    The active transactions will continue to execute and will be able to
+    commit.
+
     The three-million-transaction safety margin exists to let the
     administrator recover without data loss, by manually executing the
-    required <command>VACUUM</command> commands.  However, since the system will not
-    execute commands once it has gone into the safety shutdown mode,
+    required <command>VACUUM</command> commands.  However
     the only way to do this is to stop the server and start the server in single-user
-    mode to execute <command>VACUUM</command>.  The shutdown mode is not enforced
-    in single-user mode.  See the <xref linkend="app-postgres"/> reference
-    page for details about using single-user mode.
+    mode to execute <command>VACUUM</command>. See the
+    <xref linkend="app-postgres"/> reference page for details about using
+    single-user mode.
    </para>
 
    <sect3 id="vacuum-for-multixact-wraparound">
-- 
2.39.0

