Arrange for the postmaster (and standalone backends, initdb, etc) to
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Jul 2005 04:51:52 +0000 (04:51 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Jul 2005 04:51:52 +0000 (04:51 +0000)
chdir into PGDATA and subsequently use relative paths instead of absolute
paths to access all files under PGDATA.  This seems to give a small
performance improvement, and it should make the system more robust
against naive DBAs doing things like moving a database directory that
has a live postmaster in it.  Per recent discussion.

27 files changed:
contrib/dbsize/dbsize.c
src/backend/access/transam/slru.c
src/backend/access/transam/twophase.c
src/backend/access/transam/xlog.c
src/backend/bootstrap/bootstrap.c
src/backend/catalog/catalog.c
src/backend/commands/tablespace.c
src/backend/libpq/be-secure.c
src/backend/postmaster/pgarch.c
src/backend/postmaster/pgstat.c
src/backend/postmaster/postmaster.c
src/backend/postmaster/syslogger.c
src/backend/storage/file/fd.c
src/backend/storage/freespace/freespace.c
src/backend/storage/smgr/md.c
src/backend/tcop/postgres.c
src/backend/utils/adt/misc.c
src/backend/utils/init/flatfiles.c
src/backend/utils/init/globals.c
src/backend/utils/init/miscinit.c
src/backend/utils/init/postinit.c
src/backend/utils/misc/guc.c
src/bin/pg_resetxlog/pg_resetxlog.c
src/include/access/slru.h
src/include/access/xlog.h
src/include/access/xlog_internal.h
src/include/miscadmin.h

index 903de97b3740f850c8ac3bd3af693040e57dfd30..ac5e4c74ea8b0305d399a6c4f67efcb450a64762 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (c) 2002-2005, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.18 2005/06/19 21:34:00 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.19 2005/07/04 04:51:43 tgl Exp $
  *
  */
 
@@ -24,9 +24,6 @@
 #include "utils/syscache.h"
 
 
-/* hack to make it compile under Win32 */
-extern DLLIMPORT char *DataDir;
-
 Datum pg_tablespace_size(PG_FUNCTION_ARGS);
 Datum pg_database_size(PG_FUNCTION_ARGS);
 Datum pg_relation_size(PG_FUNCTION_ARGS);
@@ -91,11 +88,11 @@ calculate_database_size(Oid dbOid)
    /* Shared storage in pg_global is not counted */
 
    /* Include pg_default storage */
-   snprintf(pathname, MAXPGPATH, "%s/base/%u", DataDir, dbOid);
+   snprintf(pathname, MAXPGPATH, "base/%u", dbOid);
    totalsize += db_dir_size(pathname);
 
    /* Scan the non-default tablespaces */
-   snprintf(pathname, MAXPGPATH, "%s/pg_tblspc", DataDir);
+   snprintf(pathname, MAXPGPATH, "pg_tblspc");
    dirdesc = AllocateDir(pathname);
 
    while ((direntry = ReadDir(dirdesc, pathname)) != NULL)
@@ -104,8 +101,8 @@ calculate_database_size(Oid dbOid)
            strcmp(direntry->d_name, "..") == 0)
            continue;
 
-       snprintf(pathname, MAXPGPATH, "%s/pg_tblspc/%s/%u",
-                DataDir, direntry->d_name, dbOid);
+       snprintf(pathname, MAXPGPATH, "pg_tblspc/%s/%u",
+                direntry->d_name, dbOid);
        totalsize += db_dir_size(pathname);
    }
 
@@ -134,11 +131,11 @@ pg_tablespace_size(PG_FUNCTION_ARGS)
     struct dirent *direntry;
 
    if (tblspcOid == DEFAULTTABLESPACE_OID)
-       snprintf(tblspcPath, MAXPGPATH, "%s/base", DataDir);
+       snprintf(tblspcPath, MAXPGPATH, "base");
    else if (tblspcOid == GLOBALTABLESPACE_OID)
-       snprintf(tblspcPath, MAXPGPATH, "%s/global", DataDir);
+       snprintf(tblspcPath, MAXPGPATH, "global");
    else
-       snprintf(tblspcPath, MAXPGPATH, "%s/pg_tblspc/%u", DataDir, tblspcOid);
+       snprintf(tblspcPath, MAXPGPATH, "pg_tblspc/%u", tblspcOid);
 
    dirdesc = AllocateDir(tblspcPath);
 
@@ -208,12 +205,12 @@ calculate_relation_size(Oid tblspcOid, Oid relnodeOid)
        tblspcOid = MyDatabaseTableSpace;
 
    if (tblspcOid == DEFAULTTABLESPACE_OID)
-       snprintf(dirpath, MAXPGPATH, "%s/base/%u", DataDir, MyDatabaseId);
+       snprintf(dirpath, MAXPGPATH, "base/%u", MyDatabaseId);
    else if (tblspcOid == GLOBALTABLESPACE_OID)
-       snprintf(dirpath, MAXPGPATH, "%s/global", DataDir);
+       snprintf(dirpath, MAXPGPATH, "global");
    else
-       snprintf(dirpath, MAXPGPATH, "%s/pg_tblspc/%u/%u",
-                DataDir, tblspcOid, MyDatabaseId);
+       snprintf(dirpath, MAXPGPATH, "pg_tblspc/%u/%u",
+                tblspcOid, MyDatabaseId);
 
    for (segcount = 0 ;; segcount++)
    {
index 24f9a947792110d691b0806e74a265397593ffa5..c7c12470209bd8ff28b52caa2dd57dfcb10b0974 100644 (file)
@@ -48,7 +48,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.25 2005/06/19 21:34:01 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.26 2005/07/04 04:51:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -190,7 +190,7 @@ SimpleLruInit(SlruCtl ctl, const char *name,
     */
    ctl->shared = shared;
    ctl->do_fsync = true;       /* default behavior */
-   snprintf(ctl->Dir, MAXPGPATH, "%s/%s", DataDir, subdir);
+   StrNCpy(ctl->Dir, subdir, sizeof(ctl->Dir));
 }
 
 /*
index ccd8b802157ad16bebd4a067fab19cf72a755fe9..5f7ea98ffe12c66ef0e39295510a5804f10e13c4 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.7 2005/06/28 05:08:51 tgl Exp $
+ *     $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.8 2005/07/04 04:51:44 tgl Exp $
  *
  * NOTES
  *     Each global transaction is associated with a global transaction
@@ -661,7 +661,7 @@ TwoPhaseGetDummyProc(TransactionId xid)
 /************************************************************************/
 
 #define TwoPhaseFilePath(path, xid) \
-   snprintf(path, MAXPGPATH, "%s/%s/%08X", DataDir, TWOPHASE_DIR, xid)
+   snprintf(path, MAXPGPATH, TWOPHASE_DIR "/%08X", xid)
 
 /*
  * 2PC state file format:
@@ -1434,14 +1434,11 @@ PrescanPreparedTransactions(void)
 {
    TransactionId origNextXid = ShmemVariableCache->nextXid;
    TransactionId result = origNextXid;
-   char    dir[MAXPGPATH];
    DIR     *cldir;
    struct dirent *clde;
 
-   snprintf(dir, MAXPGPATH, "%s/%s", DataDir, TWOPHASE_DIR);
-
-   cldir = AllocateDir(dir);
-   while ((clde = ReadDir(cldir, dir)) != NULL)
+   cldir = AllocateDir(TWOPHASE_DIR);
+   while ((clde = ReadDir(cldir, TWOPHASE_DIR)) != NULL)
    {
        if (strlen(clde->d_name) == 8 &&
            strspn(clde->d_name, "0123456789ABCDEF") == 8)
@@ -1540,7 +1537,7 @@ RecoverPreparedTransactions(void)
    DIR     *cldir;
    struct dirent *clde;
 
-   snprintf(dir, MAXPGPATH, "%s/%s", DataDir, TWOPHASE_DIR);
+   snprintf(dir, MAXPGPATH, "%s", TWOPHASE_DIR);
 
    cldir = AllocateDir(dir);
    while ((clde = ReadDir(cldir, dir)) != NULL)
index 4c2f6a69a709e1d12e5ccf5b06213068d1155ee5..d42aa93c547318e0690bbe0743df325803bf707e 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.205 2005/06/30 00:00:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.206 2005/07/04 04:51:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #endif
 
 
+/* File path names (all relative to $PGDATA) */
+#define BACKUP_LABEL_FILE      "backup_label"
+#define RECOVERY_COMMAND_FILE  "recovery.conf"
+#define RECOVERY_COMMAND_DONE  "recovery.done"
+
+
 /* User-settable parameters */
 int            CheckPointSegments = 3;
 int            XLOGbuffers = 8;
@@ -378,11 +384,6 @@ static ControlFileData *ControlFile = NULL;
 #define NextBufIdx(idx)        \
        (((idx) == XLogCtl->XLogCacheBlck) ? 0 : ((idx) + 1))
 
-
-/* File path names */
-char       XLogDir[MAXPGPATH];
-static char ControlFilePath[MAXPGPATH];
-
 /*
  * Private, possibly out-of-date copy of shared LogwrtResult.
  * See discussion above.
@@ -991,7 +992,7 @@ XLogCheckBuffer(XLogRecData *rdata,
  *
  * The name of the notification file is the message that will be picked up
  * by the archiver, e.g. we write 0000000100000001000000C6.ready
- * and the archiver then knows to archive XLogDir/0000000100000001000000C6,
+ * and the archiver then knows to archive XLOGDIR/0000000100000001000000C6,
  * then when complete, rename it to 0000000100000001000000C6.done
  */
 static void
@@ -1645,7 +1646,7 @@ XLogFileInit(uint32 log, uint32 seg,
     * 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());
+   snprintf(tmppath, MAXPGPATH, XLOGDIR "/xlogtemp.%d", (int) getpid());
 
    unlink(tmppath);
 
@@ -1768,7 +1769,7 @@ XLogFileCopy(uint32 log, uint32 seg,
    /*
     * Copy into a temp file name.
     */
-   snprintf(tmppath, MAXPGPATH, "%s/xlogtemp.%d", XLogDir, (int)getpid());
+   snprintf(tmppath, MAXPGPATH, XLOGDIR "/xlogtemp.%d", (int) getpid());
 
    unlink(tmppath);
 
@@ -2039,8 +2040,8 @@ RestoreArchivedFile(char *path, const char *xlogfname,
 
    /*
     * When doing archive recovery, we always prefer an archived log file
-    * even if a file of the same name exists in XLogDir.  The reason is
-    * that the file in XLogDir could be an old, un-filled or
+    * even if a file of the same name exists in XLOGDIR.  The reason is
+    * that the file in XLOGDIR could be an old, un-filled or
     * partly-filled version that was copied and restored as part of
     * backing up $PGDATA.
     *
@@ -2051,18 +2052,18 @@ RestoreArchivedFile(char *path, const char *xlogfname,
     * robustness, so we elect not to do this.
     *
     * If we cannot obtain the log file from the archive, however, we will
-    * try to use the XLogDir file if it exists.  This is so that we can
+    * try to use the XLOGDIR file if it exists.  This is so that we can
     * make use of log segments that weren't yet transferred to the
     * archive.
     *
     * Notice that we don't actually overwrite any files when we copy back
     * from archive because the recoveryRestoreCommand may inadvertently
     * restore inappropriate xlogs, or they may be corrupt, so we may wish
-    * to fallback to the segments remaining in current XLogDir later. The
+    * to fallback to the segments remaining in current XLOGDIR later. The
     * copy-from-archive filename is always the same, ensuring that we
     * don't run out of disk space on long recoveries.
     */
-   snprintf(xlogpath, MAXPGPATH, "%s/%s", XLogDir, recovername);
+   snprintf(xlogpath, MAXPGPATH, XLOGDIR "/%s", recovername);
 
    /*
     * Make sure there is no existing file named recovername.
@@ -2136,7 +2137,7 @@ RestoreArchivedFile(char *path, const char *xlogfname,
                             xlogRestoreCmd)));
 
    /*
-    * Copy xlog from archival storage to XLogDir
+    * Copy xlog from archival storage to XLOGDIR
     */
    rc = system(xlogRestoreCmd);
    if (rc == 0)
@@ -2192,13 +2193,13 @@ RestoreArchivedFile(char *path, const char *xlogfname,
 
    /*
     * if an archived file is not available, there might still be a
-    * version of this file in XLogDir, so return that as the filename to
+    * version of this file in XLOGDIR, so return that as the filename to
     * open.
     *
     * In many recovery scenarios we expect this to fail also, but if so that
     * just means we've reached the end of WAL.
     */
-   snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlogfname);
+   snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlogfname);
    return false;
 }
 
@@ -2257,16 +2258,16 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr,
    XLByteToPrevSeg(endptr, endlogId, endlogSeg);
    max_advance = XLOGfileslop;
 
-   xldir = AllocateDir(XLogDir);
+   xldir = AllocateDir(XLOGDIR);
    if (xldir == NULL)
        ereport(ERROR,
                (errcode_for_file_access(),
            errmsg("could not open transaction log directory \"%s\": %m",
-                  XLogDir)));
+                  XLOGDIR)));
 
    XLogFileName(lastoff, ThisTimeLineID, log, seg);
 
