aboutsummaryrefslogtreecommitdiff
path: root/src/backend/bootstrap/bootstrap.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-03-13 01:17:06 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-03-13 01:17:06 +0000
commit4d14fe0048cf80052a3ba2053560f8aab1bb1b22 (patch)
tree599c7fde5eb9b889e507b2da77fd8c0300a5dfc7 /src/backend/bootstrap/bootstrap.c
parentb246510ccc8db96bf7a536a305cccf65aab21ce8 (diff)
downloadpostgresql-4d14fe0048cf80052a3ba2053560f8aab1bb1b22.tar.gz
postgresql-4d14fe0048cf80052a3ba2053560f8aab1bb1b22.zip
XLOG (and related) changes:
* Store two past checkpoint locations, not just one, in pg_control. On startup, we fall back to the older checkpoint if the newer one is unreadable. Also, a physical copy of the newest checkpoint record is kept in pg_control for possible use in disaster recovery (ie, complete loss of pg_xlog). Also add a version number for pg_control itself. Remove archdir from pg_control; it ought to be a GUC parameter, not a special case (not that it's implemented yet anyway). * Suppress successive checkpoint records when nothing has been entered in the WAL log since the last one. This is not so much to avoid I/O as to make it actually useful to keep track of the last two checkpoints. If the things are right next to each other then there's not a lot of redundancy gained... * Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs on alternate bytes. Polynomial borrowed from ECMA DLT1 standard. * Fix XLOG record length handling so that it will work at BLCKSZ = 32k. * Change XID allocation to work more like OID allocation. (This is of dubious necessity, but I think it's a good idea anyway.) * Fix a number of minor bugs, such as off-by-one logic for XLOG file wraparound at the 4 gig mark. * Add documentation and clean up some coding infelicities; move file format declarations out to include files where planned contrib utilities can get at them. * Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also possible to force a checkpoint by sending SIGUSR1 to the postmaster (undocumented feature...) * Defend against kill -9 postmaster by storing shmem block's key and ID in postmaster.pid lockfile, and checking at startup to ensure that no processes are still connected to old shmem block (if it still exists). * Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency stop, for symmetry with postmaster and xlog utilities. Clean up signal handling in bootstrap.c so that xlog utilities launched by postmaster will react to signals better. * Standalone bootstrap now grabs lockfile in target directory, as added insurance against running it in parallel with live postmaster.
Diffstat (limited to 'src/backend/bootstrap/bootstrap.c')
-rw-r--r--src/backend/bootstrap/bootstrap.c72
1 files changed, 50 insertions, 22 deletions
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 836a6c87ef8..95f73c356ad 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.104 2001/01/24 19:42:51 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.105 2001/03/13 01:17:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,13 +18,12 @@
#include <time.h>
#include <signal.h>
#include <setjmp.h>
-
-#define BOOTSTRAP_INCLUDE /* mask out stuff in tcop/tcopprot.h */
-
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
+#define BOOTSTRAP_INCLUDE /* mask out stuff in tcop/tcopprot.h */
+
#include "access/genam.h"
#include "access/heapam.h"
#include "access/xlog.h"
@@ -147,8 +146,6 @@ static MemoryContext nogc = NULL; /* special no-gc mem context */
extern int optind;
extern char *optarg;
-extern void SetRedoRecPtr(void);
-
/*
* At bootstrap time, we first declare all the indices to be built, and
* then build them. The IndexList structure stores enough information
@@ -294,8 +291,16 @@ BootstrapMain(int argc, char *argv[])
else if (argc - optind == 1)
dbName = argv[optind];
- SetProcessingMode(BootstrapProcessing);
- IgnoreSystemIndexes(true);
+ if (dbName == NULL)
+ {
+ dbName = getenv("USER");
+ if (dbName == NULL)
+ {
+ fputs("bootstrap backend: failed, no db name specified\n", stderr);
+ fputs(" and no USER enviroment variable\n", stderr);
+ proc_exit(1);
+ }
+ }
if (!IsUnderPostmaster)
{
@@ -312,29 +317,52 @@ BootstrapMain(int argc, char *argv[])
}
Assert(DataDir);
- if (dbName == NULL)
+ if (IsUnderPostmaster)
{
- dbName = getenv("USER");
- if (dbName == NULL)
- {
- fputs("bootstrap backend: failed, no db name specified\n", stderr);
- fputs(" and no USER enviroment variable\n", stderr);
- proc_exit(1);
- }
+ /*
+ * Properly accept or ignore signals the postmaster might send us
+ */
+ pqsignal(SIGHUP, SIG_IGN);
+ pqsignal(SIGINT, SIG_IGN); /* ignore query-cancel */
+ pqsignal(SIGTERM, die);
+ pqsignal(SIGQUIT, quickdie);
+ pqsignal(SIGUSR1, SIG_IGN);
+ pqsignal(SIGUSR2, SIG_IGN);
+ /*
+ * Reset some signals that are accepted by postmaster but not here
+ */
+ pqsignal(SIGCHLD, SIG_IGN);
+ pqsignal(SIGTTIN, SIG_DFL);
+ pqsignal(SIGTTOU, SIG_DFL);
+ pqsignal(SIGCONT, SIG_DFL);
+ pqsignal(SIGWINCH, SIG_DFL);
+ /*
+ * Unblock signals (they were blocked when the postmaster forked us)
+ */
+ PG_SETMASK(&UnBlockSig);
}
-
- XLOGPathInit();
-
- BaseInit();
-
- if (!IsUnderPostmaster)
+ else
{
+ /* Set up appropriately for interactive use */
pqsignal(SIGHUP, die);
pqsignal(SIGINT, die);
pqsignal(SIGTERM, die);
pqsignal(SIGQUIT, die);
+
+ /*
+ * Create lockfile for data directory.
+ */
+ if (! CreateDataDirLockFile(DataDir, false))
+ proc_exit(1);
}
+ SetProcessingMode(BootstrapProcessing);
+ IgnoreSystemIndexes(true);
+
+ XLOGPathInit();
+
+ BaseInit();
+
/*
* XLOG operations
*/