]> granicus.if.org Git - postgresql/commitdiff
Auto checkpoint creation.
authorVadim B. Mikheev <vadim4o@yahoo.com>
Thu, 9 Nov 2000 11:26:00 +0000 (11:26 +0000)
committerVadim B. Mikheev <vadim4o@yahoo.com>
Thu, 9 Nov 2000 11:26:00 +0000 (11:26 +0000)
src/backend/access/transam/xlog.c
src/backend/bootstrap/bootstrap.c
src/backend/postmaster/postmaster.c
src/backend/utils/misc/guc.c
src/bin/initdb/initdb.sh
src/include/bootstrap/bootstrap.h

index ffd7040a459be3311e43e5ac4caad02405626f78..6d7112ceaf1b608dcef910b480e889f4817c1aee 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.24 2000/11/05 22:50:19 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.25 2000/11/09 11:25:58 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -42,13 +42,13 @@ void                CreateCheckPoint(bool shutdown);
 
 char           XLogDir[MAXPGPATH];
 char           ControlFilePath[MAXPGPATH];
-uint32         XLOGbuffers = 0;
+int                    XLOGbuffers = 0;
 XLogRecPtr     MyLastRecPtr = {0, 0};
 bool           StopIfError = false;
 bool           InRecovery = false;
 StartUpID      ThisStartUpID = 0;
 
-int                    XLOG_DEBUG = 1;
+int                    XLOG_DEBUG = 0;
 
 /* To read/update control file and create new log file */
 SPINLOCK       ControlFileLockId;
@@ -919,7 +919,7 @@ MoveOfflineLogs(char *archdir, uint32 _logId, uint32 _logSeg)
                elog(LOG, "MoveOfflineLogs: %s %s", (archdir[0]) ? 
                        "archive" : "remove", xlde->d_name);
                sprintf(path, "%s%c%s", XLogDir, SEP_CHAR, xlde->d_name);
-               if (archdir[0] != 0)
+               if (archdir[0] == 0)
                        unlink(path);
                errno = 0;
        }
@@ -1641,9 +1641,14 @@ SetThisStartUpID(void)
 void
 ShutdownXLOG()
 {
-
+#ifdef XLOG
+       extern void CreateDummyCaches(void);
+#endif
        elog(LOG, "Data Base System shutting down at %s", str_time(time(NULL)));
 
+#ifdef XLOG
+       CreateDummyCaches();
+#endif
        CreateCheckPoint(true);
 
        elog(LOG, "Data Base System shut down at %s", str_time(time(NULL)));
index e4e26d0c3cc939b594f73cf0fab287e940d38c1b..e40dc7d7ca7bbd185662e120c293d79a3e9fb3eb 100644 (file)
@@ -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.97 2000/11/08 22:09:56 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.98 2000/11/09 11:25:58 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -220,7 +220,7 @@ BootstrapMain(int argc, char *argv[])
        int                     i;
        char       *dbName;
        int                     flag;
-       bool            xloginit = false;
+       int                     xlogop = BS_XLOG_NOP;
        char       *potential_DataDir = NULL;
 
        extern int      optind;
@@ -260,7 +260,7 @@ BootstrapMain(int argc, char *argv[])
                potential_DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
        }
 