-   while ((xlde = ReadDir(xldir, XLogDir)) != NULL)
+   while ((xlde = ReadDir(xldir, XLOGDIR)) != NULL)
    {
        /*
         * We ignore the timeline part of the XLOG segment identifiers in
@@ -2292,7 +2293,7 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr,
 
            if (recycle)
            {
-               snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name);
+               snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name);
 
                /*
                 * Before deleting the file, see if it can be recycled as
@@ -2341,14 +2342,14 @@ RemoveOldBackupHistory(void)
    struct dirent *xlde;
    char        path[MAXPGPATH];
 
-   xldir = AllocateDir(XLogDir);
+   xldir = AllocateDir(XLOGDIR);
    if (xldir == NULL)
        ereport(ERROR,
                (errcode_for_file_access(),
            errmsg("could not open transaction log directory \"%s\": %m",
-                  XLogDir)));
+                  XLOGDIR)));
 
-   while ((xlde = ReadDir(xldir, XLogDir)) != NULL)
+   while ((xlde = ReadDir(xldir, XLOGDIR)) != NULL)
    {
        if (strlen(xlde->d_name) > 24 &&
            strspn(xlde->d_name, "0123456789ABCDEF") == 24 &&
@@ -2361,7 +2362,7 @@ RemoveOldBackupHistory(void)
                ereport(DEBUG2,
                      (errmsg("removing transaction log backup history file \"%s\"",
                              xlde->d_name)));
-               snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name);
+               snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name);
                unlink(path);
                XLogArchiveCleanup(xlde->d_name);
            }
@@ -3132,7 +3133,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
    /*
     * Write into a temp file name.
     */
-   snprintf(tmppath, MAXPGPATH, "%s/xlogtemp.%d", XLogDir, (int)getpid());
+   snprintf(tmppath, MAXPGPATH, XLOGDIR "/xlogtemp.%d", (int) getpid());
 
    unlink(tmppath);
 
@@ -3291,15 +3292,6 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
  * ReadControlFile() verifies they are correct.  We could split out the
  * I/O and compatibility-check functions, but there seems no need currently.
  */
-
-void
-XLOGPathInit(void)
-{
-   /* Init XLOG file paths */
-   snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir);
-   snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
-}
-
 static void
 WriteControlFile(void)
 {
@@ -3358,13 +3350,14 @@ WriteControlFile(void)
    memset(buffer, 0, BLCKSZ);
    memcpy(buffer, ControlFile, sizeof(ControlFileData));
 
-   fd = BasicOpenFile(ControlFilePath, O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
+   fd = BasicOpenFile(XLOG_CONTROL_FILE,
+                      O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
                       S_IRUSR | S_IWUSR);
    if (fd < 0)
        ereport(PANIC,
                (errcode_for_file_access(),
                 errmsg("could not create control file \"%s\": %m",
-                       ControlFilePath)));
+                       XLOG_CONTROL_FILE)));
 
    errno = 0;
    if (write(fd, buffer, BLCKSZ) != BLCKSZ)
@@ -3397,12 +3390,14 @@ ReadControlFile(void)
    /*
     * Read data...
     */
-   fd = BasicOpenFile(ControlFilePath, O_RDWR | PG_BINARY, S_IRUSR | S_IWUSR);
+   fd = BasicOpenFile(XLOG_CONTROL_FILE,
+                      O_RDWR | PG_BINARY,
+                      S_IRUSR | S_IWUSR);
    if (fd < 0)
        ereport(PANIC,
                (errcode_for_file_access(),
                 errmsg("could not open control file \"%s\": %m",
-                       ControlFilePath)));
+                       XLOG_CONTROL_FILE)));
 
    if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
        ereport(PANIC,
@@ -3546,12 +3541,14 @@ UpdateControlFile(void)
               offsetof(ControlFileData, crc));
    FIN_CRC32(ControlFile->crc);
 
-   fd = BasicOpenFile(ControlFilePath, O_RDWR | PG_BINARY, S_IRUSR | S_IWUSR);
+   fd = BasicOpenFile(XLOG_CONTROL_FILE,
+                      O_RDWR | PG_BINARY,
+                      S_IRUSR | S_IWUSR);
    if (fd < 0)
        ereport(PANIC,
                (errcode_for_file_access(),
                 errmsg("could not open control file \"%s\": %m",
-                       ControlFilePath)));
+                       XLOG_CONTROL_FILE)));
 
    errno = 0;
    if (write(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
@@ -3814,15 +3811,13 @@ str_time(time_t tnow)
 static void
 readRecoveryCommandFile(void)
 {
-   char        recoveryCommandFile[MAXPGPATH];
    FILE       *fd;
    char        cmdline[MAXPGPATH];
    TimeLineID  rtli = 0;
    bool        rtliGiven = false;
    bool        syntaxError = false;
 
-   snprintf(recoveryCommandFile, MAXPGPATH, "%s/recovery.conf", DataDir);
-   fd = AllocateFile(recoveryCommandFile, "r");
+   fd = AllocateFile(RECOVERY_COMMAND_FILE, "r");
    if (fd == NULL)
    {
        if (errno == ENOENT)
@@ -3830,7 +3825,7 @@ readRecoveryCommandFile(void)
        ereport(FATAL,
                (errcode_for_file_access(),
                 errmsg("could not open recovery command file \"%s\": %m",
-                       recoveryCommandFile)));
+                       RECOVERY_COMMAND_FILE)));
    }
 
    ereport(LOG,
@@ -3974,7 +3969,7 @@ readRecoveryCommandFile(void)
    if (recoveryRestoreCommand == NULL)
        ereport(FATAL,
                (errmsg("recovery command file \"%s\" did not specify restore_command",
-                       recoveryCommandFile)));
+                       RECOVERY_COMMAND_FILE)));
 
    /* Enable fetching from archive recovery area */
    InArchiveRecovery = true;
@@ -4012,8 +4007,6 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
 {
    char        recoveryPath[MAXPGPATH];
    char        xlogpath[MAXPGPATH];
-   char        recoveryCommandFile[MAXPGPATH];
-   char        recoveryCommandDone[MAXPGPATH];
 
    /*
     * We are no longer in archive recovery state.
@@ -4035,7 +4028,7 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
    /*
     * If the segment was fetched from archival storage, we want to
     * replace the existing xlog segment (if any) with the archival
-    * version.  This is because whatever is in XLogDir is very possibly
+    * version.  This is because whatever is in XLOGDIR is very possibly
     * older than what we have from the archives, since it could have come
     * from restoring a PGDATA backup.  In any case, the archival version
     * certainly is more descriptive of what our current database state
@@ -4045,7 +4038,7 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
     * already set to the new value, and so we will create a new file
     * instead of overwriting any existing file.
     */
-   snprintf(recoveryPath, MAXPGPATH, "%s/RECOVERYXLOG", XLogDir);
+   snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYXLOG");
    XLogFilePath(xlogpath, ThisTimeLineID, endLogId, endLogSeg);
 
    if (restoredFromArchive)
@@ -4087,21 +4080,19 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
    XLogArchiveCleanup(xlogpath);
 
    /* Get rid of any remaining recovered timeline-history file, too */
-   snprintf(recoveryPath, MAXPGPATH, "%s/RECOVERYHISTORY", XLogDir);
+   snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYHISTORY");
    unlink(recoveryPath);       /* ignore any error */
 
    /*
     * Rename the config file out of the way, so that we don't
     * accidentally re-enter archive recovery mode in a subsequent crash.
     */
-   snprintf(recoveryCommandFile, MAXPGPATH, "%s/recovery.conf", DataDir);
-   snprintf(recoveryCommandDone, MAXPGPATH, "%s/recovery.done", DataDir);
-   unlink(recoveryCommandDone);
-   if (rename(recoveryCommandFile, recoveryCommandDone) != 0)
+   unlink(RECOVERY_COMMAND_DONE);
+   if (rename(RECOVERY_COMMAND_FILE, RECOVERY_COMMAND_DONE) != 0)
        ereport(FATAL,
                (errcode_for_file_access(),
                 errmsg("could not rename file \"%s\" to \"%s\": %m",
-                       recoveryCommandFile, recoveryCommandDone)));
+                       RECOVERY_COMMAND_FILE, RECOVERY_COMMAND_DONE)));
 
    ereport(LOG,
            (errmsg("archive recovery complete")));
@@ -5467,7 +5458,6 @@ pg_start_backup(PG_FUNCTION_ARGS)
    XLogRecPtr  startpoint;
    time_t      stamp_time;
    char        strfbuf[128];
-   char        labelfilepath[MAXPGPATH];
    char        xlogfilename[MAXFNAMELEN];
    uint32      _logId;
    uint32      _logSeg;
@@ -5526,31 +5516,30 @@ pg_start_backup(PG_FUNCTION_ARGS)
     * Check for existing backup label --- implies a backup is already
     * running
     */
