diff options
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/dbcommands.c | 14 | ||||
-rw-r--r-- | src/backend/commands/tablespace.c | 18 | ||||
-rw-r--r-- | src/backend/commands/vacuum.c | 22 |
3 files changed, 48 insertions, 6 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 4ceb962fb95..34b6da99df9 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.196 2007/06/28 00:02:38 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.197 2007/08/01 22:45:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -515,7 +515,11 @@ createdb(const CreatedbStmt *stmt) heap_close(pg_database_rel, NoLock); /* - * Set flag to update flat database file at commit. + * Set flag to update flat database file at commit. Note: this also + * forces synchronous commit, which minimizes the window between + * creation of the database files and commital of the transaction. + * If we crash before committing, we'll have a DB that's taking up + * disk space but is not in pg_database, which is not good. */ database_file_update_needed(); } @@ -675,7 +679,11 @@ dropdb(const char *dbname, bool missing_ok) heap_close(pgdbrel, NoLock); /* - * Set flag to update flat database file at commit. + * Set flag to update flat database file at commit. Note: this also + * forces synchronous commit, which minimizes the window between + * removal of the database files and commital of the transaction. + * If we crash before committing, we'll have a DB that's gone on disk + * but still there according to pg_database, which is not good. */ database_file_update_needed(); } diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c index d0dacf10782..f19e237315e 100644 --- a/src/backend/commands/tablespace.c +++ b/src/backend/commands/tablespace.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.48 2007/06/07 19:19:56 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.49 2007/08/01 22:45:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -354,6 +354,14 @@ CreateTableSpace(CreateTableSpaceStmt *stmt) (void) XLogInsert(RM_TBLSPC_ID, XLOG_TBLSPC_CREATE, rdata); } + /* + * Force synchronous commit, to minimize the window between creating + * the symlink on-disk and marking the transaction committed. It's + * not great that there is any window at all, but definitely we don't + * want to make it larger than necessary. + */ + ForceSyncCommit(); + pfree(linkloc); pfree(location); @@ -481,6 +489,14 @@ DropTableSpace(DropTableSpaceStmt *stmt) */ /* + * Force synchronous commit, to minimize the window between removing + * the files on-disk and marking the transaction committed. It's + * not great that there is any window at all, but definitely we don't + * want to make it larger than necessary. + */ + ForceSyncCommit(); + + /* * Allow TablespaceCreateDbspace again. */ LWLockRelease(TablespaceCreateLock); diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 8fa17ab2350..41c3b867912 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.353 2007/06/14 13:53:14 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.354 2007/08/01 22:45:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -27,6 +27,7 @@ #include "access/heapam.h" #include "access/transam.h" #include "access/xact.h" +#include "access/xlog.h" #include "catalog/namespace.h" #include "catalog/pg_database.h" #include "commands/dbcommands.h" @@ -1162,6 +1163,16 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt) vacuum_set_xid_limits(vacstmt->freeze_min_age, onerel->rd_rel->relisshared, &OldestXmin, &FreezeLimit); + /* + * VACUUM FULL assumes that all tuple states are well-known prior to + * moving tuples around --- see comment "known dead" in repair_frag(), + * as well as simplifications in tqual.c. So before we start we must + * ensure that any asynchronously-committed transactions with changes + * against this table have been flushed to disk. It's sufficient to do + * this once after we've acquired AccessExclusiveLock. + */ + XLogAsyncCommitFlush(); + /* * Set up statistics-gathering machinery. */ @@ -2373,8 +2384,15 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, * exclusive access to the relation. However, that would require a * lot of extra code to close and re-open the relation, indexes, etc. * For now, a quick hack: record status of current transaction as - * committed, and continue. + * committed, and continue. We force the commit to be synchronous + * so that it's down to disk before we truncate. (Note: tqual.c + * knows that VACUUM FULL always uses sync commit, too.) + * + * XXX This desperately needs to be revisited. Any failure after + * this point will result in a PANIC "cannot abort transaction nnn, + * it was already committed"! */ + ForceSyncCommit(); RecordTransactionCommit(); } |