Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c670410

Browse files
committed
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.
1 parent ee7769b commit c670410

File tree

3 files changed

+34
-44
lines changed

3 files changed

+34
-44
lines changed

src/backend/bootstrap/bootstrap.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.260 2010/02/26 02:00:35 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.261 2010/04/20 01:38:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -397,14 +397,13 @@ AuxiliaryProcessMain(int argc, char *argv[])
397397
switch (auxType)
398398
{
399399
case CheckerProcess:
400-
bootstrap_signals();
400+
/* don't set signals, they're useless here */
401401
CheckerModeMain();
402402
proc_exit(1); /* should never return */
403403

404404
case BootstrapProcess:
405405
bootstrap_signals();
406406
BootStrapXLOG();
407-
StartupXLOG();
408407
BootstrapModeMain();
409408
proc_exit(1); /* should never return */
410409

@@ -438,23 +437,12 @@ AuxiliaryProcessMain(int argc, char *argv[])
438437
/*
439438
* In shared memory checker mode, all we really want to do is create shared
440439
* memory and semaphores (just to prove we can do it with the current GUC
441-
* settings).
440+
* settings). Since, in fact, that was already done by BaseInit(),
441+
* we have nothing more to do here.
442442
*/
443443
static void
444444
CheckerModeMain(void)
445445
{
446-
/*
447-
* We must be getting invoked for bootstrap mode
448-
*/
449-
Assert(!IsUnderPostmaster);
450-
451-
SetProcessingMode(BootstrapProcessing);
452-
453-
/*
454-
* Do backend-like initialization for bootstrap mode
455-
*/
456-
InitProcess();
457-
InitPostgres(NULL, InvalidOid, NULL, NULL);
458446
proc_exit(0);
459447
}
460448

@@ -478,6 +466,7 @@ BootstrapModeMain(void)
478466
* Do backend-like initialization for bootstrap mode
479467
*/
480468
InitProcess();
469+
481470
InitPostgres(NULL, InvalidOid, NULL, NULL);
482471

483472
/* Initialize stuff for bootstrap-file processing */
@@ -498,10 +487,6 @@ BootstrapModeMain(void)
498487
*/
499488
RelationMapFinishBootstrap();
500489

501-
/* Perform a checkpoint to ensure everything's down to disk */
502-
SetProcessingMode(NormalProcessing);
503-
CreateCheckPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE);
504-
505490
/* Clean up and exit */
506491
cleanup();
507492
proc_exit(0);

src/backend/tcop/postgres.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.592 2010/03/21 00:17:58 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.593 2010/04/20 01:38:52 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -3531,11 +3531,7 @@ PostgresMain(int argc, char *argv[], const char *username)
35313531

35323532
PG_SETMASK(&BlockSig); /* block everything except SIGQUIT */
35333533

3534-
if (IsUnderPostmaster)
3535-
{
3536-
BaseInit();
3537-
}
3538-
else
3534+
if (!IsUnderPostmaster)
35393535
{
35403536
/*
35413537
* Validate we have been given a reasonable-looking DataDir (if under
@@ -3551,17 +3547,11 @@ PostgresMain(int argc, char *argv[], const char *username)
35513547
* Create lockfile for data directory.
35523548
*/
35533549
CreateDataDirLockFile(false);
3554-
3555-
BaseInit();
3556-
3557-
/*
3558-
* Start up xlog for standalone backend, and register to have it
3559-
* closed down at exit.
3560-
*/
3561-
StartupXLOG();
3562-
on_shmem_exit(ShutdownXLOG, 0);
35633550
}
35643551

3552+
/* Early initialization */
3553+
BaseInit();
3554+
35653555
/*
35663556
* Create a per-backend PGPROC struct in shared memory, except in the
35673557
* EXEC_BACKEND case where this was done in SubPostmasterMain. We must do

src/backend/utils/init/postinit.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.208 2010/03/25 20:40:17 sriggs Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.209 2010/04/20 01:38:52 tgl Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -427,11 +427,9 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
427427
* Early initialization of a backend (either standalone or under postmaster).
428428
* This happens even before InitPostgres.
429429
*
430-
* If you're wondering why this is separate from InitPostgres at all:
431-
* the critical distinction is that this stuff has to happen before we can
432-
* run XLOG-related initialization, which is done before InitPostgres --- in
433-
* fact, for cases such as the background writer process, InitPostgres may
434-
* never be done at all.
430+
* This is separate from InitPostgres because it is also called by auxiliary
431+
* processes, such as the background writer process, which may not call
432+
* InitPostgres at all.
435433
*/
436434
void
437435
BaseInit(void)
@@ -512,11 +510,28 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
512510
InitBufferPoolBackend();
513511

514512
/*
515-
* Initialize local process's access to XLOG, if appropriate. In
516-
* bootstrap case we skip this since StartupXLOG() was run instead.
513+
* Initialize local process's access to XLOG.
517514
*/
518-
if (!bootstrap)
515+
if (IsUnderPostmaster)
516+
{
517+
/*
518+
* The postmaster already started the XLOG machinery, but we need
519+
* to call InitXLOGAccess(), if the system isn't in hot-standby mode.
520+
* This is handled by calling RecoveryInProgress and ignoring the
521+
* result.
522+
*/
519523
(void) RecoveryInProgress();
524+
}
525+
else
526+
{
527+
/*
528+
* We are either a bootstrap process or a standalone backend.
529+
* Either way, start up the XLOG machinery, and register to have it
530+
* closed down at exit.
531+
*/
532+
StartupXLOG();
533+
on_shmem_exit(ShutdownXLOG, 0);
534+
}
520535

521536
/*
522537
* Initialize the relation cache and the system catalog caches. Note that

0 commit comments

Comments
 (0)