Commit e16f04cf authored by Tom Lane's avatar Tom Lane

Make CREATE/ALTER/DROP USER/GROUP transaction-safe, or at least pretty

nearly so, by postponing write of flat password file until transaction
commit.
parent de9d7f4b
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.132 2002/09/04 20:31:13 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.133 2002/10/21 19:46:45 tgl Exp $
* *
* NOTES * NOTES
* Transaction aborts can now occur two ways: * Transaction aborts can now occur two ways:
...@@ -167,6 +167,7 @@ ...@@ -167,6 +167,7 @@
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "commands/async.h" #include "commands/async.h"
#include "commands/trigger.h" #include "commands/trigger.h"
#include "commands/user.h"
#include "executor/spi.h" #include "executor/spi.h"
#include "libpq/be-fsstubs.h" #include "libpq/be-fsstubs.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -959,18 +960,25 @@ CommitTransaction(void) ...@@ -959,18 +960,25 @@ CommitTransaction(void)
s->state = TRANS_COMMIT; s->state = TRANS_COMMIT;
/* /*
* do commit processing * Do pre-commit processing (most of this stuff requires database
* access, and in fact could still cause an error...)
*/ */
AtEOXact_portals();
/* handle commit for large objects [ PA, 7/17/98 ] */ /* handle commit for large objects [ PA, 7/17/98 ] */
/* XXX probably this does not belong here */
lo_commit(true); lo_commit(true);
/* NOTIFY commit must also come before lower-level cleanup */ /* NOTIFY commit must come before lower-level cleanup */
AtCommit_Notify(); AtCommit_Notify();
AtEOXact_portals(); /* Update the flat password file if we changed pg_shadow or pg_group */
AtEOXact_UpdatePasswordFile(true);
/* Here is where we really truly commit. */ /*
* Here is where we really truly commit.
*/
RecordTransactionCommit(); RecordTransactionCommit();
/* /*
...@@ -1013,7 +1021,6 @@ CommitTransaction(void) ...@@ -1013,7 +1021,6 @@ CommitTransaction(void)
AtEOXact_CatCache(true); AtEOXact_CatCache(true);
AtCommit_Memory(); AtCommit_Memory();
AtEOXact_Buffers(true); AtEOXact_Buffers(true);
smgrabort();
AtEOXact_Files(); AtEOXact_Files();
/* Count transaction commit in statistics collector */ /* Count transaction commit in statistics collector */
...@@ -1080,9 +1087,10 @@ AbortTransaction(void) ...@@ -1080,9 +1087,10 @@ AbortTransaction(void)
* do abort processing * do abort processing
*/ */
DeferredTriggerAbortXact(); DeferredTriggerAbortXact();
AtEOXact_portals();
lo_commit(false); /* 'false' means it's abort */ lo_commit(false); /* 'false' means it's abort */
AtAbort_Notify(); AtAbort_Notify();
AtEOXact_portals(); AtEOXact_UpdatePasswordFile(false);
/* Advertise the fact that we aborted in pg_clog. */ /* Advertise the fact that we aborted in pg_clog. */
RecordTransactionAbort(); RecordTransactionAbort();
...@@ -1114,6 +1122,7 @@ AbortTransaction(void) ...@@ -1114,6 +1122,7 @@ AbortTransaction(void)
AtEOXact_CatCache(false); AtEOXact_CatCache(false);
AtAbort_Memory(); AtAbort_Memory();
AtEOXact_Buffers(false); AtEOXact_Buffers(false);
smgrabort();
AtEOXact_Files(); AtEOXact_Files();
AtAbort_Locks(); AtAbort_Locks();
......
This diff is collapsed.
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* user.h * user.h
* Commands for manipulating users and groups.
* *
* *
* $Id: user.h,v 1.19 2002/09/04 20:31:42 momjian Exp $ * $Id: user.h,v 1.20 2002/10/21 19:46:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -13,13 +14,10 @@ ...@@ -13,13 +14,10 @@
#include "fmgr.h" #include "fmgr.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#define PWD_FILE "pg_pwd"
#define USER_GROUP_FILE "pg_group"
extern char *group_getfilename(void); extern char *group_getfilename(void);
extern char *user_getfilename(void); extern char *user_getfilename(void);
extern void CreateUser(CreateUserStmt *stmt); extern void CreateUser(CreateUserStmt *stmt);
extern void AlterUser(AlterUserStmt *stmt); extern void AlterUser(AlterUserStmt *stmt);
extern void AlterUserSet(AlterUserSetStmt *stmt); extern void AlterUserSet(AlterUserSetStmt *stmt);
...@@ -31,4 +29,6 @@ extern void DropGroup(DropGroupStmt *stmt); ...@@ -31,4 +29,6 @@ extern void DropGroup(DropGroupStmt *stmt);
extern Datum update_pg_pwd_and_pg_group(PG_FUNCTION_ARGS); extern Datum update_pg_pwd_and_pg_group(PG_FUNCTION_ARGS);
extern void AtEOXact_UpdatePasswordFile(bool isCommit);
#endif /* USER_H */ #endif /* USER_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment