diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-02-07 20:48:13 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-02-07 20:48:13 +0000 |
commit | b9b8831ad60f6e4bd580fe6dbe9749359298a3c4 (patch) | |
tree | af6948498f13a43edd982b05808ed89b5b8191ab /src/backend/access | |
parent | 7fc30c488fc6e9674564206193c29b1a657a818f (diff) | |
download | postgresql-b9b8831ad60f6e4bd580fe6dbe9749359298a3c4.tar.gz postgresql-b9b8831ad60f6e4bd580fe6dbe9749359298a3c4.zip |
Create a "relation mapping" infrastructure to support changing the relfilenodes
of shared or nailed system catalogs. This has two key benefits:
* The new CLUSTER-based VACUUM FULL can be applied safely to all catalogs.
* We no longer have to use an unsafe reindex-in-place approach for reindexing
shared catalogs.
CLUSTER on nailed catalogs now works too, although I left it disabled on
shared catalogs because the resulting pg_index.indisclustered update would
only be visible in one database.
Since reindexing shared system catalogs is now fully transactional and
crash-safe, the former special cases in REINDEX behavior have been removed;
shared catalogs are treated the same as non-shared.
This commit does not do anything about the recently-discussed problem of
deadlocks between VACUUM FULL/CLUSTER on a system catalog and other
concurrent queries; will address that in a separate patch. As a stopgap,
parallel_schedule has been tweaked to run vacuum.sql by itself, to avoid
such failures during the regression tests.
Diffstat (limited to 'src/backend/access')
-rw-r--r-- | src/backend/access/index/genam.c | 5 | ||||
-rw-r--r-- | src/backend/access/transam/rmgr.c | 5 | ||||
-rw-r--r-- | src/backend/access/transam/xact.c | 41 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 4 |
4 files changed, 40 insertions, 15 deletions
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c index ddc3f6b4f96..bd280360879 100644 --- a/src/backend/access/index/genam.c +++ b/src/backend/access/index/genam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.79 2010/01/02 16:57:35 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.80 2010/02/07 20:48:09 tgl Exp $ * * NOTES * many of the old access method routines have been turned into @@ -21,6 +21,7 @@ #include "access/relscan.h" #include "access/transam.h" +#include "catalog/index.h" #include "miscadmin.h" #include "pgstat.h" #include "storage/bufmgr.h" @@ -419,7 +420,7 @@ systable_beginscan_ordered(Relation heapRelation, /* REINDEX can probably be a hard error here ... */ if (ReindexIsProcessingIndex(RelationGetRelid(indexRelation))) - elog(ERROR, "cannot do ordered scan on index \"%s\", because it is the current REINDEX target", + elog(ERROR, "cannot do ordered scan on index \"%s\", because it is being reindexed", RelationGetRelationName(indexRelation)); /* ... but we only throw a warning about violating IgnoreSystemIndexes */ if (IgnoreSystemIndexes) diff --git a/src/backend/access/transam/rmgr.c b/src/backend/access/transam/rmgr.c index 7e1e0f60fc3..8038b25d1d0 100644 --- a/src/backend/access/transam/rmgr.c +++ b/src/backend/access/transam/rmgr.c @@ -3,7 +3,7 @@ * * Resource managers definition * - * $PostgreSQL: pgsql/src/backend/access/transam/rmgr.c,v 1.28 2009/12/19 01:32:33 sriggs Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/rmgr.c,v 1.29 2010/02/07 20:48:09 tgl Exp $ */ #include "postgres.h" @@ -22,6 +22,7 @@ #include "commands/tablespace.h" #include "storage/freespace.h" #include "storage/standby.h" +#include "utils/relmapper.h" const RmgrData RmgrTable[RM_MAX_ID + 1] = { @@ -32,7 +33,7 @@ const RmgrData RmgrTable[RM_MAX_ID + 1] = { {"Database", dbase_redo, dbase_desc, NULL, NULL, NULL}, {"Tablespace", tblspc_redo, tblspc_desc, NULL, NULL, NULL}, {"MultiXact", multixact_redo, multixact_desc, NULL, NULL, NULL}, - {"Reserved 7", NULL, NULL, NULL, NULL, NULL}, + {"RelMap", relmap_redo, relmap_desc, NULL, NULL, NULL}, {"Standby", standby_redo, standby_desc, NULL, NULL, NULL}, {"Heap2", heap2_redo, heap2_desc, NULL, NULL, NULL}, {"Heap", heap_redo, heap_desc, NULL, NULL, NULL}, diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index f74a941f66e..156ed5c47be 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.282 2010/01/24 21:49:17 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.283 2010/02/07 20:48:09 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -48,6 +48,7 @@ #include "utils/inval.h" #include "utils/memutils.h" #include "utils/relcache.h" +#include "utils/relmapper.h" #include "utils/snapmgr.h" #include "pg_trace.h" @@ -250,7 +251,7 @@ static void AbortTransaction(void); static void AtAbort_Memory(void); static void AtCleanup_Memory(void); static void AtAbort_ResourceOwner(void); -static void AtCommit_LocalCache(void); +static void AtCCI_LocalCache(void); static void AtCommit_Memory(void); static void AtStart_Cache(void); static void AtStart_Memory(void); @@ -703,7 +704,7 @@ CommandCounterIncrement(void) * read-only command. (But see hacks in inval.c to make real sure we * don't think a command that queued inval messages was read-only.) */ - AtCommit_LocalCache(); + AtCCI_LocalCache(); } /* @@ -1095,12 +1096,20 @@ cleanup: /* - * AtCommit_LocalCache + * AtCCI_LocalCache */ static void -AtCommit_LocalCache(void) +AtCCI_LocalCache(void) { /* + * Make any pending relation map changes visible. We must do this + * before processing local sinval messages, so that the map changes + * will get reflected into the relcache when relcache invals are + * processed. + */ + AtCCI_RelationMap(); + + /* * Make catalog changes visible to me for the next command. */ CommandEndInvalidationMessages(); @@ -1734,6 +1743,9 @@ CommitTransaction(void) /* Prevent cancel/die interrupt while cleaning up */ HOLD_INTERRUPTS(); + /* Commit updates to the relation map --- do this as late as possible */ + AtEOXact_RelationMap(true); + /* * set the current transaction state information appropriately during * commit processing @@ -1980,6 +1992,7 @@ PrepareTransaction(void) AtPrepare_Locks(); AtPrepare_PgStat(); AtPrepare_MultiXact(); + AtPrepare_RelationMap(); /* * Here is where we really truly prepare. @@ -2148,10 +2161,11 @@ AbortTransaction(void) /* * do abort processing */ - AfterTriggerEndXact(false); + AfterTriggerEndXact(false); /* 'false' means it's abort */ AtAbort_Portals(); - AtEOXact_LargeObject(false); /* 'false' means it's abort */ + AtEOXact_LargeObject(false); AtAbort_Notify(); + AtEOXact_RelationMap(false); /* * Advertise the fact that we aborted in pg_clog (assuming that we got as @@ -4625,11 +4639,18 @@ xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec) SharedInvalidationMessage *msg = &msgs[i]; if (msg->id >= 0) - appendStringInfo(buf, "catcache id%d ", msg->id); + appendStringInfo(buf, " catcache %d", msg->id); + else if (msg->id == SHAREDINVALCATALOG_ID) + appendStringInfo(buf, " catalog %u", msg->cat.catId); else if (msg->id == SHAREDINVALRELCACHE_ID) - appendStringInfo(buf, "relcache "); + appendStringInfo(buf, " relcache %u", msg->rc.relId); + /* remaining cases not expected, but print something anyway */ else if (msg->id == SHAREDINVALSMGR_ID) - appendStringInfo(buf, "smgr "); + appendStringInfo(buf, " smgr"); + else if (msg->id == SHAREDINVALRELMAP_ID) + appendStringInfo(buf, " relmap"); + else + appendStringInfo(buf, " unknown id %d", msg->id); } } } diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 49adda12f9a..f4b03f4c1be 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.366 2010/02/01 13:40:28 sriggs Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.367 2010/02/07 20:48:09 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,7 @@ #include "utils/builtins.h" #include "utils/guc.h" #include "utils/ps_status.h" +#include "utils/relmapper.h" #include "pg_trace.h" @@ -7123,6 +7124,7 @@ CheckPointGuts(XLogRecPtr checkPointRedo, int flags) CheckPointCLOG(); CheckPointSUBTRANS(); CheckPointMultiXact(); + CheckPointRelationMap(); CheckPointBuffers(flags); /* performs all required fsyncs */ /* We deliberately delay 2PC checkpointing as long as possible */ CheckPointTwoPhase(checkPointRedo); |