-       while ((flag = getopt(argc, argv, "D:dCQxpB:F")) != EOF)
+       while ((flag = getopt(argc, argv, "D:dCQx:pB:F")) != EOF)
        {
                switch (flag)
                {
@@ -281,7 +281,7 @@ BootstrapMain(int argc, char *argv[])
                                Quiet = true;
                                break;
                        case 'x':
-                               xloginit = true;
+                               xlogop = atoi(optarg);
                                break;
                        case 'p':
                                /* indicates fork from postmaster */
@@ -339,40 +339,41 @@ BootstrapMain(int argc, char *argv[])
        }
 
        /*
-        * Bootstrap under Postmaster means two things: (xloginit) ?
-        * StartupXLOG : ShutdownXLOG
-        *
-        * If !under Postmaster and xloginit then BootStrapXLOG.
+        * XLOG operations
         */
-       if (IsUnderPostmaster || xloginit)
+       if (xlogop != BS_XLOG_NOP)
        {
                snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir);
                snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
+               if (xlogop == BS_XLOG_BOOTSTRAP)
+                       BootStrapXLOG();
+               else
+               {
+                       SetProcessingMode(NormalProcessing);
+                       if (xlogop == BS_XLOG_STARTUP)
+                               StartupXLOG();
+                       else if (xlogop == BS_XLOG_CHECKPOINT)
+                       {
+#ifdef XLOG
+                               extern void CreateDummyCaches(void);
+                               CreateDummyCaches();
+#endif
+                               CreateCheckPoint(false);
+                       }
+                       else if (xlogop == BS_XLOG_SHUTDOWN)
+                               ShutdownXLOG();
+                       else
+                               elog(STOP, "Unsupported XLOG op %d", xlogop);
+                       proc_exit(0);
+               }
        }
 
-       if (IsUnderPostmaster && xloginit)
-       {
-               SetProcessingMode(NormalProcessing);
-               StartupXLOG();
-               proc_exit(0);
-       }
-
-       if (!IsUnderPostmaster && xloginit)
-               BootStrapXLOG();
-
        /*
         * backend initialization
         */
        InitPostgres(dbName, NULL);
        LockDisable(true);
 
-       if (IsUnderPostmaster && !xloginit)
-       {
-               SetProcessingMode(NormalProcessing);
-               ShutdownXLOG();
-               proc_exit(0);
-       }
-
        for (i = 0; i < MAXATTR; i++)
        {
                attrtypes[i] = (Form_pg_attribute) NULL;
index 07e05485096f6ed1d511f4c0b2c864cd03a3b8b1..e2a1dec6fb8fab62b69064270592ce964f103c30 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.180 2000/11/08 17:57:46 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.181 2000/11/09 11:25:59 vadim Exp $
  *
  * NOTES
  *
@@ -78,7 +78,7 @@
 #include "utils/exc.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
-
+#include "bootstrap/bootstrap.h"
 
 #define INVALID_SOCK   (-1)
 #define ARGV_SIZE      64
@@ -197,8 +197,12 @@ bool NetServer = false;    /* listen on TCP/IP */
 bool EnableSSL = false;
 bool SilentMode = false;       /* silent mode (-S) */
 
-static pid_t StartupPID = 0,
-                       ShutdownPID = 0;
+int                            CheckPointTimeout = 300;
+
+static pid_t   StartupPID = 0,
+                               ShutdownPID = 0,
+                               CheckPointPID = 0;
+static time_t  checkpointed = 0;
 
 #define                        NoShutdown              0
 #define                        SmartShutdown   1
@@ -250,11 +254,11 @@ static void SignalChildren(SIGNAL_ARGS);
 static int     CountChildren(void);
 static bool CreateOptsFile(int argc, char *argv[]);
 
-extern int     BootstrapMain(int argc, char *argv[]);
-static pid_t SSDataBase(bool startup);
+static pid_t SSDataBase(int xlop);
 
-#define StartupDataBase()      SSDataBase(true)
-#define ShutdownDataBase()     SSDataBase(false)
+#define StartupDataBase()              SSDataBase(BS_XLOG_STARTUP)
+#define CheckPointDataBase()   SSDataBase(BS_XLOG_CHECKPOINT)
+#define ShutdownDataBase()             SSDataBase(BS_XLOG_SHUTDOWN)
 
 #ifdef USE_SSL
 static void InitSSL(void);
@@ -814,13 +818,27 @@ ServerLoop(void)
 
        for (;;)
        {
-               Port       *port;
-               fd_set          rmask,
-                                       wmask;
-               struct timeval *timeout = (struct timeval *) NULL;
-#ifdef USE_SSL
-               struct timeval timeout_tv;
+               Port               *port;
+               fd_set                  rmask,
+                                               wmask;
+               struct timeval *timeout = NULL;
+               struct timeval  timeout_tv;
+
+               if (CheckPointPID == 0 && checkpointed)
+               {
+                       time_t  now = time(NULL);
+
+                       if (CheckPointTimeout + checkpointed > now)
+                       {
+                               timeout_tv.tv_sec = CheckPointTimeout + checkpointed - now;
+                               timeout_tv.tv_usec = 0;
+                               timeout = &timeout_tv;
+                       }
+                       else
+                               CheckPointPID = CheckPointDataBase();
+               }
 
+#ifdef USE_SSL
                /*
                 * If we are using SSL, there may be input data already read and
                 * pending in SSL's input buffers.  If so, check for additional
@@ -850,6 +868,7 @@ ServerLoop(void)
 
                if (select(nSockets, &rmask, &wmask, (fd_set *) NULL, timeout) < 0)
                {
+                       PG_SETMASK(&BlockSig);
                        if (errno == EINTR || errno == EWOULDBLOCK)
                                continue;
                        fprintf(stderr, "%s: ServerLoop: select failed: %s\n",
@@ -1186,6 +1205,14 @@ processCancelRequest(Port *port, PacketLen len, void *pkt)
        backendPID = (int) ntohl(canc->backendPID);
        cancelAuthCode = (long) ntohl(canc->cancelAuthCode);
 
+       if (backendPID == CheckPointPID)
+       {
+               if (DebugLvl)
+                       fprintf(stderr, "%s: processCancelRequest: CheckPointPID in cancel request for process %d\n",
+                                       progname, backendPID);
+               return STATUS_ERROR;
+       }
+
        /* See if we have a matching backend */
 
        for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
@@ -1480,6 +1507,9 @@ reaper(SIGNAL_ARGS)
                         */
                        SetThisStartUpID();
 
+                       CheckPointPID = 0;
+                       checkpointed = time(NULL);
+
                        pqsignal(SIGCHLD, reaper);
                        return;
                }
@@ -1563,7 +1593,13 @@ CleanupProc(int pid,
                        curr = DLGetSucc(curr);
                }
 
-               ProcRemove(pid);
+               if (pid == CheckPointPID)
+               {
+                       CheckPointPID = 0;
+                       checkpointed = time(NULL);
+               }
+               else
+                       ProcRemove(pid);
 
                return;
        }
