Commit b0299c5d authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

Auto checkpoint creation.

parent a0951eec
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * 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); ...@@ -42,13 +42,13 @@ void CreateCheckPoint(bool shutdown);
char XLogDir[MAXPGPATH]; char XLogDir[MAXPGPATH];
char ControlFilePath[MAXPGPATH]; char ControlFilePath[MAXPGPATH];
uint32 XLOGbuffers = 0; int XLOGbuffers = 0;
XLogRecPtr MyLastRecPtr = {0, 0}; XLogRecPtr MyLastRecPtr = {0, 0};
bool StopIfError = false; bool StopIfError = false;
bool InRecovery = false; bool InRecovery = false;
StartUpID ThisStartUpID = 0; StartUpID ThisStartUpID = 0;
int XLOG_DEBUG = 1; int XLOG_DEBUG = 0;
/* To read/update control file and create new log file */ /* To read/update control file and create new log file */
SPINLOCK ControlFileLockId; SPINLOCK ControlFileLockId;
...@@ -919,7 +919,7 @@ MoveOfflineLogs(char *archdir, uint32 _logId, uint32 _logSeg) ...@@ -919,7 +919,7 @@ MoveOfflineLogs(char *archdir, uint32 _logId, uint32 _logSeg)
elog(LOG, "MoveOfflineLogs: %s %s", (archdir[0]) ? elog(LOG, "MoveOfflineLogs: %s %s", (archdir[0]) ?
"archive" : "remove", xlde->d_name); "archive" : "remove", xlde->d_name);
sprintf(path, "%s%c%s", XLogDir, SEP_CHAR, xlde->d_name); sprintf(path, "%s%c%s", XLogDir, SEP_CHAR, xlde->d_name);
if (archdir[0] != 0) if (archdir[0] == 0)
unlink(path); unlink(path);
errno = 0; errno = 0;
} }
...@@ -1641,9 +1641,14 @@ SetThisStartUpID(void) ...@@ -1641,9 +1641,14 @@ SetThisStartUpID(void)
void void
ShutdownXLOG() ShutdownXLOG()
{ {
#ifdef XLOG
extern void CreateDummyCaches(void);
#endif
elog(LOG, "Data Base System shutting down at %s", str_time(time(NULL))); elog(LOG, "Data Base System shutting down at %s", str_time(time(NULL)));
#ifdef XLOG
CreateDummyCaches();
#endif
CreateCheckPoint(true); CreateCheckPoint(true);
elog(LOG, "Data Base System shut down at %s", str_time(time(NULL))); elog(LOG, "Data Base System shut down at %s", str_time(time(NULL)));
......
...@@ -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
* $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[]) ...@@ -220,7 +220,7 @@ BootstrapMain(int argc, char *argv[])
int i; int i;
char *dbName; char *dbName;
int flag; int flag;
bool xloginit = false; int xlogop = BS_XLOG_NOP;
char *potential_DataDir = NULL; char *potential_DataDir = NULL;
extern int optind; extern int optind;
...@@ -260,7 +260,7 @@ BootstrapMain(int argc, char *argv[]) ...@@ -260,7 +260,7 @@ BootstrapMain(int argc, char *argv[])
potential_DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */ 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) switch (flag)
{ {
...@@ -281,7 +281,7 @@ BootstrapMain(int argc, char *argv[]) ...@@ -281,7 +281,7 @@ BootstrapMain(int argc, char *argv[])
Quiet = true; Quiet = true;
break; break;
case 'x': case 'x':
xloginit = true; xlogop = atoi(optarg);
break; break;
case 'p': case 'p':
/* indicates fork from postmaster */ /* indicates fork from postmaster */
...@@ -339,40 +339,41 @@ BootstrapMain(int argc, char *argv[]) ...@@ -339,40 +339,41 @@ BootstrapMain(int argc, char *argv[])
} }
/* /*
* Bootstrap under Postmaster means two things: (xloginit) ? * XLOG operations
* StartupXLOG : ShutdownXLOG
*
* If !under Postmaster and xloginit then BootStrapXLOG.
*/ */
if (IsUnderPostmaster || xloginit) if (xlogop != BS_XLOG_NOP)
{ {
snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir); snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir);
snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", 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 * backend initialization
*/ */
InitPostgres(dbName, NULL); InitPostgres(dbName, NULL);
LockDisable(true); LockDisable(true);
if (IsUnderPostmaster && !xloginit)
{
SetProcessingMode(NormalProcessing);
ShutdownXLOG();
proc_exit(0);
}
for (i = 0; i < MAXATTR; i++) for (i = 0; i < MAXATTR; i++)
{ {
attrtypes[i] = (Form_pg_attribute) NULL; attrtypes[i] = (Form_pg_attribute) NULL;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* *
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
#include "utils/exc.h" #include "utils/exc.h"
#include "utils/guc.h" #include "utils/guc.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "bootstrap/bootstrap.h"
#define INVALID_SOCK (-1) #define INVALID_SOCK (-1)
#define ARGV_SIZE 64 #define ARGV_SIZE 64
...@@ -197,8 +197,12 @@ bool NetServer = false; /* listen on TCP/IP */ ...@@ -197,8 +197,12 @@ bool NetServer = false; /* listen on TCP/IP */
bool EnableSSL = false; bool EnableSSL = false;
bool SilentMode = false; /* silent mode (-S) */ bool SilentMode = false; /* silent mode (-S) */
static pid_t StartupPID = 0, int CheckPointTimeout = 300;
ShutdownPID = 0;
static pid_t StartupPID = 0,
ShutdownPID = 0,
CheckPointPID = 0;
static time_t checkpointed = 0;
#define NoShutdown 0 #define NoShutdown 0
#define SmartShutdown 1 #define SmartShutdown 1
...@@ -250,11 +254,11 @@ static void SignalChildren(SIGNAL_ARGS); ...@@ -250,11 +254,11 @@ static void SignalChildren(SIGNAL_ARGS);
static int CountChildren(void); static int CountChildren(void);
static bool CreateOptsFile(int argc, char *argv[]); static bool CreateOptsFile(int argc, char *argv[]);
extern int BootstrapMain(int argc, char *argv[]); static pid_t SSDataBase(int xlop);
static pid_t SSDataBase(bool startup);
#define StartupDataBase() SSDataBase(true) #define StartupDataBase() SSDataBase(BS_XLOG_STARTUP)
#define ShutdownDataBase() SSDataBase(false) #define CheckPointDataBase() SSDataBase(BS_XLOG_CHECKPOINT)
#define ShutdownDataBase() SSDataBase(BS_XLOG_SHUTDOWN)
#ifdef USE_SSL #ifdef USE_SSL
static void InitSSL(void); static void InitSSL(void);
...@@ -814,13 +818,27 @@ ServerLoop(void) ...@@ -814,13 +818,27 @@ ServerLoop(void)
for (;;) for (;;)
{ {
Port *port; Port *port;
fd_set rmask, fd_set rmask,
wmask; wmask;
struct timeval *timeout = (struct timeval *) NULL; struct timeval *timeout = NULL;
#ifdef USE_SSL struct timeval timeout_tv;
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 * If we are using SSL, there may be input data already read and
* pending in SSL's input buffers. If so, check for additional * pending in SSL's input buffers. If so, check for additional
...@@ -850,6 +868,7 @@ ServerLoop(void) ...@@ -850,6 +868,7 @@ ServerLoop(void)
if (select(nSockets, &rmask, &wmask, (fd_set *) NULL, timeout) < 0) if (select(nSockets, &rmask, &wmask, (fd_set *) NULL, timeout) < 0)
{ {
PG_SETMASK(&BlockSig);
if (errno == EINTR || errno == EWOULDBLOCK) if (errno == EINTR || errno == EWOULDBLOCK)
continue; continue;
fprintf(stderr, "%s: ServerLoop: select failed: %s\n", fprintf(stderr, "%s: ServerLoop: select failed: %s\n",
...@@ -1186,6 +1205,14 @@ processCancelRequest(Port *port, PacketLen len, void *pkt) ...@@ -1186,6 +1205,14 @@ processCancelRequest(Port *port, PacketLen len, void *pkt)
backendPID = (int) ntohl(canc->backendPID); backendPID = (int) ntohl(canc->backendPID);
cancelAuthCode = (long) ntohl(canc->cancelAuthCode); 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 */ /* See if we have a matching backend */
for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr)) for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
...@@ -1480,6 +1507,9 @@ reaper(SIGNAL_ARGS) ...@@ -1480,6 +1507,9 @@ reaper(SIGNAL_ARGS)
*/ */
SetThisStartUpID(); SetThisStartUpID();
CheckPointPID = 0;
checkpointed = time(NULL);
pqsignal(SIGCHLD, reaper); pqsignal(SIGCHLD, reaper);
return; return;
} }
...@@ -1563,7 +1593,13 @@ CleanupProc(int pid, ...@@ -1563,7 +1593,13 @@ CleanupProc(int pid,
curr = DLGetSucc(curr); curr = DLGetSucc(curr);
} }
ProcRemove(pid); if (pid == CheckPointPID)
{
CheckPointPID = 0;
checkpointed = time(NULL);
}
else
ProcRemove(pid);
return; return;
} }
...@@ -1612,7 +1648,13 @@ CleanupProc(int pid, ...@@ -1612,7 +1648,13 @@ CleanupProc(int pid,
* only, couldn't we just sigpause?), so probably we'll remove * only, couldn't we just sigpause?), so probably we'll remove
* this call from here someday. -- vadim 04-10-1999 * this call from here someday. -- vadim 04-10-1999
*/ */
ProcRemove(pid); if (pid == CheckPointPID)
{
CheckPointPID = 0;
checkpointed = 0;
}
else
ProcRemove(pid);
DLRemove(curr); DLRemove(curr);
free(bp); free(bp);
...@@ -2090,6 +2132,8 @@ CountChildren(void) ...@@ -2090,6 +2132,8 @@ CountChildren(void)
if (bp->pid != mypid) if (bp->pid != mypid)
cnt++; cnt++;
} }
if (CheckPointPID != 0)
cnt--;
return cnt; return cnt;
} }
...@@ -2132,10 +2176,11 @@ InitSSL(void) ...@@ -2132,10 +2176,11 @@ InitSSL(void)
#endif #endif
static pid_t static pid_t
SSDataBase(bool startup) SSDataBase(int xlop)
{ {
pid_t pid; pid_t pid;
int i; int i;
Backend *bn;
static char ssEntry[4][2 * ARGV_SIZE]; static char ssEntry[4][2 * ARGV_SIZE];
for (i = 0; i < 4; ++i) for (i = 0; i < 4; ++i)
...@@ -2159,6 +2204,7 @@ SSDataBase(bool startup) ...@@ -2159,6 +2204,7 @@ SSDataBase(bool startup)
int ac = 0; int ac = 0;
char nbbuf[ARGV_SIZE]; char nbbuf[ARGV_SIZE];
char dbbuf[ARGV_SIZE]; char dbbuf[ARGV_SIZE];
char xlbuf[ARGV_SIZE];
/* Lose the postmaster's on-exit routines and port connections */ /* Lose the postmaster's on-exit routines and port connections */
on_exit_reset(); on_exit_reset();
...@@ -2178,8 +2224,8 @@ SSDataBase(bool startup) ...@@ -2178,8 +2224,8 @@ SSDataBase(bool startup)
sprintf(nbbuf, "-B%u", NBuffers); sprintf(nbbuf, "-B%u", NBuffers);
av[ac++] = nbbuf; av[ac++] = nbbuf;
if (startup) sprintf(xlbuf, "-x %d", xlop);
av[ac++] = "-x"; av[ac++] = xlbuf;
av[ac++] = "-p"; av[ac++] = "-p";
...@@ -2206,12 +2252,28 @@ SSDataBase(bool startup) ...@@ -2206,12 +2252,28 @@ SSDataBase(bool startup)
if (pid < 0) if (pid < 0)
{ {
fprintf(stderr, "%s Data Base: fork failed: %s\n", 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); ExitPostmaster(1);
} }
NextBackendTag -= 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); return (pid);
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Support for grand unified configuration scheme, including SET * Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options. * 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 * Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
/* XXX should be in a header file */ /* XXX should be in a header file */
extern bool Log_connections; extern bool Log_connections;
extern int CheckPointTimeout;
extern int XLOGbuffers;
extern int XLOG_DEBUG;
/* /*
* Debugging options * Debugging options
*/ */
...@@ -257,6 +261,15 @@ ConfigureNamesInt[] = ...@@ -257,6 +261,15 @@ ConfigureNamesInt[] =
{"unix_socket_permissions", PGC_POSTMASTER, &Unix_socket_permissions, {"unix_socket_permissions", PGC_POSTMASTER, &Unix_socket_permissions,
0777, 0000, 0777}, 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} {NULL, 0, NULL, 0, 0, 0}
}; };
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
# #
# Copyright (c) 1994, Regents of the University of California # 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 ...@@ -440,7 +440,7 @@ else
fi fi
BACKENDARGS="-boot -C -F -D$PGDATA $BACKEND_TALK_ARG" 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" echo "Creating template database in $PGDATA/base/1"
[ "$debug" = yes ] && echo "Running: $PGPATH/postgres $FIRSTRUN template1" [ "$debug" = yes ] && echo "Running: $PGPATH/postgres $FIRSTRUN template1"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * 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); ...@@ -57,4 +57,10 @@ extern void build_indices(void);
extern int Int_yylex(void); extern int Int_yylex(void);
extern void Int_yyerror(const char *str); 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 */ #endif /* BOOTSTRAP_H */
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