aboutsummaryrefslogtreecommitdiff
path: root/src/backend/postmaster/checkpointer.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-07-18 15:28:17 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-07-18 15:28:17 -0400
commitd843589e5ab361dd4738dab5c9016e704faf4153 (patch)
tree58678d67237e99544284fab78bc2a24cd1c25e18 /src/backend/postmaster/checkpointer.c
parentebd9e26daa3df6518e3d403ef94a86e33168eae3 (diff)
downloadpostgresql-d843589e5ab361dd4738dab5c9016e704faf4153.tar.gz
postgresql-d843589e5ab361dd4738dab5c9016e704faf4153.zip
Fix management of pendingOpsTable in auxiliary processes.
mdinit() was misusing IsBootstrapProcessingMode() to decide whether to create an fsync pending-operations table in the current process. This led to creating a table not only in the startup and checkpointer processes as intended, but also in the bgwriter process, not to mention other auxiliary processes such as walwriter and walreceiver. Creation of the table in the bgwriter is fatal, because it absorbs fsync requests that should have gone to the checkpointer; instead they just sit in bgwriter local memory and are never acted on. So writes performed by the bgwriter were not being fsync'd which could result in data loss after an OS crash. I think there is no live bug with respect to walwriter and walreceiver because those never perform any writes of shared buffers; but the potential is there for future breakage in those processes too. To fix, make AuxiliaryProcessMain() export the current process's AuxProcType as a global variable, and then make mdinit() test directly for the types of aux process that should have a pendingOpsTable. Having done that, we might as well also get rid of the random bool flags such as am_walreceiver that some of the aux processes had grown. (Note that we could not have fixed the bug by examining those variables in mdinit(), because it's called from BaseInit() which is run by AuxiliaryProcessMain() before entering any of the process-type-specific code.) Back-patch to 9.2, where the problem was introduced by the split-up of bgwriter and checkpointer processes. The bogus pendingOpsTable exists in walwriter and walreceiver processes in earlier branches, but absent any evidence that it causes actual problems there, I'll leave the older branches alone.
Diffstat (limited to 'src/backend/postmaster/checkpointer.c')
-rw-r--r--src/backend/postmaster/checkpointer.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index fe4f4053588..aa5577d3570 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -153,8 +153,6 @@ static volatile sig_atomic_t shutdown_requested = false;
/*
* Private state
*/
-static bool am_checkpointer = false;
-
static bool ckpt_active = false;
/* these values are valid when ckpt_active is true: */
@@ -185,8 +183,8 @@ static void ReqShutdownHandler(SIGNAL_ARGS);
/*
* Main entry point for checkpointer process
*
- * This is invoked from BootstrapMain, which has already created the basic
- * execution environment, but not enabled signals yet.
+ * This is invoked from AuxiliaryProcessMain, which has already created the
+ * basic execution environment, but not enabled signals yet.
*/
void
CheckpointerMain(void)
@@ -195,7 +193,6 @@ CheckpointerMain(void)
MemoryContext checkpointer_context;
CheckpointerShmem->checkpointer_pid = MyProcPid;
- am_checkpointer = true;
/*
* If possible, make this process a group leader, so that the postmaster
@@ -685,7 +682,7 @@ CheckpointWriteDelay(int flags, double progress)
static int absorb_counter = WRITES_PER_ABSORB;
/* Do nothing if checkpoint is being executed by non-checkpointer process */
- if (!am_checkpointer)
+ if (!AmCheckpointerProcess())
return;
/*
@@ -1132,7 +1129,7 @@ ForwardFsyncRequest(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
if (!IsUnderPostmaster)
return false; /* probably shouldn't even get here */
- if (am_checkpointer)
+ if (AmCheckpointerProcess())
elog(ERROR, "ForwardFsyncRequest must not be called in checkpointer");
LWLockAcquire(CheckpointerCommLock, LW_EXCLUSIVE);
@@ -1309,7 +1306,7 @@ AbsorbFsyncRequests(void)
CheckpointerRequest *request;
int n;
- if (!am_checkpointer)
+ if (!AmCheckpointerProcess())
return;
/*