mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +03:00
Support an optional asynchronous commit mode, in which we don't flush WAL
before reporting a transaction committed. Data consistency is still guaranteed (unlike setting fsync = off), but a crash may lose the effects of the last few transactions. Patch by Simon, some editorialization by Tom.
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
@ -480,6 +488,14 @@ DropTableSpace(DropTableSpaceStmt *stmt)
|
||||
* entries for relations in the tablespace.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user