diff --git a/CN/modules/ROOT/pages/3.3.adoc b/CN/modules/ROOT/pages/3.3.adoc index 54d3428d..bfc74205 100644 --- a/CN/modules/ROOT/pages/3.3.adoc +++ b/CN/modules/ROOT/pages/3.3.adoc @@ -117,17 +117,24 @@ SELECT datname, age(datfrozenxid) FROM pg_database; ``` WARNING: database "mydb" must be vacuumed within 39985967 transactions -HINT: To avoid a database shutdown, execute a database-wide VACUUM in that database. +HINT: To avoid transaction ID assignment failures, execute a database-wide VACUUM in that database. ``` -(如该示例所建议的,一次手动的`VACUUM`应该会修复该问题;但是注意该次`VACUUM`必须由一个超级用户来执行,否则它将无法处理系统目录并且因而不能推进数据库的`datfrozenxid`)。如果这些警告被忽略,一旦距离回卷点只剩下 3 百万个事务时,该系统将会关闭并且拒绝开始任何新的事务: +以超级用户身份执行数据库范围的 `VACUUM`,才能处理系统目录并推进 `datfrozenxid`。如果忽略这些警告,当距离回卷点不足 3 百万个事务时,服务器会拒绝分配新事务 ID 的命令。以下是错误消息的节选。 ``` -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. +ERROR: database is not accepting commands that assign new transaction IDs to avoid wraparound data loss in database "mydb" +HINT: Execute a database-wide VACUUM in that database. ``` -这 3 百万个事务的安全余量是为了让管理员能通过手动执行所要求的`VACUUM`命令进行恢复而不丢失数据。但是,由于一旦系统进入到安全关闭模式,它将不会执行命令。做这个操作的唯一方法是停止服务器并且以单一用户启动服务器来执行`VACUUM`。单一用户模式中不会强制该关闭模式。 +剩余事务数为恢复保留了安全余量。以超级用户连接错误消息中指出的数据库,在服务器运行期间执行数据库范围的普通 `VACUUM`。 + +[source,sql] +---- +VACUUM; +---- + +长期运行的事务、预备事务和陈旧复制槽可能阻碍清理推进冻结 XID。应根据应用或复制需求排查并解决这些阻碍。恢复时使用普通 `VACUUM`。`VACUUM FULL` 需要分配新的 XID,`VACUUM FREEZE` 的工作量超出了恢复正常操作所需的最低范围。恢复后检查数据库年龄及自动清理配置。 *Multixact ID*被用来支持被多个事务锁定的行。由于在一个元组头部 只有有限的空间可以用来存储锁信息,所以只要有多于一个事务并发地锁住一个行, 锁信息将使用一个“多个事务 ID”(或简称多事务 ID)来编码。任何特定 多事务 ID 中包括的事务 ID 的信息被独立地存储在`pg_multixact`子目 录中,并且只有多事务 ID 出现在元组头部的`xmax`域中。和事务 ID 类似,多事务 ID 也是用一个 32 位计数器实现,并且也采用了相似的存储,这些都要 求仔细的年龄管理、存储清除和回卷处理。在每个多事务中都有一个独立的存储区域 保存成员列表,它也使用一个 32 位计数器并且也应被管理。 diff --git a/EN/modules/ROOT/pages/3.3.adoc b/EN/modules/ROOT/pages/3.3.adoc index a094274f..dc59406e 100644 --- a/EN/modules/ROOT/pages/3.3.adoc +++ b/EN/modules/ROOT/pages/3.3.adoc @@ -119,17 +119,24 @@ If for some reason autovacuum fails to clear old XIDs from a table, the system w ``` WARNING: database "mydb" must be vacuumed within 39985967 transactions -HINT: To avoid a database shutdown, execute a database-wide VACUUM in that database. +HINT: To avoid transaction ID assignment failures, execute a database-wide VACUUM in that database. ``` -(A manual `VACUUM` should fix the problem, as suggested by the hint; but note that the `VACUUM` must be performed by a superuser, else it will fail to process system catalogs and thus not be able to advance the database's `datfrozenxid`.) 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: +Run the database-wide `VACUUM` as a superuser so it can process system catalogs and advance `datfrozenxid`. If these warnings are ignored and fewer than three million transactions remain before wraparound, the server rejects commands that assign new transaction IDs. An excerpt of the resulting error is shown below. ``` -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. +ERROR: database is not accepting commands that assign new transaction IDs to avoid wraparound data loss in database "mydb" +HINT: Execute a database-wide VACUUM in that database. ``` -The three-million-transaction safety margin exists to let the administrator recover without data loss, by manually executing the required `VACUUM` commands. However, since the system will not execute commands once it has gone into the safety shutdown mode, the only way to do this is to stop the server and start the server in single-user mode to execute `VACUUM`. The shutdown mode is not enforced in single-user mode. See the https://www.postgresql.org/docs/current/app-postgres.html[postgres] reference page for details about using single-user mode. +The remaining transactions provide a safety margin for recovery. Connect to the database named in the error as a superuser and run a database-wide plain `VACUUM` while the server is running. + +[source,sql] +---- +VACUUM; +---- + +Long-running or prepared transactions and stale replication slots can prevent cleanup from advancing the frozen XID. Investigate these blockers and resolve them according to their application or replication requirements. Use plain `VACUUM` for recovery. `VACUUM FULL` requires a new XID, and `VACUUM FREEZE` performs more work than the minimum needed to restore normal operation. After recovery, check the database age and autovacuum configuration. *Multixact IDs* are used to support row locking by multiple transactions. Since there is only limited space in a tuple header to store lock information, that information is encoded as a “multiple transaction ID”, or multixact ID for short, whenever there is more than one transaction concurrently locking a row. Information about which transaction IDs are included in any particular multixact ID is stored separately in the `pg_multixact` subdirectory, and only the multixact ID appears in the `xmax` field in the tuple header. Like transaction IDs, multixact IDs are implemented as a 32-bit counter and corresponding storage, all of which requires careful aging management, storage cleanup, and wraparound handling. There is a separate storage area which holds the list of members in each multixact, which also uses a 32-bit counter and which must also be managed.