* Copyright (c) 2002-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.18 2005/06/19 21:34:00 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.19 2005/07/04 04:51:43 tgl Exp $
*
*/
#include "utils/syscache.h"
-/* hack to make it compile under Win32 */
-extern DLLIMPORT char *DataDir;
-
Datum pg_tablespace_size(PG_FUNCTION_ARGS);
Datum pg_database_size(PG_FUNCTION_ARGS);
Datum pg_relation_size(PG_FUNCTION_ARGS);
/* Shared storage in pg_global is not counted */
/* Include pg_default storage */
- snprintf(pathname, MAXPGPATH, "%s/base/%u", DataDir, dbOid);
+ snprintf(pathname, MAXPGPATH, "base/%u", dbOid);
totalsize += db_dir_size(pathname);
/* Scan the non-default tablespaces */
- snprintf(pathname, MAXPGPATH, "%s/pg_tblspc", DataDir);
+ snprintf(pathname, MAXPGPATH, "pg_tblspc");
dirdesc = AllocateDir(pathname);
while ((direntry = ReadDir(dirdesc, pathname)) != NULL)
strcmp(direntry->d_name, "..") == 0)
continue;
- snprintf(pathname, MAXPGPATH, "%s/pg_tblspc/%s/%u",
- DataDir, direntry->d_name, dbOid);
+ snprintf(pathname, MAXPGPATH, "pg_tblspc/%s/%u",
+ direntry->d_name, dbOid);
totalsize += db_dir_size(pathname);
}
struct dirent *direntry;
if (tblspcOid == DEFAULTTABLESPACE_OID)
- snprintf(tblspcPath, MAXPGPATH, "%s/base", DataDir);
+ snprintf(tblspcPath, MAXPGPATH, "base");
else if (tblspcOid == GLOBALTABLESPACE_OID)
- snprintf(tblspcPath, MAXPGPATH, "%s/global", DataDir);
+ snprintf(tblspcPath, MAXPGPATH, "global");
else
- snprintf(tblspcPath, MAXPGPATH, "%s/pg_tblspc/%u", DataDir, tblspcOid);
+ snprintf(tblspcPath, MAXPGPATH, "pg_tblspc/%u", tblspcOid);
dirdesc = AllocateDir(tblspcPath);
tblspcOid = MyDatabaseTableSpace;
if (tblspcOid == DEFAULTTABLESPACE_OID)
- snprintf(dirpath, MAXPGPATH, "%s/base/%u", DataDir, MyDatabaseId);
+ snprintf(dirpath, MAXPGPATH, "base/%u", MyDatabaseId);
else if (tblspcOid == GLOBALTABLESPACE_OID)
- snprintf(dirpath, MAXPGPATH, "%s/global", DataDir);
+ snprintf(dirpath, MAXPGPATH, "global");
else
- snprintf(dirpath, MAXPGPATH, "%s/pg_tblspc/%u/%u",
- DataDir, tblspcOid, MyDatabaseId);
+ snprintf(dirpath, MAXPGPATH, "pg_tblspc/%u/%u",
+ tblspcOid, MyDatabaseId);
for (segcount = 0 ;; segcount++)
{
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.25 2005/06/19 21:34:01 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.26 2005/07/04 04:51:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
ctl->shared = shared;
ctl->do_fsync = true; /* default behavior */
- snprintf(ctl->Dir, MAXPGPATH, "%s/%s", DataDir, subdir);
+ StrNCpy(ctl->Dir, subdir, sizeof(ctl->Dir));
}
/*
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.7 2005/06/28 05:08:51 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.8 2005/07/04 04:51:44 tgl Exp $
*
* NOTES
* Each global transaction is associated with a global transaction
/************************************************************************/
#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:
{
TransactionId origNextXid = ShmemVariableCache->nextXid;
TransactionId result = origNextXid;
- char dir[MAXPGPATH];
DIR *cldir;
struct dirent *clde;
- snprintf(dir, MAXPGPATH, "%s/%s", DataDir, TWOPHASE_DIR);
-
- cldir = AllocateDir(dir);
- while ((clde = ReadDir(cldir, dir)) != NULL)
+ cldir = AllocateDir(TWOPHASE_DIR);
+ while ((clde = ReadDir(cldir, TWOPHASE_DIR)) != NULL)
{
if (strlen(clde->d_name) == 8 &&
strspn(clde->d_name, "0123456789ABCDEF") == 8)
DIR *cldir;
struct dirent *clde;
- snprintf(dir, MAXPGPATH, "%s/%s", DataDir, TWOPHASE_DIR);
+ snprintf(dir, MAXPGPATH, "%s", TWOPHASE_DIR);
cldir = AllocateDir(dir);
while ((clde = ReadDir(cldir, dir)) != NULL)
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.205 2005/06/30 00:00:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.206 2005/07/04 04:51:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#endif
+/* File path names (all relative to $PGDATA) */
+#define BACKUP_LABEL_FILE "backup_label"
+#define RECOVERY_COMMAND_FILE "recovery.conf"
+#define RECOVERY_COMMAND_DONE "recovery.done"
+
+
/* User-settable parameters */
int CheckPointSegments = 3;
int XLOGbuffers = 8;
#define NextBufIdx(idx) \
(((idx) == XLogCtl->XLogCacheBlck) ? 0 : ((idx) + 1))
-
-/* File path names */
-char XLogDir[MAXPGPATH];
-static char ControlFilePath[MAXPGPATH];
-
/*
* Private, possibly out-of-date copy of shared LogwrtResult.
* See discussion above.
*
* The name of the notification file is the message that will be picked up
* by the archiver, e.g. we write 0000000100000001000000C6.ready
- * and the archiver then knows to archive XLogDir/0000000100000001000000C6,
+ * and the archiver then knows to archive XLOGDIR/0000000100000001000000C6,
* then when complete, rename it to 0000000100000001000000C6.done
*/
static void
* up pre-creating an extra log segment. That seems OK, and better
* than holding the lock throughout this lengthy process.
*/
- snprintf(tmppath, MAXPGPATH, "%s/xlogtemp.%d", XLogDir, (int)getpid());
+ snprintf(tmppath, MAXPGPATH, XLOGDIR "/xlogtemp.%d", (int) getpid());
unlink(tmppath);
/*
* 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);
/*
* When doing archive recovery, we always prefer an archived log file
- * even if a file of the same name exists in XLogDir. The reason is
- * that the file in XLogDir could be an old, un-filled or
+ * even if a file of the same name exists in XLOGDIR. The reason is
+ * that the file in XLOGDIR could be an old, un-filled or
* partly-filled version that was copied and restored as part of
* backing up $PGDATA.
*
* robustness, so we elect not to do this.
*
* If we cannot obtain the log file from the archive, however, we will
- * try to use the XLogDir file if it exists. This is so that we can
+ * try to use the XLOGDIR file if it exists. This is so that we can
* make use of log segments that weren't yet transferred to the
* archive.
*
* Notice that we don't actually overwrite any files when we copy back
* from archive because the recoveryRestoreCommand may inadvertently
* restore inappropriate xlogs, or they may be corrupt, so we may wish
- * to fallback to the segments remaining in current XLogDir later. The
+ * to fallback to the segments remaining in current XLOGDIR later. The
* copy-from-archive filename is always the same, ensuring that we
* don't run out of disk space on long recoveries.
*/
- snprintf(xlogpath, MAXPGPATH, "%s/%s", XLogDir, recovername);
+ snprintf(xlogpath, MAXPGPATH, XLOGDIR "/%s", recovername);
/*
* Make sure there is no existing file named recovername.
xlogRestoreCmd)));
/*
- * Copy xlog from archival storage to XLogDir
+ * Copy xlog from archival storage to XLOGDIR
*/
rc = system(xlogRestoreCmd);
if (rc == 0)
/*
* if an archived file is not available, there might still be a
- * version of this file in XLogDir, so return that as the filename to
+ * version of this file in XLOGDIR, so return that as the filename to
* open.
*
* In many recovery scenarios we expect this to fail also, but if so that
* just means we've reached the end of WAL.
*/
- snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlogfname);
+ snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlogfname);
return false;
}
XLByteToPrevSeg(endptr, endlogId, endlogSeg);
max_advance = XLOGfileslop;
- xldir = AllocateDir(XLogDir);
+ xldir = AllocateDir(XLOGDIR);
if (xldir == NULL)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open transaction log directory \"%s\": %m",
- XLogDir)));
+ XLOGDIR)));
XLogFileName(lastoff, ThisTimeLineID, log, seg);
- while ((xlde = ReadDir(xldir, XLogDir)) != NULL)
+ while ((xlde = ReadDir(xldir, XLOGDIR)) != NULL)
{
/*
* We ignore the timeline part of the XLOG segment identifiers in
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
struct dirent *xlde;
char path[MAXPGPATH];
- xldir = AllocateDir(XLogDir);
+ xldir = AllocateDir(XLOGDIR);
if (xldir == NULL)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open transaction log directory \"%s\": %m",
- XLogDir)));
+ XLOGDIR)));
- while ((xlde = ReadDir(xldir, XLogDir)) != NULL)
+ while ((xlde = ReadDir(xldir, XLOGDIR)) != NULL)
{
if (strlen(xlde->d_name) > 24 &&
strspn(xlde->d_name, "0123456789ABCDEF") == 24 &&
ereport(DEBUG2,
(errmsg("removing transaction log backup history file \"%s\"",
xlde->d_name)));
- snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name);
+ snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name);
unlink(path);
XLogArchiveCleanup(xlde->d_name);
}
/*
* 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);
* ReadControlFile() verifies they are correct. We could split out the
* I/O and compatibility-check functions, but there seems no need currently.
*/
-
-void
-XLOGPathInit(void)
-{
- /* Init XLOG file paths */
- snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir);
- snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
-}
-
static void
WriteControlFile(void)
{
memset(buffer, 0, BLCKSZ);
memcpy(buffer, ControlFile, sizeof(ControlFileData));
- fd = BasicOpenFile(ControlFilePath, O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
+ fd = BasicOpenFile(XLOG_CONTROL_FILE,
+ O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
S_IRUSR | S_IWUSR);
if (fd < 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not create control file \"%s\": %m",
- ControlFilePath)));
+ XLOG_CONTROL_FILE)));
errno = 0;
if (write(fd, buffer, BLCKSZ) != BLCKSZ)
/*
* Read data...
*/
- fd = BasicOpenFile(ControlFilePath, O_RDWR | PG_BINARY, S_IRUSR | S_IWUSR);
+ fd = BasicOpenFile(XLOG_CONTROL_FILE,
+ O_RDWR | PG_BINARY,
+ S_IRUSR | S_IWUSR);
if (fd < 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not open control file \"%s\": %m",
- ControlFilePath)));
+ XLOG_CONTROL_FILE)));
if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
ereport(PANIC,
offsetof(ControlFileData, crc));
FIN_CRC32(ControlFile->crc);
- fd = BasicOpenFile(ControlFilePath, O_RDWR | PG_BINARY, S_IRUSR | S_IWUSR);
+ fd = BasicOpenFile(XLOG_CONTROL_FILE,
+ O_RDWR | PG_BINARY,
+ S_IRUSR | S_IWUSR);
if (fd < 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not open control file \"%s\": %m",
- ControlFilePath)));
+ XLOG_CONTROL_FILE)));
errno = 0;
if (write(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
static void
readRecoveryCommandFile(void)
{
- char recoveryCommandFile[MAXPGPATH];
FILE *fd;
char cmdline[MAXPGPATH];
TimeLineID rtli = 0;
bool rtliGiven = false;
bool syntaxError = false;
- snprintf(recoveryCommandFile, MAXPGPATH, "%s/recovery.conf", DataDir);
- fd = AllocateFile(recoveryCommandFile, "r");
+ fd = AllocateFile(RECOVERY_COMMAND_FILE, "r");
if (fd == NULL)
{
if (errno == ENOENT)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not open recovery command file \"%s\": %m",
- recoveryCommandFile)));
+ RECOVERY_COMMAND_FILE)));
}
ereport(LOG,
if (recoveryRestoreCommand == NULL)
ereport(FATAL,
(errmsg("recovery command file \"%s\" did not specify restore_command",
- recoveryCommandFile)));
+ RECOVERY_COMMAND_FILE)));
/* Enable fetching from archive recovery area */
InArchiveRecovery = true;
{
char recoveryPath[MAXPGPATH];
char xlogpath[MAXPGPATH];
- char recoveryCommandFile[MAXPGPATH];
- char recoveryCommandDone[MAXPGPATH];
/*
* We are no longer in archive recovery state.
/*
* If the segment was fetched from archival storage, we want to
* replace the existing xlog segment (if any) with the archival
- * version. This is because whatever is in XLogDir is very possibly
+ * version. This is because whatever is in XLOGDIR is very possibly
* older than what we have from the archives, since it could have come
* from restoring a PGDATA backup. In any case, the archival version
* certainly is more descriptive of what our current database state
* already set to the new value, and so we will create a new file
* instead of overwriting any existing file.
*/
- snprintf(recoveryPath, MAXPGPATH, "%s/RECOVERYXLOG", XLogDir);
+ snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYXLOG");
XLogFilePath(xlogpath, ThisTimeLineID, endLogId, endLogSeg);
if (restoredFromArchive)
XLogArchiveCleanup(xlogpath);
/* Get rid of any remaining recovered timeline-history file, too */
- snprintf(recoveryPath, MAXPGPATH, "%s/RECOVERYHISTORY", XLogDir);
+ snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYHISTORY");
unlink(recoveryPath); /* ignore any error */
/*
* Rename the config file out of the way, so that we don't
* accidentally re-enter archive recovery mode in a subsequent crash.
*/
- snprintf(recoveryCommandFile, MAXPGPATH, "%s/recovery.conf", DataDir);
- snprintf(recoveryCommandDone, MAXPGPATH, "%s/recovery.done", DataDir);
- unlink(recoveryCommandDone);
- if (rename(recoveryCommandFile, recoveryCommandDone) != 0)
+ unlink(RECOVERY_COMMAND_DONE);
+ if (rename(RECOVERY_COMMAND_FILE, RECOVERY_COMMAND_DONE) != 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not rename file \"%s\" to \"%s\": %m",
- recoveryCommandFile, recoveryCommandDone)));
+ RECOVERY_COMMAND_FILE, RECOVERY_COMMAND_DONE)));
ereport(LOG,
(errmsg("archive recovery complete")));
XLogRecPtr startpoint;
time_t stamp_time;
char strfbuf[128];
- char labelfilepath[MAXPGPATH];
char xlogfilename[MAXFNAMELEN];
uint32 _logId;
uint32 _logSeg;
* Check for existing backup label --- implies a backup is already
* running
*/
- snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir);
- if (stat(labelfilepath, &stat_buf) != 0)
+ if (stat(BACKUP_LABEL_FILE, &stat_buf) != 0)
{
if (errno != ENOENT)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not stat file \"%s\": %m",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
}
else
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("a backup is already in progress"),
errhint("If you're sure there is no backup in progress, remove file \"%s\" and try again.",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
/*
* Okay, write the file
*/
- fp = AllocateFile(labelfilepath, "w");
+ fp = AllocateFile(BACKUP_LABEL_FILE, "w");
if (!fp)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not create file \"%s\": %m",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
fprintf(fp, "START WAL LOCATION: %X/%X (file %s)\n",
startpoint.xlogid, startpoint.xrecoff, xlogfilename);
fprintf(fp, "CHECKPOINT LOCATION: %X/%X\n",
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write file \"%s\": %m",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
/*
* We're done. As a convenience, return the starting WAL offset.
XLogRecPtr stoppoint;
time_t stamp_time;
char strfbuf[128];
- char labelfilepath[MAXPGPATH];
char histfilepath[MAXPGPATH];
char startxlogfilename[MAXFNAMELEN];
char stopxlogfilename[MAXFNAMELEN];
/*
* Open the existing label file
*/
- snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir);
- lfp = AllocateFile(labelfilepath, "r");
+ lfp = AllocateFile(BACKUP_LABEL_FILE, "r");
if (!lfp)
{
if (errno != ENOENT)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("a backup is not in progress")));
&ch) != 4 || ch != '\n')
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
- errmsg("invalid data in file \"%s\"", labelfilepath)));
+ errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
/*
* Write the backup history file
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m",
- labelfilepath)));
- if (unlink(labelfilepath) != 0)
+ BACKUP_LABEL_FILE)));
+ if (unlink(BACKUP_LABEL_FILE) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not remove file \"%s\": %m",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
RemoveOldBackupHistory();
{
XLogRecPtr startpoint;
XLogRecPtr stoppoint;
- char labelfilepath[MAXPGPATH];
char histfilename[MAXFNAMELEN];
char histfilepath[MAXPGPATH];
char startxlogfilename[MAXFNAMELEN];
/*
* See if label file is present
*/
- snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir);
- lfp = AllocateFile(labelfilepath, "r");
+ lfp = AllocateFile(BACKUP_LABEL_FILE, "r");
if (!lfp)
{
if (errno != ENOENT)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
return false; /* it's not there, all is fine */
}
startxlogfilename, &ch) != 5 || ch != '\n')
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
- errmsg("invalid data in file \"%s\"", labelfilepath)));
+ errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
if (fscanf(lfp, "CHECKPOINT LOCATION: %X/%X%c",
&checkPointLoc->xlogid, &checkPointLoc->xrecoff,
&ch) != 3 || ch != '\n')
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
- errmsg("invalid data in file \"%s\"", labelfilepath)));
+ errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
if (ferror(lfp) || FreeFile(lfp))
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
/*
* Try to retrieve the backup history file (no error if we can't)
static void
remove_backup_label(void)
{
- char labelfilepath[MAXPGPATH];
-
- snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir);
- if (unlink(labelfilepath) != 0)
+ if (unlink(BACKUP_LABEL_FILE) != 0)
if (errno != ENOENT)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not remove file \"%s\": %m",
- labelfilepath)));
+ BACKUP_LABEL_FILE)));
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.204 2005/05/06 17:24:52 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.205 2005/07/04 04:51:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Assert(DataDir);
ValidatePgVersion(DataDir);
+ /* Change into DataDir (if under postmaster, should be done already) */
+ if (!IsUnderPostmaster)
+ ChangeToDataDir();
+
/* If standalone, create lockfile for data directory */
if (!IsUnderPostmaster)
- CreateDataDirLockFile(DataDir, false);
+ CreateDataDirLockFile(false);
SetProcessingMode(BootstrapProcessing);
IgnoreSystemIndexes(true);
- XLOGPathInit();
-
BaseInit();
/* needed to get LWLocks */
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
{
/* Shared system relations live in {datadir}/global */
Assert(rnode.dbNode == 0);
- pathlen = strlen(DataDir) + 8 + OIDCHARS + 1;
+ pathlen = 7 + OIDCHARS + 1;
path = (char *) palloc(pathlen);
- snprintf(path, pathlen, "%s/global/%u",
- DataDir, rnode.relNode);
+ snprintf(path, pathlen, "global/%u",
+ rnode.relNode);
}
else if (rnode.spcNode == DEFAULTTABLESPACE_OID)
{
/* The default tablespace is {datadir}/base */
- pathlen = strlen(DataDir) + 6 + OIDCHARS + 1 + OIDCHARS + 1;
+ pathlen = 5 + OIDCHARS + 1 + OIDCHARS + 1;
path = (char *) palloc(pathlen);
- snprintf(path, pathlen, "%s/base/%u/%u",
- DataDir, rnode.dbNode, rnode.relNode);
+ snprintf(path, pathlen, "base/%u/%u",
+ rnode.dbNode, rnode.relNode);
}
else
{
/* All other tablespaces are accessed via symlinks */
- pathlen = strlen(DataDir) + 11 + OIDCHARS + 1 + OIDCHARS + 1 + OIDCHARS + 1;
+ pathlen = 10 + OIDCHARS + 1 + OIDCHARS + 1 + OIDCHARS + 1;
path = (char *) palloc(pathlen);
- snprintf(path, pathlen, "%s/pg_tblspc/%u/%u/%u",
- DataDir, rnode.spcNode, rnode.dbNode, rnode.relNode);
+ snprintf(path, pathlen, "pg_tblspc/%u/%u/%u",
+ rnode.spcNode, rnode.dbNode, rnode.relNode);
}
return path;
}
{
/* Shared system relations live in {datadir}/global */
Assert(dbNode == 0);
- pathlen = strlen(DataDir) + 7 + 1;
+ pathlen = 6 + 1;
path = (char *) palloc(pathlen);
- snprintf(path, pathlen, "%s/global",
- DataDir);
+ snprintf(path, pathlen, "global");
}
else if (spcNode == DEFAULTTABLESPACE_OID)
{
/* The default tablespace is {datadir}/base */
- pathlen = strlen(DataDir) + 6 + OIDCHARS + 1;
+ pathlen = 5 + OIDCHARS + 1;
path = (char *) palloc(pathlen);
- snprintf(path, pathlen, "%s/base/%u",
- DataDir, dbNode);
+ snprintf(path, pathlen, "base/%u",
+ dbNode);
}
else
{
/* All other tablespaces are accessed via symlinks */
- pathlen = strlen(DataDir) + 11 + OIDCHARS + 1 + OIDCHARS + 1;
+ pathlen = 10 + OIDCHARS + 1 + OIDCHARS + 1;
path = (char *) palloc(pathlen);
- snprintf(path, pathlen, "%s/pg_tblspc/%u/%u",
- DataDir, spcNode, dbNode);
+ snprintf(path, pathlen, "pg_tblspc/%u/%u",
+ spcNode, dbNode);
}
return path;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/*
* All seems well, create the symlink
*/
- linkloc = (char *) palloc(strlen(DataDir) + 11 + 10 + 1);
- sprintf(linkloc, "%s/pg_tblspc/%u", DataDir, tablespaceoid);
+ linkloc = (char *) palloc(10 + 10 + 1);
+ sprintf(linkloc, "pg_tblspc/%u", tablespaceoid);
if (symlink(location, linkloc) < 0)
ereport(ERROR,
char *subfile;
struct stat st;
- location = (char *) palloc(strlen(DataDir) + 11 + 10 + 1);
- sprintf(location, "%s/pg_tblspc/%u", DataDir, tablespaceoid);
+ location = (char *) palloc(10 + 10 + 1);
+ sprintf(location, "pg_tblspc/%u", tablespaceoid);
/*
* Check if the tablespace still contains any files. We try to rmdir
set_short_version(location);
/* Create the symlink if not already present */
- linkloc = (char *) palloc(strlen(DataDir) + 11 + 10 + 1);
- sprintf(linkloc, "%s/pg_tblspc/%u", DataDir, xlrec->ts_id);
+ linkloc = (char *) palloc(10 + 10 + 1);
+ sprintf(linkloc, "pg_tblspc/%u", xlrec->ts_id);
if (symlink(location, linkloc) < 0)
{
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.57 2005/06/02 21:03:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.58 2005/07/04 04:51:46 tgl Exp $
*
* Since the server static private key ($DataDir/server.key)
* will normally be stored unencrypted so that the database
#ifdef USE_SSL
+
+#define ROOT_CERT_FILE "root.crt"
+#define SERVER_CERT_FILE "server.crt"
+#define SERVER_PRIVATE_KEY_FILE "server.key"
+
static DH *load_dh_file(int keylength);
static DH *load_dh_buffer(const char *, size_t);
static DH *tmp_dh_cb(SSL *s, int is_export, int keylength);
int codes;
/* attempt to open file. It's not an error if it doesn't exist. */
- snprintf(fnbuf, sizeof(fnbuf), "%s/dh%d.pem", DataDir, keylength);
+ snprintf(fnbuf, sizeof(fnbuf), "dh%d.pem", keylength);
if ((fp = fopen(fnbuf, "r")) == NULL)
return NULL;
static int
initialize_SSL(void)
{
- char fnbuf[MAXPGPATH];
struct stat buf;
if (!SSL_context)
/*
* Load and verify certificate and private key
*/
- snprintf(fnbuf, sizeof(fnbuf), "%s/server.crt", DataDir);
- if (!SSL_CTX_use_certificate_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
+ if (!SSL_CTX_use_certificate_file(SSL_context,
+ SERVER_CERT_FILE,
+ SSL_FILETYPE_PEM))
ereport(FATAL,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("could not load server certificate file \"%s\": %s",
- fnbuf, SSLerrmessage())));
+ SERVER_CERT_FILE, SSLerrmessage())));
- snprintf(fnbuf, sizeof(fnbuf), "%s/server.key", DataDir);
- if (stat(fnbuf, &buf) == -1)
+ if (stat(SERVER_PRIVATE_KEY_FILE, &buf) == -1)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not access private key file \"%s\": %m",
- fnbuf)));
+ SERVER_PRIVATE_KEY_FILE)));
/*
* Require no public access to key file.
ereport(FATAL,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("unsafe permissions on private key file \"%s\"",
- fnbuf),
+ SERVER_PRIVATE_KEY_FILE),
errdetail("File must be owned by the database user and must have no permissions for \"group\" or \"other\".")));
#endif
- if (!SSL_CTX_use_PrivateKey_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
+ if (!SSL_CTX_use_PrivateKey_file(SSL_context,
+ SERVER_PRIVATE_KEY_FILE,
+ SSL_FILETYPE_PEM))
ereport(FATAL,
(errmsg("could not load private key file \"%s\": %s",
- fnbuf, SSLerrmessage())));
+ SERVER_PRIVATE_KEY_FILE, SSLerrmessage())));
if (!SSL_CTX_check_private_key(SSL_context))
ereport(FATAL,
/*
* Require and check client certificates only if we have a root.crt file.
*/
- snprintf(fnbuf, sizeof(fnbuf), "%s/root.crt", DataDir);
- if (!SSL_CTX_load_verify_locations(SSL_context, fnbuf, NULL))
+ if (!SSL_CTX_load_verify_locations(SSL_context, ROOT_CERT_FILE, NULL))
{
/* Not fatal - we do not require client certificates */
ereport(LOG,
(errmsg("could not load root certificate file \"%s\": %s",
- fnbuf, SSLerrmessage()),
+ ROOT_CERT_FILE, SSLerrmessage()),
errdetail("Will not verify client certificates.")));
}
else
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
init_ps_display("archiver process", "", "");
set_ps_display("");
- /* Init XLOG file paths --- needed in EXEC_BACKEND case */
- XLOGPathInit();
-
pgarch_MainLoop();
exit(0);
const char *sp;
int rc;
- snprintf(pathname, MAXPGPATH, "%s/%s", XLogDir, xlog);
+ snprintf(pathname, MAXPGPATH, XLOGDIR "/%s", xlog);
/*
* construct the command to be executed
struct dirent *rlde;
bool found = false;
- snprintf(XLogArchiveStatusDir, MAXPGPATH, "%s/archive_status", XLogDir);
+ snprintf(XLogArchiveStatusDir, MAXPGPATH, XLOGDIR "/archive_status");
rldir = AllocateDir(XLogArchiveStatusDir);
if (rldir == NULL)
ereport(ERROR,
*
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.98 2005/06/29 22:51:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.99 2005/07/04 04:51:47 tgl Exp $
* ----------
*/
#include "postgres.h"
/* ----------
- * Paths for the statistics files. The %s is replaced with the
- * installation's $PGDATA.
+ * Paths for the statistics files (relative to installation's $PGDATA).
* ----------
*/
-#define PGSTAT_STAT_FILENAME "%s/global/pgstat.stat"
-#define PGSTAT_STAT_TMPFILE "%s/global/pgstat.tmp.%d"
+#define PGSTAT_STAT_FILENAME "global/pgstat.stat"
+#define PGSTAT_STAT_TMPFILE "global/pgstat.tmp"
/* ----------
* Timer definitions.
static PgStat_StatBeEntry *pgStatBeTable = NULL;
static int pgStatNumBackends = 0;
-static char pgStat_fname[MAXPGPATH];
-static char pgStat_tmpfname[MAXPGPATH];
-
/* ----------
* Local function forward declarations
pgstat_collect_blocklevel)
pgstat_collect_startcollector = true;
- /*
- * Initialize the filename for the status reports. (In the
- * EXEC_BACKEND case, this only sets the value in the postmaster. The
- * collector subprocess will recompute the value for itself, and
- * individual backends must do so also if they want to access the
- * file.)
- */
- snprintf(pgStat_fname, MAXPGPATH, PGSTAT_STAT_FILENAME, DataDir);
-
/*
* If we don't have to start a collector or should reset the collected
- * statistics on postmaster start, simply remove the file.
+ * statistics on postmaster start, simply remove the stats file.
*/
if (!pgstat_collect_startcollector || pgstat_collect_resetonpmstart)
- unlink(pgStat_fname);
+ unlink(PGSTAT_STAT_FILENAME);
/*
* Nothing else required if collector will not get started
init_ps_display("stats collector process", "", "");
set_ps_display("");
- /*
- * Initialize filenames needed for status reports.
- */
- snprintf(pgStat_fname, MAXPGPATH, PGSTAT_STAT_FILENAME, DataDir);
- /* tmpfname need only be set correctly in this process */
- snprintf(pgStat_tmpfname, MAXPGPATH, PGSTAT_STAT_TMPFILE,
- DataDir, (int)getpid());
-
/*
* Arrange to write the initial status file right away
*/
/*
* Open the statistics temp file to write out the current values.
*/
- fpout = fopen(pgStat_tmpfname, PG_BINARY_W);
+ fpout = fopen(PGSTAT_STAT_TMPFILE, PG_BINARY_W);
if (fpout == NULL)
{
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not open temporary statistics file \"%s\": %m",
- pgStat_tmpfname)));
+ PGSTAT_STAT_TMPFILE)));
return;
}
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not close temporary statistics file \"%s\": %m",
- pgStat_tmpfname)));
+ PGSTAT_STAT_TMPFILE)));
}
else
{
- if (rename(pgStat_tmpfname, pgStat_fname) < 0)
+ if (rename(PGSTAT_STAT_TMPFILE, PGSTAT_STAT_FILENAME) < 0)
{
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not rename temporary statistics file \"%s\" to \"%s\": %m",
- pgStat_tmpfname, pgStat_fname)));
+ PGSTAT_STAT_TMPFILE, PGSTAT_STAT_FILENAME)));
}
}
if (betab != NULL)
*betab = NULL;
- /*
- * In EXEC_BACKEND case, we won't have inherited pgStat_fname from
- * postmaster, so compute it first time through.
- */
-#ifdef EXEC_BACKEND
- if (pgStat_fname[0] == '\0')
- {
- Assert(DataDir != NULL);
- snprintf(pgStat_fname, MAXPGPATH, PGSTAT_STAT_FILENAME, DataDir);
- }
-#endif
-
/*
* Try to open the status file. If it doesn't exist, the backends
* simply return zero for anything and the collector simply starts
* from scratch with empty counters.
*/
- if ((fpin = AllocateFile(pgStat_fname, PG_BINARY_R)) == NULL)
+ if ((fpin = AllocateFile(PGSTAT_STAT_FILENAME, PG_BINARY_R)) == NULL)
return;
/*
*
*
* 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
*
ExitPostmaster(1);
}
+#ifdef EXEC_BACKEND
+ /* Locate executable backend before we change working directory */
+ if (find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
+ postgres_exec_path) < 0)
+ ereport(FATAL,
+ (errmsg("%s: could not locate matching postgres executable",
+ progname)));
+#endif
+
/*
* Locate the proper configuration files and data directory, and
* read postgresql.conf for the first time.
/* Verify that DataDir looks reasonable */
checkDataDir();
+ /* And switch working directory into it */
+ ChangeToDataDir();
+
/*
* Check for invalid combinations of GUC settings.
*/
(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.
*/
* :-(). For the same reason, it's best to grab the TCP socket(s)
* before the Unix socket.
*/
- CreateDataDirLockFile(DataDir, true);
+ CreateDataDirLockFile(true);
/*
* Remove old temporary files. At this point there can be no other
ereport(FATAL,
(errmsg("no socket created for listening")));
- XLOGPathInit();
-
/*
* Set up shared memory and semaphores.
*/
return -1; /* log made by save_backend_variables */
/* Calculate name for temp file */
- Assert(DataDir);
- snprintf(tmpfilename, MAXPGPATH, "%s/%s/%s.backend_var.%d.%lu",
- DataDir, PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
+ snprintf(tmpfilename, MAXPGPATH, "%s/%s.backend_var.%d.%lu",
+ PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
MyProcPid, ++tmpBackendFileNum);
/* Open file */
fp = AllocateFile(tmpfilename, PG_BINARY_W);
if (!fp)
{
- /* As per OpenTemporaryFile... */
- char dirname[MAXPGPATH];
-
- snprintf(dirname, MAXPGPATH, "%s/%s", DataDir, PG_TEMP_FILES_DIR);
- mkdir(dirname, S_IRWXU);
+ /* As in OpenTemporaryFile, try to make the temp-file directory */
+ mkdir(PG_TEMP_FILES_DIR, S_IRWXU);
fp = AllocateFile(tmpfilename, PG_BINARY_W);
if (!fp)
static bool
CreateOptsFile(int argc, char *argv[], char *fullprogname)
{
- char filename[MAXPGPATH];
FILE *fp;
int i;
- snprintf(filename, sizeof(filename), "%s/postmaster.opts", DataDir);
+#define OPTS_FILE "postmaster.opts"
- if ((fp = fopen(filename, "w")) == NULL)
+ if ((fp = fopen(OPTS_FILE, "w")) == NULL)
{
- elog(LOG, "could not create file \"%s\": %m", filename);
+ elog(LOG, "could not create file \"%s\": %m", OPTS_FILE);
return false;
}
if (fclose(fp))
{
- elog(LOG, "could not write file \"%s\": %m", filename);
+ elog(LOG, "could not write file \"%s\": %m", OPTS_FILE);
return false;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#endif
/*
- * create log directory if not present; ignore errors
+ * Create log directory if not present; ignore errors
*/
- if (is_absolute_path(Log_directory))
- mkdir(Log_directory, 0700);
- else
- {
- filename = palloc(MAXPGPATH);
- snprintf(filename, MAXPGPATH, "%s/%s", DataDir, Log_directory);
- mkdir(filename, 0700);
- pfree(filename);
- }
+ mkdir(Log_directory, 0700);
/*
* The initial logfile is created right in the postmaster, to verify
filename = palloc(MAXPGPATH);
- if (is_absolute_path(Log_directory))
- snprintf(filename, MAXPGPATH, "%s/", Log_directory);
- else
- snprintf(filename, MAXPGPATH, "%s/%s/", DataDir, Log_directory);
+ snprintf(filename, MAXPGPATH, "%s/", Log_directory);
len = strlen(filename);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.117 2005/06/19 21:34:02 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.118 2005/07/04 04:51:48 tgl Exp $
*
* NOTES:
*
static void FreeVfd(File file);
static int FileAccess(File file);
-static File fileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
-static char *filepath(const char *filename);
+static char *make_database_relative(const char *filename);
static void AtProcExit_Files(int code, Datum arg);
static void CleanupTempFiles(bool isProcExit);
static void RemovePgTempFilesInDir(const char *tmpdirname);
VfdCache[0].nextFree = file;
}
-/* filepath()
- * Convert given pathname to absolute.
+/*
+ * make_database_relative()
+ * Prepend DatabasePath to the given file name.
*
* Result is a palloc'd string.
- *
- * (Generally, this isn't actually necessary, considering that we
- * should be cd'd into the database directory. Presently it is only
- * necessary to do it in "bootstrap" mode. Maybe we should change
- * bootstrap mode to do the cd, and save a few cycles/bytes here.)
*/
static char *
-filepath(const char *filename)
+make_database_relative(const char *filename)
{
char *buf;
- /* Not an absolute path name? Then fill in with database path... */
- if (!is_absolute_path(filename))
- {
- buf = (char *) palloc(strlen(DatabasePath) + strlen(filename) + 2);
- sprintf(buf, "%s/%s", DatabasePath, filename);
- }
- else
- buf = pstrdup(filename);
-
-#ifdef FILEDEBUG
- printf("filepath: path is %s\n", buf);
-#endif
-
+ Assert(!is_absolute_path(filename));
+ buf = (char *) palloc(strlen(DatabasePath) + strlen(filename) + 2);
+ sprintf(buf, "%s/%s", DatabasePath, filename);
return buf;
}
}
#endif
-static File
-fileNameOpenFile(FileName fileName,
- int fileFlags,
- int fileMode)
+/*
+ * open a file in an arbitrary directory
+ *
+ * NB: if the passed pathname is relative (which it usually is),
+ * it will be interpreted relative to the process' working directory
+ * (which should always be $PGDATA when this code is running).
+ */
+File
+PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
{
char *fnamecopy;
File file;
Vfd *vfdP;
- DO_DB(elog(LOG, "fileNameOpenFile: %s %x %o",
+ DO_DB(elog(LOG, "PathNameOpenFile: %s %x %o",
fileName, fileFlags, fileMode));
/*
return -1;
}
++nfile;
- DO_DB(elog(LOG, "fileNameOpenFile: success %d",
+ DO_DB(elog(LOG, "PathNameOpenFile: success %d",
vfdP->fd));
Insert(file);
}
/*
- * open a file in the database directory ($PGDATA/base/...)
+ * open a file in the database directory ($PGDATA/base/DIROID/)
+ *
+ * The passed name MUST be a relative path. Effectively, this
+ * prepends DatabasePath to it and then acts like PathNameOpenFile.
*/
File
FileNameOpenFile(FileName fileName, int fileFlags, int fileMode)
File fd;
char *fname;
- fname = filepath(fileName);
- fd = fileNameOpenFile(fname, fileFlags, fileMode);
+ fname = make_database_relative(fileName);
+ fd = PathNameOpenFile(fname, fileFlags, fileMode);
pfree(fname);
return fd;
}
-/*
- * open a file in an arbitrary directory
- */
-File
-PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
-{
- return fileNameOpenFile(fileName, fileFlags, fileMode);
-}
-
/*
* Open a temporary file that will disappear when we close it.
*
* just did the same thing. If it doesn't work then we'll bomb
* out on the second create attempt, instead.
*/
- dirpath = filepath(PG_TEMP_FILES_DIR);
+ dirpath = make_database_relative(PG_TEMP_FILES_DIR);
mkdir(dirpath, S_IRWXU);
pfree(dirpath);
void
RemovePgTempFiles(void)
{
- char db_path[MAXPGPATH];
char temp_path[MAXPGPATH];
DIR *db_dir;
struct dirent *db_de;
* Cycle through pgsql_tmp directories for all databases and remove old
* temp files.
*/
- snprintf(db_path, sizeof(db_path), "%s/base", DataDir);
- db_dir = AllocateDir(db_path);
+ db_dir = AllocateDir("base");
- while ((db_de = ReadDir(db_dir, db_path)) != NULL)
+ while ((db_de = ReadDir(db_dir, "base")) != NULL)
{
if (strcmp(db_de->d_name, ".") == 0 ||
strcmp(db_de->d_name, "..") == 0)
continue;
- snprintf(temp_path, sizeof(temp_path), "%s/%s/%s",
- db_path, db_de->d_name, PG_TEMP_FILES_DIR);
+ snprintf(temp_path, sizeof(temp_path), "base/%s/%s",
+ db_de->d_name, PG_TEMP_FILES_DIR);
RemovePgTempFilesInDir(temp_path);
}
* level of DataDir as well.
*/
#ifdef EXEC_BACKEND
- snprintf(temp_path, sizeof(temp_path), "%s/%s",
- DataDir, PG_TEMP_FILES_DIR);
- RemovePgTempFilesInDir(temp_path);
+ RemovePgTempFilesInDir(PG_TEMP_FILES_DIR);
#endif
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.45 2005/05/29 04:23:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.46 2005/07/04 04:51:48 tgl Exp $
*
*
* NOTES:
DumpFreeSpaceMap(int code, Datum arg)
{
FILE *fp;
- char cachefilename[MAXPGPATH];
FsmCacheFileHeader header;
FSMRelation *fsmrel;
/* Try to create file */
- snprintf(cachefilename, sizeof(cachefilename), "%s/%s",
- DataDir, FSM_CACHE_FILENAME);
+ unlink(FSM_CACHE_FILENAME); /* in case it exists w/wrong permissions */
- unlink(cachefilename); /* in case it exists w/wrong permissions */
-
- fp = AllocateFile(cachefilename, PG_BINARY_W);
+ fp = AllocateFile(FSM_CACHE_FILENAME, PG_BINARY_W);
if (fp == NULL)
{
- elog(LOG, "could not write \"%s\": %m", cachefilename);
+ elog(LOG, "could not write \"%s\": %m", FSM_CACHE_FILENAME);
return;
}
if (FreeFile(fp))
{
- elog(LOG, "could not write \"%s\": %m", cachefilename);
+ elog(LOG, "could not write \"%s\": %m", FSM_CACHE_FILENAME);
/* Remove busted cache file */
- unlink(cachefilename);
+ unlink(FSM_CACHE_FILENAME);
}
return;
write_failed:
- elog(LOG, "could not write \"%s\": %m", cachefilename);
+ elog(LOG, "could not write \"%s\": %m", FSM_CACHE_FILENAME);
/* Clean up */
LWLockRelease(FreeSpaceLock);
FreeFile(fp);
/* Remove busted cache file */
- unlink(cachefilename);
+ unlink(FSM_CACHE_FILENAME);
}
/*
LoadFreeSpaceMap(void)
{
FILE *fp;
- char cachefilename[MAXPGPATH];
FsmCacheFileHeader header;
int relno;
/* Try to open file */
- snprintf(cachefilename, sizeof(cachefilename), "%s/%s",
- DataDir, FSM_CACHE_FILENAME);
-
- fp = AllocateFile(cachefilename, PG_BINARY_R);
+ fp = AllocateFile(FSM_CACHE_FILENAME, PG_BINARY_R);
if (fp == NULL)
{
if (errno != ENOENT)
- elog(LOG, "could not read \"%s\": %m", cachefilename);
+ elog(LOG, "could not read \"%s\": %m", FSM_CACHE_FILENAME);
return;
}
header.version != FSM_CACHE_VERSION ||
header.numRels < 0)
{
- elog(LOG, "bogus file header in \"%s\"", cachefilename);
+ elog(LOG, "bogus file header in \"%s\"", FSM_CACHE_FILENAME);
goto read_failed;
}
relheader.lastPageCount < 0 ||
relheader.storedPages < 0)
{
- elog(LOG, "bogus rel header in \"%s\"", cachefilename);
+ elog(LOG, "bogus rel header in \"%s\"", FSM_CACHE_FILENAME);
goto read_failed;
}
data = (char *) palloc(len);
if (fread(data, 1, len, fp) != len)
{
- elog(LOG, "premature EOF in \"%s\"", cachefilename);
+ elog(LOG, "premature EOF in \"%s\"", FSM_CACHE_FILENAME);
pfree(data);
goto read_failed;
}
FreeFile(fp);
/* Remove cache file before it can become stale; see notes above */
- unlink(cachefilename);
+ unlink(FSM_CACHE_FILENAME);
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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)
{
* mdopen)
*/
if (isRedo || IsBootstrapProcessingMode())
- fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
+ fd = PathNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
if (fd < 0)
{
pfree(path);
path = relpath(reln->smgr_rnode);
- fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
+ fd = PathNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
if (fd < 0)
{
* (See mdcreate)
*/
if (IsBootstrapProcessingMode())
- fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
+ fd = PathNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
if (fd < 0)
{
pfree(path);
fullpath = path;
/* open the file */
- fd = FileNameOpenFile(fullpath, O_RDWR | PG_BINARY | oflags, 0600);
+ fd = PathNameOpenFile(fullpath, O_RDWR | PG_BINARY | oflags, 0600);
pfree(fullpath);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.451 2005/06/29 22:51:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.452 2005/07/04 04:51:49 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
errhint("Try \"%s --help\" for more information.", argv[0])));
}
- XLOGPathInit();
-
BaseInit();
}
else
Assert(DataDir);
ValidatePgVersion(DataDir);
+ /* Change into DataDir (if under postmaster, was done already) */
+ ChangeToDataDir();
+
/*
* Create lockfile for data directory.
*/
- CreateDataDirLockFile(DataDir, false);
+ CreateDataDirLockFile(false);
- XLOGPathInit();
BaseInit();
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
fctx = palloc(sizeof(ts_db_fctx));
/*
- * size = path length + tablespace dirname length + 2 dir sep
- * chars + oid + terminator
+ * size = tablespace dirname length + dir sep
+ * char + oid + terminator
*/
- fctx->location = (char *) palloc(strlen(DataDir) + 11 + 10 + 1);
+ fctx->location = (char *) palloc(10 + 10 + 1);
if (tablespaceOid == GLOBALTABLESPACE_OID)
{
fctx->dirdesc = NULL;
else
{
if (tablespaceOid == DEFAULTTABLESPACE_OID)
- sprintf(fctx->location, "%s/base", DataDir);
+ sprintf(fctx->location, "base");
else
- sprintf(fctx->location, "%s/pg_tblspc/%u", DataDir,
- tablespaceOid);
+ sprintf(fctx->location, "pg_tblspc/%u", tablespaceOid);
fctx->dirdesc = AllocateDir(fctx->location);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.11 2005/06/29 20:34:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.12 2005/07/04 04:51:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "utils/syscache.h"
-/* Actual names of the flat files (within $PGDATA/global/) */
-#define DATABASE_FLAT_FILE "pg_database"
-#define AUTH_FLAT_FILE "pg_auth"
+/* Actual names of the flat files (within $PGDATA) */
+#define DATABASE_FLAT_FILE "global/pg_database"
+#define AUTH_FLAT_FILE "global/pg_auth"
/* Info bits in a flatfiles 2PC record */
#define FF_BIT_DATABASE 1
/*
- * database_getflatfilename --- get full pathname of database file
+ * database_getflatfilename --- get pathname of database file
*
* Note that result string is palloc'd, and should be freed by the caller.
+ * (This convention is not really needed anymore, since the relative path
+ * is fixed.)
*/
char *
database_getflatfilename(void)
{
- int bufsize;
- char *pfnam;
-
- bufsize = strlen(DataDir) + strlen("/global/") +
- strlen(DATABASE_FLAT_FILE) + 1;
- pfnam = (char *) palloc(bufsize);
- snprintf(pfnam, bufsize, "%s/global/%s", DataDir, DATABASE_FLAT_FILE);
-
- return pfnam;
+ return pstrdup(DATABASE_FLAT_FILE);
}
/*
- * auth_getflatfilename --- get full pathname of auth file
+ * auth_getflatfilename --- get pathname of auth file
*
* Note that result string is palloc'd, and should be freed by the caller.
+ * (This convention is not really needed anymore, since the relative path
+ * is fixed.)
*/
char *
auth_getflatfilename(void)
{
- int bufsize;
- char *pfnam;
-
- bufsize = strlen(DataDir) + strlen("/global/") +
- strlen(AUTH_FLAT_FILE) + 1;
- pfnam = (char *) palloc(bufsize);
- snprintf(pfnam, bufsize, "%s/global/%s", DataDir, AUTH_FLAT_FILE);
-
- return pfnam;
+ return pstrdup(AUTH_FLAT_FILE);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.95 2004/12/31 22:01:40 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.96 2005/07/04 04:51:50 tgl Exp $
*
* NOTES
* Globals used all over the place should be declared here and not
struct Port *MyProcPort;
long MyCancelKey;
+/*
+ * DataDir is the absolute path to the top level of the PGDATA directory tree.
+ * Except during early startup, this is also the server's working directory;
+ * most code therefore can simply use relative paths and not reference DataDir
+ * explicitly.
+ */
char *DataDir = NULL;
- /*
- * The PGDATA directory user says to use, or defaults to via environment
- * variable. NULL if no option given and no environment variable set
- */
-
char OutputFileName[MAXPGPATH]; /* debugging output file */
char my_exec_path[MAXPGPATH]; /* full path to my executable */
BackendId MyBackendId = InvalidBackendId;
-char *DatabasePath = NULL;
Oid MyDatabaseId = InvalidOid;
Oid MyDatabaseTableSpace = InvalidOid;
+/*
+ * DatabasePath is the path (relative to DataDir) of my database's
+ * primary directory, ie, its directory in the default tablespace.
+ */
+char *DatabasePath = NULL;
+
pid_t PostmasterPid = 0;
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.144 2005/06/28 22:16:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.145 2005/07/04 04:51:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "utils/syscache.h"
+#define DIRECTORY_LOCK_FILE "postmaster.pid"
+
ProcessingMode Mode = InitProcessing;
-/* Note: we rely on these to initialize as zeroes */
-static char directoryLockFile[MAXPGPATH];
+/* Note: we rely on this to initialize as zeroes */
static char socketLockFile[MAXPGPATH];
DataDir = new;
}
+/*
+ * Change working directory to DataDir. Most of the postmaster and backend
+ * code assumes that we are in DataDir so it can use relative paths to access
+ * stuff in and under the data directory. For convenience during path
+ * setup, however, we don't force the chdir to occur during SetDataDir.
+ */
+void
+ChangeToDataDir(void)
+{
+ AssertState(DataDir);
+
+ if (chdir(DataDir) < 0)
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not change directory to \"%s\": %m",
+ DataDir)));
+}
+
/*
* If the given pathname isn't already absolute, make it so, interpreting
* it relative to the current working directory.
*
* Also canonicalizes the path. The result is always a malloc'd copy.
*
- * Note: it is probably unwise to use this in running backends, since they
- * have chdir'd to a database-specific subdirectory; the results would not be
- * consistent across backends. Currently this is used only during postmaster
- * or standalone-backend startup.
+ * Note: interpretation of relative-path arguments during postmaster startup
+ * should happen before doing ChangeToDataDir(), else the user will probably
+ * not like the results.
*/
char *
make_absolute_path(const char *path)
on_proc_exit(UnlinkLockFile, PointerGetDatum(strdup(filename)));
}
+/*
+ * Create the data directory lockfile.
+ *
+ * When this is called, we must have already switched the working
+ * directory to DataDir, so we can just use a relative path. This
+ * helps ensure that we are locking the directory we should be.
+ */
void
-CreateDataDirLockFile(const char *datadir, bool amPostmaster)
+CreateDataDirLockFile(bool amPostmaster)
{
- char lockfile[MAXPGPATH];
-
- snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir);
- CreateLockFile(lockfile, amPostmaster, true, datadir);
- /* Save name of lockfile for RecordSharedMemoryInLockFile */
- strcpy(directoryLockFile, lockfile);
+ CreateLockFile(DIRECTORY_LOCK_FILE, amPostmaster, true, DataDir);
}
+/*
+ * Create a lockfile for the specified Unix socket file.
+ */
void
CreateSocketLockFile(const char *socketfile, bool amPostmaster)
{
/*
* Append information about a shared memory segment to the data directory
- * lock file (if we have created one).
+ * lock file.
*
* This may be called multiple times in the life of a postmaster, if we
* delete and recreate shmem due to backend crash. Therefore, be prepared
char *ptr;
char buffer[BLCKSZ];
- /*
- * Do nothing if we did not create a lockfile (probably because we are
- * running standalone).
- */
- if (directoryLockFile[0] == '\0')
- return;
-
- fd = open(directoryLockFile, O_RDWR | PG_BINARY, 0);
+ fd = open(DIRECTORY_LOCK_FILE, O_RDWR | PG_BINARY, 0);
if (fd < 0)
{
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m",
- directoryLockFile)));
+ DIRECTORY_LOCK_FILE)));
return;
}
len = read(fd, buffer, sizeof(buffer) - 100);
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not read from file \"%s\": %m",
- directoryLockFile)));
+ DIRECTORY_LOCK_FILE)));
close(fd);
return;
}
if (ptr == NULL ||
(ptr = strchr(ptr + 1, '\n')) == NULL)
{
- elog(LOG, "bogus data in \"%s\"", directoryLockFile);
+ elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE);
close(fd);
return;
}
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not write to file \"%s\": %m",
- directoryLockFile)));
+ DIRECTORY_LOCK_FILE)));
close(fd);
return;
}
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not write to file \"%s\": %m",
- directoryLockFile)));
+ DIRECTORY_LOCK_FILE)));
}
}
*
*
* 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 $
*
*
*-------------------------------------------------------------------------
ValidatePgVersion(fullpath);
- if (chdir(fullpath) == -1)
- ereport(FATAL,
- (errcode_for_file_access(),
- errmsg("could not change directory to \"%s\": %m",
- fullpath)));
-
SetDatabasePath(fullpath);
}
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.271 2005/06/28 05:09:02 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.272 2005/07/04 04:51:51 tgl Exp $
*
*--------------------------------------------------------------------
*/
#ifdef EXEC_BACKEND
#define CONFIG_EXEC_PARAMS "global/config_exec_params"
+#define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
#endif
/* XXX these should appear in other modules' header files */
* Reflect the final DataDir value back into the data_directory GUC var.
* (If you are wondering why we don't just make them a single variable,
* it's because the EXEC_BACKEND case needs DataDir to be transmitted to
- * child backends specially.)
+ * child backends specially. XXX is that still true? Given that we
+ * now chdir to DataDir, EXEC_BACKEND can read the config file without
+ * knowing DataDir in advance.)
*/
SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
#ifdef EXEC_BACKEND
+
/*
* This routine dumps out all non-default GUC options into a binary
* file that is read by all exec'ed backends. The format is:
write_nondefault_variables(GucContext context)
{
int i;
- char *new_filename,
- *filename;
int elevel;
FILE *fp;
Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
- Assert(DataDir);
elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
/*
* Open file
*/
- new_filename = guc_malloc(elevel, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) +
- strlen(".new") + 2);
- if (new_filename == NULL)
- return;
-
- filename = guc_malloc(elevel, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) + 2);
- if (filename == NULL)
- {
- free(new_filename);
- return;
- }
-
- sprintf(new_filename, "%s/" CONFIG_EXEC_PARAMS ".new", DataDir);
- sprintf(filename, "%s/" CONFIG_EXEC_PARAMS, DataDir);
-
- fp = AllocateFile(new_filename, "w");
+ fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
if (!fp)
{
- free(new_filename);
- free(filename);
ereport(elevel,
(errcode_for_file_access(),
- errmsg("could not write to file \"%s\": %m", CONFIG_EXEC_PARAMS)));
+ errmsg("could not write to file \"%s\": %m",
+ CONFIG_EXEC_PARAMS_NEW)));
return;
}
if (FreeFile(fp))
{
- free(new_filename);
- free(filename);
ereport(elevel,
(errcode_for_file_access(),
- errmsg("could not write to file \"%s\": %m", CONFIG_EXEC_PARAMS)));
+ errmsg("could not write to file \"%s\": %m",
+ CONFIG_EXEC_PARAMS_NEW)));
return;
}
* Put new file in place. This could delay on Win32, but we don't
* hold any exclusive locks.
*/
- rename(new_filename, filename);
- free(new_filename);
- free(filename);
+ rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
}
void
read_nondefault_variables(void)
{
- char *filename;
FILE *fp;
char *varname,
*varvalue;
int varsource;
- Assert(DataDir);
-
/*
* Open file
*/
- filename = guc_malloc(FATAL, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) + 2);
- sprintf(filename, "%s/" CONFIG_EXEC_PARAMS, DataDir);
-
- fp = AllocateFile(filename, "r");
+ fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
if (!fp)
{
- free(filename);
/* File not found is fine */
if (errno != ENOENT)
ereport(FATAL,
(errcode_for_file_access(),
- errmsg("could not read from file \"%s\": %m", CONFIG_EXEC_PARAMS)));
+ errmsg("could not read from file \"%s\": %m",
+ CONFIG_EXEC_PARAMS)));
return;
}
}
FreeFile(fp);
- free(filename);
- return;
}
-#endif
+
+#endif /* EXEC_BACKEND */
/*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.34 2005/06/08 15:50:27 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.35 2005/07/04 04:51:51 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern char *optarg;
-char XLogDir[MAXPGPATH]; /* not static, see xlog_internal.h */
-static char ControlFilePath[MAXPGPATH];
-
static ControlFileData ControlFile; /* pg_control values */
static uint32 newXlogId,
newXlogSeg; /* ID/Segment of new XLOG segment */
#endif
DataDir = argv[optind];
- snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir);
- snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
+
+ if (chdir(DataDir) < 0)
+ {
+ fprintf(stderr, _("%s: could not change directory to \"%s\": %s\n"),
+ progname, DataDir, strerror(errno));
+ exit(1);
+ }
/*
* Check for a postmaster lock file --- if there is one, refuse to
char *buffer;
pg_crc32 crc;
- if ((fd = open(ControlFilePath, O_RDONLY)) < 0)
+ if ((fd = open(XLOG_CONTROL_FILE, O_RDONLY)) < 0)
{
/*
* If pg_control is not there at all, or we can't read it, the
* can do "touch pg_control" to force us to proceed.
*/
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
- progname, ControlFilePath, strerror(errno));
+ progname, XLOG_CONTROL_FILE, strerror(errno));
if (errno == ENOENT)
fprintf(stderr, _("If you are sure the data directory path is correct, execute\n"
" touch %s\n"
"and try again.\n"),
- ControlFilePath);
+ XLOG_CONTROL_FILE);
exit(1);
}
if (len < 0)
{
fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
- progname, ControlFilePath, strerror(errno));
+ progname, XLOG_CONTROL_FILE, strerror(errno));
exit(1);
}
close(fd);
memset(buffer, 0, BLCKSZ);
memcpy(buffer, &ControlFile, sizeof(ControlFileData));
- unlink(ControlFilePath);
+ unlink(XLOG_CONTROL_FILE);
- fd = open(ControlFilePath, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, S_IRUSR | S_IWUSR);
+ fd = open(XLOG_CONTROL_FILE,
+ O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
+ S_IRUSR | S_IWUSR);
if (fd < 0)
{
fprintf(stderr, _("%s: could not create pg_control file: %s\n"),
struct dirent *xlde;
char path[MAXPGPATH];
- xldir = opendir(XLogDir);
+ xldir = opendir(XLOGDIR);
if (xldir == NULL)
{
fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
- progname, XLogDir, strerror(errno));
+ progname, XLOGDIR, strerror(errno));
exit(1);
}
if (strlen(xlde->d_name) == 24 &&
strspn(xlde->d_name, "0123456789ABCDEF") == 24)
{
- snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name);
+ snprintf(path, MAXPGPATH, "%s/%s", XLOGDIR, xlde->d_name);
if (unlink(path) < 0)
{
fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"),
if (errno)
{
fprintf(stderr, _("%s: could not read from directory \"%s\": %s\n"),
- progname, XLogDir, strerror(errno));
+ progname, XLOGDIR, strerror(errno));
exit(1);
}
closedir(xldir);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.11 2004/12/31 22:03:21 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.12 2005/07/04 04:51:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Dir is set during SimpleLruInit and does not change thereafter.
* Since it's always the same, it doesn't need to be in shared memory.
*/
- char Dir[MAXPGPATH];
+ char Dir[64];
} SlruCtlData;
typedef SlruCtlData *SlruCtl;
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.65 2005/06/08 15:50:28 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.66 2005/07/04 04:51:52 tgl Exp $
*/
#ifndef XLOG_H
#define XLOG_H
extern void UpdateControlFile(void);
extern int XLOGShmemSize(void);
extern void XLOGShmemInit(void);
-extern void XLOGPathInit(void);
extern void BootStrapXLOG(void);
extern void StartupXLOG(void);
extern void ShutdownXLOG(int code, Datum arg);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.8 2005/06/06 17:01:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.9 2005/07/04 04:51:52 tgl Exp $
*/
#ifndef XLOG_INTERNAL_H
#define XLOG_INTERNAL_H
((xrecoff) % BLCKSZ >= SizeOfXLogShortPHD && \
(BLCKSZ - (xrecoff) % BLCKSZ) >= SizeOfXLogRecord)
+/*
+ * The XLog directory and control file (relative to $PGDATA)
+ */
+#define XLOGDIR "pg_xlog"
+#define XLOG_CONTROL_FILE "global/pg_control"
+
/*
* These macros encapsulate knowledge about the exact layout of XLog file
* names, timeline history file names, and archive-status file names.
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
#define XLogFilePath(path, tli, log, seg) \
- snprintf(path, MAXPGPATH, "%s/%08X%08X%08X", XLogDir, tli, log, seg)
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, log, seg)
#define TLHistoryFileName(fname, tli) \
snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
#define TLHistoryFilePath(path, tli) \
- snprintf(path, MAXPGPATH, "%s/%08X.history", XLogDir, tli)
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)
#define StatusFilePath(path, xlog, suffix) \
- snprintf(path, MAXPGPATH, "%s/archive_status/%s%s", XLogDir, xlog, suffix)
+ snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
#define BackupHistoryFileName(fname, tli, log, seg, offset) \
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, log, seg, offset)
#define BackupHistoryFilePath(path, tli, log, seg, offset) \
- snprintf(path, MAXPGPATH, "%s/%08X%08X%08X.%08X.backup", XLogDir, tli, log, seg, offset)
-
-extern char XLogDir[MAXPGPATH];
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, log, seg, offset)
/*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.176 2005/06/28 05:09:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.177 2005/07/04 04:51:52 tgl Exp $
*
* NOTES
* some of the information in this file should be moved to other files.
extern void SetSessionAuthorization(Oid roleid, bool is_superuser);
extern void SetDataDir(const char *dir);
+extern void ChangeToDataDir(void);
extern char *make_absolute_path(const char *path);
/* in utils/misc/superuser.c */
extern void ResetReindexProcessing(void);
extern bool ReindexIsProcessingHeap(Oid heapOid);
extern bool ReindexIsProcessingIndex(Oid indexOid);
-extern void CreateDataDirLockFile(const char *datadir, bool amPostmaster);
+extern void CreateDataDirLockFile(bool amPostmaster);
extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster);
extern void TouchSocketLockFile(void);
extern void RecordSharedMemoryInLockFile(unsigned long id1,