Commit c670410e authored by Tom Lane's avatar Tom Lane

Move the responsibility for calling StartupXLOG into InitPostgres, for

those process types that go through InitPostgres; in particular, bootstrap
and standalone-backend cases.  This ensures that we have set up a PGPROC
and done some other basic initialization steps (corresponding to the
if (IsUnderPostmaster) block in AuxiliaryProcessMain) before we attempt to
run WAL recovery in a standalone backend.  As was discovered last September,
this is necessary for some corner-case code paths during WAL recovery,
particularly end-of-WAL cleanup.

Moving the bootstrap case here too is not necessary for correctness, but it
seems like a good idea since it reduces the number of distinct code paths.
parent ee7769bb
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.260 2010/02/26 02:00:35 momjian Exp $ * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.261 2010/04/20 01:38:52 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -397,14 +397,13 @@ AuxiliaryProcessMain(int argc, char *argv[]) ...@@ -397,14 +397,13 @@ AuxiliaryProcessMain(int argc, char *argv[])
switch (auxType) switch (auxType)
{ {
case CheckerProcess: case CheckerProcess:
bootstrap_signals(); /* don't set signals, they're useless here */
CheckerModeMain(); CheckerModeMain();
proc_exit(1); /* should never return */ proc_exit(1); /* should never return */
case BootstrapProcess: case BootstrapProcess:
bootstrap_signals(); bootstrap_signals();
BootStrapXLOG(); BootStrapXLOG();
StartupXLOG();
BootstrapModeMain(); BootstrapModeMain();
proc_exit(1); /* should never return */ proc_exit(1); /* should never return */
...@@ -438,23 +437,12 @@ AuxiliaryProcessMain(int argc, char *argv[]) ...@@ -438,23 +437,12 @@ AuxiliaryProcessMain(int argc, char *argv[])
/* /*
* In shared memory checker mode, all we really want to do is create shared * In shared memory checker mode, all we really want to do is create shared
* memory and semaphores (just to prove we can do it with the current GUC * memory and semaphores (just to prove we can do it with the current GUC
* settings). * settings). Since, in fact, that was already done by BaseInit(),
* we have nothing more to do here.
*/ */
static void static void
CheckerModeMain(void) CheckerModeMain(void)
{ {
/*
* We must be getting invoked for bootstrap mode
*/
Assert(!IsUnderPostmaster);
SetProcessingMode(BootstrapProcessing);
/*
* Do backend-like initialization for bootstrap mode
*/
InitProcess();
InitPostgres(NULL, InvalidOid, NULL, NULL);
proc_exit(0); proc_exit(0);
} }
...@@ -478,6 +466,7 @@ BootstrapModeMain(void) ...@@ -478,6 +466,7 @@ BootstrapModeMain(void)
* Do backend-like initialization for bootstrap mode * Do backend-like initialization for bootstrap mode
*/ */
InitProcess(); InitProcess();
InitPostgres(NULL, InvalidOid, NULL, NULL); InitPostgres(NULL, InvalidOid, NULL, NULL);
/* Initialize stuff for bootstrap-file processing */ /* Initialize stuff for bootstrap-file processing */
...@@ -498,10 +487,6 @@ BootstrapModeMain(void) ...@@ -498,10 +487,6 @@ BootstrapModeMain(void)
*/ */
RelationMapFinishBootstrap(); RelationMapFinishBootstrap();
/* Perform a checkpoint to ensure everything's down to disk */
SetProcessingMode(NormalProcessing);
CreateCheckPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE);
/* Clean up and exit */ /* Clean up and exit */
cleanup(); cleanup();
proc_exit(0); proc_exit(0);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.592 2010/03/21 00:17:58 petere Exp $ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.593 2010/04/20 01:38:52 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -3531,11 +3531,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -3531,11 +3531,7 @@ PostgresMain(int argc, char *argv[], const char *username)
PG_SETMASK(&BlockSig); /* block everything except SIGQUIT */ PG_SETMASK(&BlockSig); /* block everything except SIGQUIT */
if (IsUnderPostmaster) if (!IsUnderPostmaster)
{
BaseInit();
}
else
{ {
/* /*
* Validate we have been given a reasonable-looking DataDir (if under * Validate we have been given a reasonable-looking DataDir (if under
...@@ -3551,17 +3547,11 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -3551,17 +3547,11 @@ PostgresMain(int argc, char *argv[], const char *username)
* Create lockfile for data directory. * Create lockfile for data directory.
*/ */
CreateDataDirLockFile(false); CreateDataDirLockFile(false);
BaseInit();
/*
* Start up xlog for standalone backend, and register to have it
* closed down at exit.
*/
StartupXLOG();
on_shmem_exit(ShutdownXLOG, 0);
} }
/* Early initialization */
BaseInit();
/* /*
* Create a per-backend PGPROC struct in shared memory, except in the * Create a per-backend PGPROC struct in shared memory, except in the
* EXEC_BACKEND case where this was done in SubPostmasterMain. We must do * EXEC_BACKEND case where this was done in SubPostmasterMain. We must do
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.208 2010/03/25 20:40:17 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.209 2010/04/20 01:38:52 tgl Exp $
* *
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
...@@ -427,11 +427,9 @@ pg_split_opts(char **argv, int *argcp, char *optstr) ...@@ -427,11 +427,9 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
* Early initialization of a backend (either standalone or under postmaster). * Early initialization of a backend (either standalone or under postmaster).
* This happens even before InitPostgres. * This happens even before InitPostgres.
* *
* If you're wondering why this is separate from InitPostgres at all: * This is separate from InitPostgres because it is also called by auxiliary
* the critical distinction is that this stuff has to happen before we can * processes, such as the background writer process, which may not call
* run XLOG-related initialization, which is done before InitPostgres --- in * InitPostgres at all.
* fact, for cases such as the background writer process, InitPostgres may
* never be done at all.
*/ */
void void
BaseInit(void) BaseInit(void)
...@@ -512,11 +510,28 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, ...@@ -512,11 +510,28 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
InitBufferPoolBackend(); InitBufferPoolBackend();
/* /*
* Initialize local process's access to XLOG, if appropriate. In * Initialize local process's access to XLOG.
* bootstrap case we skip this since StartupXLOG() was run instead.
*/ */
if (!bootstrap) if (IsUnderPostmaster)
{
/*
* The postmaster already started the XLOG machinery, but we need
* to call InitXLOGAccess(), if the system isn't in hot-standby mode.
* This is handled by calling RecoveryInProgress and ignoring the
* result.
*/
(void) RecoveryInProgress(); (void) RecoveryInProgress();
}
else
{
/*
* We are either a bootstrap process or a standalone backend.
* Either way, start up the XLOG machinery, and register to have it
* closed down at exit.
*/
StartupXLOG();
on_shmem_exit(ShutdownXLOG, 0);
}
/* /*
* Initialize the relation cache and the system catalog caches. Note that * Initialize the relation cache and the system catalog caches. Note that
......
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