@@ -1612,7 +1648,13 @@ CleanupProc(int pid,
                         * only, couldn't we just sigpause?), so probably we'll remove
                         * this call from here someday.  -- vadim 04-10-1999
                         */
-                       ProcRemove(pid);
+                       if (pid == CheckPointPID)
+                       {
+                               CheckPointPID = 0;
+                               checkpointed = 0;
+                       }
+                       else
+                               ProcRemove(pid);
 
                        DLRemove(curr);
                        free(bp);
@@ -2090,6 +2132,8 @@ CountChildren(void)
                if (bp->pid != mypid)
                        cnt++;
        }
+       if (CheckPointPID != 0)
+               cnt--;
        return cnt;
 }
 
@@ -2132,10 +2176,11 @@ InitSSL(void)
 #endif
 
 static pid_t
-SSDataBase(bool startup)
+SSDataBase(int xlop)
 {
        pid_t           pid;
        int                     i;
+       Backend    *bn;
        static char ssEntry[4][2 * ARGV_SIZE];
 
        for (i = 0; i < 4; ++i)
@@ -2159,6 +2204,7 @@ SSDataBase(bool startup)
                int                     ac = 0;
                char            nbbuf[ARGV_SIZE];
                char            dbbuf[ARGV_SIZE];
+               char            xlbuf[ARGV_SIZE];
 
                /* Lose the postmaster's on-exit routines and port connections */
                on_exit_reset();
@@ -2178,8 +2224,8 @@ SSDataBase(bool startup)
                sprintf(nbbuf, "-B%u", NBuffers);
                av[ac++] = nbbuf;
 
-               if (startup)
-                       av[ac++] = "-x";
+               sprintf(xlbuf, "-x %d", xlop);
+               av[ac++] = xlbuf;
 
                av[ac++] = "-p";
 
@@ -2206,12 +2252,28 @@ SSDataBase(bool startup)
        if (pid < 0)
        {
                fprintf(stderr, "%s Data Base: fork failed: %s\n",
-                               ((startup) ? "Startup" : "Shutdown"), strerror(errno));
+                               ((xlop == BS_XLOG_STARTUP) ? "Startup" : 
+                                       ((xlop == BS_XLOG_CHECKPOINT) ? "CheckPoint" :
+                                               "Shutdown")), strerror(errno));
                ExitPostmaster(1);
        }
 
        NextBackendTag -= 1;
 
