From 0d30ef662a52b6b02496a6618c0457d6d6773992 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 4 Oct 2016 14:41:15 +0900 Subject: [PATCH 2/2] Rename pg_clog to pg_transaction pg_upgrade is updated to handle the transfer correctly to post-10 clusters. --- doc/src/sgml/backup.sgml | 6 +++--- doc/src/sgml/catalogs.sgml | 6 +++--- doc/src/sgml/config.sgml | 2 +- doc/src/sgml/func.sgml | 2 +- doc/src/sgml/maintenance.sgml | 12 +++++------ doc/src/sgml/ref/pg_resetxlog.sgml | 6 +++--- doc/src/sgml/ref/pg_rewind.sgml | 2 +- doc/src/sgml/storage.sgml | 10 ++++----- doc/src/sgml/wal.sgml | 2 +- src/backend/access/heap/heapam.c | 10 ++++----- src/backend/access/transam/README | 22 ++++++++++---------- src/backend/access/transam/clog.c | 2 +- src/backend/access/transam/commit_ts.c | 4 ++-- src/backend/access/transam/multixact.c | 8 +++---- src/backend/access/transam/subtrans.c | 18 ++++++++-------- src/backend/access/transam/transam.c | 2 +- src/backend/access/transam/twophase.c | 6 +++--- src/backend/access/transam/xact.c | 38 ++++++++++++++++++++-------------- src/backend/access/transam/xlog.c | 6 +++--- src/backend/commands/vacuum.c | 14 ++++++------- src/backend/postmaster/autovacuum.c | 4 ++-- src/backend/storage/buffer/README | 4 ++-- src/backend/storage/ipc/procarray.c | 5 +++-- src/backend/utils/time/tqual.c | 29 +++++++++++++------------- src/bin/initdb/initdb.c | 2 +- src/bin/pg_upgrade/exec.c | 6 ++++++ src/bin/pg_upgrade/pg_upgrade.c | 30 ++++++++++++++++----------- src/include/access/slru.h | 12 +++++------ 28 files changed, 145 insertions(+), 125 deletions(-) diff --git a/doc/src/sgml/backup.sgml b/doc/src/sgml/backup.sgml index 6eaed1e..eb4f962 100644 --- a/doc/src/sgml/backup.sgml +++ b/doc/src/sgml/backup.sgml @@ -382,10 +382,10 @@ tar -cf backup.tar /usr/local/pgsql/data directories. This will not work because the information contained in these files is not usable without the commit log files, - pg_clog/*, which contain the commit status of - all transactions. A table file is only usable with this + pg_transaction/*, which contain the commit status + of all transactions. A table file is only usable with this information. Of course it is also impossible to restore only a - table and the associated pg_clog data + table and the associated pg_transaction data because that would render all other tables in the database cluster useless. So file system backups only work for complete backup and restoration of an entire database cluster. diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 29738b0..77b395e 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -1847,7 +1847,7 @@ All transaction IDs before this one have been replaced with a permanent (frozen) transaction ID in this table. This is used to track whether the table needs to be vacuumed in order to prevent transaction - ID wraparound or to allow pg_clog to be shrunk. Zero + ID wraparound or to allow pg_transaction to be shrunk. Zero (InvalidTransactionId) if the relation is not a table. @@ -2514,8 +2514,8 @@ All transaction IDs before this one have been replaced with a permanent (frozen) transaction ID in this database. This is used to track whether the database needs to be vacuumed in order to prevent - transaction ID wraparound or to allow pg_clog to be shrunk. - It is the minimum of the per-table + transaction ID wraparound or to allow pg_transaction to be + shrunk. It is the minimum of the per-table pg_class.relfrozenxid values. diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 1bb501c..b0b7215 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -5822,7 +5822,7 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; Vacuum also allows removal of old files from the - pg_clog subdirectory, which is why the default + pg_transaction subdirectory, which is why the default is a relatively low 200 million transactions. This parameter can only be set at server start, but the setting can be reduced for individual tables by diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 2e64cc4..a9d2ec4 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -15323,7 +15323,7 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n); postmaster.pid | 9 pg_ident.conf | 10 global | 11 - pg_clog | 12 + pg_transaction | 12 pg_snapshots | 13 pg_multixact | 14 PG_VERSION | 15 diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml index f87f3e0..c741a9b 100644 --- a/doc/src/sgml/maintenance.sgml +++ b/doc/src/sgml/maintenance.sgml @@ -527,18 +527,18 @@ The sole disadvantage of increasing autovacuum_freeze_max_age (and vacuum_freeze_table_age along with it) - is that the pg_clog subdirectory of the database cluster - will take more space, because it must store the commit status of all - transactions back to the autovacuum_freeze_max_age horizon. + is that the pg_transaction subdirectory of the database + cluster will take more space, because it must store the commit status of + all transactions back to the autovacuum_freeze_max_age horizon. The commit status uses two bits per transaction, so if autovacuum_freeze_max_age is set to its maximum allowed - value of two billion, pg_clog can be expected to + value of two billion, pg_transaction can be expected to grow to about half a gigabyte. If this is trivial compared to your total database size, setting autovacuum_freeze_max_age to its maximum allowed value is recommended. Otherwise, set it depending - on what you are willing to allow for pg_clog storage. + on what you are willing to allow for pg_transaction storage. (The default, 200 million transactions, translates to about 50MB of - pg_clog storage.) + pg_transaction storage.) diff --git a/doc/src/sgml/ref/pg_resetxlog.sgml b/doc/src/sgml/ref/pg_resetxlog.sgml index c949c5e..67b048b 100644 --- a/doc/src/sgml/ref/pg_resetxlog.sgml +++ b/doc/src/sgml/ref/pg_resetxlog.sgml @@ -256,12 +256,12 @@ PostgreSQL documentation A safe value can be determined by looking for the numerically largest - file name in the directory pg_clog under the data directory, - adding one, + file name in the directory pg_transaction under the data + directory, adding one, and then multiplying by 1048576 (0x100000). Note that the file names are in hexadecimal. It is usually easiest to specify the option value in hexadecimal too. For example, if 0011 is the largest entry - in pg_clog, -x 0x1200000 will work (five + in pg_transaction, -x 0x1200000 will work (five trailing zeroes provide the proper multiplier). diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml index 371c4a4..34ef4f1 100644 --- a/doc/src/sgml/ref/pg_rewind.sgml +++ b/doc/src/sgml/ref/pg_rewind.sgml @@ -229,7 +229,7 @@ PostgreSQL documentation - Copy all other files such as pg_clog and + Copy all other files such as pg_transaction and configuration files from the source cluster to the target cluster (everything except the relation files). diff --git a/doc/src/sgml/storage.sgml b/doc/src/sgml/storage.sgml index fddb69b..61d15d4 100644 --- a/doc/src/sgml/storage.sgml +++ b/doc/src/sgml/storage.sgml @@ -72,11 +72,6 @@ Item - pg_clog - Subdirectory containing transaction commit status data - - - pg_dynshmem Subdirectory containing files used by the dynamic shared memory subsystem @@ -136,6 +131,11 @@ Item + pg_transaction + Subdirectory containing transaction commit status data + + + pg_twophase Subdirectory containing state files for prepared transactions diff --git a/doc/src/sgml/wal.sgml b/doc/src/sgml/wal.sgml index 346aa76..aac0a8d 100644 --- a/doc/src/sgml/wal.sgml +++ b/doc/src/sgml/wal.sgml @@ -201,7 +201,7 @@ - Internal data structures such as pg_clog, pg_subtrans, pg_multixact, + Internal data structures such as pg_transaction, pg_subtrans, pg_multixact, pg_serial, pg_notify, pg_stat, pg_snapshots 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 diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index b019bc1..075d06a 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -6762,11 +6762,11 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, TransactionId cutoff_xid, * Note: it might seem we could make the changes without exclusive lock, since * TransactionId read/write is assumed atomic anyway. However there is a race * condition: someone who just fetched an old XID that we overwrite here could - * conceivably not finish checking the XID against pg_clog before we finish - * the VACUUM and perhaps truncate off the part of pg_clog he needs. Getting - * exclusive lock ensures no other backend is in process of checking the - * tuple status. Also, getting exclusive lock makes it safe to adjust the - * infomask bits. + * conceivably not finish checking the XID against pg_transaction before we + * finish the VACUUM and perhaps truncate off the part of pg_transaction he + * needs. Getting exclusive lock ensures no other backend is in process of + * checking the tuple status. Also, getting exclusive lock makes it safe to + * adjust the infomask bits. * * NB: All code in here must be safe to execute during crash recovery! */ diff --git a/src/backend/access/transam/README b/src/backend/access/transam/README index 4ae4715..36bcde9 100644 --- a/src/backend/access/transam/README +++ b/src/backend/access/transam/README @@ -331,18 +331,18 @@ of the xid fields is atomic, so assuming it for xmin as well is no extra risk. -pg_clog and pg_subtrans ------------------------ +pg_transaction and pg_subtrans +------------------------------ -pg_clog and pg_subtrans are permanent (on-disk) storage of transaction related -information. There is a limited number of pages of each kept in memory, so -in many cases there is no need to actually read from disk. However, if -there's a long running transaction or a backend sitting idle with an open +pg_transaction and pg_subtrans are permanent (on-disk) storage of transaction +related information. There is a limited number of pages of each kept in +memory, so in many cases there is no need to actually read from disk. However, +if there's a long running transaction or a backend sitting idle with an open transaction, it may be necessary to be able to read and write this information from disk. They also allow information to be permanent across server restarts. -pg_clog records the commit status for each transaction that has been assigned -an XID. A transaction can be in progress, committed, aborted, or +pg_transaction records the commit status for each transaction that has been +assigned an XID. A transaction can be in progress, committed, aborted, or "sub-committed". This last state means that it's a subtransaction that's no longer running, but its parent has not updated its state yet. It is not necessary to update a subtransaction's transaction status to subcommit, so we @@ -381,10 +381,10 @@ each transaction we keep a "cache" of Xids that are known to be part of the transaction tree, so we can skip looking at pg_subtrans unless we know the cache has been overflowed. See storage/ipc/procarray.c for the gory details. -slru.c is the supporting mechanism for both pg_clog and pg_subtrans. It +slru.c is the supporting mechanism for both pg_transaction and pg_subtrans. It implements the LRU policy for in-memory buffer pages. The high-level routines -for pg_clog are implemented in transam.c, while the low-level functions are in -clog.c. pg_subtrans is contained completely in subtrans.c. +for pg_transaction are implemented in transam.c, while the low-level functions +are in clog.c. pg_subtrans is contained completely in subtrans.c. Write-Ahead Log Coding diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c index 2634476..c7a3cbb 100644 --- a/src/backend/access/transam/clog.c +++ b/src/backend/access/transam/clog.c @@ -450,7 +450,7 @@ CLOGShmemInit(void) { ClogCtl->PagePrecedes = CLOGPagePrecedes; SimpleLruInit(ClogCtl, "clog", CLOGShmemBuffers(), CLOG_LSNS_PER_PAGE, - CLogControlLock, "pg_clog", LWTRANCHE_CLOG_BUFFERS); + CLogControlLock, "pg_transaction", LWTRANCHE_CLOG_BUFFERS); } /* diff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.c index a8d275f..4a48f76 100644 --- a/src/backend/access/transam/commit_ts.c +++ b/src/backend/access/transam/commit_ts.c @@ -3,8 +3,8 @@ * commit_ts.c * PostgreSQL commit timestamp manager * - * This module is a pg_clog-like system that stores the commit timestamp - * for each transaction. + * This module is a pg_transaction-like system that stores the commit + * timestamp for each transaction. * * XLOG interactions: this module generates an XLOG record whenever a new * CommitTs page is initialized to zeroes. Also, one XLOG record is diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index e9588a7..aa8e07e 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -3,10 +3,10 @@ * multixact.c * PostgreSQL multi-transaction-log manager * - * The pg_multixact manager is a pg_clog-like manager that stores an array of - * MultiXactMember for each MultiXactId. It is a fundamental part of the - * shared-row-lock implementation. Each MultiXactMember is comprised of a - * TransactionId and a set of flag bits. The name is a bit historical: + * The pg_multixact manager is a pg_transaction-like manager that stores an + * array of MultiXactMember for each MultiXactId. It is a fundamental part + * of the shared-row-lock implementation. Each MultiXactMember is comprised + * of a TransactionId and a set of flag bits. The name is a bit historical: * originally, a MultiXactId consisted of more than one TransactionId (except * in rare corner cases), hence "multi". Nowadays, however, it's perfectly * legitimate to have MultiXactIds that only include a single Xid. diff --git a/src/backend/access/transam/subtrans.c b/src/backend/access/transam/subtrans.c index 908fe2d..d96a487 100644 --- a/src/backend/access/transam/subtrans.c +++ b/src/backend/access/transam/subtrans.c @@ -3,17 +3,17 @@ * subtrans.c * PostgreSQL subtransaction-log manager * - * The pg_subtrans manager is a pg_clog-like manager that stores the parent - * transaction Id for each transaction. It is a fundamental part of the - * nested transactions implementation. A main transaction has a parent - * of InvalidTransactionId, and each subtransaction has its immediate parent. - * The tree can easily be walked from child to parent, but not in the - * opposite direction. + * The pg_subtrans manager is a pg_transaction-like manager that stores + * the parent transaction Id for each transaction. It is a fundamental + * part of the nested transactions implementation. A main transaction has + * a parent of InvalidTransactionId, and each subtransaction has its + * immediate parent. The tree can easily be walked from child to parent, + * but not in the opposite direction. * * This code is based on clog.c, but the robustness requirements - * are completely different from pg_clog, because we only need to remember - * pg_subtrans information for currently-open transactions. Thus, there is - * no need to preserve data over a crash and restart. + * are completely different from pg_transaction, because we only need to + * remember pg_subtrans information for currently-open transactions. Thus, + * there is no need to preserve data over a crash and restart. * * There are no XLOG interactions since we do not care about preserving * data across crashes. During database startup, we simply force the diff --git a/src/backend/access/transam/transam.c b/src/backend/access/transam/transam.c index 1eba49a..8a41c7f 100644 --- a/src/backend/access/transam/transam.c +++ b/src/backend/access/transam/transam.c @@ -224,7 +224,7 @@ TransactionIdDidAbort(TransactionId transactionId) * True iff transaction associated with the identifier is currently * known to have either committed or aborted. * - * This does NOT look into pg_clog but merely probes our local cache + * This does NOT look into pg_transaction but merely probes our local cache * (and so it's not named TransactionIdDidComplete, which would be the * appropriate name for a function that worked that way). The intended * use is just to short-circuit TransactionIdIsInProgress calls when doing diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 5415604..52de336 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1379,8 +1379,8 @@ FinishPreparedTransaction(const char *gid, bool isCommit) /* * The order of operations here is critical: make the XLOG entry for * commit or abort, then mark the transaction committed or aborted in - * pg_clog, then remove its PGPROC from the global ProcArray (which means - * TransactionIdIsInProgress will stop saying the prepared xact is in + * pg_transaction, then remove its PGPROC from the global ProcArray (which + * means TransactionIdIsInProgress will stop saying the prepared xact is in * progress), then run the post-commit or post-abort callbacks. The * callbacks will release the locks the transaction held. */ @@ -2093,7 +2093,7 @@ RecordTransactionCommitPrepared(TransactionId xid, /* Flush XLOG to disk */ XLogFlush(recptr); - /* Mark the transaction committed in pg_clog */ + /* Mark the transaction committed in pg_transaction */ TransactionIdCommitTree(xid, nchildren, children); /* Checkpoint can proceed now */ diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index e11b229..817b323 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -1206,10 +1206,10 @@ RecordTransactionCommit(void) /* * Mark ourselves as within our "commit critical section". This * forces any concurrent checkpoint to wait until we've updated - * pg_clog. Without this, it is possible for the checkpoint to set - * REDO after the XLOG record but fail to flush the pg_clog update to - * disk, leading to loss of the transaction commit if the system - * crashes a little later. + * pg_transaction. Without this, it is possible for the checkpoint + * to set REDO after the XLOG record but fail to flush the pg_trans + * update to disk, leading to loss of the transaction commit if the + * system crashes a little later. * * Note: we could, but don't bother to, set this flag in * RecordTransactionAbort. That's because loss of a transaction abort @@ -2033,8 +2033,8 @@ CommitTransaction(void) if (!is_parallel_worker) { /* - * We need to mark our XIDs as committed in pg_clog. This is where we - * durably commit. + * We need to mark our XIDs as committed in pg_transaction. This is + * where we durably commit. */ latestXid = RecordTransactionCommit(); } @@ -2539,10 +2539,10 @@ AbortTransaction(void) AtAbort_Twophase(); /* - * Advertise the fact that we aborted in pg_clog (assuming that we got as - * far as assigning an XID to advertise). But if we're inside a parallel - * worker, skip this; the user backend must be the one to write the abort - * record. + * Advertise the fact that we aborted in pg_transaction (assuming that we + * got as far as assigning an XID to advertise). But if we're inside a + * parallel worker, skip this; the user backend must be the one to write + * the abort record. */ if (!is_parallel_worker) latestXid = RecordTransactionAbort(false); @@ -4625,7 +4625,7 @@ AbortSubTransaction(void) s->parent->subTransactionId); AtSubAbort_Notify(); - /* Advertise the fact that we aborted in pg_clog. */ + /* Advertise the fact that we aborted in pg_transaction. */ (void) RecordTransactionAbort(true); /* Post-abort cleanup */ @@ -5371,7 +5371,7 @@ xact_redo_commit(xl_xact_parsed_commit *parsed, if (standbyState == STANDBY_DISABLED) { /* - * Mark the transaction committed in pg_clog. + * Mark the transaction committed in pg_transaction. */ TransactionIdCommitTree(xid, parsed->nsubxacts, parsed->subxacts); } @@ -5389,8 +5389,8 @@ xact_redo_commit(xl_xact_parsed_commit *parsed, RecordKnownAssignedTransactionIds(max_xid); /* - * Mark the transaction committed in pg_clog. We use async commit - * protocol during recovery to provide information on database + * Mark the transaction committed in pg_transaction. We use async + * commit protocol during recovery to provide information on database * consistency for when users try to set hint bits. It is important * that we do not set hint bits until the minRecoveryPoint is past * this commit record. This ensures that if we crash we don't see hint @@ -5526,7 +5526,10 @@ xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid) if (standbyState == STANDBY_DISABLED) { - /* Mark the transaction aborted in pg_clog, no need for async stuff */ + /* + * Mark the transaction aborted in pg_transaction, no need for async + * stuff. + */ TransactionIdAbortTree(xid, parsed->nsubxacts, parsed->subxacts); } else @@ -5542,7 +5545,10 @@ xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid) */ RecordKnownAssignedTransactionIds(max_xid); - /* Mark the transaction aborted in pg_clog, no need for async stuff */ + /* + * Mark the transaction aborted in pg_transaction, no need for async + * stuff. + */ TransactionIdAbortTree(xid, parsed->nsubxacts, parsed->subxacts); /* diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 48c18e8..2262ae0 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8487,9 +8487,9 @@ CreateCheckPoint(int flags) * that are currently in commit critical sections. If an xact inserted * its commit record into XLOG just before the REDO point, then a crash * restart from the REDO point would not replay that record, which means - * that our flushing had better include the xact's update of pg_clog. So - * we wait till he's out of his commit critical section before proceeding. - * See notes in RecordTransactionCommit(). + * that our flushing had better include the xact's update of + * pg_transaction. So we wait till he's out of his commit critical + * section before proceeding. See notes in RecordTransactionCommit(). * * Because we've already released the insertion locks, this test is a bit * fuzzy: it is possible that we will wait for xacts we didn't really need diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 58bbf55..5c61d1a 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -356,8 +356,8 @@ vacuum(int options, RangeVar *relation, Oid relid, VacuumParams *params, if ((options & VACOPT_VACUUM) && !IsAutoVacuumWorkerProcess()) { /* - * Update pg_database.datfrozenxid, and truncate pg_clog if possible. - * (autovacuum.c does this for itself.) + * Update pg_database.datfrozenxid, and truncate pg_transaction if + * possible. (autovacuum.c does this for itself.) */ vac_update_datfrozenxid(); } @@ -880,7 +880,7 @@ vac_update_relstats(Relation relation, * pg_class.relminmxid values. * * If we are able to advance either pg_database value, also try to - * truncate pg_clog and pg_multixact. + * truncate pg_transaction and pg_multixact. * * We violate transaction semantics here by overwriting the database's * existing pg_database tuple with the new values. This is reasonably @@ -1026,7 +1026,7 @@ vac_update_datfrozenxid(void) /* * If we were able to advance datfrozenxid or datminmxid, see if we can - * truncate pg_clog and/or pg_multixact. Also do it if the shared + * truncate pg_transaction and/or pg_multixact. Also do it if the shared * XID-wrap-limit info is stale, since this action will update that too. */ if (dirty || ForceTransactionIdLimitUpdate()) @@ -1039,7 +1039,7 @@ vac_update_datfrozenxid(void) * vac_truncate_clog() -- attempt to truncate the commit log * * Scan pg_database to determine the system-wide oldest datfrozenxid, - * and use it to truncate the transaction commit log (pg_clog). + * and use it to truncate the transaction commit log (pg_transaction). * Also update the XID wrap limit info maintained by varsup.c. * Likewise for datminmxid. * @@ -1086,8 +1086,8 @@ vac_truncate_clog(TransactionId frozenXID, * of the interlock against copying a DB containing an active backend. * Hence the new entry will not reduce the minimum. Also, if two VACUUMs * concurrently modify the datfrozenxid's of different databases, the - * worst possible outcome is that pg_clog is not truncated as aggressively - * as it could be. + * worst possible outcome is that pg_transaction is not truncated as + * aggressively as it could be. */ relation = heap_open(DatabaseRelationId, AccessShareLock); diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 1a92ca1..31fcd51 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -2394,8 +2394,8 @@ deleted: */ /* - * Update pg_database.datfrozenxid, and truncate pg_clog if possible. We - * only need to do this once, not after each table. + * Update pg_database.datfrozenxid, and truncate pg_transaction if + * possible. We only need to do this once, not after each table. */ vac_update_datfrozenxid(); diff --git a/src/backend/storage/buffer/README b/src/backend/storage/buffer/README index 248883f..94da258 100644 --- a/src/backend/storage/buffer/README +++ b/src/backend/storage/buffer/README @@ -63,8 +63,8 @@ at about the same time would OR the same bits into the field, so there is little or no risk of conflicting update; what's more, if there did manage to be a conflict it would merely mean that one bit-update would be lost and need to be done again later. These four bits are only hints -(they cache the results of transaction status lookups in pg_clog), so no -great harm is done if they get reset to zero by conflicting updates. +(they cache the results of transaction status lookups in pg_transaction), +so no great harm is done if they get reset to zero by conflicting updates. Note, however, that a tuple is frozen by setting both HEAP_XMIN_INVALID and HEAP_XMIN_COMMITTED; this is a critical update and accordingly requires an exclusive buffer lock (and it must also be WAL-logged). diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index e5d487d..dd5c79a 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -388,7 +388,7 @@ ProcArrayRemove(PGPROC *proc, TransactionId latestXid) * ProcArrayEndTransaction -- mark a transaction as no longer running * * This is used interchangeably for commit and abort cases. The transaction - * commit/abort must already be reported to WAL and pg_clog. + * commit/abort must already be reported to WAL and pg_transaction. * * proc is currently always MyProc, but we pass it explicitly for flexibility. * latestXid is the latest Xid among the transaction's main XID and @@ -1180,7 +1180,8 @@ TransactionIdIsInProgress(TransactionId xid) * At this point, we know it's either a subtransaction of one of the Xids * in xids[], or it's not running. If it's an already-failed * subtransaction, we want to say "not running" even though its parent may - * still be running. So first, check pg_clog to see if it's been aborted. + * still be running. So first, check pg_transaction to see if it's been + * aborted. */ xc_slow_answer_inc(); diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index 26a3be3..fbf9c6c 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -13,23 +13,24 @@ * NOTE: When using a non-MVCC snapshot, we must check * TransactionIdIsInProgress (which looks in the PGXACT array) * before TransactionIdDidCommit/TransactionIdDidAbort (which look in - * pg_clog). Otherwise we have a race condition: we might decide that a - * just-committed transaction crashed, because none of the tests succeed. - * xact.c is careful to record commit/abort in pg_clog before it unsets - * MyPgXact->xid in the PGXACT array. That fixes that problem, but it - * also means there is a window where TransactionIdIsInProgress and - * TransactionIdDidCommit will both return true. If we check only - * TransactionIdDidCommit, we could consider a tuple committed when a - * later GetSnapshotData call will still think the originating transaction - * is in progress, which leads to application-level inconsistency. The - * upshot is that we gotta check TransactionIdIsInProgress first in all - * code paths, except for a few cases where we are looking at - * subtransactions of our own main transaction and so there can't be any - * race condition. + * pg_transaction). Otherwise we have a race condition: we might decide + * that a just-committed transaction crashed, because none of the tests + * succeed. xact.c is careful to record commit/abort in pg_transaction + * before it unsets MyPgXact->xid in the PGXACT array. That fixes that + * problem, but it also means there is a window where + * TransactionIdIsInProgress and TransactionIdDidCommit will both return + * true. If we check only TransactionIdDidCommit, we could consider a + * tuple committed when a later GetSnapshotData call will still think + * the originating transaction is in progress, which leads to + * application-level inconsistency. The upshot is that we gotta check + * TransactionIdIsInProgress first in all code paths, except for a few + * cases where we are looking at subtransactions of our own main + * transaction and so there can't be any race condition. * * When using an MVCC snapshot, we rely on XidInMVCCSnapshot rather than * TransactionIdIsInProgress, but the logic is otherwise the same: do not - * check pg_clog until after deciding that the xact is no longer in progress. + * check pg_transaction until after deciding that the xact is no longer + * in progress. * * * Summary of visibility functions: diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 385e808..974f11a 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -196,7 +196,6 @@ static const char *backend_options = "--single -F -O -j -c search_path=pg_catalo static const char *const subdirs[] = { "global", "pg_wal/archive_status", - "pg_clog", "pg_commit_ts", "pg_dynshmem", "pg_notify", @@ -213,6 +212,7 @@ static const char *const subdirs[] = { "pg_tblspc", "pg_stat", "pg_stat_tmp", + "pg_transaction", "pg_logical", "pg_logical/snapshots", "pg_logical/mappings" diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 55a6f0d..a3a0a0f 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -309,6 +309,12 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_xlog"); else check_single_dir(pg_data, "pg_wal"); + + /* pg_clog has been renamed to pg_transaction in post-10 cluster */ + if (GET_MAJOR_VERSION(cluster->major_version) < 1000) + check_single_dir(pg_data, "pg_clog"); + else + check_single_dir(pg_data, "pg_transaction"); } diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index 90c0720..04704c2 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -47,7 +47,7 @@ static void prepare_new_cluster(void); static void prepare_new_databases(void); static void create_new_objects(void); -static void copy_clog_xlog_xid(void); +static void copy_trans_xlog_xid(void); static void set_frozenxids(bool minmxid_only); static void setup(char *argv0, bool *live_check); static void cleanup(void); @@ -113,7 +113,7 @@ main(int argc, char **argv) * Destructive Changes to New Cluster */ - copy_clog_xlog_xid(); + copy_trans_xlog_xid(); /* New now using xids of the old system */ @@ -374,17 +374,17 @@ remove_new_subdir(char *subdir, bool rmtopdir) * Copy the files from the old cluster into it */ static void -copy_subdir_files(char *subdir) +copy_subdir_files(char *old_subdir, char *new_subdir) { char old_path[MAXPGPATH]; char new_path[MAXPGPATH]; - remove_new_subdir(subdir, true); + remove_new_subdir(new_subdir, true); - snprintf(old_path, sizeof(old_path), "%s/%s", old_cluster.pgdata, subdir); - snprintf(new_path, sizeof(new_path), "%s/%s", new_cluster.pgdata, subdir); + snprintf(old_path, sizeof(old_path), "%s/%s", old_cluster.pgdata, old_subdir); + snprintf(new_path, sizeof(new_path), "%s/%s", new_cluster.pgdata, new_subdir); - prep_status("Copying old %s to new server", subdir); + prep_status("Copying old %s to new server", old_subdir); exec_prog(UTILITY_LOG_FILE, NULL, true, #ifndef WIN32 @@ -399,10 +399,16 @@ copy_subdir_files(char *subdir) } static void -copy_clog_xlog_xid(void) +copy_trans_xlog_xid(void) { - /* copy old commit logs to new data dir */ - copy_subdir_files("pg_clog"); + /* + * Copy old commit logs to new data dir. pg_clog has been renamed to + * pg_transaction in post-10 clusters. + */ + copy_subdir_files(GET_MAJOR_VERSION(old_cluster.major_version) < 1000 ? + "pg_clog" : "pg_transaction", + GET_MAJOR_VERSION(new_cluster.major_version) < 1000 ? + "pg_clog" : "pg_transaction"); /* set the next transaction id and epoch of the new cluster */ prep_status("Setting next transaction ID and epoch for new cluster"); @@ -432,8 +438,8 @@ copy_clog_xlog_xid(void) if (old_cluster.controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER && new_cluster.controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER) { - copy_subdir_files("pg_multixact/offsets"); - copy_subdir_files("pg_multixact/members"); + copy_subdir_files("pg_multixact/offsets", "pg_multixact/offsets"); + copy_subdir_files("pg_multixact/members", "pg_multixact/members"); prep_status("Setting next multixact ID and offset for new cluster"); diff --git a/src/include/access/slru.h b/src/include/access/slru.h index 5fcebc5..001817f 100644 --- a/src/include/access/slru.h +++ b/src/include/access/slru.h @@ -76,10 +76,10 @@ typedef struct SlruSharedData /* * Optional array of WAL flush LSNs associated with entries in the SLRU * pages. If not zero/NULL, we must flush WAL before writing pages (true - * for pg_clog, false for multixact, pg_subtrans, pg_notify). group_lsn[] - * has lsn_groups_per_page entries per buffer slot, each containing the - * highest LSN known for a contiguous group of SLRU entries on that slot's - * page. + * for pg_transaction, false for multixact, pg_subtrans, pg_notify). + * group_lsn[] has lsn_groups_per_page entries per buffer slot, each + * containing the highest LSN known for a contiguous group of SLRU entries + * on that slot's page. */ XLogRecPtr *group_lsn; int lsn_groups_per_page; @@ -120,8 +120,8 @@ typedef struct SlruCtlData SlruShared shared; /* - * This flag tells whether to fsync writes (true for pg_clog and multixact - * stuff, false for pg_subtrans and pg_notify). + * This flag tells whether to fsync writes (true for pg_transaction and + * multixact stuff, false for pg_subtrans and pg_notify). */ bool do_fsync; -- 2.10.0