diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/access/transam/xlog.c /usr1/richt/pgsql_mirror.pitr/src/backend/access/transam/xlog.c *** /usr1/richt/pgsql_mirror/src/backend/access/transam/xlog.c Thu Jun 20 16:29:25 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/access/transam/xlog.c Fri Jul 26 16:40:45 2002 *************** *** 32,37 **** --- 32,40 ---- #include "catalog/catversion.h" #include "catalog/pg_control.h" #include "storage/bufpage.h" + + #include "storage/buf_internals.h" + #include "storage/lwlock.h" #include "storage/pmsignal.h" #include "storage/proc.h" *************** *** 116,121 **** --- 119,149 ---- #define MinXLOGbuffers 4 + extern PageInfoStruct* PageInfo; + bool WalFileReuse = true; + bool RollForward = false; + static time_t RollUntil = 0; + char *XLOG_duplicate_dir = NULL; + static int openLogFile2 = -1; + static uint32 openLogId2 = 0; + static uint32 openLogSeg2 = 0; + static uint32 openLogOff2 = 0; + + static int readFile2 = -1; + static uint32 readId2 = 0; + static uint32 readSeg2 = 0; + static uint32 readOff2 = 0; + + static void XLOGDuplicateDirInit(void); + static void XLogCopyFileToDuplicateDir(char *segmentName); + static void XLogWrite2(void); + static bool checkDuplicateLogPage(XLogPageHeader hdr); + static int readDuplicatePage(XLogRecPtr pageaddr, char *pbuf); + static int32 getSegmentFileSize(char *path); + static void writeDuplicatePage(XLogPageHeader hdr); + static void XLWalFileOldest(char *whichLog); + static XLogRecord * xactTimeCheck(XLogRecord * record); + static void XLogReinit(XLogRecPtr EndOfLog); /* * ThisStartUpID will be same in all backends --- it identifies current *************** *** 264,270 **** XLogwrtResult LogwrtResult; /* Protected by WALWriteLock: */ XLogCtlWrite Write; ! /* * These values do not change after startup, although the pointed-to * pages and xlblocks values certainly do. Permission to read/write --- 292,300 ---- XLogwrtResult LogwrtResult; /* Protected by WALWriteLock: */ XLogCtlWrite Write; ! /* Protected by WALWriteLock2 */ ! XLogCtlWrite Write2; /* Keeps track of write/flush position in ! secondary log segments. */ /* * These values do not change after startup, although the pointed-to * pages and xlblocks values certainly do. Permission to read/write *************** *** 370,375 **** --- 400,409 ---- snprintf(path, MAXPGPATH, "%s/%08X%08X", \ XLogDir, log, seg) + #define XLogFileName2(path, log, seg) \ + snprintf(path, MAXPGPATH, "%s/%08X%08X", \ + XLOG_duplicate_dir, log, seg) + #define PrevBufIdx(idx) \ (((idx) == 0) ? XLogCtl->XLogCacheBlck : ((idx) - 1)) *************** *** 435,447 **** static bool AdvanceXLInsertBuffer(void); static void XLogWrite(XLogwrtRqst WriteRqst); static int XLogFileInit(uint32 log, uint32 seg, ! bool *use_existent, bool use_lock); static bool InstallXLogFileSegment(uint32 log, uint32 seg, char *tmppath, bool find_free, int max_advance, ! bool use_lock); ! static int XLogFileOpen(uint32 log, uint32 seg, bool econt); static void PreallocXlogFiles(XLogRecPtr endptr); ! static void MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr); static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode, char *buffer); static bool ValidXLOGHeader(XLogPageHeader hdr, int emode, bool checkSUI); static XLogRecord *ReadCheckpointRecord(XLogRecPtr RecPtr, --- 469,482 ---- static bool AdvanceXLInsertBuffer(void); static void XLogWrite(XLogwrtRqst WriteRqst); static int XLogFileInit(uint32 log, uint32 seg, ! bool *use_existent, bool use_lock, bool duplicateLog); static bool InstallXLogFileSegment(uint32 log, uint32 seg, char *tmppath, bool find_free, int max_advance, ! bool use_lock,bool duplicateLog); ! static int XLogFileOpen(uint32 log, uint32 seg, bool econt, bool duplicateLog); static void PreallocXlogFiles(XLogRecPtr endptr); ! static void MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr, ! bool duplicateDir); static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode, char *buffer); static bool ValidXLOGHeader(XLogPageHeader hdr, int emode, bool checkSUI); static XLogRecord *ReadCheckpointRecord(XLogRecPtr RecPtr, *************** *** 451,457 **** static void ReadControlFile(void); static char *str_time(time_t tnow); static void xlog_outrec(char *buf, XLogRecord *record); ! static void issue_xlog_fsync(void); /* --- 486,492 ---- static void ReadControlFile(void); static char *str_time(time_t tnow); static void xlog_outrec(char *buf, XLogRecord *record); ! static void issue_xlog_fsync(int logFd); /* *************** *** 956,962 **** } } } ! /* * Now the next buffer slot is free and we can set it up to be the * next output page. --- 991,997 ---- } } } ! XLogWrite2(); /* * Now the next buffer slot is free and we can set it up to be the * next output page. *************** *** 1046,1055 **** /* create/use new log file */ use_existent = true; openLogFile = XLogFileInit(openLogId, openLogSeg, ! &use_existent, true); openLogOff = 0; ! if (!use_existent) /* there was no precreated file */ elog(LOG, "XLogWrite: new log file created - " "consider increasing 'wal_files' in postgresql.conf."); --- 1081,1090 ---- /* create/use new log file */ use_existent = true; openLogFile = XLogFileInit(openLogId, openLogSeg, ! &use_existent, true, false); openLogOff = 0; ! if (!use_existent && WalFileReuse) /* there was no precreated file */ elog(LOG, "XLogWrite: new log file created - " "consider increasing 'wal_files' in postgresql.conf."); *************** *** 1086,1092 **** if (openLogFile < 0) { XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg); ! openLogFile = XLogFileOpen(openLogId, openLogSeg, false); openLogOff = 0; } --- 1121,1127 ---- if (openLogFile < 0) { XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg); ! openLogFile = XLogFileOpen(openLogId, openLogSeg, false, false); openLogOff = 0; } *************** *** 1121,1127 **** */ if (openLogOff >= XLogSegSize && !ispartialpage) { ! issue_xlog_fsync(); LogwrtResult.Flush = LogwrtResult.Write; /* end of current page */ } --- 1156,1162 ---- */ if (openLogOff >= XLogSegSize && !ispartialpage) { ! issue_xlog_fsync(openLogFile); LogwrtResult.Flush = LogwrtResult.Write; /* end of current page */ } *************** *** 1158,1167 **** if (openLogFile < 0) { XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg); ! openLogFile = XLogFileOpen(openLogId, openLogSeg, false); openLogOff = 0; } ! issue_xlog_fsync(); } LogwrtResult.Flush = LogwrtResult.Write; } --- 1193,1202 ---- if (openLogFile < 0) { XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg); ! openLogFile = XLogFileOpen(openLogId, openLogSeg, false, false); openLogOff = 0; } ! issue_xlog_fsync(openLogFile); } LogwrtResult.Flush = LogwrtResult.Write; } *************** *** 1306,1311 **** --- 1341,1348 ---- "XLogFlush: request %X/%X is not satisfied --- flushed only to %X/%X", record.xlogid, record.xrecoff, LogwrtResult.Flush.xlogid, LogwrtResult.Flush.xrecoff); + + XLogWrite2(); } /* *************** *** 1325,1331 **** */ static int XLogFileInit(uint32 log, uint32 seg, ! bool *use_existent, bool use_lock) { char path[MAXPGPATH]; char tmppath[MAXPGPATH]; --- 1362,1368 ---- */ static int XLogFileInit(uint32 log, uint32 seg, ! bool *use_existent, bool use_lock, bool duplicateLog) { char path[MAXPGPATH]; char tmppath[MAXPGPATH]; *************** *** 1333,1339 **** int fd; int nbytes; ! XLogFileName(path, log, seg); /* * Try to use existent file (checkpoint maker may have created it --- 1370,1379 ---- int fd; int nbytes; ! if(duplicateLog) ! XLogFileName2(path,log,seg); ! else ! XLogFileName(path, log, seg); /* * Try to use existent file (checkpoint maker may have created it *************** *** 1359,1365 **** * up pre-creating an extra log segment. That seems OK, and better * than holding the lock throughout this lengthy process. */ ! snprintf(tmppath, MAXPGPATH, "%s/xlogtemp.%d", XLogDir, (int) getpid()); unlink(tmppath); --- 1399,1409 ---- * up pre-creating an extra log segment. That seems OK, and better * than holding the lock throughout this lengthy process. */ ! if(duplicateLog) ! snprintf(tmppath, MAXPGPATH, "%s/xlogtemp.%d", ! XLOG_duplicate_dir, (int) getpid()); ! else ! snprintf(tmppath, MAXPGPATH, "%s/xlogtemp.%d", XLogDir, (int) getpid()); unlink(tmppath); *************** *** 1414,1420 **** */ if (!InstallXLogFileSegment(log, seg, tmppath, *use_existent, XLOGfiles + XLOGfileslop, ! use_lock)) { /* No need for any more future segments... */ unlink(tmppath); --- 1458,1464 ---- */ if (!InstallXLogFileSegment(log, seg, tmppath, *use_existent, XLOGfiles + XLOGfileslop, ! use_lock, duplicateLog)) { /* No need for any more future segments... */ unlink(tmppath); *************** *** 1461,1471 **** static bool InstallXLogFileSegment(uint32 log, uint32 seg, char *tmppath, bool find_free, int max_advance, ! bool use_lock) { char path[MAXPGPATH]; int fd; XLogFileName(path, log, seg); /* --- 1505,1518 ---- static bool InstallXLogFileSegment(uint32 log, uint32 seg, char *tmppath, bool find_free, int max_advance, ! bool use_lock, bool duplicateLog) { char path[MAXPGPATH]; int fd; + if(duplicateLog) + XLogFileName2(path,log,seg); + else XLogFileName(path, log, seg); /* *************** *** 1494,1500 **** return false; } NextLogSeg(log, seg); ! XLogFileName(path, log, seg); } } --- 1541,1550 ---- return false; } NextLogSeg(log, seg); ! if(duplicateLog) ! XLogFileName2(path, log, seg); ! else ! XLogFileName(path, log, seg); } } *************** *** 1524,1534 **** * Open a pre-existing logfile segment. */ static int ! XLogFileOpen(uint32 log, uint32 seg, bool econt) { char path[MAXPGPATH]; int fd; XLogFileName(path, log, seg); fd = BasicOpenFile(path, O_RDWR | PG_BINARY | XLOG_SYNC_BIT, --- 1574,1587 ---- * Open a pre-existing logfile segment. */ static int ! XLogFileOpen(uint32 log, uint32 seg, bool econt, bool duplicateLog) { char path[MAXPGPATH]; int fd; + if(duplicateLog) + XLogFileName2(path, log, seg); + else XLogFileName(path, log, seg); fd = BasicOpenFile(path, O_RDWR | PG_BINARY | XLOG_SYNC_BIT, *************** *** 1568,1574 **** { NextLogSeg(_logId, _logSeg); use_existent = true; ! lf = XLogFileInit(_logId, _logSeg, &use_existent, true); close(lf); } } --- 1621,1627 ---- { NextLogSeg(_logId, _logSeg); use_existent = true; ! lf = XLogFileInit(_logId, _logSeg, &use_existent, true, false); close(lf); } } *************** *** 1577,1583 **** { NextLogSeg(_logId, _logSeg); use_existent = true; ! lf = XLogFileInit(_logId, _logSeg, &use_existent, true); close(lf); } } --- 1630,1636 ---- { NextLogSeg(_logId, _logSeg); use_existent = true; ! lf = XLogFileInit(_logId, _logSeg, &use_existent, true, false); close(lf); } } *************** *** 1589,1595 **** * whether we want to recycle rather than delete no-longer-wanted log files. */ static void ! MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr) { uint32 endlogId; uint32 endlogSeg; --- 1642,1648 ---- * whether we want to recycle rather than delete no-longer-wanted log files. */ static void ! MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr, bool duplicateDir) { uint32 endlogId; uint32 endlogSeg; *************** *** 1600,1609 **** XLByteToPrevSeg(endptr, endlogId, endlogSeg); xldir = opendir(XLogDir); if (xldir == NULL) elog(PANIC, "could not open transaction log directory (%s): %m", ! XLogDir); sprintf(lastoff, "%08X%08X", log, seg); --- 1653,1666 ---- XLByteToPrevSeg(endptr, endlogId, endlogSeg); + if(duplicateDir) + xldir = opendir(XLOG_duplicate_dir); + else xldir = opendir(XLogDir); + if (xldir == NULL) elog(PANIC, "could not open transaction log directory (%s): %m", ! duplicateDir ? XLOG_duplicate_dir : XLogDir); sprintf(lastoff, "%08X%08X", log, seg); *************** *** 1614,1620 **** --- 1671,1682 ---- strspn(xlde->d_name, "0123456789ABCDEF") == 16 && strcmp(xlde->d_name, lastoff) <= 0) { + if(duplicateDir) + snprintf(path, MAXPGPATH, "%s/%s", + XLOG_duplicate_dir, xlde->d_name); + else snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name); + if (XLOG_archive_dir[0]) { elog(LOG, "archiving transaction log file %s", *************** *** 1629,1637 **** * to XLOGfiles + XLOGfileslop segments beyond the current * XLOG location. */ ! if (InstallXLogFileSegment(endlogId, endlogSeg, path, true, XLOGfiles + XLOGfileslop, ! true)) { elog(LOG, "recycled transaction log file %s", xlde->d_name); --- 1691,1700 ---- * to XLOGfiles + XLOGfileslop segments beyond the current * XLOG location. */ ! if ( !RollForward && ! InstallXLogFileSegment(endlogId, endlogSeg, path, true, XLOGfiles + XLOGfileslop, ! true, false)) { elog(LOG, "recycled transaction log file %s", xlde->d_name); *************** *** 1823,1829 **** XLByteToSeg(*RecPtr, readId, readSeg); if (readFile < 0) { ! readFile = XLogFileOpen(readId, readSeg, (emode == LOG)); if (readFile < 0) goto next_record_is_invalid; readOff = (uint32) (-1); /* force read to occur below */ --- 1886,1892 ---- XLByteToSeg(*RecPtr, readId, readSeg); if (readFile < 0) { ! readFile = XLogFileOpen(readId, readSeg, (emode == LOG), false); if (readFile < 0) goto next_record_is_invalid; readOff = (uint32) (-1); /* force read to occur below */ *************** *** 1918,1924 **** close(readFile); readFile = -1; NextLogSeg(readId, readSeg); ! readFile = XLogFileOpen(readId, readSeg, (emode == LOG)); if (readFile < 0) goto next_record_is_invalid; readOff = 0; --- 1981,1987 ---- close(readFile); readFile = -1; NextLogSeg(readId, readSeg); ! readFile = XLogFileOpen(readId, readSeg, (emode == LOG),false); if (readFile < 0) goto next_record_is_invalid; readOff = 0; *************** *** 2047,2053 **** } } lastReadSUI = hdr->xlp_sui; ! return true; } /* --- 2110,2116 ---- } } lastReadSUI = hdr->xlp_sui; ! return (checkDuplicateLogPage(hdr)); } /* *************** *** 2426,2432 **** record->xl_crc = crc; use_existent = false; ! openLogFile = XLogFileInit(0, 0, &use_existent, false); errno = 0; if (write(openLogFile, buffer, BLCKSZ) != BLCKSZ) --- 2489,2495 ---- record->xl_crc = crc; use_existent = false; ! openLogFile = XLogFileInit(0, 0, &use_existent, false, false); errno = 0; if (write(openLogFile, buffer, BLCKSZ) != BLCKSZ) *************** *** 2486,2491 **** --- 2549,2559 ---- EndOfLog; XLogRecord *record; char *buffer; + bool timeCheckAbort = false; + + if(XLOG_duplicate_dir && !WalFileReuse) + elog(PANIC, + "Cannot use wal_file_duplicate parameter with wal_file_reuse=no"); /* Use malloc() to ensure record buffer is MAXALIGNED */ buffer = (char *) malloc(_INTL_MAXLOGRECSZ); *************** *** 2499,2504 **** --- 2567,2583 ---- * not do ReadControlFile() here, but might as well do it to be sure. */ ReadControlFile(); + if(RollUntil) + { + if(RollUntil < ControlFile->time) + { + elog(NOTICE, + "Database is more current than the 'roll_forward_until' time"); + elog(NOTICE,"Database: %s", + str_time(ControlFile->time)); + elog(PANIC,"roll_forward_until: %s",str_time(RollUntil)); + } + } if (ControlFile->logSeg == 0 || ControlFile->state < DB_SHUTDOWNED || *************** *** 2529,2536 **** if (record != NULL) { checkPointLoc = ControlFile->checkPoint; ! elog(LOG, "checkpoint record is at %X/%X", ! checkPointLoc.xlogid, checkPointLoc.xrecoff); } else { --- 2608,2625 ---- if (record != NULL) { checkPointLoc = ControlFile->checkPoint; ! { ! char path[MAXPGPATH]; ! uint32 log; ! uint32 seg; ! uint32 offset; ! ! XLByteToSeg(checkPointLoc,log,seg); ! snprintf(path, MAXPGPATH, "pg_xlog/%08X%08X", log, seg); ! offset = checkPointLoc.xrecoff % XLogSegSize; ! elog(LOG, "checkpoint record is in %s at offset %u", ! path,offset); ! } } else { *************** *** 2578,2591 **** elog(PANIC, "invalid redo/undo record in shutdown checkpoint"); InRecovery = true; } ! else if (ControlFile->state != DB_SHUTDOWNED) InRecovery = true; /* REDO */ if (InRecovery) { elog(LOG, "database system was not properly shut down; " "automatic recovery in progress"); ControlFile->state = DB_IN_RECOVERY; ControlFile->time = time(NULL); UpdateControlFile(); --- 2667,2684 ---- elog(PANIC, "invalid redo/undo record in shutdown checkpoint"); InRecovery = true; } ! else if (ControlFile->state != DB_SHUTDOWNED || RollForward) InRecovery = true; /* REDO */ if (InRecovery) { + if(RollForward) + elog(LOG, "roll forward recovery is in progress"); + else elog(LOG, "database system was not properly shut down; " "automatic recovery in progress"); + ControlFile->state = DB_IN_RECOVERY; ControlFile->time = time(NULL); UpdateControlFile(); *************** *** 2593,2599 **** XLogInitRelationCache(); /* Is REDO required ? */ ! if (XLByteLT(checkPoint.redo, RecPtr)) record = ReadRecord(&(checkPoint.redo), PANIC, buffer); else { --- 2686,2692 ---- XLogInitRelationCache(); /* Is REDO required ? */ ! if (XLByteLT(checkPoint.redo, RecPtr) || RollForward) record = ReadRecord(&(checkPoint.redo), PANIC, buffer); else { *************** *** 2604,2611 **** if (record != NULL) { InRedo = true; ! elog(LOG, "redo starts at %X/%X", ! ReadRecPtr.xlogid, ReadRecPtr.xrecoff); do { /* nextXid must be beyond record's xid */ --- 2697,2715 ---- if (record != NULL) { InRedo = true; ! { ! char path[MAXPGPATH]; ! uint32 log; ! uint32 seg; ! uint32 offset; ! ! XLByteToSeg(ReadRecPtr,log,seg); ! snprintf(path, MAXPGPATH, "pg_xlog/%08X%08X", log, seg); ! offset = ReadRecPtr.xrecoff % XLogSegSize; ! elog(LOG, "redo begins in %s at offset %u", ! path,offset); ! } ! do { /* nextXid must be beyond record's xid */ *************** *** 2632,2642 **** if (record->xl_info & XLR_BKP_BLOCK_MASK) RestoreBkpBlocks(record, EndRecPtr); RmgrTable[record->xl_rmid].rm_redo(EndRecPtr, record); record = ReadRecord(NULL, LOG, buffer); } while (record != NULL); ! elog(LOG, "redo done at %X/%X", ! ReadRecPtr.xlogid, ReadRecPtr.xrecoff); LastRec = ReadRecPtr; InRedo = false; } --- 2736,2764 ---- if (record->xl_info & XLR_BKP_BLOCK_MASK) RestoreBkpBlocks(record, EndRecPtr); + record = xactTimeCheck(record); + if(record) + { RmgrTable[record->xl_rmid].rm_redo(EndRecPtr, record); record = ReadRecord(NULL, LOG, buffer); + } + else + { + timeCheckAbort = true; + } } while (record != NULL); ! { ! char path[MAXPGPATH]; ! uint32 log; ! uint32 seg; ! uint32 offset; ! ! XLByteToSeg(ReadRecPtr,log,seg); ! snprintf(path, MAXPGPATH, "pg_xlog/%08X%08X", log, seg); ! offset = ReadRecPtr.xrecoff % XLogSegSize; ! elog(LOG, "redo done in %s at offset %u", ! path,offset); ! } LastRec = ReadRecPtr; InRedo = false; } *************** *** 2651,2657 **** record = ReadRecord(&LastRec, PANIC, buffer); EndOfLog = EndRecPtr; XLByteToPrevSeg(EndOfLog, openLogId, openLogSeg); ! openLogFile = XLogFileOpen(openLogId, openLogSeg, false); openLogOff = 0; ControlFile->logId = openLogId; ControlFile->logSeg = openLogSeg + 1; --- 2773,2779 ---- record = ReadRecord(&LastRec, PANIC, buffer); EndOfLog = EndRecPtr; XLByteToPrevSeg(EndOfLog, openLogId, openLogSeg); ! openLogFile = XLogFileOpen(openLogId, openLogSeg, false, false); openLogOff = 0; ControlFile->logId = openLogId; ControlFile->logSeg = openLogSeg + 1; *************** *** 2710,2721 **** --- 2832,2863 ---- LogwrtResult.Write = LogwrtResult.Flush = EndOfLog; XLogCtl->Write.LogwrtResult = LogwrtResult; + XLogCtl->Write2.LogwrtResult = LogwrtResult; Insert->LogwrtResult = LogwrtResult; XLogCtl->LogwrtResult = LogwrtResult; XLogCtl->LogwrtRqst.Write = EndOfLog; XLogCtl->LogwrtRqst.Flush = EndOfLog; + if(RollForward) + { + /* If its a roll forward operation flush the buffer pool + and remove unneeded log files. Don't write a new + checkpoint record. */ + FlushBufferPool(); + ShutdownCLOG(); + XLRemoveLog(NULL); + if(RollUntil && timeCheckAbort) + { + XLogReinit(LastRec); + } + + ControlFile->state = DB_IN_PRODUCTION; + UpdateControlFile(); + + return; + } + #ifdef NOT_USED /* UNDO */ if (InRecovery) *************** *** 2758,2763 **** --- 2900,2911 ---- * Preallocate additional log files, if wanted. */ PreallocXlogFiles(EndOfLog); + if(XLOG_duplicate_dir) + { + /* Make sure the duplicate directory has every file + the primary pg_xlog directory has. */ + XLOGDuplicateDirInit(); + } InRecovery = false; *************** *** 2900,2906 **** ShutdownXLOG(void) { elog(LOG, "shutting down"); ! /* suppress in-transaction check in CreateCheckPoint */ MyLastRecPtr.xrecoff = 0; MyXactMadeXLogEntry = false; --- 3048,3060 ---- ShutdownXLOG(void) { elog(LOG, "shutting down"); ! if (RollForward) ! { ! /* Don't want a shutdown check point if rolling ! forward the database. */ ! elog(LOG, "database system is shut down"); ! return; ! } /* suppress in-transaction check in CreateCheckPoint */ MyLastRecPtr.xrecoff = 0; MyXactMadeXLogEntry = false; *************** *** 2930,2936 **** if (MyXactMadeXLogEntry) elog(ERROR, "CreateCheckPoint: cannot be called inside transaction block"); ! /* * The CheckpointLock can be held for quite a while, which is not good * because we won't respond to a cancel/die request while waiting for --- 3084,3105 ---- if (MyXactMadeXLogEntry) elog(ERROR, "CreateCheckPoint: cannot be called inside transaction block"); ! /* ! * Wait for online backup to finish. ! */ ! LWLockAcquire(PagerLock, LW_EXCLUSIVE); ! while (PageInfo->backupPID) ! { ! if (kill(PageInfo->backupPID, 0)) ! { ! PageInfo->backupPID = 0; ! break; ! } ! LWLockRelease(PagerLock); ! sleep(1); ! LWLockAcquire(PagerLock, LW_EXCLUSIVE); ! } ! LWLockRelease(PagerLock); /* * The CheckpointLock can be held for quite a while, which is not good * because we won't respond to a cancel/die request while waiting for *************** *** 3063,3068 **** --- 3232,3245 ---- checkPoint.nextOid += ShmemVariableCache->oidCount; LWLockRelease(OidGenLock); + LWLockAcquire(PagerLock, LW_EXCLUSIVE); + if (PageInfo->backupPID) + { + LWLockRelease(PagerLock); + END_CRIT_SECTION(); + return; + } + LWLockRelease(PagerLock); /* * Having constructed the checkpoint record, ensure all shmem disk * buffers are flushed to disk. *************** *** 3131,3140 **** * Delete offline log files (those no longer needed even for previous * checkpoint). */ ! if (_logId || _logSeg) { PrevLogSeg(_logId, _logSeg); ! MoveOfflineLogs(_logId, _logSeg, recptr); } /* --- 3308,3317 ---- * Delete offline log files (those no longer needed even for previous * checkpoint). */ ! if (WalFileReuse && (_logId || _logSeg)) { PrevLogSeg(_logId, _logSeg); ! MoveOfflineLogs(_logId, _logSeg, recptr, false); } /* *************** *** 3173,3178 **** --- 3350,3356 ---- { uint8 info = record->xl_info & ~XLR_INFO_MASK; + LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); if (info == XLOG_NEXTOID) { Oid nextOid; *************** *** 3193,3198 **** --- 3371,3380 ---- ShmemVariableCache->nextXid = checkPoint.nextXid; ShmemVariableCache->nextOid = checkPoint.nextOid; ShmemVariableCache->oidCount = 0; + ControlFile->prevCheckPoint = ControlFile->checkPoint; + ControlFile->checkPoint = ReadRecPtr; + ControlFile->checkPointCopy = checkPoint; + ControlFile->time = checkPoint.time; } else if (info == XLOG_CHECKPOINT_ONLINE) { *************** *** 3208,3214 **** --- 3390,3401 ---- ShmemVariableCache->nextOid = checkPoint.nextOid; ShmemVariableCache->oidCount = 0; } + ControlFile->prevCheckPoint = ControlFile->checkPoint; + ControlFile->checkPoint = ReadRecPtr; + ControlFile->checkPointCopy = checkPoint; + ControlFile->time = checkPoint.time; } + LWLockRelease(ControlFileLock); } void *************** *** 3347,3364 **** * Issue appropriate kind of fsync (if any) on the current XLOG output file */ static void ! issue_xlog_fsync(void) { switch (sync_method) { case SYNC_METHOD_FSYNC: ! if (pg_fsync(openLogFile) != 0) elog(PANIC, "fsync of log file %u, segment %u failed: %m", openLogId, openLogSeg); break; #ifdef HAVE_FDATASYNC case SYNC_METHOD_FDATASYNC: ! if (pg_fdatasync(openLogFile) != 0) elog(PANIC, "fdatasync of log file %u, segment %u failed: %m", openLogId, openLogSeg); break; --- 3534,3552 ---- * Issue appropriate kind of fsync (if any) on the current XLOG output file */ static void ! issue_xlog_fsync(int logFd) { + switch (sync_method) { case SYNC_METHOD_FSYNC: ! if (pg_fsync(logFd) != 0) elog(PANIC, "fsync of log file %u, segment %u failed: %m", openLogId, openLogSeg); break; #ifdef HAVE_FDATASYNC case SYNC_METHOD_FDATASYNC: ! if (pg_fdatasync(logFd) != 0) elog(PANIC, "fdatasync of log file %u, segment %u failed: %m", openLogId, openLogSeg); break; *************** *** 3370,3373 **** --- 3558,4319 ---- elog(PANIC, "bogus wal_sync_method %d", sync_method); break; } + } + + void XLFinishBackup(void) + { + uint32 freespace; + XLogCtlInsert *Insert; + XLogRecPtr WriteRqstPtr; + + Insert = &XLogCtl->Insert; + freespace = INSERT_FREESPACE(Insert); + + /* flush/write the log upto wherever the current insert point is now */ + if (freespace < SizeOfXLogRecord) /* buffer is full */ + WriteRqstPtr = XLogCtl->xlblocks[Insert->curridx]; + else + { + WriteRqstPtr = XLogCtl->xlblocks[Insert->curridx]; + WriteRqstPtr.xrecoff -= freespace; + } + } + + /* XLRemoveLog - gets called in behalf of the + "alter system purge wal_files" statement. + Removes all xlog files <= to the specified + file name. If the file name is null it removes + all xlog files not needed for crash recovery. + */ + void + XLRemoveLog(char *pXLogName) + { + uint32 _logId,logId; + uint32 _logSeg, logSeg; + XLogRecPtr current; + XLogCtlInsert *Insert; + + + LWLockAcquire(ControlFileLock, LW_SHARED); + /* Get log id and segment id of the first segment required for + crash recovery. We can't remove this or later segments. */ + XLByteToSeg(ControlFile->checkPointCopy.redo, _logId, _logSeg); + LWLockRelease(ControlFileLock); + + if(pXLogName) + { + if (strlen(pXLogName) == 16 && + strspn(pXLogName, "0123456789ABCDEF") == 16) + sscanf(pXLogName,"%8x%8x",&logId, &logSeg); + else + { + elog(NOTICE,"%s: invalid wal file name",pXLogName); + return; + } + if(logId > _logId) + { + logId = _logId; + } + { + /* elog(NOTICE,"%s Can't purge that wal file",pXLogName); */ + logSeg = _logSeg; + if(logId || logSeg) + PrevLogSeg(logId,logSeg); + else + /* Nothing can be purged */ + return; + } + _logId = logId; + _logSeg = logSeg; + } + else + { + if(_logId || _logSeg) + PrevLogSeg(_logId, _logSeg); + else + return; /* Nothing to do */ + } + + LWLockAcquire(WALInsertLock, LW_SHARED); + Insert = &XLogCtl->Insert; + current = XLogCtl->xlblocks[Insert->curridx]; + LWLockRelease(WALInsertLock); + + MoveOfflineLogs(_logId, _logSeg, current, + XLOG_duplicate_dir ? true : false); + } + + /* + * XLogReinit - is called at the end of a roll forward to a point + * in time session. It removes all logs after the + * last log rolled forward and zeroes out the last + * log after the last record processed in that log. + * This is done so that a subsequent crash recovery + * can't redo beyond the point in time roll forward + * recovery session. + */ + static void + XLogReinit(XLogRecPtr EndOfLog) + { + /* Remove all of the existing log files */ + DIR *xldir; + struct dirent *xlde; + uint32 logId,segId; + char lastoff[32]; + + xldir = opendir(XLogDir); + if (xldir == NULL) + elog(PANIC, "could not open transaction log directory (%s): %m", + XLogDir); + + XLByteToSeg(EndOfLog,logId,segId); + sprintf(lastoff, "%08X%08X", logId, segId); + + errno = 0; + while ((xlde = readdir(xldir)) != NULL) + { + if (strlen(xlde->d_name) == 16 && + strspn(xlde->d_name, "0123456789ABCDEF") == 16 && + strcmp(xlde->d_name,lastoff) > 0) + { + char path[MAXPGPATH]; + snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name); + unlink(path); + } + } + closedir(xldir); + { + int endingOffset; + int written; + + openLogFile = XLogFileOpen(logId,segId,false,false); + openLogOff = EndOfLog.xrecoff % XLogSegSize; + endingOffset = openLogOff % BLCKSZ; + openLogOff -= endingOffset; + lseek(openLogFile,(off_t)openLogOff,SEEK_SET); + written = read(openLogFile,readBuf,BLCKSZ); + memset(readBuf+endingOffset,0,BLCKSZ - endingOffset); + lseek(openLogFile,(off_t)openLogOff,SEEK_SET); + written = write(openLogFile,readBuf,BLCKSZ); + openLogOff += BLCKSZ; + memset(readBuf,0,BLCKSZ); + for(;openLogOff < XLogSegSize;openLogOff += BLCKSZ) + written = write(openLogFile,readBuf,BLCKSZ); + close(openLogFile); + openLogFile = -1; + } + } + + bool + XLRollForward() + { + return RollForward; + } + + /* + * GUC support routine for checking for valid XLOG duplicate directory. + */ + const char * + XLogCheckDupdir(const char *dirPath,bool doit, bool interactive) + { + DIR *xldir; + const char *goodDir; + + xldir = opendir(dirPath); + if(xldir == NULL) + goodDir = NULL; + else + { + goodDir = dirPath; + XLOGPathInit(); + /* Make sure duplicate dir is not the pg_xlog directory. */ + if(strcmp(XLogDir,dirPath)==0) + { + goodDir = NULL; + } + } + closedir(xldir); + + return goodDir; + } + + /* + * GUC support routine for checking that the roll_forward_until time + * is a valid time. + */ + const char * + XLcheckTime(const char *timeString,bool doit, bool interactive) + { + struct tm untilTime; + char work[5]; + char *errorPosition; + + if(strlen(timeString) != 19) + { + elog(NOTICE,"Invalid time specification string"); + elog(NOTICE,"Time specification must be of the form: 'yyyy:mm:dd:hh:mm:ss'"); + return NULL; + } + memset(&untilTime,0,sizeof(struct tm)); + strncpy(work,timeString,4); + work[4] = '\0'; + untilTime.tm_year = (int)strtol(work,&errorPosition,10); + if(errorPosition - work != 4) + { + elog(NOTICE,"Invalid year specified for roll_forward_until '%s'",work); + return NULL; + } + if(untilTime.tm_year < 2002 || untilTime.tm_year > 3000) + { + elog(NOTICE,"Invalid year specified for roll_forward_until: '%s'", + work); + return NULL; + } + untilTime.tm_year -= 1900; + strncpy(work,timeString+5,2); + work[2] = '\0'; + untilTime.tm_mon = (int)strtol(work,&errorPosition,10); + if(errorPosition - work != 2) + { + elog(NOTICE,"Invalid month specified for roll_forward_until: '%s'",work); + return NULL; + } + if(untilTime.tm_mon < 1 || untilTime.tm_mon > 12) + { + elog(NOTICE,"Invalid month specified for roll_forward_until: '%s'",work); + return NULL; + } + untilTime.tm_mon--; + strncpy(work,timeString+8,2); + untilTime.tm_mday = (int)strtol(work,&errorPosition,10); + if(errorPosition - work != 2) + { + elog(NOTICE,"Invalid day specified for roll_forward_until: '%s'",work); + return NULL; + } + if(untilTime.tm_mday < 1 || untilTime.tm_mday > 31) + { + elog(NOTICE,"Invalid day specified for roll_forward_until: '%s'",work); + return NULL; + } + strncpy(work,timeString+11,2); + untilTime.tm_hour = (int)strtol(work,&errorPosition,10); + if(errorPosition - work != 2) + { + elog(NOTICE,"Invalid hour specified for roll_forward_until: '%s'",work); + return NULL; + } + if(untilTime.tm_hour < 0 || untilTime.tm_hour > 23) + { + elog(NOTICE,"Invalid hour specified for roll_forward_until: '%s'",work); + return NULL; + } + strncpy(work,timeString+14,2); + untilTime.tm_min = (int)strtol(work,&errorPosition,10); + if(errorPosition - work != 2) + { + elog(NOTICE,"Invalid minute specified for roll_forward_until: '%s'", + work); + return NULL; + } + if(untilTime.tm_min < 0 || untilTime.tm_min > 59) + { + elog(NOTICE,"Invalid minute specified for roll_forward_until: '%s'", + work); + return NULL; + } + strncpy(work,timeString+17,2); + untilTime.tm_sec = (int)strtol(work,&errorPosition,10); + if(errorPosition - work != 2) + { + elog(NOTICE,"Invalid second specified for roll_forward_until: '%s'", + work); + return NULL; + } + if(untilTime.tm_sec < 0 || untilTime.tm_sec > 59) + { + elog(NOTICE,"Invalid second specified for roll_forward_until: '%s'", + work); + return NULL; + } + untilTime.tm_isdst = -1; + RollUntil = mktime(&untilTime); + if(RollUntil < 0) + { + return NULL; + } + RollForward = true; + + return timeString; + } + + /* + * Check if its a commit or abort record and if so + * is past the time we are to roll forward to. + * + * returns null if point in time has been exceeded. + * otherwise it returns pointer to input record. + */ + static XLogRecord * + xactTimeCheck(XLogRecord * record) + { + if(!RollUntil) + return record; + + if(record->xl_rmid == RM_XACT_ID) + { + time_t theTime = 0; + uint8 xl_info = record->xl_info & XLR_INFO_MASK; + + if(xl_info == XLOG_XACT_COMMIT) + { + xl_xact_commit *xlrec; + xlrec = (xl_xact_commit *)XLogRecGetData(record); + theTime = xlrec->xtime; + } + else if(xl_info == XLOG_XACT_ABORT) + { + xl_xact_abort *xlrec; + xlrec = (xl_xact_abort *)XLogRecGetData(record); + theTime = xlrec->xtime; + } + if(theTime >= RollUntil) + record = NULL; + } + + return record; + } + + /* + * Make sure duplicate xlog dir has a copy of every file in the primary + * directory. + */ + static void + XLOGDuplicateDirInit() + { + DIR *xldir; + struct dirent *xlde; + + + xldir = opendir(XLogDir); + if (xldir == NULL) + elog(PANIC, "could not open transaction log directory (%s): %m", + XLogDir); + + errno = 0; + while ((xlde = readdir(xldir)) != NULL) + { + if (strlen(xlde->d_name) == 16 && + strspn(xlde->d_name, "0123456789ABCDEF") == 16) + { + bool foundit = false; + DIR *xldir2; + struct dirent *xlde2; + xldir2 = opendir(XLOG_duplicate_dir); + while(foundit == false && ((xlde2 = readdir(xldir2)) != NULL)) + { + if(strcmp(xlde->d_name,xlde2->d_name) == 0) + foundit = true; + } + closedir(xldir2); + if(!foundit) + { + /* copy file into duplicate directory */ + XLogCopyFileToDuplicateDir(xlde->d_name); + } + } + } + closedir(xldir); + } + + void + XLogCopyFileToDuplicateDir(char *segmentName) + { + int fd1,fd2; + char path[MAXPGPATH]; + char aBuffer[BLCKSZ]; + + snprintf(path, MAXPGPATH, "%s/%s", XLogDir, segmentName); + + fd1 = BasicOpenFile(path, O_RDWR | PG_BINARY, + S_IRUSR | S_IWUSR); + if (fd1 < 0) + { + if (errno != ENOENT) + { + elog(PANIC, "open of %s failed: %m", path); + } + } + snprintf(path, MAXPGPATH, "%s/%s", XLOG_duplicate_dir, segmentName); + + fd2 = BasicOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, + S_IRUSR | S_IWUSR); + if (fd2 < 0) + elog(PANIC, "creation of file %s failed: %m", path); + + while((read(fd1,aBuffer,BLCKSZ)) == BLCKSZ) + { + write(fd2,aBuffer,BLCKSZ); + } + close(fd1); + pg_fsync(fd2); + close(fd2); + } + + /* + * Write and/or fsync the duplicate log (XLogCtlData->Write2) as far as the + * the primary log (XLogCtlData->Write) has been written/flushed. + * + */ + static void + XLogWrite2() + { + XLogwrtResult log1; + XLogwrtResult log2; + char *from; + bool ispartialpage,use_existent; + + if(!XLOG_duplicate_dir) + return; + + /* Get the current write/flush position of the primary log. */ + SpinLockAcquire_NoHoldoff(&XLogCtl->info_lck); + log1 = XLogCtl->LogwrtResult; + SpinLockRelease_NoHoldoff(&XLogCtl->info_lck); + + /* Lock the WalWriteLock2 lock */ + LWLockAcquire(WALWriteLock2, LW_EXCLUSIVE); + log2 = XLogCtl->Write2.LogwrtResult; + + if ((XLByteLE(log1.Write,log2.Write)) && + (XLByteLE(log1.Flush,log2.Flush))) + { + /* writes to duplicate log are up to date with primary so we're done */ + /* Release the WalWriteLock2 lock */ + LWLockRelease(WALWriteLock2); + return; + } + + while((XLByteLT(log2.Write,log1.Write))) + { + log2.Write = XLogCtl->xlblocks[XLogCtl->Write2.curridx]; + ispartialpage = XLByteLT(log1.Write, log2.Write); + + /* Do some writes to catch the duplicate log up with the primary log. */ + if (!XLByteInPrevSeg(log2.Write, openLogId2, openLogSeg2)) + { + /* + * Switch to new logfile segment. + */ + if (openLogFile2 >= 0) + { + if (close(openLogFile2) != 0) + elog(PANIC, "close of log file %u, segment %u failed: %m", + openLogId2, openLogSeg2); + openLogFile2 = -1; + } + XLByteToPrevSeg(log2.Write, openLogId2, openLogSeg2); + + /* create/use new log file */ + use_existent = true; + openLogFile2 = XLogFileInit(openLogId2, openLogSeg2, + &use_existent, true, true); + openLogOff2 = 0; + } + if (openLogFile2 < 0) + { + XLByteToPrevSeg(log2.Write, openLogId2, openLogSeg2); + openLogFile2 = XLogFileOpen(openLogId2, openLogSeg2, false,true); + openLogOff2 = 0; + } + /* Need to seek in the file? */ + if (openLogOff2 != (log2.Write.xrecoff - BLCKSZ) % XLogSegSize) + { + openLogOff2 = (log2.Write.xrecoff - BLCKSZ) % XLogSegSize; + if (lseek(openLogFile2, (off_t) openLogOff2, SEEK_SET) < 0) + elog(PANIC, + "lseek of duplicate log file %u, segment %u, offset %u failed: %m", + openLogId2, openLogSeg2, openLogOff2); + } + from = XLogCtl->pages + XLogCtl->Write2.curridx * BLCKSZ; + errno = 0; + if (write(openLogFile2, from, BLCKSZ) != BLCKSZ) + { + /* if write didn't set errno, assume problem is no disk space */ + if (errno == 0) + errno = ENOSPC; + elog(PANIC, + "write of duplicate log file %u, segment %u, offset %u failed: %m", + openLogId2, openLogSeg2, openLogOff2); + } + openLogOff2 += BLCKSZ; + /* + * If we just wrote the whole last page of a logfile segment, + * fsync the segment immediately. This avoids having to go back + * and re-open prior segments when an fsync request comes along + * later. Doing it here ensures that one and only one backend will + * perform this fsync. + */ + if (openLogOff2 >= XLogSegSize && !ispartialpage) + { + issue_xlog_fsync(openLogFile2); + log2.Flush = log2.Write; /* end of current page */ + } + + if (ispartialpage) + { + /* Only asked to write a partial page */ + log2.Write = log1.Write; + break; + } + XLogCtl->Write2.curridx = NextBufIdx(XLogCtl->Write2.curridx); + } + /* + * If asked to flush, do so + */ + if (XLByteLT(log2.Flush, log1.Flush) && + XLByteLT(log2.Flush, log2.Write)) + { + /* + * Could get here without iterating above loop, in which case we + * might have no open file or the wrong one. However, we do not + * need to fsync more than one file. + */ + if (sync_method != SYNC_METHOD_OPEN) + { + if (openLogFile2 >= 0 && + !XLByteInPrevSeg(log2.Write, openLogId2, openLogSeg2)) + { + if (close(openLogFile2) != 0) + elog(PANIC, "close of duplicate log file %u, segment %u failed: %m", + openLogId2, openLogSeg2); + openLogFile2 = -1; + } + if (openLogFile2 < 0) + { + XLByteToPrevSeg(log2.Write, openLogId2, openLogSeg2); + openLogFile2 = XLogFileOpen(openLogId2, openLogSeg2, false, true); + openLogOff2 = 0; + } + issue_xlog_fsync(openLogFile2); + } + log2.Flush = log2.Write; + } + XLogCtl->Write2.LogwrtResult = log2; + LWLockRelease(WALWriteLock2); + } + + /* + * Check to make sure page pointed to by hdr was written to the duplicate log area. + * + */ + static bool + checkDuplicateLogPage(XLogPageHeader hdr) + { + int rc; + uint64 buf[BLCKSZ / sizeof(uint64)]; + char *pbuf = (char *)buf; + + if(!XLOG_duplicate_dir) + return true; + + /* Read the page from the duplicate log */ + rc = readDuplicatePage(hdr->xlp_pageaddr, pbuf); + if(rc) + return false; + /* Compare the page to the primary log page */ + if(memcmp(pbuf,hdr,BLCKSZ)) + { + /* If they don't compare then write the page from the primary log + to the secondary log. */ + writeDuplicatePage(hdr); + } + + return true; + } + + /* + * Read the specified page from the secondary log + * + */ + static int + readDuplicatePage(XLogRecPtr pageaddr, char *pbuf) + { + uint32 logId, logSeg; + bool use_existant = true; + int32 size; + char path[MAXPGPATH]; + uint32 offset; + + XLByteToSeg(pageaddr, logId, logSeg); + if (readFile2 < 0) + { + readFile2 = XLogFileOpen(logId, logSeg,true, true); + + if (readFile2 < 0) + { + /* XLogFileOpen stops on error unless the error is that the + file doesn't exist, so create it. */ + XLogFileName2(path,logId,logSeg); + elog(LOG,"Creating log file %s",path); + readFile2 = XLogFileInit(logId, logSeg, &use_existant, true, true); + } + } + else if(logId != readId2 || logSeg != readSeg2) + { + /* Open the new file */ + close(readFile2); + readFile2 = XLogFileOpen(logId, logSeg, true, true); + /* Check if its the right size */ + if (readFile2 < 0) + { + /* XLogFileOpen stops on error unless the error is that the + file doesn't exist, so create it. */ + readFile2 = XLogFileInit(logId, logSeg, &use_existant, true, true); + } + + /* If its not the right size remove it and re-initialize */ + /* Check the file size to handle the case where the system + crashed while the segment was being created. */ + XLogFileName2(path,logId,logSeg); + size = getSegmentFileSize(path); + if(size < 0) + { + elog(PANIC, "Could not get the size of file %s : %m", path); + } + if(size != XLogSegSize) + { + elog(LOG,"segment %s is %d bytes it should be %d",path,size,XLogSegSize); + elog(LOG,"Re-creating the segment to make it the correct size"); + close(readFile2); + unlink(path); + use_existant = false; + /* Note the file init procedure either succeeds or never returns */ + readFile2 = XLogFileInit(logId, logSeg, &use_existant, true, true); + } + } + readId2 = logId; + readSeg2 = logSeg; + + /* Get the offset */ + offset = pageaddr.xrecoff % XLogSegSize; + if(offset != readOff2) + { + if (lseek(readFile2, (off_t) offset, SEEK_SET) < 0) + elog(PANIC, "lseek of duplicate log file %u, segment %u, offset %u failed: %m", + readId2, readSeg2, offset); + } + if (read(readFile2, pbuf, BLCKSZ) != BLCKSZ) + elog(PANIC, "read of duplicate log file %u, segment %u, offset %u failed: %m", + readId2, readSeg2, offset); + + readOff2 = offset + BLCKSZ; + + return 0; + } + + static int32 + getSegmentFileSize(char *path) + { + int rc; + struct stat statBuf; + + rc = stat(path, &statBuf); + if(rc) + return rc; + + return (int32)statBuf.st_size; + } + + static void + writeDuplicatePage(XLogPageHeader hdr) + { + + if (lseek(readFile2, (off_t) readOff2 - BLCKSZ, SEEK_SET) < 0) + elog(PANIC, "lseek of duplicate log file %u, segment %u, offset %u failed: %m", + readId2, readSeg2, readOff2 - BLCKSZ); + + if(write(readFile2,hdr,BLCKSZ) != BLCKSZ) + { + elog(PANIC,"write to duplicate log file %u, segment %u, offset %u failed %m", + readId2, readSeg2, readOff2 - BLCKSZ); + } + } + + /* + * XLWalFileStatus - procedure to support the wal_file sql function. + */ + void + XLWalFileStatus(char *whichLog) + { + XLogCtlInsert *Insert; + XLogRecPtr WriteRqstPtr; + uint32 logId,logSeg; + + if(strcmp(whichLog,"OLDEST")==0) + { + XLWalFileOldest(whichLog); + return; + } + LWLockAcquire(WALInsertLock, LW_SHARED); + Insert = &XLogCtl->Insert; + /* We'll flush/write the log upto whatever the current insert point + is now */ + WriteRqstPtr = XLogCtl->xlblocks[Insert->curridx]; + LWLockRelease(WALInsertLock); + + if(strcmp(whichLog,"CURRENT")==0) + { + XLByteToSeg(WriteRqstPtr,logId,logSeg); + } + else if(strcmp(whichLog,"LAST")==0) + { + XLByteToSeg(WriteRqstPtr,logId,logSeg); + if(logId || logSeg) + PrevLogSeg(logId, logSeg); + } + else + { + LWLockAcquire(ControlFileLock, LW_SHARED); + WriteRqstPtr = ControlFile->checkPointCopy.redo; + LWLockRelease(ControlFileLock); + XLByteToSeg(WriteRqstPtr,logId,logSeg); + } + sprintf(whichLog, "%08X%08X", logId, logSeg); + } + + /* + * Return the name of the oldest log file found in the pg_xlog directory + */ + static void + XLWalFileOldest(char *whichLog) + { + DIR *xldir; + struct dirent *xlde; + + if(XLOG_duplicate_dir) + xldir = opendir(XLOG_duplicate_dir); + else + xldir = opendir(XLogDir); + if (xldir == NULL) + { + elog(ERROR, "could not open transaction log directory (%s): %m", + XLOG_duplicate_dir ? XLOG_duplicate_dir : XLogDir); + return; + } + + sprintf(whichLog, "%08X%08X", (unsigned)0xFFFFFFFFFF, (unsigned)0xFFFFFFFF); + errno = 0; + while ((xlde = readdir(xldir)) != NULL) + { + if (strlen(xlde->d_name) == 16 && + strspn(xlde->d_name, "0123456789ABCDEF") == 16) + { + if(strcmp(xlde->d_name, whichLog) < 0) + strcpy(whichLog,xlde->d_name); + } + } + closedir(xldir); + + return; } diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/commands/Makefile /usr1/richt/pgsql_mirror.pitr/src/backend/commands/Makefile *** /usr1/richt/pgsql_mirror/src/backend/commands/Makefile Thu Jul 11 03:39:27 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/commands/Makefile Fri Jul 26 16:34:22 2002 *************** *** 19,24 **** --- 19,26 ---- schemacmds.o sequence.o tablecmds.o trigger.o typecmds.o user.o \ vacuum.o vacuumlazy.o variable.o view.o + OBJS := $(OBJS) backup.o + all: SUBSYS.o SUBSYS.o: $(OBJS) diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/commands/backup.c /usr1/richt/pgsql_mirror.pitr/src/backend/commands/backup.c *** /usr1/richt/pgsql_mirror/src/backend/commands/backup.c Wed Dec 31 19:00:00 1969 --- /usr1/richt/pgsql_mirror.pitr/src/backend/commands/backup.c Fri Jul 26 16:34:22 2002 *************** *** 0 **** --- 1,274 ---- + /*------------------------------------------------------------------------- + * + * backup.c + * + * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * $Header: /nusphere/nsdb/Repository/cvsroot/pgsql_nsdb/src/backend/commands/backup.c,v 1.4 2002/07/25 20:00:47 mquayle Exp $ + * + *------------------------------------------------------------------------- + */ + + #include "postgres.h" + #include "postgres_ext.h" + #include + #include + #include + #include + + #include "access/heapam.h" + #include "miscadmin.h" + #include "catalog/catname.h" + #include "access/genam.h" + #include "commands/dbcommands.h" + #include "storage/buf_internals.h" + #include "access/xlog.h" + + extern PageInfoStruct* PageInfo; + + void hook(void); + + void ASbegin(char* copyDir) + { + char command[8192]; + DIR *dp = NULL; + + /* Check copyDir is empty */ + if ((dp = opendir(copyDir))) + { + struct dirent *dirp; + + while ((dirp = readdir(dp))) + { + if (!strcmp(".", dirp->d_name)) + continue; + if (!strcmp("..", dirp->d_name)) + continue; + elog(ERROR, "foo: Backup directory '%s' is not empty\n", copyDir); + } + } + else + { + sprintf(command, "mkdir -p %s", copyDir); + system(command); + } + + LWLockAcquire(PagerLock, LW_EXCLUSIVE); + PageInfo->backupPID = getpid(); + LWLockRelease(PagerLock); + + sprintf(command, "chmod 700 %s", copyDir); + system(command); + sprintf(command, "%s/global", copyDir); + mkdir(command, S_IRWXU); + sprintf(command, "cp %s/global/pg_control %s/global", DataDir, copyDir); + system(command); + sprintf(command, "%s/base", copyDir); + mkdir(command, S_IRWXU); + sprintf(command, "%s/pg_xlog", copyDir); + mkdir(command, S_IRWXU); + sprintf(command, "cp -r %s/pg_clog %s", DataDir, copyDir); + system(command); + sprintf(command, "cp %s/pg_hba.conf %s", DataDir, copyDir); + system(command); + sprintf(command, "cp %s/pg_ident.conf %s", DataDir, copyDir); + system(command); + sprintf(command, "cp %s/pgruntime.conf %s", DataDir, copyDir); + system(command); + sprintf(command, "cp %s/postgresql.conf %s", DataDir, copyDir); + system(command); + sprintf(command, "cp %s/postmaster.opts %s", DataDir, copyDir); + system(command); + sprintf(command, "cp %s/PG_VERSION %s", DataDir, copyDir); + system(command); + } + + void ASbackup(char* copyDir, char* DBoid) + { + Buffer buffer = InvalidBuffer; + Relation reln = NULL; + HeapTuple tuple; + Relation table; + TupleDesc tupdesc; + HeapScanDesc scan; + char command[8192]; + + if (!strcmp(DatabaseName, "template1")) + { + if (atoi(DBoid) != 1) + { + sprintf(command, "cp -r %s/base/%s %s/base", DataDir, DBoid, copyDir); + system(command); + return; + } + } + + sprintf(command, "%s/base/%s", copyDir, DBoid); + mkdir(command, S_IRWXU); + sprintf(command, "cp %s/base/%s/pg_internal.init %s/base/%s", DataDir, DBoid, copyDir, DBoid); + system(command); + sprintf(command, "cp %s/base/%s/PG_VERSION %s/base/%s", DataDir, DBoid, copyDir, DBoid); + system(command); + + table = heap_openr(RelationRelationName, AccessShareLock); + tupdesc = RelationGetDescr(table); + scan = heap_beginscan(table, SnapshotNow, 0, NULL); + while (HeapTupleIsValid(tuple = heap_getnext(scan, ForwardScanDirection))) + { + int failed; + bool isNull; + char *relname; + BlockNumber page; + BlockNumber pages; + Oid relationOid; + + Datum item = heap_getattr(tuple, Anum_pg_class_relkind, tupdesc, &isNull); + char relkind = DatumGetChar(item); + + item = heap_getattr(tuple, ObjectIdAttributeNumber, tupdesc, &isNull); + relationOid = DatumGetObjectId(item); + switch (relkind) + { + case RELKIND_RELATION: + case RELKIND_TOASTVALUE: + reln = heap_open(relationOid, AccessShareLock); + break; + case RELKIND_INDEX: + reln = index_open(relationOid); + break; + default: + continue; + } + + buffer = InvalidBuffer; + pages = RelationGetNumberOfBlocks(reln); + BufferBackup(reln, buffer, copyDir); + for (page = 0; page < pages; page++) + { + buffer = ReleaseAndReadBuffer(buffer, reln, page); + if (!BufferIsValid(buffer)) + elog(ERROR, "foo: failed ReadBuffer"); + LockBuffer(buffer, BUFFER_LOCK_SHARE); + failed = BufferBackup(reln, buffer, copyDir); + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + if (failed) + break; + } + ReleaseBuffer(buffer); + + switch (relkind) + { + case RELKIND_RELATION: + case RELKIND_TOASTVALUE: + heap_close(reln, NoLock); + break; + case RELKIND_INDEX: + index_close(reln); + break; + } + } + if(reln) + BufferBackup(reln, buffer, NULL); + heap_endscan(scan); + heap_close(table, AccessShareLock); + } + + void ASfinish(char* copyDir, char* archDir) + { + int currNum; + int checkNum; + DIR *dp = NULL; + char command[8192]; + char destDir[8192]; + char fullpath[8192]; + char *ptr; + + strcpy(command, "CURRENT"); + XLWalFileStatus(command); + currNum = atoi(command); + strcpy(command, "CHECKPOINT"); + XLWalFileStatus(command); + checkNum = atoi(command); + sprintf(fullpath, "%s/pg_xlog", DataDir); + if ((dp = opendir(fullpath))) + { + int logNum; + struct dirent *dirp; + struct stat statbuf; + + ptr = fullpath + strlen(fullpath); + *ptr++ = '/'; + while ((dirp = readdir(dp))) + { + if (!strcmp(dirp->d_name, ".")) + continue; + if (!strcmp(dirp->d_name, "..")) + continue; + strcpy(ptr, dirp->d_name); + if (lstat(fullpath, &statbuf) < 0) + continue; + if ((statbuf.st_mode & S_IFMT) != S_IFREG) + continue; + logNum = atoi(dirp->d_name); + if (logNum == currNum) + continue; + if (logNum > currNum) + { + int dummy = currNum; + currNum = logNum; + logNum = dummy; + } + + if (logNum >= checkNum) + { + sprintf(command, "cp %s/pg_xlog/%016d %s/pg_xlog", DataDir, logNum, copyDir); + system(command); + } + if (logNum <= checkNum) + { + sprintf(command, "%s/pg_xlog/%016d", DataDir, logNum); + if (archDir) + { + sprintf(command, "%s/%016d", archDir, logNum); + rename(command, destDir); + } + else + unlink(command); + } + } + closedir(dp); + + Assert(currNum >= checkNum); + LWLockAcquire(WALInsertLock, LW_EXCLUSIVE); + XLFinishBackup(); + if (currNum == checkNum) + { + if (archDir) + { + sprintf(command, "cp %s/pg_xlog/%016d %s", DataDir, currNum, archDir); + system(command); + } + } + + do + { + sprintf(command, "cp %s/pg_xlog/%016d %s/pg_xlog 2>/dev/null", DataDir, currNum, copyDir); + currNum++; + } + while (system(command) == 0); + LWLockRelease(WALInsertLock); + } + else + elog(ERROR, "Unable to open directory: %s", command); + + LWLockAcquire(PagerLock, LW_EXCLUSIVE); + PageInfo->backupPID = 0; + LWLockRelease(PagerLock); + } + + void ASabort() + { + } diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/parser/gram.y /usr1/richt/pgsql_mirror.pitr/src/backend/parser/gram.y *** /usr1/richt/pgsql_mirror/src/backend/parser/gram.y Wed Jul 24 15:11:10 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/parser/gram.y Mon Jul 29 19:37:41 2002 *************** *** 132,138 **** } %type stmt, schema_stmt, ! AlterDatabaseSetStmt, AlterGroupStmt, AlterTableStmt, AlterUserStmt, AlterUserSetStmt, AnalyzeStmt, ClosePortalStmt, ClusterStmt, CommentStmt, ConstraintsSetStmt, CopyStmt, CreateAsStmt, CreateCastStmt, --- 132,138 ---- } %type stmt, schema_stmt, ! AlterDatabaseSetStmt, AlterGroupStmt, AlterSystemStmt, AlterTableStmt, AlterUserStmt, AlterUserSetStmt, AnalyzeStmt, ClosePortalStmt, ClusterStmt, CommentStmt, ConstraintsSetStmt, CopyStmt, CreateAsStmt, CreateCastStmt, *************** *** 319,326 **** /* ordinary key words in alphabetical order */ %token ABORT_TRANS, ABSOLUTE, ACCESS, ACTION, ADD, AFTER, ! AGGREGATE, ALL, ALTER, ANALYSE, ANALYZE, AND, ANY, AS, ASC, ! ASSERTION, ASSIGNMENT, AT, AUTHORIZATION, BACKWARD, BEFORE, BEGIN_TRANS, BETWEEN, BIGINT, BINARY, BIT, BOTH, BOOLEAN, BY, --- 319,326 ---- /* ordinary key words in alphabetical order */ %token ABORT_TRANS, ABSOLUTE, ACCESS, ACTION, ADD, AFTER, ! AGGREGATE, ALL, ALTER, ANALYSE, ANALYZE, AND, ANY, ARCHIVE, AS, ASC, ! ASSERTION, ASSIGNMENT, AT, AUTHORIZATION, BACKUP BACKWARD, BEFORE, BEGIN_TRANS, BETWEEN, BIGINT, BINARY, BIT, BOTH, BOOLEAN, BY, *************** *** 339,345 **** EACH, ELSE, ENCODING, ENCRYPTED, END_TRANS, ESCAPE, EXCEPT, EXCLUSIVE, EXECUTE, EXISTS, EXPLAIN, EXTERNAL, EXTRACT, ! FALSE_P, FETCH, FLOAT_P, FOR, FORCE, FOREIGN, FORWARD, FREEZE, FROM, FULL, FUNCTION, GET, GLOBAL, GRANT, GROUP_P, --- 339,345 ---- EACH, ELSE, ENCODING, ENCRYPTED, END_TRANS, ESCAPE, EXCEPT, EXCLUSIVE, EXECUTE, EXISTS, EXPLAIN, EXTERNAL, EXTRACT, ! FALSE_P, FETCH, FINISH, FLOAT_P, FOR, FORCE, FOREIGN, FORWARD, FREEZE, FROM, FULL, FUNCTION, GET, GLOBAL, GRANT, GROUP_P, *************** *** 369,375 **** PARTIAL, PASSWORD, PATH_P, PENDANT, PLACING, POSITION, PRECISION, PRIMARY, PRIOR, PRIVILEGES, PROCEDURE, ! PROCEDURAL, READ, REAL, REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE, RESET, RESTRICT, RETURNS, REVOKE, RIGHT, ROLLBACK, ROW, --- 369,375 ---- PARTIAL, PASSWORD, PATH_P, PENDANT, PLACING, POSITION, PRECISION, PRIMARY, PRIOR, PRIVILEGES, PROCEDURE, ! PROCEDURAL, PURGE, READ, REAL, REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE, RESET, RESTRICT, RETURNS, REVOKE, RIGHT, ROLLBACK, ROW, *************** *** 379,385 **** SERIALIZABLE, SESSION, SESSION_USER, SET, SETOF, SHARE, SHOW, SIMILAR, SIMPLE, SMALLINT, SOME, STABLE, START, STATEMENT, STATISTICS, STDIN, STDOUT, STORAGE, STRICT, SUBSTRING, ! SYSID, TABLE, TEMP, TEMPLATE, TEMPORARY, THEN, TIME, TIMESTAMP, TO, TOAST, TRAILING, TRANSACTION, TREAT, TRIGGER, TRIM, TRUE_P, --- 379,385 ---- SERIALIZABLE, SESSION, SESSION_USER, SET, SETOF, SHARE, SHOW, SIMILAR, SIMPLE, SMALLINT, SOME, STABLE, START, STATEMENT, STATISTICS, STDIN, STDOUT, STORAGE, STRICT, SUBSTRING, ! SYSID, SYSTEM, TABLE, TEMP, TEMPLATE, TEMPORARY, THEN, TIME, TIMESTAMP, TO, TOAST, TRAILING, TRANSACTION, TREAT, TRIGGER, TRIM, TRUE_P, *************** *** 391,397 **** VACUUM, VALID, VALIDATOR, VALUES, VARCHAR, VARYING, VERBOSE, VERSION, VIEW, VOLATILE, ! WHEN, WHERE, WITH, WITHOUT, WORK, WRITE, YEAR_P, --- 391,397 ---- VACUUM, VALID, VALIDATOR, VALUES, VARCHAR, VARYING, VERBOSE, VERSION, VIEW, VOLATILE, ! WAL_FILES, WHEN, WHERE, WITH, WITHOUT, WORK, WRITE, YEAR_P, *************** *** 468,473 **** --- 468,474 ---- stmt : AlterDatabaseSetStmt | AlterGroupStmt + | AlterSystemStmt | AlterTableStmt | AlterUserStmt | AlterUserSetStmt *************** *** 3679,3684 **** --- 3680,3748 ---- /***************************************************************************** * * QUERY: + * alter system + * + *****************************************************************************/ + + AlterSystemStmt: ALTER SYSTEM PURGE WAL_FILES file_name + { + AlterSystemStmt *n = makeNode(AlterSystemStmt); + n->subType = AS_Purge; + n->logName = $5; + n->backupDir = NULL; + n->archivDir = NULL; + $$ = (Node *)n; + } + | ALTER SYSTEM BEGIN_TRANS BACKUP file_name + { + AlterSystemStmt *n = makeNode(AlterSystemStmt); + n->subType = AS_Begin; + n->logName = NULL; + n->backupDir = $5; + n->archivDir = NULL; + $$ = (Node *)n; + } + | ALTER SYSTEM BACKUP file_name TO file_name + { + AlterSystemStmt *n = makeNode(AlterSystemStmt); + n->subType = AS_Backup; + n->logName = NULL; + n->backupDir = $6; + n->archivDir = $4; + $$ = (Node *)n; + } + | ALTER SYSTEM FINISH BACKUP file_name ARCHIVE file_name + { + AlterSystemStmt *n = makeNode(AlterSystemStmt); + n->subType = AS_Finish; + n->logName = NULL; + n->backupDir = $5; + n->archivDir = $7; + $$ = (Node *)n; + } + | ALTER SYSTEM FINISH BACKUP file_name + { + AlterSystemStmt *n = makeNode(AlterSystemStmt); + n->subType = AS_Finish; + n->logName = NULL; + n->backupDir = $5; + n->archivDir = NULL; + $$ = (Node *)n; + } + | ALTER SYSTEM ABORT_TRANS BACKUP file_name + { + AlterSystemStmt *n = makeNode(AlterSystemStmt); + n->subType = AS_Abort; + n->logName = NULL; + n->backupDir = $5; + n->archivDir = NULL; + $$ = (Node *)n; + } + ; + + /***************************************************************************** + * + * QUERY: * vacuum * analyze * *************** *** 6611,6619 **** --- 6675,6685 ---- | AFTER | AGGREGATE | ALTER + | ARCHIVE | ASSERTION | ASSIGNMENT | AT + | BACKUP | BACKWARD | BEFORE | BEGIN_TRANS *************** *** 6656,6661 **** --- 6722,6728 ---- | EXPLAIN | EXTERNAL | FETCH + | FINISH | FORCE | FORWARD | FUNCTION *************** *** 6714,6719 **** --- 6781,6787 ---- | PRIVILEGES | PROCEDURAL | PROCEDURE + | PURGE | READ | REINDEX | RELATIVE *************** *** 6745,6750 **** --- 6813,6819 ---- | STORAGE | STRICT | SYSID + | SYSTEM | TEMP | TEMPLATE | TEMPORARY *************** *** 6768,6773 **** --- 6837,6843 ---- | VERSION | VIEW | VOLATILE + | WAL_FILES | WITH | WITHOUT | WRITE diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/parser/keywords.c /usr1/richt/pgsql_mirror.pitr/src/backend/parser/keywords.c *** /usr1/richt/pgsql_mirror/src/backend/parser/keywords.c Thu Jul 18 19:11:28 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/parser/keywords.c Fri Jul 26 16:34:22 2002 *************** *** 41,52 **** --- 41,54 ---- {"analyze", ANALYZE}, {"and", AND}, {"any", ANY}, + {"archive", ARCHIVE}, {"as", AS}, {"asc", ASC}, {"assertion", ASSERTION}, {"assignment", ASSIGNMENT}, {"at", AT}, {"authorization", AUTHORIZATION}, + {"backup", BACKUP}, {"backward", BACKWARD}, {"before", BEFORE}, {"begin", BEGIN_TRANS}, *************** *** 123,128 **** --- 125,131 ---- {"extract", EXTRACT}, {"false", FALSE_P}, {"fetch", FETCH}, + {"finish", FINISH}, {"float", FLOAT_P}, {"for", FOR}, {"force", FORCE}, *************** *** 230,235 **** --- 233,239 ---- {"privileges", PRIVILEGES}, {"procedural", PROCEDURAL}, {"procedure", PROCEDURE}, + {"purge", PURGE}, {"read", READ}, {"real", REAL}, {"references", REFERENCES}, *************** *** 272,277 **** --- 276,282 ---- {"strict", STRICT}, {"substring", SUBSTRING}, {"sysid", SYSID}, + {"system", SYSTEM}, {"table", TABLE}, {"temp", TEMP}, {"template", TEMPLATE}, *************** *** 310,315 **** --- 315,321 ---- {"version", VERSION}, {"view", VIEW}, {"volatile", VOLATILE}, + {"wal_files", WAL_FILES}, {"when", WHEN}, {"where", WHERE}, {"with", WITH}, diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/postmaster/postmaster.c /usr1/richt/pgsql_mirror.pitr/src/backend/postmaster/postmaster.c *** /usr1/richt/pgsql_mirror/src/backend/postmaster/postmaster.c Fri Jul 12 21:02:14 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/postmaster/postmaster.c Fri Jul 26 16:34:22 2002 *************** *** 751,756 **** --- 751,763 ---- */ StartupPID = StartupDataBase(); + if (XLRollForward()) + /* + * This startup was for a roll forward recovery operation so + * just shutdown now. + */ + Shutdown = SmartShutdown; + status = ServerLoop(); /* diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/storage/buffer/buf_init.c /usr1/richt/pgsql_mirror.pitr/src/backend/storage/buffer/buf_init.c *** /usr1/richt/pgsql_mirror/src/backend/storage/buffer/buf_init.c Thu Jun 20 16:29:34 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/storage/buffer/buf_init.c Fri Jul 26 16:34:22 2002 *************** *** 38,43 **** --- 38,45 ---- static void ShutdownBufferPoolAccess(void); + PageInfoStruct* PageInfo; + /* * if BMTRACE is defined, we trace the last 200 buffer allocations and * deallocations in a circular buffer in shared memory. *************** *** 135,140 **** --- 137,145 ---- foundDescs; int i; + bool foundPager; + + Data_Descriptors = NBuffers; Free_List_Descriptor = Data_Descriptors; Lookup_List_Descriptor = Data_Descriptors + 1; *************** *** 146,151 **** --- 151,165 ---- * problems. */ LWLockAcquire(BufMgrLock, LW_EXCLUSIVE); + + PageInfo = (PageInfoStruct*)ShmemInitStruct("Page Writer Info", + sizeof(PageInfoStruct), + &foundPager); + + if (!foundPager) + { + PageInfo->backupPID = 0; + } #ifdef BMTRACE CurTraceBuf = (long *) ShmemInitStruct("Buffer trace", diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/storage/buffer/bufmgr.c /usr1/richt/pgsql_mirror.pitr/src/backend/storage/buffer/bufmgr.c *** /usr1/richt/pgsql_mirror/src/backend/storage/buffer/bufmgr.c Tue Jul 2 01:47:37 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/storage/buffer/bufmgr.c Fri Jul 26 16:34:22 2002 *************** *** 41,46 **** --- 41,48 ---- */ #include "postgres.h" + #include "storage/relfilenode.h" + #include #include #include *************** *** 2151,2154 **** --- 2153,2175 ---- bufHdr = &BufferDescriptors[buffer - 1]; return (bufHdr->tag.rnode); + } + + int + BufferBackup(Relation reln, Buffer buffer, char* dirName) + { + File oldFd = RelationGetFile(reln); + BufferDesc *bufHdr = BufferIsValid(buffer) ? &BufferDescriptors[buffer - 1] : NULL; + char *data = bufHdr ? (char*)MAKE_PTR(bufHdr->data) : NULL; + return (WriteBackup(oldFd, data, dirName, reln->rd_node)); + } + + + void hook(void); + void + hook() + { + fprintf(stderr, "Starting HOOK\n"); + sleep(60); + fprintf(stderr, "Finished HOOK\n"); } diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/storage/file/fd.c /usr1/richt/pgsql_mirror.pitr/src/backend/storage/file/fd.c *** /usr1/richt/pgsql_mirror/src/backend/storage/file/fd.c Thu Jun 20 16:29:34 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/storage/file/fd.c Fri Jul 26 16:34:22 2002 *************** *** 53,58 **** --- 53,63 ---- #include "storage/fd.h" #include "storage/ipc.h" + #include "utils/rel.h" + #include "storage/block.h" + #include "storage/relfilenode.h" + #include "catalog/catalog.h" + /* Filename components for OpenTemporaryFile */ #define PG_TEMP_FILES_DIR "pgsql_tmp" *************** *** 1333,1336 **** --- 1338,1403 ---- } closedir(db_dir); } + } + + #define PATHSIZE 2048 + static char* backupName(RelFileNode, char*); + char* + backupName(RelFileNode relNode, char* dirName) + { + static char path[PATHSIZE]; + + if (relNode.tblNode == (Oid) 0) + { + if (strcmp(DatabaseName, "template1")) + return NULL; + else + { + /* Shared system relations live in {dirName}/global */ + int size = strlen(dirName) + 8 + sizeof(NameData) + 1; + Assert(size < PATHSIZE); + sprintf(path, "%s/global/%u", dirName, relNode.relNode); + } + } + else + { + int size = strlen(dirName) + 6 + 2 * sizeof(NameData) + 3; + Assert(size < PATHSIZE); + sprintf(path, "%s/base/%u/%u", dirName, relNode.tblNode, relNode.relNode); + } + return (path); + } + + /* + * copy a file to the backup directory + */ + int + WriteBackup(File theFd, char* data, char* dirName, RelFileNode relNode) + { + static File newFd = VFD_CLOSED; + static File oldFd = VFD_CLOSED; + + if (oldFd != theFd) + { + char *newName = backupName(relNode, dirName); + if (newName == NULL) + return 1; + oldFd = theFd; + if (newFd != VFD_CLOSED) + FileClose(newFd); + newFd = fileNameOpenFile(newName, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600); + if (newFd == VFD_CLOSED) + { + fprintf(stderr, "Error opening %s(%d)\n", newName, newFd); + return 1; + } + } + if (dirName) + { + if (data) + FileWrite(newFd, data, BLCKSZ); + } + else if (newFd != VFD_CLOSED) + FileClose(newFd); + return 0; } diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/tcop/postgres.c /usr1/richt/pgsql_mirror.pitr/src/backend/tcop/postgres.c *** /usr1/richt/pgsql_mirror/src/backend/tcop/postgres.c Thu Jul 18 19:11:28 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/tcop/postgres.c Fri Jul 26 16:34:22 2002 *************** *** 2348,2353 **** --- 2348,2357 ---- tag = "ANALYZE"; break; + case T_AlterSystemStmt: + tag = "ALTER SYSTEM"; + break; + case T_ExplainStmt: tag = "EXPLAIN"; break; diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/tcop/utility.c /usr1/richt/pgsql_mirror.pitr/src/backend/tcop/utility.c *** /usr1/richt/pgsql_mirror/src/backend/tcop/utility.c Thu Jul 25 06:07:11 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/tcop/utility.c Mon Jul 29 19:37:42 2002 *************** *** 670,675 **** --- 670,734 ---- vacuum((VacuumStmt *) parsetree); break; + case T_AlterSystemStmt: + switch (((AlterSystemStmt*)parsetree)->subType) + { + case AS_Purge: + if (!superuser()) + { + elog(ERROR,"ALTER SYSTEM: permission denied"); + break; + } + + XLRemoveLog(((AlterSystemStmt*)parsetree)->logName); + break; + + case AS_Begin: + if (!superuser()) + { + elog(ERROR,"ALTER SYSTEM: permission denied"); + break; + } + + ASbegin(((AlterSystemStmt*)parsetree)->backupDir); + break; + + case AS_Backup: + if (!superuser()) + { + elog(ERROR,"ALTER SYSTEM: permission denied"); + break; + } + + ASbackup(((AlterSystemStmt*)parsetree)->backupDir, ((AlterSystemStmt*)parsetree)->archivDir); + break; + + case AS_Finish: + if (!superuser()) + { + elog(ERROR,"ALTER SYSTEM: permission denied"); + break; + } + + ASfinish(((AlterSystemStmt*)parsetree)->backupDir, ((AlterSystemStmt*)parsetree)->archivDir); + break; + + case AS_Abort: + if (!superuser()) + { + elog(ERROR,"ALTER SYSTEM: permission denied"); + break; + } + + ASabort(); + break; + + case AS_Invalid: + elog(ERROR,"ALTER SYSTEM: invalid command"); + break; + } + break; + case T_ExplainStmt: ExplainQuery((ExplainStmt *) parsetree, dest); break; diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/utils/adt/misc.c /usr1/richt/pgsql_mirror.pitr/src/backend/utils/adt/misc.c *** /usr1/richt/pgsql_mirror/src/backend/utils/adt/misc.c Thu Jun 20 16:29:37 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/utils/adt/misc.c Fri Jul 26 16:34:22 2002 *************** *** 20,25 **** --- 20,26 ---- #include "utils/builtins.h" + #include "access/xlog.h" /* * Check if data is Null *************** *** 110,113 **** --- 111,144 ---- int32 i = PG_GETARG_INT32(0); PG_RETURN_INT32(i); + } + + Datum + wal_file_status(PG_FUNCTION_ARGS) + { + Name arg = PG_GETARG_NAME(0); + char *ret; + int i; + + ret = palloc(64); + memset(ret,0,64); + if(strlen(arg->data) > strlen("CHECKPOINT")) + { + elog(NOTICE,"Invalid argument %s",arg->data); + PG_RETURN_NAME(ret); + } + for(i = 0; i < strlen(arg->data);i++) + ret[i] = (char)toupper(arg->data[i]); + + if(strcmp(ret,"CURRENT") !=0 && + strcmp(ret,"LAST") != 0 && + strcmp(ret,"CHECKPOINT") !=0 && + strcmp(ret,"OLDEST") ) + { + elog(NOTICE,"Invalid argument %s",arg->data); + PG_RETURN_NAME(""); + } + XLWalFileStatus(ret); + + PG_RETURN_NAME(ret); } diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/backend/utils/misc/guc.c /usr1/richt/pgsql_mirror.pitr/src/backend/utils/misc/guc.c *** /usr1/richt/pgsql_mirror/src/backend/utils/misc/guc.c Sat Jul 20 11:12:55 2002 --- /usr1/richt/pgsql_mirror.pitr/src/backend/utils/misc/guc.c Fri Jul 26 16:34:22 2002 *************** *** 60,65 **** --- 60,70 ---- extern int CommitSiblings; extern bool FixBTree; + extern bool WalFileReuse; + extern bool RollForward; + extern char *XLOG_duplicate_dir; + static char *RollForwardUntil; + #ifdef HAVE_SYSLOG extern char *Syslog_facility; extern char *Syslog_ident; *************** *** 481,486 **** --- 486,497 ---- { "transform_null_equals", PGC_USERSET }, &Transform_null_equals, false, NULL, NULL }, + { + {"wal_file_reuse", PGC_POSTMASTER}, &WalFileReuse, true, NULL + }, + { + {"roll_forward", PGC_POSTMASTER}, &RollForward, false, NULL + }, { { NULL, 0 }, NULL, false, NULL, NULL *************** *** 806,811 **** --- 817,831 ---- { { "wal_sync_method", PGC_SIGHUP }, &XLOG_sync_method, XLOG_sync_method_default, assign_xlog_sync_method, NULL + }, + + { + {"wal_file_duplicate", PGC_POSTMASTER}, &XLOG_duplicate_dir, + NULL, XLogCheckDupdir, NULL + }, + { + {"roll_forward_until",PGC_POSTMASTER}, &RollForwardUntil, + NULL, XLcheckTime,NULL }, { diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/bin/Makefile /usr1/richt/pgsql_mirror.pitr/src/bin/Makefile *** /usr1/richt/pgsql_mirror/src/bin/Makefile Thu Jun 20 16:29:41 2002 --- /usr1/richt/pgsql_mirror.pitr/src/bin/Makefile Fri Jul 26 16:34:22 2002 *************** *** 27,32 **** --- 27,34 ---- DIRS += pgtclsh endif + DIRS := $(DIRS) pg_copy + all install installdirs uninstall depend distprep: @for dir in $(DIRS); do $(MAKE) -C $$dir $@ || exit; done diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/bin/pg_copy/Makefile /usr1/richt/pgsql_mirror.pitr/src/bin/pg_copy/Makefile *** /usr1/richt/pgsql_mirror/src/bin/pg_copy/Makefile Wed Dec 31 19:00:00 1969 --- /usr1/richt/pgsql_mirror.pitr/src/bin/pg_copy/Makefile Fri Jul 26 16:34:22 2002 *************** *** 0 **** --- 1,44 ---- + #------------------------------------------------------------------------- + # + # Makefile for src/bin/pg_copy + # + # Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group + # Portions Copyright (c) 1994, Regents of the University of California + # + # $Header: /nusphere/nsdb/Repository/cvsroot/pgsql_nsdb/src/bin/pg_copy/Makefile,v 1.1 2002/07/23 20:34:35 mquayle Exp $ + # + #------------------------------------------------------------------------- + + subdir = src/bin/pg_copy + top_builddir = ../../.. + include $(top_builddir)/src/Makefile.global + + override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) + + all: submake pg_copy + + pg_copy: pg_copy.o $(libpq_builddir)/libpq.a + $(CC) $(CFLAGS) pg_copy.o $(libpq) $(LDFLAGS) $(LIBS) -o $@ + + .PHONY: submake + submake: + $(MAKE) -C $(libpq_builddir) all + + install: all installdirs + $(INSTALL_PROGRAM) pg_copy$(X) $(DESTDIR)$(bindir)/pg_copy$(X) + + installdirs: + $(mkinstalldirs) $(DESTDIR)$(bindir) + + uninstall: + rm -f $(addprefix $(DESTDIR)$(bindir)/, pg_copy$(X)) + + depend dep: + $(CC) -MM $(CFLAGS) *.c >depend + + clean distclean maintainer-clean: + rm -f pg_copy$(X) pg_copy.o + + ifeq (depend,$(wildcard depend)) + include depend + endif diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/bin/pg_copy/pg_copy.c /usr1/richt/pgsql_mirror.pitr/src/bin/pg_copy/pg_copy.c *** /usr1/richt/pgsql_mirror/src/bin/pg_copy/pg_copy.c Wed Dec 31 19:00:00 1969 --- /usr1/richt/pgsql_mirror.pitr/src/bin/pg_copy/pg_copy.c Fri Jul 26 16:34:22 2002 *************** *** 0 **** --- 1,443 ---- + /*------------------------------------------------------------------------- + * + * pg_copy.c + * pg_copy is a utility for creating an online copy of a database + * cluster for eventual use during roll forward recovery. + * + * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * $Header: /nusphere/nsdb/Repository/cvsroot/pgsql_nsdb/src/bin/pg_copy/pg_copy.c,v 1.1 2002/07/23 20:34:35 mquayle Exp $ + * + *------------------------------------------------------------------------- + */ + + /* + * Although this is not a backend module, we must include postgres.h anyway + * so that we can include a bunch of backend include files. pg_copy has + * never pretended to be very independent of the backend anyhow ... + */ + #include "postgres.h" + #include "libpq-fe.h" + #include "libpq/libpq-fs.h" + + #include + #ifdef HAVE_GETOPT_H + #include + #endif + #ifdef HAVE_TERMIOS_H + #include + #endif + extern char *optarg; + extern int optind, opterr, optopt; + + #define PG_COPY_VERSION "1.0" + + static const char *progname; + static const char *modulename = gettext_noop("archiver (db)"); + + /* + * simple_prompt --- borrowed from psql + * + * Generalized function especially intended for reading in usernames and + * password interactively. Reads from /dev/tty or stdin/stderr. + * + * prompt: The prompt to print + * maxlen: How many characters to accept + * echo: Set to false if you want to hide what is entered (for passwords) + * + * Returns a malloc()'ed string with the input (w/o trailing newline). + */ + static char * + simple_prompt(const char *prompt, int maxlen, bool echo) + { + int length; + char *destination; + FILE *termin, + *termout; + + #ifdef HAVE_TERMIOS_H + struct termios t_orig, t; + #endif + + destination = (char *) malloc(maxlen + 2); + if (!destination) + return NULL; + + /* + * Do not try to collapse these into one "w+" mode file. Doesn't work + * on some platforms (eg, HPUX 10.20). + */ + termin = fopen("/dev/tty", "r"); + termout = fopen("/dev/tty", "w"); + if (!termin || !termout) + { + if (termin) + fclose(termin); + if (termout) + fclose(termout); + termin = stdin; + termout = stderr; + } + + #ifdef HAVE_TERMIOS_H + if (!echo) + { + tcgetattr(fileno(termin), &t); + t_orig = t; + t.c_lflag &= ~ECHO; + tcsetattr(fileno(termin), TCSAFLUSH, &t); + } + #endif + + if (prompt) + { + fputs(gettext(prompt), termout); + fflush(termout); + } + + if (fgets(destination, maxlen, termin) == NULL) + destination[0] = '\0'; + + length = strlen(destination); + if (length > 0 && destination[length - 1] != '\n') + { + /* eat rest of the line */ + char buf[128]; + int buflen; + + do + { + if (fgets(buf, sizeof(buf), termin) == NULL) + break; + buflen = strlen(buf); + } while (buflen > 0 && buf[buflen - 1] != '\n'); + } + + if (length > 0 && destination[length - 1] == '\n') + /* remove trailing newline */ + destination[length - 1] = '\0'; + + #ifdef HAVE_TERMIOS_H + if (!echo) + { + tcsetattr(fileno(termin), TCSAFLUSH, &t_orig); + fputs("\n", termout); + fflush(termout); + } + #endif + + if (termin != stdin) + { + fclose(termin); + fclose(termout); + } + + return destination; + } + + /* Common exit code */ + /* Archiver use (just different arg declaration) */ + static void + _write_msg(const char *modulename, const char *fmt, va_list ap) + { + if (modulename) + fprintf(stderr, "%s: [%s] ", progname, gettext(modulename)); + else + fprintf(stderr, "%s: ", progname); + vfprintf(stderr, gettext(fmt), ap); + } + + static void + write_msg(const char *modulename, const char *fmt,...) + { + va_list ap; + + va_start(ap, fmt); + _write_msg(modulename, fmt, ap); + va_end(ap); + } + + static void + notice_processor(void *arg, const char *message) + { + write_msg(NULL, "%s", message); + } + + static void + _die_horribly(PGconn *conn, const char *modulename, const char *fmt, va_list ap) + { + _write_msg(modulename, fmt, ap); + + if (conn) + PQfinish(conn); + + exit(1); + } + + static void + die_horribly(PGconn *conn, const char *modulename, const char *fmt,...) + { + va_list ap; + + va_start(ap, fmt); + _die_horribly(conn, modulename, fmt, ap); + } + + static void + exit_horribly(PGconn *conn, const char *modulename, const char *fmt,...) + { + va_list ap; + + va_start(ap, fmt); + _die_horribly((PGconn *) conn, modulename, fmt, ap); + } + + static void + help(const char *progname) + { + printf(gettext("\n%s creates a copy of a cluster while the database is online\n\n"), progname); + puts(gettext("Usage:")); + printf(gettext(" %s [options] \n\n"), progname); + puts(gettext("Options:")); + + #ifdef HAVE_GETOPT_LONG + puts(gettext( + " -a, --archive_wal_files_dir=ARCHDIR\n" + " location to copy log files used\n" + " prior to the current checkpoint\n" + " -h, --host=HOSTNAME database server host name\n" + " -p, --port=PORT database server port number\n" + " -U, --username=NAME connect as specified database user\n" + " -V, --version display version information\n" + " -W, --password force password prompt (should happen automatically)\n" + " -?, --help view this message\n" + )); + #else + puts(gettext( + " -a, location to copy log files used\n" + " prior to the current checkpoint\n" + " -h, database server host name\n" + " -p, database server port number\n" + " -U, connect as specified database user\n" + " -V, display version information\n" + " -W, force password prompt (should happen automatically)\n" + " -?, view this message\n" + )); + #endif + puts(gettext("Report bugs to .")); + } + + + /* + * Make a database connection with the given parameters. + */ + static PGconn * + ConnectDatabase(const char *dbname, + const char *pghost, + const char *pgport, + const char *username, + const int reqPwd) + { + PGconn *connection = NULL; + char *password = NULL; + bool need_pass = false; + + if (dbname == NULL) + dbname = getenv("PGDATABASE"); + + if (reqPwd) + { + password = simple_prompt("Password: ", 100, false); + if (password == NULL) + die_horribly(connection, modulename, "out of memory\n"); + } + + /* + * Start the connection. Loop until we have a password if requested + * by backend. + */ + do + { + need_pass = false; + connection = PQsetdbLogin(pghost, pgport, NULL, NULL, + dbname, username, password); + + if (!connection) + die_horribly(connection, modulename, "failed to connect to database\n"); + + if (PQstatus(connection) == CONNECTION_BAD && + strcmp(PQerrorMessage(connection), "fe_sendauth: no password supplied\n") == 0 && + !feof(stdin)) + { + PQfinish(connection); + need_pass = true; + free(password); + password = NULL; + password = simple_prompt("Password: ", 100, false); + } + } + while (need_pass); + + if (password) + free(password); + + /* check to see that the backend connection was successfully made */ + if (PQstatus(connection) == CONNECTION_BAD) + die_horribly(connection, modulename, "connection to database \"%s\" failed: %s", dbname, PQerrorMessage(connection)); + + PQsetNoticeProcessor(connection, notice_processor, NULL); + + return connection; + } + + int + main(int argc, char **argv) + { + int c = 0; + int row = 0; + int rows = 0; + int optindex = 0; + PGresult *res = NULL; + PGconn *g_conn = NULL; + const char *archDir = NULL; + const char *copyDir = NULL; + const char *pghost = NULL; + const char *pgport = NULL; + const char *username = NULL; + bool force_password = false; + char command[1024]; + + #ifdef HAVE_GETOPT_LONG + static struct option long_options[] = { + {"archive_wal_files_dir", required_argument, NULL, 'a'}, + {"host", required_argument, NULL, 'h'}, + {"port", required_argument, NULL, 'p'}, + {"username", required_argument, NULL, 'U'}, + {"version", no_argument, NULL, 'V'}, + {"password", no_argument, NULL, 'W'}, + {"help", no_argument, NULL, '?'} + }; + #endif + + if (strrchr(argv[0], '/')) + progname = strrchr(argv[0], '/') + 1; + else + progname = argv[0]; + + if (argc > 1) + { + if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) + { + help(progname); + exit(0); + } + if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) + { + puts("pg_copy " PG_COPY_VERSION " (PostgreSQL " PG_VERSION ")"); + exit(0); + } + } + + #ifdef HAVE_GETOPT_LONG + while ((c = getopt_long(argc, argv, "a:h:p:U:VW?", long_options, &optindex)) != -1) + #else + while ((c = getopt_long(argc, argv, "a:h:p:U:VW?-")) != -1) + #endif + + { + switch (c) + { + case 'a': /* archive dir */ + archDir = optarg; + break; + + case 'h': /* server host */ + pghost = optarg; + break; + + case 'p': /* server port */ + pgport = optarg; + break; + + case 'U': + username = optarg; + break; + + case 'W': + force_password = true; + break; + + #ifndef HAVE_GETOPT_LONG + case '-': + fprintf(stderr, gettext("%s was compiled without support for long options.\n" "Use --help for help on invocation options.\n"), progname); + exit(1); + break; + #endif + default: + fprintf(stderr, gettext("Unknown Option: %c. Try '%s --help' for more information.\n"), c, progname); + exit(1); + } + } + + if (optind < (argc - 1)) + { + fprintf(stderr, gettext("%s: too many command line options (first is '%s')\n" "Try '%s --help' for more information.\n"), progname, argv[optind + 1], progname); + exit(1); + } + + /* Get the target directory name */ + if (optind >= argc) + { + write_msg(NULL, "no target directory specified\n"); + exit(1); + } + copyDir = argv[optind]; + + g_conn = ConnectDatabase("template1", pghost, pgport, username, force_password); + + sprintf(command, "ALTER SYSTEM BEGIN BACKUP '%s'", copyDir); + res = PQexec(g_conn, command); + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + exit_horribly(g_conn, NULL, "BEGIN BACKUP command failed: %s", PQerrorMessage(g_conn)); + PQclear(res); + + res = PQexec(g_conn, "SELECT datname, oid, datallowconn FROM pg_database"); + if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) + exit_horribly(g_conn, NULL, "SELECT command failed: %s", PQerrorMessage(g_conn)); + rows = PQntuples(res); + for (row = 0; row < rows; row++) + { + PGconn *conn; + PGresult *foo; + char* DBname = PQgetvalue(res, row, 0); + char* DBoid = PQgetvalue(res, row, 1); + char* DBconn = PQgetvalue(res, row, 2); + + if (strcmp(DBconn, "t")) + DBname = "template1"; + + conn = ConnectDatabase(DBname, pghost, pgport, username, force_password); + sprintf(command, "ALTER SYSTEM BACKUP '%s' TO '%s'", DBoid, copyDir); + foo = PQexec(conn, command); + if (!foo || PQresultStatus(foo) != PGRES_COMMAND_OK) + exit_horribly(conn, NULL, "BACKUP command failed: %s", PQerrorMessage(conn)); + PQclear(foo); + PQfinish(conn); + } + PQclear(res); + + if (archDir) + sprintf(command, "ALTER SYSTEM FINISH BACKUP '%s' ARCHIVE '%s'", copyDir, archDir); + else + sprintf(command, "ALTER SYSTEM FINISH BACKUP '%s'", copyDir); + res = PQexec(g_conn, command); + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + exit_horribly(g_conn, NULL, "FINISH BACKUP command failed: %s", PQerrorMessage(g_conn)); + PQclear(res); + + PQfinish(g_conn); + exit(0); + } diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/access/xlog.h /usr1/richt/pgsql_mirror.pitr/src/include/access/xlog.h *** /usr1/richt/pgsql_mirror/src/include/access/xlog.h Thu Jun 20 16:29:43 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/access/xlog.h Fri Jul 26 16:34:22 2002 *************** *** 204,209 **** --- 204,220 ---- extern void BootStrapXLOG(void); extern void StartupXLOG(void); extern void ShutdownXLOG(void); + extern void XLFinishBackup(void); + extern const char * + XLcheckTime(const char *timeString,bool doit, bool interactive); + + extern void XLRemoveLog(char *pXLogName); + extern bool XLRollForward(void); + extern const char * + XLogCheckDupdir(const char *dirPath,bool doit, bool interactive); + + extern void XLWalFileStatus(char *whichLog); + extern void CreateCheckPoint(bool shutdown); extern void SetThisStartUpID(void); extern void XLogPutNextOid(Oid nextOid); diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/catalog/pg_proc.h /usr1/richt/pgsql_mirror.pitr/src/include/catalog/pg_proc.h *** /usr1/richt/pgsql_mirror/src/include/catalog/pg_proc.h Wed Jul 24 15:11:13 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/catalog/pg_proc.h Tue Jul 30 19:09:27 2002 *************** *** 2973,2978 **** --- 2973,2980 ---- DESCR("(internal)"); DATA(insert OID = 2248 ( fmgr_sql_validator PGNSP PGUID 12 f f t f s 1 26 "23" fmgr_sql_validator - _null_ )); DESCR("(internal)"); + DATA(insert OID = 2076 ( wal_file PGNSP PGUID 12 f t f f s 1 19 "19" wal_file_status - _null_)); + DESCR("wal file status"); #define SQLvalidatorId 2248 /* diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/commands/dbcommands.h /usr1/richt/pgsql_mirror.pitr/src/include/commands/dbcommands.h *** /usr1/richt/pgsql_mirror/src/include/commands/dbcommands.h Thu Jun 20 16:29:49 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/commands/dbcommands.h Fri Jul 26 16:34:22 2002 *************** *** 20,23 **** --- 20,28 ---- extern void dropdb(const char *dbname); extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt); + extern void ASbegin(char*); + extern void ASbackup(char*, char*); + extern void ASfinish(char*, char*); + extern void ASabort(void); + #endif /* DBCOMMANDS_H */ diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/nodes/nodes.h /usr1/richt/pgsql_mirror.pitr/src/include/nodes/nodes.h *** /usr1/richt/pgsql_mirror/src/include/nodes/nodes.h Thu Jul 18 19:11:32 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/nodes/nodes.h Fri Jul 26 16:34:22 2002 *************** *** 195,200 **** --- 195,201 ---- T_DropGroupStmt, T_ReindexStmt, T_CheckPointStmt, + T_AlterSystemStmt, T_CreateSchemaStmt, T_AlterDatabaseSetStmt, T_AlterUserSetStmt, *************** *** 243,248 **** --- 244,262 ---- T_ReturnSetInfo /* in nodes/execnodes.h */ } NodeTag; + + typedef enum ASNodeTag + { + AS_Invalid = 0, + /* + * TAGS FOR PLAN NODES (plannodes.h) + */ + AS_Purge = 10, + AS_Begin, + AS_Backup, + AS_Finish, + AS_Abort + } ASNodeTag; /* * The first field of a node of any type is guaranteed to be the NodeTag. diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/nodes/parsenodes.h /usr1/richt/pgsql_mirror.pitr/src/include/nodes/parsenodes.h *** /usr1/richt/pgsql_mirror/src/include/nodes/parsenodes.h Wed Jul 24 15:11:14 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/nodes/parsenodes.h Mon Jul 29 19:37:49 2002 *************** *** 1448,1453 **** --- 1448,1466 ---- List *va_cols; /* list of column names, or NIL for all */ } VacuumStmt; + /* ------------------------- + * Alter System Statement + * ------------------------ + */ + typedef struct AlterSystemStmt + { + NodeTag type; + ASNodeTag subType; + char *logName; /* ALTER SYSTEM REMOVE XLOGS */ + char *backupDir; /* ALTER SYSTEM *BACKUP* */ + char *archivDir; /* ALTER SYSTEM *BACKUP* */ + }AlterSystemStmt; + /* ---------------------- * Explain Statement * ---------------------- diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/storage/buf_internals.h /usr1/richt/pgsql_mirror.pitr/src/include/storage/buf_internals.h *** /usr1/richt/pgsql_mirror/src/include/storage/buf_internals.h Thu Jun 20 16:29:52 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/storage/buf_internals.h Fri Jul 26 16:34:22 2002 *************** *** 181,184 **** --- 181,189 ---- extern void LocalBufferSync(void); extern void ResetLocalBufferPool(void); + typedef struct + { + int backupPID; + } PageInfoStruct; + #endif /* BUFMGR_INTERNALS_H */ diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/storage/bufmgr.h /usr1/richt/pgsql_mirror.pitr/src/include/storage/bufmgr.h *** /usr1/richt/pgsql_mirror/src/include/storage/bufmgr.h Tue Jul 2 01:47:37 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/storage/bufmgr.h Fri Jul 26 16:34:22 2002 *************** *** 184,189 **** --- 184,191 ---- extern void BufmgrCommit(void); extern void BufferSync(void); + extern int BufferBackup(Relation, Buffer, char*); + extern void InitLocalBuffer(void); #endif diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/storage/fd.h /usr1/richt/pgsql_mirror.pitr/src/include/storage/fd.h *** /usr1/richt/pgsql_mirror/src/include/storage/fd.h Thu Jun 20 16:29:52 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/storage/fd.h Fri Jul 26 16:34:22 2002 *************** *** 43,48 **** --- 43,50 ---- typedef int File; + #include "storage/relfilenode.h" + extern int WriteBackup(File, char*, char*, RelFileNode); /* GUC parameter */ extern int max_files_per_process; diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/storage/lwlock.h /usr1/richt/pgsql_mirror.pitr/src/include/storage/lwlock.h *** /usr1/richt/pgsql_mirror/src/include/storage/lwlock.h Thu Jun 20 16:29:52 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/storage/lwlock.h Fri Jul 26 16:34:22 2002 *************** *** 35,40 **** --- 35,42 ---- MMCacheLock, WALInsertLock, WALWriteLock, + WALWriteLock2, + PagerLock, ControlFileLock, CheckpointLock, CLogControlLock, diff -cNr --exclude=CVS /usr1/richt/pgsql_mirror/src/include/utils/builtins.h /usr1/richt/pgsql_mirror.pitr/src/include/utils/builtins.h *** /usr1/richt/pgsql_mirror/src/include/utils/builtins.h Sat Jul 20 01:49:28 2002 --- /usr1/richt/pgsql_mirror.pitr/src/include/utils/builtins.h Fri Jul 26 16:34:22 2002 *************** *** 637,640 **** --- 637,642 ---- extern Datum show_config_by_name(PG_FUNCTION_ARGS); extern Datum set_config_by_name(PG_FUNCTION_ARGS); + extern Datum wal_file_status(PG_FUNCTION_ARGS); + #endif /* BUILTINS_H */