+       if (xlop != BS_XLOG_CHECKPOINT)
+               return(pid);
+
+       if (!(bn = (Backend *) calloc(1, sizeof(Backend))))
+       {
+               fprintf(stderr, "%s: CheckPointDataBase: malloc failed\n",
+                               progname);
+               ExitPostmaster(1);
+       }
+
+       bn->pid = pid;
+       bn->cancel_key = 0;
+       DLAddHead(BackendList, DLNewElem(bn));
+
        return (pid);
 }
 
index 54d858c0ce39351d433c6fb286211aeda0b31caa..8fe7bd36fa309ac2ea9cbbbcdfd8bebb6eee3ce2 100644 (file)
@@ -4,7 +4,7 @@
  * Support for grand unified configuration scheme, including SET
  * command, configuration file, and command line options.
  *
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.15 2000/11/01 21:14:03 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.16 2000/11/09 11:25:59 vadim Exp $
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  * Written by Peter Eisentraut <peter_e@gmx.net>.
 /* XXX should be in a header file */
 extern bool Log_connections;
 
+extern int CheckPointTimeout;
+extern int XLOGbuffers;
+extern int XLOG_DEBUG;
+
 /*
  * Debugging options
  */
@@ -257,6 +261,15 @@ ConfigureNamesInt[] =
        {"unix_socket_permissions", PGC_POSTMASTER,         &Unix_socket_permissions,
         0777, 0000, 0777},
 
+       {"checkpoint_timeout", PGC_POSTMASTER,         &CheckPointTimeout,
+        300, 30, 1800},
+
+       {"wal_buffers", PGC_POSTMASTER,         &XLOGbuffers,
+        4, 4, INT_MAX},
+
+       {"wal_debug", PGC_POSTMASTER,         &XLOG_DEBUG,
+        0, 0, 16},
+
     {NULL, 0, NULL, 0, 0, 0}
 };
 
index c938310c438bc3a27888fb2889ba4a3fcdb7f336..343a0c27d7f6342a0b314bda86d53c82c0b2d3e5 100644 (file)
@@ -23,7 +23,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.111 2000/11/06 22:18:09 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.112 2000/11/09 11:26:00 vadim Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -440,7 +440,7 @@ else
 fi
 
 BACKENDARGS="-boot -C -F -D$PGDATA $BACKEND_TALK_ARG"
-FIRSTRUN="-boot -x -C -F -D$PGDATA $BACKEND_TALK_ARG"
+FIRSTRUN="-boot -x1 -C -F -D$PGDATA $BACKEND_TALK_ARG"
 
 echo "Creating template database in $PGDATA/base/1"
 [ "$debug" = yes ] && echo "Running: $PGPATH/postgres $FIRSTRUN template1"
index 882ac3c7d1cfd68c16b276027c314f91e74e5d44..d19231ce419b9a4eb03de8baa06db4c537d24b96 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: bootstrap.h,v 1.19 2000/07/14 22:17:54 tgl Exp $
+ * $Id: bootstrap.h,v 1.20 2000/11/09 11:26:00 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -57,4 +57,10 @@ extern void build_indices(void);
 extern int     Int_yylex(void);
 extern void Int_yyerror(const char *str);
 
+#define BS_XLOG_NOP                    0
+#define BS_XLOG_BOOTSTRAP      1
+#define BS_XLOG_STARTUP                2
+#define BS_XLOG_CHECKPOINT     3
+#define BS_XLOG_SHUTDOWN       4
+
 #endif  /* BOOTSTRAP_H */