-   snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir);
-   if (stat(labelfilepath, &stat_buf) != 0)
+   if (stat(BACKUP_LABEL_FILE, &stat_buf) != 0)
    {
        if (errno != ENOENT)
            ereport(ERROR,
                    (errcode_for_file_access(),
                     errmsg("could not stat file \"%s\": %m",
-                           labelfilepath)));
+                           BACKUP_LABEL_FILE)));
    }
    else
        ereport(ERROR,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                 errmsg("a backup is already in progress"),
                 errhint("If you're sure there is no backup in progress, remove file \"%s\" and try again.",
-                        labelfilepath)));
+                        BACKUP_LABEL_FILE)));
 
    /*
     * Okay, write the file
     */
-   fp = AllocateFile(labelfilepath, "w");
+   fp = AllocateFile(BACKUP_LABEL_FILE, "w");
    if (!fp)
        ereport(ERROR,
                (errcode_for_file_access(),
                 errmsg("could not create file \"%s\": %m",
-                       labelfilepath)));
+                       BACKUP_LABEL_FILE)));
    fprintf(fp, "START WAL LOCATION: %X/%X (file %s)\n",
            startpoint.xlogid, startpoint.xrecoff, xlogfilename);
    fprintf(fp, "CHECKPOINT LOCATION: %X/%X\n",
@@ -5561,7 +5550,7 @@ pg_start_backup(PG_FUNCTION_ARGS)
        ereport(ERROR,
                (errcode_for_file_access(),
                 errmsg("could not write file \"%s\": %m",
-                       labelfilepath)));
+                       BACKUP_LABEL_FILE)));
 
    /*
     * We're done.  As a convenience, return the starting WAL offset.
@@ -5590,7 +5579,6 @@ pg_stop_backup(PG_FUNCTION_ARGS)
    XLogRecPtr  stoppoint;
    time_t      stamp_time;
    char        strfbuf[128];
-   char        labelfilepath[MAXPGPATH];
    char        histfilepath[MAXPGPATH];
    char        startxlogfilename[MAXFNAMELEN];
    char        stopxlogfilename[MAXFNAMELEN];
@@ -5631,15 +5619,14 @@ pg_stop_backup(PG_FUNCTION_ARGS)
    /*
     * Open the existing label file
     */
-   snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir);
-   lfp = AllocateFile(labelfilepath, "r");
+   lfp = AllocateFile(BACKUP_LABEL_FILE, "r");
    if (!lfp)
    {
        if (errno != ENOENT)
            ereport(ERROR,
                    (errcode_for_file_access(),
                     errmsg("could not read file \"%s\": %m",
-                           labelfilepath)));
+                           BACKUP_LABEL_FILE)));
        ereport(ERROR,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                 errmsg("a backup is not in progress")));
@@ -5655,7 +5642,7 @@ pg_stop_backup(PG_FUNCTION_ARGS)
               &ch) != 4 || ch != '\n')
        ereport(ERROR,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
-                errmsg("invalid data in file \"%s\"", labelfilepath)));
+                errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
 
    /*
     * Write the backup history file
@@ -5690,12 +5677,12 @@ pg_stop_backup(PG_FUNCTION_ARGS)
        ereport(ERROR,
                (errcode_for_file_access(),
                 errmsg("could not read file \"%s\": %m",
-                       labelfilepath)));
-   if (unlink(labelfilepath) != 0)
+                       BACKUP_LABEL_FILE)));
+   if (unlink(BACKUP_LABEL_FILE) != 0)
        ereport(ERROR,
                (errcode_for_file_access(),
                 errmsg("could not remove file \"%s\": %m",
-                       labelfilepath)));
+                       BACKUP_LABEL_FILE)));
 
    RemoveOldBackupHistory();
    
@@ -5741,7 +5728,6 @@ read_backup_label(XLogRecPtr *checkPointLoc)
 {
    XLogRecPtr  startpoint;
    XLogRecPtr  stoppoint;
-   char        labelfilepath[MAXPGPATH];
    char        histfilename[MAXFNAMELEN];
    char        histfilepath[MAXPGPATH];
    char        startxlogfilename[MAXFNAMELEN];
@@ -5756,15 +5742,14 @@ read_backup_label(XLogRecPtr *checkPointLoc)
    /*
     * See if label file is present
     */
-   snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir);
-   lfp = AllocateFile(labelfilepath, "r");
+   lfp = AllocateFile(BACKUP_LABEL_FILE, "r");
    if (!lfp)
    {
        if (errno != ENOENT)
            ereport(FATAL,
                    (errcode_for_file_access(),
                     errmsg("could not read file \"%s\": %m",
-                           labelfilepath)));
+                           BACKUP_LABEL_FILE)));
        return false;           /* it's not there, all is fine */
    }
 
@@ -5778,18 +5763,18 @@ read_backup_label(XLogRecPtr *checkPointLoc)
               startxlogfilename, &ch) != 5 || ch != '\n')
        ereport(FATAL,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
-                errmsg("invalid data in file \"%s\"", labelfilepath)));
+                errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
    if (fscanf(lfp, "CHECKPOINT LOCATION: %X/%X%c",
               &checkPointLoc->xlogid, &checkPointLoc->xrecoff,
               &ch) != 3 || ch != '\n')
        ereport(FATAL,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
-                errmsg("invalid data in file \"%s\"", labelfilepath)));
+                errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
    if (ferror(lfp) || FreeFile(lfp))
        ereport(FATAL,
                (errcode_for_file_access(),
                 errmsg("could not read file \"%s\": %m",
-                       labelfilepath)));
+                       BACKUP_LABEL_FILE)));
 
    /*
     * Try to retrieve the backup history file (no error if we can't)
@@ -5843,13 +5828,10 @@ read_backup_label(XLogRecPtr *checkPointLoc)
 static void
 remove_backup_label(void)
 {
-   char        labelfilepath[MAXPGPATH];
-
-   snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir);
-   if (unlink(labelfilepath) != 0)
+   if (unlink(BACKUP_LABEL_FILE) != 0)
        if (errno != ENOENT)
            ereport(FATAL,
                    (errcode_for_file_access(),
                     errmsg("could not remove file \"%s\": %m",
-                           labelfilepath)));
+                           BACKUP_LABEL_FILE)));
 }
index b38f9f926500b913895db992ec900ba835f15ef1..e8261c82311d3659717d7bc40d18dd649f2ba98e 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.204 2005/05/06 17:24:52 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.205 2005/07/04 04:51:45 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -365,15 +365,17 @@ BootstrapMain(int argc, char *argv[])
    Assert(DataDir);
    ValidatePgVersion(DataDir);
 
+   /* Change into DataDir (if under postmaster, should be done already) */
+   if (!IsUnderPostmaster)
+       ChangeToDataDir();
+
    /* If standalone, create lockfile for data directory */
    if (!IsUnderPostmaster)
-       CreateDataDirLockFile(DataDir, false);
+       CreateDataDirLockFile(false);
 
    SetProcessingMode(BootstrapProcessing);
    IgnoreSystemIndexes(true);
 
-   XLOGPathInit();
-
    BaseInit();
 
    /* needed to get LWLocks */
index f00e9aeec5f9483331f78b7d78401f558d387c86..480fbc056288f7bc452850a12807e2cc406eda84 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.61 2005/05/10 22:27:29 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.62 2005/07/04 04:51:45 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,26 +41,26 @@ relpath(RelFileNode rnode)
    {
        /* Shared system relations live in {datadir}/global */
        Assert(rnode.dbNode == 0);
-       pathlen = strlen(DataDir) + 8 + OIDCHARS + 1;
+       pathlen = 7 + OIDCHARS + 1;
        path = (char *) palloc(pathlen);
-       snprintf(path, pathlen, "%s/global/%u",
-                DataDir, rnode.relNode);
+       snprintf(path, pathlen, "global/%u",
+                rnode.relNode);
    }
    else if (rnode.spcNode == DEFAULTTABLESPACE_OID)
    {
        /* The default tablespace is {datadir}/base */
-       pathlen = strlen(DataDir) + 6 + OIDCHARS + 1 + OIDCHARS + 1;
+       pathlen = 5 + OIDCHARS + 1 + OIDCHARS + 1;
        path = (char *) palloc(pathlen);
-       snprintf(path, pathlen, "%s/base/%u/%u",
-                DataDir, rnode.dbNode, rnode.relNode);
+       snprintf(path, pathlen, "base/%u/%u",
+                rnode.dbNode, rnode.relNode);
    }
    else
    {
        /* All other tablespaces are accessed via symlinks */
-       pathlen = strlen(DataDir) + 11 + OIDCHARS + 1 + OIDCHARS + 1 + OIDCHARS + 1;
+       pathlen = 10 + OIDCHARS + 1 + OIDCHARS + 1 + OIDCHARS + 1;
        path = (char *) palloc(pathlen);
-       snprintf(path, pathlen, "%s/pg_tblspc/%u/%u/%u",
-                DataDir, rnode.spcNode, rnode.dbNode, rnode.relNode);
+       snprintf(path, pathlen, "pg_tblspc/%u/%u/%u",
+                rnode.spcNode, rnode.dbNode, rnode.relNode);
    }
    return path;
 }
@@ -82,26 +82,25 @@ GetDatabasePath(Oid dbNode, Oid spcNode)
    {
        /* Shared system relations live in {datadir}/global */
        Assert(dbNode == 0);
-       pathlen = strlen(DataDir) + 7 + 1;
+       pathlen = 6 + 1;
        path = (char *) palloc(pathlen);
-       snprintf(path, pathlen, "%s/global",
-                DataDir);
+       snprintf(path, pathlen, "global");
    }
    else if (spcNode == DEFAULTTABLESPACE_OID)
    {
        /* The default tablespace is {datadir}/base */
-       pathlen = strlen(DataDir) + 6 + OIDCHARS + 1;
+       pathlen = 5 + OIDCHARS + 1;
        path = (char *) palloc(pathlen);
-       snprintf(path, pathlen, "%s/base/%u",
-                DataDir, dbNode);
+       snprintf(path, pathlen, "base/%u",
+                dbNode);
    }
    else
    {
        /* All other tablespaces are accessed via symlinks */
-       pathlen = strlen(DataDir) + 11 + OIDCHARS + 1 + OIDCHARS + 1;
+       pathlen = 10 + OIDCHARS + 1 + OIDCHARS + 1;
        path = (char *) palloc(pathlen);
-       snprintf(path, pathlen, "%s/pg_tblspc/%u/%u",
-                DataDir, spcNode, dbNode);
+       snprintf(path, pathlen, "pg_tblspc/%u/%u",
+                spcNode, dbNode);
    }
    return path;
 }
index 15a263b8efd2a7aaad5718979d4b0ce54719e66a..b925825062fc17a560cd838f21e42db142ed9405 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.23 2005/06/28 05:08:54 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.24 2005/07/04 04:51:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -338,8 +338,8 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
    /*
     * All seems well, create the symlink
     */
-   linkloc = (char *) palloc(strlen(DataDir) + 11 + 10 + 1);
-   sprintf(linkloc, "%s/pg_tblspc/%u", DataDir, tablespaceoid);
+   linkloc = (char *) palloc(10 + 10 + 1);
+   sprintf(linkloc, "pg_tblspc/%u", tablespaceoid);
 
    if (symlink(location, linkloc) < 0)
        ereport(ERROR,
@@ -491,8 +491,8 @@ remove_tablespace_directories(Oid tablespaceoid, bool redo)
    char       *subfile;
    struct stat st;
 
-   location = (char *) palloc(strlen(DataDir) + 11 + 10 + 1);
-   sprintf(location, "%s/pg_tblspc/%u", DataDir, tablespaceoid);
+   location = (char *) palloc(10 + 10 + 1);
+   sprintf(location, "pg_tblspc/%u", tablespaceoid);
 
    /*
     * Check if the tablespace still contains any files.  We try to rmdir
@@ -989,8 +989,8 @@ tblspc_redo(XLogRecPtr lsn, XLogRecord *record)
        set_short_version(location);
 
        /* Create the symlink if not already present */
-       linkloc = (char *) palloc(strlen(DataDir) + 11 + 10 + 1);
-       sprintf(linkloc, "%s/pg_tblspc/%u", DataDir, xlrec->ts_id);
+       linkloc = (char *) palloc(10 + 10 + 1);
+       sprintf(linkloc, "pg_tblspc/%u", xlrec->ts_id);
 
        if (symlink(location, linkloc) < 0)
        {
index 3d5ae65a40e3386d2b2adbe2a2e093bedf5ad212..01dc4f1af0d6a933f45d1195a92c3618a3f94017 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.57 2005/06/02 21:03:17 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.58 2005/07/04 04:51:46 tgl Exp $
  *
  *   Since the server static private key ($DataDir/server.key)
  *   will normally be stored unencrypted so that the database
 
 
 #ifdef USE_SSL
+
+#define ROOT_CERT_FILE         "root.crt"
+#define SERVER_CERT_FILE       "server.crt"
+#define SERVER_PRIVATE_KEY_FILE    "server.key"
+
 static DH  *load_dh_file(int keylength);
 static DH  *load_dh_buffer(const char *, size_t);
 static DH  *tmp_dh_cb(SSL *s, int is_export, int keylength);
@@ -500,7 +505,7 @@ load_dh_file(int keylength)
    int         codes;
 
    /* attempt to open file.  It's not an error if it doesn't exist. */
-   snprintf(fnbuf, sizeof(fnbuf), "%s/dh%d.pem", DataDir, keylength);
+   snprintf(fnbuf, sizeof(fnbuf), "dh%d.pem", keylength);
    if ((fp = fopen(fnbuf, "r")) == NULL)
        return NULL;
 
@@ -710,7 +715,6 @@ info_cb(const SSL *ssl, int type, int args)
 static int
 initialize_SSL(void)
 {
-   char        fnbuf[MAXPGPATH];
    struct stat buf;
 
    if (!SSL_context)
@@ -726,19 +730,19 @@ initialize_SSL(void)
        /*
         * Load and verify certificate and private key
         */
-       snprintf(fnbuf, sizeof(fnbuf), "%s/server.crt", DataDir);
-       if (!SSL_CTX_use_certificate_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
+       if (!SSL_CTX_use_certificate_file(SSL_context,
+                                         SERVER_CERT_FILE,
+                                         SSL_FILETYPE_PEM))
            ereport(FATAL,
                    (errcode(ERRCODE_CONFIG_FILE_ERROR),
              errmsg("could not load server certificate file \"%s\": %s",
-                    fnbuf, SSLerrmessage())));
+                    SERVER_CERT_FILE, SSLerrmessage())));
 
-       snprintf(fnbuf, sizeof(fnbuf), "%s/server.key", DataDir);
-       if (stat(fnbuf, &buf) == -1)
+       if (stat(SERVER_PRIVATE_KEY_FILE, &buf) == -1)
            ereport(FATAL,
                    (errcode_for_file_access(),
                   errmsg("could not access private key file \"%s\": %m",
-                         fnbuf)));
+                         SERVER_PRIVATE_KEY_FILE)));
 
        /*
         * Require no public access to key file.
@@ -754,14 +758,16 @@ initialize_SSL(void)
            ereport(FATAL,
                    (errcode(ERRCODE_CONFIG_FILE_ERROR),
                  errmsg("unsafe permissions on private key file \"%s\"",
-                        fnbuf),
+                        SERVER_PRIVATE_KEY_FILE),
                     errdetail("File must be owned by the database user and must have no permissions for \"group\" or \"other\".")));
 #endif
 
-       if (!SSL_CTX_use_PrivateKey_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
+       if (!SSL_CTX_use_PrivateKey_file(SSL_context,
+                                        SERVER_PRIVATE_KEY_FILE,
+                                        SSL_FILETYPE_PEM))
            ereport(FATAL,
                    (errmsg("could not load private key file \"%s\": %s",
-                           fnbuf, SSLerrmessage())));
+                           SERVER_PRIVATE_KEY_FILE, SSLerrmessage())));
 
        if (!SSL_CTX_check_private_key(SSL_context))
            ereport(FATAL,
@@ -780,13 +786,12 @@ initialize_SSL(void)
    /*
     * Require and check client certificates only if we have a root.crt file.
     */
-   snprintf(fnbuf, sizeof(fnbuf), "%s/root.crt", DataDir);
-   if (!SSL_CTX_load_verify_locations(SSL_context, fnbuf, NULL))
+   if (!SSL_CTX_load_verify_locations(SSL_context, ROOT_CERT_FILE, NULL))
    {
        /* Not fatal - we do not require client certificates */
        ereport(LOG,
                (errmsg("could not load root certificate file \"%s\": %s",
-                       fnbuf, SSLerrmessage()),
+                       ROOT_CERT_FILE, SSLerrmessage()),
                 errdetail("Will not verify client certificates.")));
    }
    else
index e5eecb2dbc5d52c6f349c201dbdaedadda18f660..2f52053a2c38913244b3e05047e27b4cb23a47b7 100644 (file)
@@ -19,7 +19,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.16 2005/06/19 21:34:01 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.17 2005/07/04 04:51:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -248,9 +248,6 @@ PgArchiverMain(int argc, char *argv[])
    init_ps_display("archiver process", "", "");
    set_ps_display("");
 
-   /* Init XLOG file paths --- needed in EXEC_BACKEND case */
-   XLOGPathInit();
-
    pgarch_MainLoop();
 
    exit(0);
@@ -400,7 +397,7 @@ pgarch_archiveXlog(char *xlog)
    const char *sp;
    int         rc;
 
-   snprintf(pathname, MAXPGPATH, "%s/%s", XLogDir, xlog);
+   snprintf(pathname, MAXPGPATH, XLOGDIR "/%s", xlog);
 
    /*
     * construct the command to be executed
@@ -502,7 +499,7 @@ pgarch_readyXlog(char *xlog)
    struct dirent *rlde;
    bool        found = false;
 
-   snprintf(XLogArchiveStatusDir, MAXPGPATH, "%s/archive_status", XLogDir);
+   snprintf(XLogArchiveStatusDir, MAXPGPATH, XLOGDIR "/archive_status");
    rldir = AllocateDir(XLogArchiveStatusDir);
    if (rldir == NULL)
        ereport(ERROR,
index 86b873ab36b3b528b471b9a172868824a45968b4..325bb8b451ac77c4573189d72c87f15b9973c406 100644 (file)
@@ -13,7 +13,7 @@
  *
  * Copyright (c) 2001-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.98 2005/06/29 22:51:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.99 2005/07/04 04:51:47 tgl Exp $
  * ----------
  */
 #include "postgres.h"
 
 
 /* ----------
- * Paths for the statistics files. The %s is replaced with the
- * installation's $PGDATA.
+ * Paths for the statistics files (relative to installation's $PGDATA).
  * ----------
  */
-#define PGSTAT_STAT_FILENAME   "%s/global/pgstat.stat"
-#define PGSTAT_STAT_TMPFILE        "%s/global/pgstat.tmp.%d"
+#define PGSTAT_STAT_FILENAME   "global/pgstat.stat"
+#define PGSTAT_STAT_TMPFILE        "global/pgstat.tmp"
 
 /* ----------
  * Timer definitions.
@@ -134,9 +133,6 @@ static HTAB *pgStatBeDead = NULL;
 static PgStat_StatBeEntry *pgStatBeTable = NULL;
 static int pgStatNumBackends = 0;
 
-static char pgStat_fname[MAXPGPATH];
-static char pgStat_tmpfname[MAXPGPATH];
-
 
 /* ----------
  * Local function forward declarations
@@ -220,21 +216,12 @@ pgstat_init(void)
        pgstat_collect_blocklevel)
        pgstat_collect_startcollector = true;
 
-   /*
-    * Initialize the filename for the status reports.  (In the
-    * EXEC_BACKEND case, this only sets the value in the postmaster.  The
-    * collector subprocess will recompute the value for itself, and
-    * individual backends must do so also if they want to access the
-    * file.)
-    */
-   snprintf(pgStat_fname, MAXPGPATH, PGSTAT_STAT_FILENAME, DataDir);
-
    /*
     * If we don't have to start a collector or should reset the collected
-    * statistics on postmaster start, simply remove the file.
+    * statistics on postmaster start, simply remove the stats file.
     */
    if (!pgstat_collect_startcollector || pgstat_collect_resetonpmstart)
-       unlink(pgStat_fname);
+       unlink(PGSTAT_STAT_FILENAME);
 
    /*
     * Nothing else required if collector will not get started
@@ -1470,14 +1457,6 @@ PgstatCollectorMain(int argc, char *argv[])
    init_ps_display("stats collector process", "", "");
    set_ps_display("");
 
-   /*
-    * Initialize filenames needed for status reports.
-    */
-   snprintf(pgStat_fname, MAXPGPATH, PGSTAT_STAT_FILENAME, DataDir);
-   /* tmpfname need only be set correctly in this process */
-   snprintf(pgStat_tmpfname, MAXPGPATH, PGSTAT_STAT_TMPFILE,
-            DataDir, (int)getpid());
-
    /*
     * Arrange to write the initial status file right away
     */
@@ -2161,13 +2140,13 @@ pgstat_write_statsfile(void)
    /*
     * Open the statistics temp file to write out the current values.
     */
-   fpout = fopen(pgStat_tmpfname, PG_BINARY_W);
+   fpout = fopen(PGSTAT_STAT_TMPFILE, PG_BINARY_W);
    if (fpout == NULL)
    {
        ereport(LOG,
                (errcode_for_file_access(),
            errmsg("could not open temporary statistics file \"%s\": %m",
-                  pgStat_tmpfname)));
+                  PGSTAT_STAT_TMPFILE)));
        return;
    }
 
@@ -2276,16 +2255,16 @@ pgstat_write_statsfile(void)
        ereport(LOG,
                (errcode_for_file_access(),
           errmsg("could not close temporary statistics file \"%s\": %m",
-                 pgStat_tmpfname)));
+                 PGSTAT_STAT_TMPFILE)));
    }
    else
    {
-       if (rename(pgStat_tmpfname, pgStat_fname) < 0)
+       if (rename(PGSTAT_STAT_TMPFILE, PGSTAT_STAT_FILENAME) < 0)
        {
            ereport(LOG,
                    (errcode_for_file_access(),
                     errmsg("could not rename temporary statistics file \"%s\" to \"%s\": %m",
-                           pgStat_tmpfname, pgStat_fname)));
+                           PGSTAT_STAT_TMPFILE, PGSTAT_STAT_FILENAME)));
        }
    }
 
@@ -2376,24 +2355,12 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
    if (betab != NULL)
        *betab = NULL;
 
-   /*
-    * In EXEC_BACKEND case, we won't have inherited pgStat_fname from
-    * postmaster, so compute it first time through.
-    */
-#ifdef EXEC_BACKEND
-   if (pgStat_fname[0] == '\0')
-   {
-       Assert(DataDir != NULL);
-       snprintf(pgStat_fname, MAXPGPATH, PGSTAT_STAT_FILENAME, DataDir);
-   }
-#endif
-
    /*
     * Try to open the status file. If it doesn't exist, the backends
     * simply return zero for anything and the collector simply starts
     * from scratch with empty counters.
     */
-   if ((fpin = AllocateFile(pgStat_fname, PG_BINARY_R)) == NULL)
+   if ((fpin = AllocateFile(PGSTAT_STAT_FILENAME, PG_BINARY_R)) == NULL)
        return;
 
    /*
index d14f6db1630068cc96124914037d817a53bf5053..2de5527648303808ffa23e7334ee285b8bd913e6 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.457 2005/06/30 10:02:22 petere Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.458 2005/07/04 04:51:47 tgl Exp $
  *
  * NOTES
  *
@@ -585,6 +585,15 @@ PostmasterMain(int argc, char *argv[])
        ExitPostmaster(1);
    }
 
+#ifdef EXEC_BACKEND
+   /* Locate executable backend before we change working directory */
+   if (find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
+                       postgres_exec_path) < 0)
+       ereport(FATAL,
+            (errmsg("%s: could not locate matching postgres executable",
+                    progname)));
+#endif
+
    /*
     * Locate the proper configuration files and data directory, and
     * read postgresql.conf for the first time.
@@ -595,6 +604,9 @@ PostmasterMain(int argc, char *argv[])
    /* Verify that DataDir looks reasonable */
    checkDataDir();
 
+   /* And switch working directory into it */
+   ChangeToDataDir();
+
    /*
     * Check for invalid combinations of GUC settings.
     */
@@ -650,14 +662,6 @@ PostmasterMain(int argc, char *argv[])
         (errmsg_internal("-----------------------------------------")));
    }
 
-#ifdef EXEC_BACKEND
-   if (find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
-                       postgres_exec_path) < 0)
-       ereport(FATAL,
-            (errmsg("%s: could not locate matching postgres executable",
-                    progname)));
-#endif
-
    /*
     * Initialize SSL library, if specified.
     */
@@ -691,7 +695,7 @@ PostmasterMain(int argc, char *argv[])
     * :-(). For the same reason, it's best to grab the TCP socket(s)
     * before the Unix socket.
     */
-   CreateDataDirLockFile(DataDir, true);
+   CreateDataDirLockFile(true);
 
    /*
     * Remove old temporary files.  At this point there can be no other
@@ -786,8 +790,6 @@ PostmasterMain(int argc, char *argv[])
        ereport(FATAL,
                (errmsg("no socket created for listening")));
 
-   XLOGPathInit();
-
    /*
     * Set up shared memory and semaphores.
     */
@@ -2866,20 +2868,16 @@ internal_forkexec(int argc, char *argv[], Port *port)
        return -1;              /* log made by save_backend_variables */
 
    /* Calculate name for temp file */
-   Assert(DataDir);
-   snprintf(tmpfilename, MAXPGPATH, "%s/%s/%s.backend_var.%d.%lu",
-            DataDir, PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
+   snprintf(tmpfilename, MAXPGPATH, "%s/%s.backend_var.%d.%lu",
+            PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
             MyProcPid, ++tmpBackendFileNum);
 
    /* Open file */
    fp = AllocateFile(tmpfilename, PG_BINARY_W);
    if (!fp)
    {
-       /* As per OpenTemporaryFile... */
-       char        dirname[MAXPGPATH];
-
-       snprintf(dirname, MAXPGPATH, "%s/%s", DataDir, PG_TEMP_FILES_DIR);
-       mkdir(dirname, S_IRWXU);
+       /* As in OpenTemporaryFile, try to make the temp-file directory */
+       mkdir(PG_TEMP_FILES_DIR, S_IRWXU);
 
        fp = AllocateFile(tmpfilename, PG_BINARY_W);
        if (!fp)
@@ -3527,15 +3525,14 @@ StartChildProcess(int xlop)
 static bool
 CreateOptsFile(int argc, char *argv[], char *fullprogname)
 {
-   char        filename[MAXPGPATH];
    FILE       *fp;
    int         i;
 
-   snprintf(filename, sizeof(filename), "%s/postmaster.opts", DataDir);
+#define OPTS_FILE  "postmaster.opts"
 
-   if ((fp = fopen(filename, "w")) == NULL)
+   if ((fp = fopen(OPTS_FILE, "w")) == NULL)
    {
-       elog(LOG, "could not create file \"%s\": %m", filename);
+       elog(LOG, "could not create file \"%s\": %m", OPTS_FILE);
        return false;
    }
 
@@ -3546,7 +3543,7 @@ CreateOptsFile(int argc, char *argv[], char *fullprogname)
 
    if (fclose(fp))
    {
-       elog(LOG, "could not write file \"%s\": %m", filename);
+       elog(LOG, "could not write file \"%s\": %m", OPTS_FILE);
        return false;
    }
 
index 1899d8f21a1c5630558ecb538147eb83b93deaaa..c6f02520bfcdfd05324fb4709d5cdc4e46b40fc8 100644 (file)
@@ -18,7 +18,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.15 2005/04/19 03:13:59 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.16 2005/07/04 04:51:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -422,17 +422,9 @@ SysLogger_Start(void)
 #endif
 
    /*
-    * create log directory if not present; ignore errors
+    * Create log directory if not present; ignore errors
     */
-   if (is_absolute_path(Log_directory))
-       mkdir(Log_directory, 0700);
-   else
-   {
-       filename = palloc(MAXPGPATH);
-       snprintf(filename, MAXPGPATH, "%s/%s", DataDir, Log_directory);
-       mkdir(filename, 0700);
-       pfree(filename);
-   }
+   mkdir(Log_directory, 0700);
 
    /*
     * The initial logfile is created right in the postmaster, to verify
@@ -823,10 +815,7 @@ logfile_getname(pg_time_t timestamp)
 
    filename = palloc(MAXPGPATH);
 
-   if (is_absolute_path(Log_directory))
-       snprintf(filename, MAXPGPATH, "%s/", Log_directory);
-   else
-       snprintf(filename, MAXPGPATH, "%s/%s/", DataDir, Log_directory);
+   snprintf(filename, MAXPGPATH, "%s/", Log_directory);
 
    len = strlen(filename);
 
index b91e667d0b31466c0429700eae34e05f6c4a1fcc..11c7b8076650f0088b99836ea9ad5963413acf68 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.117 2005/06/19 21:34:02 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.118 2005/07/04 04:51:48 tgl Exp $
  *
  * NOTES:
  *
@@ -224,8 +224,7 @@ static File AllocateVfd(void);
 static void FreeVfd(File file);
 
 static int FileAccess(File file);
-static File fileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
-static char *filepath(const char *filename);
+static char *make_database_relative(const char *filename);
 static void AtProcExit_Files(int code, Datum arg);
 static void CleanupTempFiles(bool isProcExit);
 static void RemovePgTempFilesInDir(const char *tmpdirname);
@@ -699,34 +698,20 @@ FreeVfd(File file)
    VfdCache[0].nextFree = file;
 }
 
-/* filepath()
- * Convert given pathname to absolute.
+/*
+ * make_database_relative()
+ *     Prepend DatabasePath to the given file name.
  *
  * Result is a palloc'd string.
- *
- * (Generally, this isn't actually necessary, considering that we
- * should be cd'd into the database directory.  Presently it is only
- * necessary to do it in "bootstrap" mode. Maybe we should change
- * bootstrap mode to do the cd, and save a few cycles/bytes here.)
  */
 static char *
-filepath(const char *filename)
+make_database_relative(const char *filename)
 {
    char       *buf;
 
-   /* Not an absolute path name? Then fill in with database path... */
-   if (!is_absolute_path(filename))
-   {
-       buf = (char *) palloc(strlen(DatabasePath) + strlen(filename) + 2);
-       sprintf(buf, "%s/%s", DatabasePath, filename);
-   }
-   else
-       buf = pstrdup(filename);
-
-#ifdef FILEDEBUG
-   printf("filepath: path is %s\n", buf);
-#endif
-
+   Assert(!is_absolute_path(filename));
+   buf = (char *) palloc(strlen(DatabasePath) + strlen(filename) + 2);
+   sprintf(buf, "%s/%s", DatabasePath, filename);
    return buf;
 }
 
@@ -779,16 +764,21 @@ FileInvalidate(File file)
 }
 #endif
 
-static File
-fileNameOpenFile(FileName fileName,
-                int fileFlags,
-                int fileMode)
+/*
+ * open a file in an arbitrary directory
+ *
+ * NB: if the passed pathname is relative (which it usually is),
+ * it will be interpreted relative to the process' working directory
+ * (which should always be $PGDATA when this code is running).
+ */
+File
+PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
 {
    char       *fnamecopy;
    File        file;
    Vfd        *vfdP;
 
-   DO_DB(elog(LOG, "fileNameOpenFile: %s %x %o",
+   DO_DB(elog(LOG, "PathNameOpenFile: %s %x %o",
               fileName, fileFlags, fileMode));
 
    /*
@@ -818,7 +808,7 @@ fileNameOpenFile(FileName fileName,
        return -1;
    }
    ++nfile;
-   DO_DB(elog(LOG, "fileNameOpenFile: success %d",
+   DO_DB(elog(LOG, "PathNameOpenFile: success %d",
               vfdP->fd));
 
    Insert(file);
@@ -834,7 +824,10 @@ fileNameOpenFile(FileName fileName,
 }
 
 /*
- * open a file in the database directory ($PGDATA/base/...)
+ * open a file in the database directory ($PGDATA/base/DIROID/)
+ *
+ * The passed name MUST be a relative path.  Effectively, this
+ * prepends DatabasePath to it and then acts like PathNameOpenFile.
  */
 File
 FileNameOpenFile(FileName fileName, int fileFlags, int fileMode)
@@ -842,21 +835,12 @@ FileNameOpenFile(FileName fileName, int fileFlags, int fileMode)
    File        fd;
    char       *fname;
 
-   fname = filepath(fileName);
-   fd = fileNameOpenFile(fname, fileFlags, fileMode);
+   fname = make_database_relative(fileName);
+   fd = PathNameOpenFile(fname, fileFlags, fileMode);
    pfree(fname);
    return fd;
 }
 
-/*
- * open a file in an arbitrary directory
- */
-File
-PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
-{
-   return fileNameOpenFile(fileName, fileFlags, fileMode);
-}
-
 /*
  * Open a temporary file that will disappear when we close it.
  *
@@ -903,7 +887,7 @@ OpenTemporaryFile(bool interXact)
         * just did the same thing.  If it doesn't work then we'll bomb
         * out on the second create attempt, instead.
         */
-       dirpath = filepath(PG_TEMP_FILES_DIR);
+       dirpath = make_database_relative(PG_TEMP_FILES_DIR);
        mkdir(dirpath, S_IRWXU);
        pfree(dirpath);
 
@@ -1568,7 +1552,6 @@ CleanupTempFiles(bool isProcExit)
 void
 RemovePgTempFiles(void)
 {
-   char        db_path[MAXPGPATH];
    char        temp_path[MAXPGPATH];
    DIR        *db_dir;
    struct dirent *db_de;
@@ -1577,17 +1560,16 @@ RemovePgTempFiles(void)
     * Cycle through pgsql_tmp directories for all databases and remove old
     * temp files.
     */
-   snprintf(db_path, sizeof(db_path), "%s/base", DataDir);
-   db_dir = AllocateDir(db_path);
+   db_dir = AllocateDir("base");
 
-   while ((db_de = ReadDir(db_dir, db_path)) != NULL)
+   while ((db_de = ReadDir(db_dir, "base")) != NULL)
    {
        if (strcmp(db_de->d_name, ".") == 0 ||
            strcmp(db_de->d_name, "..") == 0)
            continue;
 
-       snprintf(temp_path, sizeof(temp_path), "%s/%s/%s",
-                db_path, db_de->d_name, PG_TEMP_FILES_DIR);
+       snprintf(temp_path, sizeof(temp_path), "base/%s/%s",
+                db_de->d_name, PG_TEMP_FILES_DIR);
        RemovePgTempFilesInDir(temp_path);
    }
 
@@ -1598,9 +1580,7 @@ RemovePgTempFiles(void)
     * level of DataDir as well.
     */
 #ifdef EXEC_BACKEND
-   snprintf(temp_path, sizeof(temp_path), "%s/%s",
-            DataDir, PG_TEMP_FILES_DIR);
-   RemovePgTempFilesInDir(temp_path);
+   RemovePgTempFilesInDir(PG_TEMP_FILES_DIR);
 #endif
 }
 
index 27e9952b3ff083f644a7235ee56824c3e1c204b4..355282db1a4562e489290912a8a48478d7f9254f 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.45 2005/05/29 04:23:04 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.46 2005/07/04 04:51:48 tgl Exp $
  *
  *
  * NOTES:
@@ -752,20 +752,16 @@ void
 DumpFreeSpaceMap(int code, Datum arg)
 {
    FILE       *fp;
-   char        cachefilename[MAXPGPATH];
    FsmCacheFileHeader header;
    FSMRelation *fsmrel;
 
    /* Try to create file */
-   snprintf(cachefilename, sizeof(cachefilename), "%s/%s",
-            DataDir, FSM_CACHE_FILENAME);
+   unlink(FSM_CACHE_FILENAME);     /* in case it exists w/wrong permissions */
 
-   unlink(cachefilename);      /* in case it exists w/wrong permissions */
-
-   fp = AllocateFile(cachefilename, PG_BINARY_W);
+   fp = AllocateFile(FSM_CACHE_FILENAME, PG_BINARY_W);
    if (fp == NULL)
    {
-       elog(LOG, "could not write \"%s\": %m", cachefilename);
+       elog(LOG, "could not write \"%s\": %m", FSM_CACHE_FILENAME);
        return;
    }
 
@@ -821,15 +817,15 @@ DumpFreeSpaceMap(int code, Datum arg)
 
    if (FreeFile(fp))
    {
-       elog(LOG, "could not write \"%s\": %m", cachefilename);
+       elog(LOG, "could not write \"%s\": %m", FSM_CACHE_FILENAME);
        /* Remove busted cache file */
-       unlink(cachefilename);
+       unlink(FSM_CACHE_FILENAME);
    }
 
    return;
 
 write_failed:
-   elog(LOG, "could not write \"%s\": %m", cachefilename);
+   elog(LOG, "could not write \"%s\": %m", FSM_CACHE_FILENAME);
 
    /* Clean up */
    LWLockRelease(FreeSpaceLock);
@@ -837,7 +833,7 @@ write_failed:
    FreeFile(fp);
 
    /* Remove busted cache file */
-   unlink(cachefilename);
+   unlink(FSM_CACHE_FILENAME);
 }
 
 /*
@@ -858,19 +854,15 @@ void
 LoadFreeSpaceMap(void)
 {
    FILE       *fp;
-   char        cachefilename[MAXPGPATH];
    FsmCacheFileHeader header;
    int         relno;
 
    /* Try to open file */
-   snprintf(cachefilename, sizeof(cachefilename), "%s/%s",
-            DataDir, FSM_CACHE_FILENAME);
-
-   fp = AllocateFile(cachefilename, PG_BINARY_R);
+   fp = AllocateFile(FSM_CACHE_FILENAME, PG_BINARY_R);
    if (fp == NULL)
    {
        if (errno != ENOENT)
-           elog(LOG, "could not read \"%s\": %m", cachefilename);
+           elog(LOG, "could not read \"%s\": %m", FSM_CACHE_FILENAME);
        return;
    }
 
@@ -883,7 +875,7 @@ LoadFreeSpaceMap(void)
        header.version != FSM_CACHE_VERSION ||
        header.numRels < 0)
    {
-       elog(LOG, "bogus file header in \"%s\"", cachefilename);
+       elog(LOG, "bogus file header in \"%s\"", FSM_CACHE_FILENAME);
        goto read_failed;
    }
 
@@ -905,7 +897,7 @@ LoadFreeSpaceMap(void)
            relheader.lastPageCount < 0 ||
            relheader.storedPages < 0)
        {
-           elog(LOG, "bogus rel header in \"%s\"", cachefilename);
+           elog(LOG, "bogus rel header in \"%s\"", FSM_CACHE_FILENAME);
            goto read_failed;
        }
 
@@ -922,7 +914,7 @@ LoadFreeSpaceMap(void)
        data = (char *) palloc(len);
        if (fread(data, 1, len, fp) != len)
        {
-           elog(LOG, "premature EOF in \"%s\"", cachefilename);
+           elog(LOG, "premature EOF in \"%s\"", FSM_CACHE_FILENAME);
            pfree(data);
            goto read_failed;
        }
@@ -993,7 +985,7 @@ read_failed:
    FreeFile(fp);
 
    /* Remove cache file before it can become stale; see notes above */
-   unlink(cachefilename);
+   unlink(FSM_CACHE_FILENAME);
 }
 
 
index fa7913aff74bd5db0e3559e008200a9abf1cd874..3a0a1f1262bd807b908cf801556b801aa602b7ff 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.116 2005/06/20 18:37:01 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.117 2005/07/04 04:51:49 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -155,7 +155,7 @@ mdcreate(SMgrRelation reln, bool isRedo)
 
    path = relpath(reln->smgr_rnode);
 
-   fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
+   fd = PathNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
 
    if (fd < 0)
    {
@@ -169,7 +169,7 @@ mdcreate(SMgrRelation reln, bool isRedo)
         * mdopen)
         */
        if (isRedo || IsBootstrapProcessingMode())
-           fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
+           fd = PathNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
        if (fd < 0)
        {
            pfree(path);
@@ -340,7 +340,7 @@ mdopen(SMgrRelation reln, bool allowNotFound)
 
    path = relpath(reln->smgr_rnode);
 
-   fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
+   fd = PathNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
 
    if (fd < 0)
    {
@@ -352,7 +352,7 @@ mdopen(SMgrRelation reln, bool allowNotFound)
         * (See mdcreate)
         */
        if (IsBootstrapProcessingMode())
-           fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
+           fd = PathNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
        if (fd < 0)
        {
            pfree(path);
@@ -879,7 +879,7 @@ _mdfd_openseg(SMgrRelation reln, BlockNumber segno, int oflags)
        fullpath = path;
 
    /* open the file */
-   fd = FileNameOpenFile(fullpath, O_RDWR | PG_BINARY | oflags, 0600);
+   fd = PathNameOpenFile(fullpath, O_RDWR | PG_BINARY | oflags, 0600);
 
    pfree(fullpath);
 
index 534e4796611c1c8aa94f089ddbc7fd05e07aca27..6973e9d3b3cb48fd566ead7ecbb23425b04de60c 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.451 2005/06/29 22:51:55 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.452 2005/07/04 04:51:49 tgl Exp $
  *
  * NOTES
  *   this is the "main" module of the postgres backend and
@@ -2809,8 +2809,6 @@ PostgresMain(int argc, char *argv[], const char *username)
            errhint("Try \"%s --help\" for more information.", argv[0])));
        }
 
-       XLOGPathInit();
-
        BaseInit();
    }
    else
@@ -2841,12 +2839,14 @@ PostgresMain(int argc, char *argv[], const char *username)
        Assert(DataDir);
        ValidatePgVersion(DataDir);
 
+       /* Change into DataDir (if under postmaster, was done already) */
+       ChangeToDataDir();
+
        /*
         * Create lockfile for data directory.
         */
-       CreateDataDirLockFile(DataDir, false);
+       CreateDataDirLockFile(false);
 
-       XLOGPathInit();
        BaseInit();
 
        /*
index 45532539664f21f93d8f293bc21270b0b94436fb..867f7da7e2a7d8187bc15770f2591082d7be9d51 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.44 2005/06/19 21:34:02 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.45 2005/07/04 04:51:50 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -145,10 +145,10 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
        fctx = palloc(sizeof(ts_db_fctx));
 
        /*
-        * size = path length + tablespace dirname length + 2 dir sep
-        * chars + oid + terminator
+        * size = tablespace dirname length + dir sep
+        * char + oid + terminator
         */
-       fctx->location = (char *) palloc(strlen(DataDir) + 11 + 10 + 1);
+       fctx->location = (char *) palloc(10 + 10 + 1);
        if (tablespaceOid == GLOBALTABLESPACE_OID)
        {
            fctx->dirdesc = NULL;
@@ -158,10 +158,9 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
        else
        {
            if (tablespaceOid == DEFAULTTABLESPACE_OID)
-               sprintf(fctx->location, "%s/base", DataDir);
+               sprintf(fctx->location, "base");
            else
-               sprintf(fctx->location, "%s/pg_tblspc/%u", DataDir,
-                       tablespaceOid);
+               sprintf(fctx->location, "pg_tblspc/%u", tablespaceOid);
 
            fctx->dirdesc = AllocateDir(fctx->location);
 
index 2343c01b54882155e5af1910afec7fa90334b846..e4b7154b93b283bad3206a741a04f674c303d67f 100644 (file)
@@ -23,7 +23,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.11 2005/06/29 20:34:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.12 2005/07/04 04:51:50 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -50,9 +50,9 @@
 #include "utils/syscache.h"
 
 
-/* Actual names of the flat files (within $PGDATA/global/) */
-#define DATABASE_FLAT_FILE "pg_database"
-#define AUTH_FLAT_FILE     "pg_auth"
+/* Actual names of the flat files (within $PGDATA) */
+#define DATABASE_FLAT_FILE "global/pg_database"
+#define AUTH_FLAT_FILE     "global/pg_auth"
 
 /* Info bits in a flatfiles 2PC record */
 #define FF_BIT_DATABASE    1
@@ -98,41 +98,29 @@ auth_file_update_needed(void)
 
 
 /*
- * database_getflatfilename --- get full pathname of database file
+ * database_getflatfilename --- get pathname of database file
  *
  * Note that result string is palloc'd, and should be freed by the caller.
+ * (This convention is not really needed anymore, since the relative path
+ * is fixed.)
  */
 char *
 database_getflatfilename(void)
 {
-   int         bufsize;
-   char       *pfnam;
-
-   bufsize = strlen(DataDir) + strlen("/global/") +
-       strlen(DATABASE_FLAT_FILE) + 1;
-   pfnam = (char *) palloc(bufsize);
-   snprintf(pfnam, bufsize, "%s/global/%s", DataDir, DATABASE_FLAT_FILE);
-
-   return pfnam;
+   return pstrdup(DATABASE_FLAT_FILE);
 }
 
 /*
- * auth_getflatfilename --- get full pathname of auth file
+ * auth_getflatfilename --- get pathname of auth file
  *
  * Note that result string is palloc'd, and should be freed by the caller.
+ * (This convention is not really needed anymore, since the relative path
+ * is fixed.)
  */
 char *
 auth_getflatfilename(void)
 {
-   int         bufsize;
-   char       *pfnam;
-
-   bufsize = strlen(DataDir) + strlen("/global/") +
-       strlen(AUTH_FLAT_FILE) + 1;
-   pfnam = (char *) palloc(bufsize);
-   snprintf(pfnam, bufsize, "%s/global/%s", DataDir, AUTH_FLAT_FILE);
-
-   return pfnam;
+   return pstrdup(AUTH_FLAT_FILE);
 }
 
 
index 1c9725d62987e1fef8af507d6ced74e2e137ff6c..a4fb354a4c998058243dc4c0660b04d1c6c0b0b2 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.95 2004/12/31 22:01:40 pgsql Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.96 2005/07/04 04:51:50 tgl Exp $
  *
  * NOTES
  *   Globals used all over the place should be declared here and not
@@ -36,13 +36,14 @@ int         MyProcPid;
 struct Port *MyProcPort;
 long       MyCancelKey;
 
+/*
+ * DataDir is the absolute path to the top level of the PGDATA directory tree.
+ * Except during early startup, this is also the server's working directory;
+ * most code therefore can simply use relative paths and not reference DataDir
+ * explicitly.
+ */
 char      *DataDir = NULL;
 
- /*
-  * The PGDATA directory user says to use, or defaults to via environment
-  * variable.  NULL if no option given and no environment variable set
-  */
-
 char       OutputFileName[MAXPGPATH];  /* debugging output file */
 
 char       my_exec_path[MAXPGPATH];    /* full path to my executable */
@@ -56,11 +57,16 @@ char        postgres_exec_path[MAXPGPATH];      /* full path to backend */
 
 BackendId  MyBackendId = InvalidBackendId;
 
-char      *DatabasePath = NULL;
 Oid            MyDatabaseId = InvalidOid;
 
 Oid            MyDatabaseTableSpace = InvalidOid;
 
+/*
+ * DatabasePath is the path (relative to DataDir) of my database's
+ * primary directory, ie, its directory in the default tablespace.
+ */
+char      *DatabasePath = NULL;
+
 pid_t      PostmasterPid = 0;
 
 /*
index be1f6e704962e858314d2d173e9d3bbaf4249804..ffe7db5f7e517b45da36d5f3bd3547123b0ccd32 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.144 2005/06/28 22:16:45 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.145 2005/07/04 04:51:50 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "utils/syscache.h"
 
 
+#define DIRECTORY_LOCK_FILE        "postmaster.pid"
+
 ProcessingMode Mode = InitProcessing;
 
-/* Note: we rely on these to initialize as zeroes */
-static char directoryLockFile[MAXPGPATH];
+/* Note: we rely on this to initialize as zeroes */
 static char socketLockFile[MAXPGPATH];
 
 
@@ -177,16 +178,33 @@ SetDataDir(const char *dir)
    DataDir = new;
 }
 
+/*
+ * Change working directory to DataDir.  Most of the postmaster and backend
+ * code assumes that we are in DataDir so it can use relative paths to access
+ * stuff in and under the data directory.  For convenience during path
+ * setup, however, we don't force the chdir to occur during SetDataDir.
+ */
+void
+ChangeToDataDir(void)
+{
+   AssertState(DataDir);
+
+   if (chdir(DataDir) < 0)
+       ereport(FATAL,
+               (errcode_for_file_access(),
+                errmsg("could not change directory to \"%s\": %m",
+                       DataDir)));
+}
+
 /*
  * If the given pathname isn't already absolute, make it so, interpreting
  * it relative to the current working directory.
  *
  * Also canonicalizes the path.  The result is always a malloc'd copy.
  *
- * Note: it is probably unwise to use this in running backends, since they
- * have chdir'd to a database-specific subdirectory; the results would not be
- * consistent across backends.  Currently this is used only during postmaster
- * or standalone-backend startup.
+ * Note: interpretation of relative-path arguments during postmaster startup
+ * should happen before doing ChangeToDataDir(), else the user will probably
+ * not like the results.
  */
 char *
 make_absolute_path(const char *path)
@@ -713,17 +731,22 @@ CreateLockFile(const char *filename, bool amPostmaster,
    on_proc_exit(UnlinkLockFile, PointerGetDatum(strdup(filename)));
 }
 
+/*
+ * Create the data directory lockfile.
+ *
+ * When this is called, we must have already switched the working
+ * directory to DataDir, so we can just use a relative path.  This
+ * helps ensure that we are locking the directory we should be.
+ */
 void
-CreateDataDirLockFile(const char *datadir, bool amPostmaster)
+CreateDataDirLockFile(bool amPostmaster)
 {
-   char        lockfile[MAXPGPATH];
-
-   snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir);
-   CreateLockFile(lockfile, amPostmaster, true, datadir);
-   /* Save name of lockfile for RecordSharedMemoryInLockFile */
-   strcpy(directoryLockFile, lockfile);
+   CreateLockFile(DIRECTORY_LOCK_FILE, amPostmaster, true, DataDir);
 }
 
+/*
+ * Create a lockfile for the specified Unix socket file.
+ */
 void
 CreateSocketLockFile(const char *socketfile, bool amPostmaster)
 {
@@ -777,7 +800,7 @@ TouchSocketLockFile(void)
 
 /*
  * Append information about a shared memory segment to the data directory
- * lock file (if we have created one).
+ * lock file.
  *
  * This may be called multiple times in the life of a postmaster, if we
  * delete and recreate shmem due to backend crash. Therefore, be prepared
@@ -793,20 +816,13 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
    char       *ptr;
    char        buffer[BLCKSZ];
 
-   /*
-    * Do nothing if we did not create a lockfile (probably because we are
-    * running standalone).
-    */
-   if (directoryLockFile[0] == '\0')
-       return;
-
-   fd = open(directoryLockFile, O_RDWR | PG_BINARY, 0);
+   fd = open(DIRECTORY_LOCK_FILE, O_RDWR | PG_BINARY, 0);
    if (fd < 0)
    {
        ereport(LOG,
                (errcode_for_file_access(),
                 errmsg("could not open file \"%s\": %m",
-                       directoryLockFile)));
+                       DIRECTORY_LOCK_FILE)));
        return;
    }
    len = read(fd, buffer, sizeof(buffer) - 100);
@@ -815,7 +831,7 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
        ereport(LOG,
                (errcode_for_file_access(),
                 errmsg("could not read from file \"%s\": %m",
-                       directoryLockFile)));
+                       DIRECTORY_LOCK_FILE)));
        close(fd);
        return;
    }
@@ -828,7 +844,7 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
    if (ptr == NULL ||
        (ptr = strchr(ptr + 1, '\n')) == NULL)
    {
-       elog(LOG, "bogus data in \"%s\"", directoryLockFile);
+       elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE);
        close(fd);
        return;
    }
@@ -855,7 +871,7 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
        ereport(LOG,
                (errcode_for_file_access(),
                 errmsg("could not write to file \"%s\": %m",
-                       directoryLockFile)));
+                       DIRECTORY_LOCK_FILE)));
        close(fd);
        return;
    }
@@ -864,7 +880,7 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
        ereport(LOG,
                (errcode_for_file_access(),
                 errmsg("could not write to file \"%s\": %m",
-                       directoryLockFile)));
+                       DIRECTORY_LOCK_FILE)));
    }
 }
 
index 21b0650e8278458a6cf457b4c6643a4359d4c937..18e60cab0f108d4b9be2167ece1c88c7d99e8821 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.151 2005/06/28 19:51:23 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.152 2005/07/04 04:51:50 tgl Exp $
  *
  *
  *-------------------------------------------------------------------------
@@ -338,12 +338,6 @@ InitPostgres(const char *dbname, const char *username)
 
        ValidatePgVersion(fullpath);
 
-       if (chdir(fullpath) == -1)
-           ereport(FATAL,
-                   (errcode_for_file_access(),
-                    errmsg("could not change directory to \"%s\": %m",
-                           fullpath)));
-
        SetDatabasePath(fullpath);
    }
 
index 84d8085503a7603df2a2588a98fbcbc64ee0259b..0ea335770c330552164b3e112cda41ddcef780cf 100644 (file)
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut <peter_e@gmx.net>.
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.271 2005/06/28 05:09:02 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.272 2005/07/04 04:51:51 tgl Exp $
  *
  *--------------------------------------------------------------------
  */
@@ -74,6 +74,7 @@
 
 #ifdef EXEC_BACKEND
 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
+#define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
 #endif
 
 /* XXX these should appear in other modules' header files */
@@ -2619,7 +2620,9 @@ SelectConfigFiles(const char *userDoption, const char *progname)
     * Reflect the final DataDir value back into the data_directory GUC var.
     * (If you are wondering why we don't just make them a single variable,
     * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
-    * child backends specially.)
+    * child backends specially.  XXX is that still true?  Given that we
+    * now chdir to DataDir, EXEC_BACKEND can read the config file without
+    * knowing DataDir in advance.)
     */
    SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
 
@@ -4849,6 +4852,7 @@ _ShowOption(struct config_generic * record)
 
 
 #ifdef EXEC_BACKEND
+
 /*
  * This routine dumps out all non-default GUC options into a binary
  * file that is read by all exec'ed backends.  The format is:
@@ -4861,42 +4865,23 @@ void
 write_nondefault_variables(GucContext context)
 {
    int         i;
-   char       *new_filename,
-              *filename;
    int         elevel;
    FILE       *fp;
 
    Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
-   Assert(DataDir);
 
    elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
 
    /*
     * Open file
     */
-   new_filename = guc_malloc(elevel, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) +
-                             strlen(".new") + 2);
-   if (new_filename == NULL)
-       return;
-
-   filename = guc_malloc(elevel, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) + 2);
-   if (filename == NULL)
-   {
-       free(new_filename);
-       return;
-   }
-
-   sprintf(new_filename, "%s/" CONFIG_EXEC_PARAMS ".new", DataDir);
-   sprintf(filename, "%s/" CONFIG_EXEC_PARAMS, DataDir);
-
-   fp = AllocateFile(new_filename, "w");
+   fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
    if (!fp)
    {
-       free(new_filename);
-       free(filename);
        ereport(elevel,
                (errcode_for_file_access(),
-                errmsg("could not write to file \"%s\": %m", CONFIG_EXEC_PARAMS)));
+                errmsg("could not write to file \"%s\": %m",
+                       CONFIG_EXEC_PARAMS_NEW)));
        return;
    }
 
@@ -4956,11 +4941,10 @@ write_nondefault_variables(GucContext context)
 
    if (FreeFile(fp))
    {
-       free(new_filename);
-       free(filename);
        ereport(elevel,
                (errcode_for_file_access(),
-                errmsg("could not write to file \"%s\": %m", CONFIG_EXEC_PARAMS)));
+                errmsg("could not write to file \"%s\": %m",
+                       CONFIG_EXEC_PARAMS_NEW)));
        return;
    }
 
@@ -4968,9 +4952,7 @@ write_nondefault_variables(GucContext context)
     * Put new file in place.  This could delay on Win32, but we don't
     * hold any exclusive locks.
     */
-   rename(new_filename, filename);
-   free(new_filename);
-   free(filename);
+   rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
 }
 
 
@@ -5014,29 +4996,23 @@ read_string_with_null(FILE *fp)
 void
 read_nondefault_variables(void)
 {
-   char       *filename;
    FILE       *fp;
    char       *varname,
               *varvalue;
    int         varsource;
 
-   Assert(DataDir);
-
    /*
     * Open file
     */
-   filename = guc_malloc(FATAL, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) + 2);
-   sprintf(filename, "%s/" CONFIG_EXEC_PARAMS, DataDir);
-
-   fp = AllocateFile(filename, "r");
+   fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
    if (!fp)
    {
-       free(filename);
        /* File not found is fine */
        if (errno != ENOENT)
            ereport(FATAL,
                    (errcode_for_file_access(),
-                    errmsg("could not read from file \"%s\": %m", CONFIG_EXEC_PARAMS)));
+                    errmsg("could not read from file \"%s\": %m",
+                           CONFIG_EXEC_PARAMS)));
        return;
    }
 
@@ -5061,10 +5037,9 @@ read_nondefault_variables(void)
    }
 
    FreeFile(fp);
-   free(filename);
-   return;
 }
-#endif
+
+#endif /* EXEC_BACKEND */
 
 
 /*
index 15c291b1ee6b979d484bdacfd7f36a937f32e0de..13a65c77849eca65d1005532826850468d5c09cb 100644 (file)
@@ -23,7 +23,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.34 2005/06/08 15:50:27 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.35 2005/07/04 04:51:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -50,9 +50,6 @@ extern int    optind;
 extern char *optarg;
 
 
-char       XLogDir[MAXPGPATH]; /* not static, see xlog_internal.h */
-static char ControlFilePath[MAXPGPATH];
-
 static ControlFileData ControlFile;        /* pg_control values */
 static uint32 newXlogId,
            newXlogSeg;         /* ID/Segment of new XLOG segment */
@@ -236,8 +233,13 @@ main(int argc, char *argv[])
 #endif
 
    DataDir = argv[optind];
-   snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir);
-   snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
+
+   if (chdir(DataDir) < 0)
+   {
+       fprintf(stderr, _("%s: could not change directory to \"%s\": %s\n"),
+               progname, DataDir, strerror(errno));
+       exit(1);
+   }
 
    /*
     * Check for a postmaster lock file --- if there is one, refuse to
@@ -348,7 +350,7 @@ ReadControlFile(void)
    char       *buffer;
    pg_crc32    crc;
 
-   if ((fd = open(ControlFilePath, O_RDONLY)) < 0)
+   if ((fd = open(XLOG_CONTROL_FILE, O_RDONLY)) < 0)
    {
        /*
         * If pg_control is not there at all, or we can't read it, the
@@ -356,12 +358,12 @@ ReadControlFile(void)
         * can do "touch pg_control" to force us to proceed.
         */
        fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
-               progname, ControlFilePath, strerror(errno));
+               progname, XLOG_CONTROL_FILE, strerror(errno));
        if (errno == ENOENT)
            fprintf(stderr, _("If you are sure the data directory path is correct, execute\n"
                              "  touch %s\n"
                              "and try again.\n"),
-                   ControlFilePath);
+                   XLOG_CONTROL_FILE);
        exit(1);
    }
 
@@ -372,7 +374,7 @@ ReadControlFile(void)
    if (len < 0)
    {
        fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
-               progname, ControlFilePath, strerror(errno));
+               progname, XLOG_CONTROL_FILE, strerror(errno));
        exit(1);
    }
    close(fd);
@@ -598,9 +600,11 @@ RewriteControlFile(void)
    memset(buffer, 0, BLCKSZ);
    memcpy(buffer, &ControlFile, sizeof(ControlFileData));
 
-   unlink(ControlFilePath);
+   unlink(XLOG_CONTROL_FILE);
 
-   fd = open(ControlFilePath, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, S_IRUSR | S_IWUSR);
+   fd = open(XLOG_CONTROL_FILE,
+             O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
+             S_IRUSR | S_IWUSR);
    if (fd < 0)
    {
        fprintf(stderr, _("%s: could not create pg_control file: %s\n"),
@@ -639,11 +643,11 @@ KillExistingXLOG(void)
    struct dirent *xlde;
    char        path[MAXPGPATH];
 
-   xldir = opendir(XLogDir);
+   xldir = opendir(XLOGDIR);
    if (xldir == NULL)
    {
        fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
-               progname, XLogDir, strerror(errno));
+               progname, XLOGDIR, strerror(errno));
        exit(1);
    }
 
@@ -653,7 +657,7 @@ KillExistingXLOG(void)
        if (strlen(xlde->d_name) == 24 &&
            strspn(xlde->d_name, "0123456789ABCDEF") == 24)
        {
-           snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name);
+           snprintf(path, MAXPGPATH, "%s/%s", XLOGDIR, xlde->d_name);
            if (unlink(path) < 0)
            {
                fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"),
@@ -676,7 +680,7 @@ KillExistingXLOG(void)
    if (errno)
    {
        fprintf(stderr, _("%s: could not read from directory \"%s\": %s\n"),
-               progname, XLogDir, strerror(errno));
+               progname, XLOGDIR, strerror(errno));
        exit(1);
    }
    closedir(xldir);
index 0db7019a1692577962d1ee8077320bb99a7248ba..602e2e3c1f24706126e1db52a3f2e38191869131 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.11 2004/12/31 22:03:21 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.12 2005/07/04 04:51:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -87,7 +87,7 @@ typedef struct SlruCtlData
     * Dir is set during SimpleLruInit and does not change thereafter.
     * Since it's always the same, it doesn't need to be in shared memory.
     */
-   char        Dir[MAXPGPATH];
+   char        Dir[64];
 } SlruCtlData;
 
 typedef SlruCtlData *SlruCtl;
index ead4619b027c995f2e3e2c97875f6cb2d305ac2c..8bbc6846de6471167e703468410d3d84b17b6f85 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.65 2005/06/08 15:50:28 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.66 2005/07/04 04:51:52 tgl Exp $
  */
 #ifndef XLOG_H
 #define XLOG_H
@@ -158,7 +158,6 @@ extern void xlog_desc(char *buf, uint8 xl_info, char *rec);
 extern void UpdateControlFile(void);
 extern int XLOGShmemSize(void);
 extern void XLOGShmemInit(void);
-extern void XLOGPathInit(void);
 extern void BootStrapXLOG(void);
 extern void StartupXLOG(void);
 extern void ShutdownXLOG(int code, Datum arg);
index 76e20b0355fe6986a128f292f09125854428e69d..4c65bdaec7e68d5c5213f886d05420f4624f2f00 100644 (file)
@@ -11,7 +11,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.8 2005/06/06 17:01:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.9 2005/07/04 04:51:52 tgl Exp $
  */
 #ifndef XLOG_INTERNAL_H
 #define XLOG_INTERNAL_H
@@ -185,6 +185,12 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
        ((xrecoff) % BLCKSZ >= SizeOfXLogShortPHD && \
        (BLCKSZ - (xrecoff) % BLCKSZ) >= SizeOfXLogRecord)
 
+/*
+ * The XLog directory and control file (relative to $PGDATA)
+ */
+#define XLOGDIR                "pg_xlog"
+#define XLOG_CONTROL_FILE  "global/pg_control"
+
 /*
  * These macros encapsulate knowledge about the exact layout of XLog file
  * names, timeline history file names, and archive-status file names.
@@ -195,24 +201,22 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
    snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
 
 #define XLogFilePath(path, tli, log, seg)  \
-   snprintf(path, MAXPGPATH, "%s/%08X%08X%08X", XLogDir, tli, log, seg)
+   snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, log, seg)
 
 #define TLHistoryFileName(fname, tli)  \
    snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
 
 #define TLHistoryFilePath(path, tli)   \
-   snprintf(path, MAXPGPATH, "%s/%08X.history", XLogDir, tli)
+   snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)
 
 #define StatusFilePath(path, xlog, suffix) \
-   snprintf(path, MAXPGPATH, "%s/archive_status/%s%s", XLogDir, xlog, suffix)
+   snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
 
 #define BackupHistoryFileName(fname, tli, log, seg, offset) \
    snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, log, seg, offset)
 
 #define BackupHistoryFilePath(path, tli, log, seg, offset) \
-   snprintf(path, MAXPGPATH, "%s/%08X%08X%08X.%08X.backup", XLogDir, tli, log, seg, offset)
-
-extern char XLogDir[MAXPGPATH];
+   snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, log, seg, offset)
 
 
 /*
index 8f6930cd1319ac1ccf24ed83dde8e4bd0d525be3..1ee085e51a00343ee55f4b28394dd2971ac98152 100644 (file)
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.176 2005/06/28 05:09:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.177 2005/07/04 04:51:52 tgl Exp $
  *
  * NOTES
  *   some of the information in this file should be moved to other files.
@@ -238,6 +238,7 @@ extern void InitializeSessionUserIdStandalone(void);
 extern void SetSessionAuthorization(Oid roleid, bool is_superuser);
 
 extern void SetDataDir(const char *dir);
+extern void ChangeToDataDir(void);
 extern char *make_absolute_path(const char *path);
 
 /* in utils/misc/superuser.c */
@@ -309,7 +310,7 @@ extern void SetReindexProcessing(Oid heapOid, Oid indexOid);
 extern void ResetReindexProcessing(void);
 extern bool ReindexIsProcessingHeap(Oid heapOid);
 extern bool ReindexIsProcessingIndex(Oid indexOid);
-extern void CreateDataDirLockFile(const char *datadir, bool amPostmaster);
+extern void CreateDataDirLockFile(bool amPostmaster);
 extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster);
 extern void TouchSocketLockFile(void);
 extern void RecordSharedMemoryInLockFile(unsigned long id1,