A prototype patch is posted to -patches, which is WORK IN PROGRESS. [This patch matches discussion thread on -hackers.]
The following TODO items remain 1. discuss which process will issue regular XLogFlush(). If agreed, implement WALWriter process to perform this task. (Yes, the patch isn't fully implemented, yet). 2. remove fsync parameter 3. Prevent COMMIT NOWAIT when commit_delay = 0 4. Discuss whether commit_delay is OK to usurp; twas just an earlier suggestion from someone else, can go either way. 5. docs -- Simon Riggs EnterpriseDB http://www.enterprisedb.com
Index: src/backend/access/transam/xact.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xact.c,v retrieving revision 1.234 diff -c -r1.234 xact.c *** src/backend/access/transam/xact.c 9 Feb 2007 03:35:33 -0000 1.234 --- src/backend/access/transam/xact.c 26 Feb 2007 22:04:44 -0000 *************** *** 58,63 **** --- 58,66 ---- int CommitDelay = 0; /* precommit delay in microseconds */ int CommitSiblings = 5; /* # concurrent xacts needed to sleep */ + bool DefaultXactCommitWait = true; + bool XactCommitWait = true; + /* * transaction states - transaction state from server perspective *************** *** 789,795 **** * Note: if we generated a commit record above, MyXactMadeXLogEntry * will certainly be set now. */ ! if (MyXactMadeXLogEntry) { /* * Sleep before flush! So we can flush more than one commit --- 792,798 ---- * Note: if we generated a commit record above, MyXactMadeXLogEntry * will certainly be set now. */ ! if (MyXactMadeXLogEntry && XactCommitWait) { /* * Sleep before flush! So we can flush more than one commit Index: src/backend/parser/gram.y =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/parser/gram.y,v retrieving revision 2.580 diff -c -r2.580 gram.y *** src/backend/parser/gram.y 20 Feb 2007 17:32:16 -0000 2.580 --- src/backend/parser/gram.y 26 Feb 2007 22:05:01 -0000 *************** *** 4813,4818 **** --- 4813,4819 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_ROLLBACK; n->options = NIL; + n->wait = true; $$ = (Node *)n; } | BEGIN_P opt_transaction transaction_mode_list_or_empty *************** *** 4820,4825 **** --- 4821,4827 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_BEGIN; n->options = $3; + n->wait = true; $$ = (Node *)n; } | START TRANSACTION transaction_mode_list_or_empty *************** *** 4827,4832 **** --- 4829,4835 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_START; n->options = $3; + n->wait = true; $$ = (Node *)n; } | COMMIT opt_transaction *************** *** 4834,4839 **** --- 4837,4851 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_COMMIT; n->options = NIL; + n->wait = true; + $$ = (Node *)n; + } + | COMMIT opt_transaction_write NOWAIT opt_transaction_immed + { + TransactionStmt *n = makeNode(TransactionStmt); + n->kind = TRANS_STMT_COMMIT; + n->options = NIL; + n->wait = false; $$ = (Node *)n; } | END_P opt_transaction *************** *** 4841,4846 **** --- 4853,4859 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_COMMIT; n->options = NIL; + n->wait = true; $$ = (Node *)n; } | ROLLBACK opt_transaction *************** *** 4848,4853 **** --- 4861,4867 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_ROLLBACK; n->options = NIL; + n->wait = true; $$ = (Node *)n; } | SAVEPOINT ColId *************** *** 4856,4861 **** --- 4870,4876 ---- n->kind = TRANS_STMT_SAVEPOINT; n->options = list_make1(makeDefElem("savepoint_name", (Node *)makeString($2))); + n->wait = true; $$ = (Node *)n; } | RELEASE SAVEPOINT ColId *************** *** 4864,4869 **** --- 4879,4885 ---- n->kind = TRANS_STMT_RELEASE; n->options = list_make1(makeDefElem("savepoint_name", (Node *)makeString($3))); + n->wait = true; $$ = (Node *)n; } | RELEASE ColId *************** *** 4872,4877 **** --- 4888,4894 ---- n->kind = TRANS_STMT_RELEASE; n->options = list_make1(makeDefElem("savepoint_name", (Node *)makeString($2))); + n->wait = true; $$ = (Node *)n; } | ROLLBACK opt_transaction TO SAVEPOINT ColId *************** *** 4880,4885 **** --- 4897,4903 ---- n->kind = TRANS_STMT_ROLLBACK_TO; n->options = list_make1(makeDefElem("savepoint_name", (Node *)makeString($5))); + n->wait = true; $$ = (Node *)n; } | ROLLBACK opt_transaction TO ColId *************** *** 4888,4893 **** --- 4906,4912 ---- n->kind = TRANS_STMT_ROLLBACK_TO; n->options = list_make1(makeDefElem("savepoint_name", (Node *)makeString($4))); + n->wait = true; $$ = (Node *)n; } | PREPARE TRANSACTION Sconst *************** *** 4895,4900 **** --- 4914,4920 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_PREPARE; n->gid = $3; + n->wait = true; $$ = (Node *)n; } | COMMIT PREPARED Sconst *************** *** 4902,4907 **** --- 4922,4928 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_COMMIT_PREPARED; n->gid = $3; + n->wait = true; $$ = (Node *)n; } | ROLLBACK PREPARED Sconst *************** *** 4909,4914 **** --- 4930,4936 ---- TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_ROLLBACK_PREPARED; n->gid = $3; + n->wait = true; $$ = (Node *)n; } ; *************** *** 4918,4923 **** --- 4940,4955 ---- | /*EMPTY*/ {} ; + opt_transaction_write: + WRITE {} + | /* EMPTY */ {} + ; + + opt_transaction_immed: + IMMEDIATE {} + | /* EMPTY */ {} + ; + transaction_mode_item: ISOLATION LEVEL iso_level { $$ = makeDefElem("transaction_isolation", Index: src/backend/tcop/utility.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/tcop/utility.c,v retrieving revision 1.273 diff -c -r1.273 utility.c *** src/backend/tcop/utility.c 20 Feb 2007 17:32:16 -0000 1.273 --- src/backend/tcop/utility.c 26 Feb 2007 22:05:12 -0000 *************** *** 432,437 **** --- 432,444 ---- if (completionTag) strcpy(completionTag, "ROLLBACK"); } + else + { + if (stmt->wait) + XactCommitWait = DefaultXactCommitWait; + else + XactCommitWait = false; + } break; case TRANS_STMT_PREPARE: Index: src/backend/utils/misc/guc.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/utils/misc/guc.c,v retrieving revision 1.377 diff -c -r1.377 guc.c *** src/backend/utils/misc/guc.c 23 Feb 2007 21:36:18 -0000 1.377 --- src/backend/utils/misc/guc.c 26 Feb 2007 22:05:21 -0000 *************** *** 871,876 **** --- 871,884 ---- true, assign_phony_autocommit, NULL }, { + {"commit_wait_default", PGC_USERSET, WAL_SETTINGS, + gettext_noop("Sets the default of wait-for-commit."), + NULL + }, + &DefaultXactCommitWait, + true, NULL, NULL + }, + { {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT, gettext_noop("Sets the default read-only status of new transactions."), NULL Index: src/backend/utils/misc/postgresql.conf.sample =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/utils/misc/postgresql.conf.sample,v retrieving revision 1.209 diff -c -r1.209 postgresql.conf.sample *** src/backend/utils/misc/postgresql.conf.sample 16 Feb 2007 17:07:00 -0000 1.209 --- src/backend/utils/misc/postgresql.conf.sample 26 Feb 2007 22:05:22 -0000 *************** *** 161,166 **** --- 161,167 ---- #full_page_writes = on # recover from partial page writes #wal_buffers = 64kB # min 32kB # (change requires restart) + #commit_wait_default = on # default wait-at-commit #commit_delay = 0 # range 0-100000, in microseconds #commit_siblings = 5 # range 1-1000 Index: src/include/access/xact.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/access/xact.h,v retrieving revision 1.84 diff -c -r1.84 xact.h *** src/include/access/xact.h 5 Jan 2007 22:19:51 -0000 1.84 --- src/include/access/xact.h 26 Feb 2007 22:05:28 -0000 *************** *** 41,46 **** --- 41,49 ---- extern bool DefaultXactReadOnly; extern bool XactReadOnly; + extern bool DefaultXactCommitWait; + extern bool XactCommitWait; + /* * start- and end-of-transaction callbacks for dynamically loaded modules */ Index: src/include/nodes/parsenodes.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/nodes/parsenodes.h,v retrieving revision 1.341 diff -c -r1.341 parsenodes.h *** src/include/nodes/parsenodes.h 20 Feb 2007 17:32:17 -0000 1.341 --- src/include/nodes/parsenodes.h 26 Feb 2007 22:05:30 -0000 *************** *** 1689,1694 **** --- 1689,1695 ---- NodeTag type; TransactionStmtKind kind; /* see above */ List *options; /* for BEGIN/START and savepoint commands */ + bool wait; /* explicit NOWAIT or use default wait-at-commit */ char *gid; /* for two-phase-commit related commands */ } TransactionStmt;
---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings