Commit eb5949d1 authored by Tom Lane's avatar Tom Lane

Arrange for the postmaster (and standalone backends, initdb, etc) to

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