summaryrefslogtreecommitdiff
path: root/src/backend/postmaster
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/postmaster')
-rw-r--r--src/backend/postmaster/pgarch.c9
-rw-r--r--src/backend/postmaster/pgstat.c57
-rw-r--r--src/backend/postmaster/postmaster.c47
-rw-r--r--src/backend/postmaster/syslogger.c19
4 files changed, 41 insertions, 91 deletions
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index e5eecb2dbc..2f52053a2c 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -19,7 +19,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.16 2005/06/19 21:34:01 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.17 2005/07/04 04:51:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -248,9 +248,6 @@ PgArchiverMain(int argc, char *argv[])
init_ps_display("archiver process", "", "");
set_ps_display("");
- /* Init XLOG file paths --- needed in EXEC_BACKEND case */
- XLOGPathInit();
-
pgarch_MainLoop();
exit(0);
@@ -400,7 +397,7 @@ pgarch_archiveXlog(char *xlog)
const char *sp;
int rc;
- snprintf(pathname, MAXPGPATH, "%s/%s", XLogDir, xlog);
+ snprintf(pathname, MAXPGPATH, XLOGDIR "/%s", xlog);
/*
* construct the command to be executed
@@ -502,7 +499,7 @@ pgarch_readyXlog(char *xlog)
struct dirent *rlde;
bool found = false;
- snprintf(XLogArchiveStatusDir, MAXPGPATH, "%s/archive_status", XLogDir);
+ snprintf(XLogArchiveStatusDir, MAXPGPATH, XLOGDIR "/archive_status");
rldir = AllocateDir(XLogArchiveStatusDir);
if (rldir == NULL)
ereport(ERROR,
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 86b873ab36..325bb8b451 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.98 2005/06/29 22:51:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.99 2005/07/04 04:51:47 tgl Exp $
* ----------
*/
#include "postgres.h"
@@ -54,12 +54,11 @@
/* ----------
- * Paths for the statistics files. The %s is replaced with the
- * installation's $PGDATA.
+ * Paths for the statistics files (relative to installation's $PGDATA).
* ----------
*/
-#define PGSTAT_STAT_FILENAME "%s/global/pgstat.stat"
-#define PGSTAT_STAT_TMPFILE "%s/global/pgstat.tmp.%d"
+#define PGSTAT_STAT_FILENAME "global/pgstat.stat"
+#define PGSTAT_STAT_TMPFILE "global/pgstat.tmp"
/* ----------
* Timer definitions.
@@ -134,9 +133,6 @@ static HTAB *pgStatBeDead = NULL;
static PgStat_StatBeEntry *pgStatBeTable = NULL;
static int pgStatNumBackends = 0;
-static char pgStat_fname[MAXPGPATH];
-static char pgStat_tmpfname[MAXPGPATH];
-
/* ----------
* Local function forward declarations
@@ -221,20 +217,11 @@ pgstat_init(void)
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
@@ -1471,14 +1458,6 @@ PgstatCollectorMain(int argc, char *argv[])
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
*/
gettimeofday(&next_statwrite, NULL);
@@ -2161,13 +2140,13 @@ pgstat_write_statsfile(void)
/*
* Open the statistics temp file to write out the current values.
*/
- fpout = fopen(pgStat_tmpfname, PG_BINARY_W);
+ fpout = fopen(PGSTAT_STAT_TMPFILE, PG_BINARY_W);
if (fpout == NULL)
{
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not open temporary statistics file \"%s\": %m",
- pgStat_tmpfname)));
+ PGSTAT_STAT_TMPFILE)));
return;
}
@@ -2276,16 +2255,16 @@ pgstat_write_statsfile(void)
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not close temporary statistics file \"%s\": %m",
- pgStat_tmpfname)));
+ PGSTAT_STAT_TMPFILE)));
}
else
{
- if (rename(pgStat_tmpfname, pgStat_fname) < 0)
+ if (rename(PGSTAT_STAT_TMPFILE, PGSTAT_STAT_FILENAME) < 0)
{
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not rename temporary statistics file \"%s\" to \"%s\": %m",
- pgStat_tmpfname, pgStat_fname)));
+ PGSTAT_STAT_TMPFILE, PGSTAT_STAT_FILENAME)));
}
}
@@ -2377,23 +2356,11 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
*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;
/*
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index d14f6db163..2de5527648 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.457 2005/06/30 10:02:22 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.458 2005/07/04 04:51:47 tgl Exp $
*
* NOTES
*
@@ -585,6 +585,15 @@ PostmasterMain(int argc, char *argv[])
ExitPostmaster(1);
}
+#ifdef EXEC_BACKEND
+ /* Locate executable backend before we change working directory */
+ if (find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
+ postgres_exec_path) < 0)
+ ereport(FATAL,
+ (errmsg("%s: could not locate matching postgres executable",
+ progname)));
+#endif
+
/*
* Locate the proper configuration files and data directory, and
* read postgresql.conf for the first time.
@@ -595,6 +604,9 @@ PostmasterMain(int argc, char *argv[])
/* Verify that DataDir looks reasonable */
checkDataDir();
+ /* And switch working directory into it */
+ ChangeToDataDir();
+
/*
* Check for invalid combinations of GUC settings.
*/
@@ -650,14 +662,6 @@ PostmasterMain(int argc, char *argv[])
(errmsg_internal("-----------------------------------------")));
}
-#ifdef EXEC_BACKEND
- if (find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
- postgres_exec_path) < 0)
- ereport(FATAL,
- (errmsg("%s: could not locate matching postgres executable",
- progname)));
-#endif
-
/*
* Initialize SSL library, if specified.
*/
@@ -691,7 +695,7 @@ PostmasterMain(int argc, char *argv[])
* :-(). For the same reason, it's best to grab the TCP socket(s)
* before the Unix socket.
*/
- CreateDataDirLockFile(DataDir, true);
+ CreateDataDirLockFile(true);
/*
* Remove old temporary files. At this point there can be no other
@@ -786,8 +790,6 @@ PostmasterMain(int argc, char *argv[])
ereport(FATAL,
(errmsg("no socket created for listening")));
- XLOGPathInit();
-
/*
* Set up shared memory and semaphores.
*/
@@ -2866,20 +2868,16 @@ internal_forkexec(int argc, char *argv[], Port *port)
return -1; /* log made by save_backend_variables */
/* Calculate name for temp file */
- Assert(DataDir);
- snprintf(tmpfilename, MAXPGPATH, "%s/%s/%s.backend_var.%d.%lu",
- DataDir, PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
+ snprintf(tmpfilename, MAXPGPATH, "%s/%s.backend_var.%d.%lu",
+ PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
MyProcPid, ++tmpBackendFileNum);
/* Open file */
fp = AllocateFile(tmpfilename, PG_BINARY_W);
if (!fp)
{
- /* As per OpenTemporaryFile... */
- char dirname[MAXPGPATH];
-
- snprintf(dirname, MAXPGPATH, "%s/%s", DataDir, PG_TEMP_FILES_DIR);
- mkdir(dirname, S_IRWXU);
+ /* As in OpenTemporaryFile, try to make the temp-file directory */
+ mkdir(PG_TEMP_FILES_DIR, S_IRWXU);
fp = AllocateFile(tmpfilename, PG_BINARY_W);
if (!fp)
@@ -3527,15 +3525,14 @@ StartChildProcess(int xlop)
static bool
CreateOptsFile(int argc, char *argv[], char *fullprogname)
{
- char filename[MAXPGPATH];
FILE *fp;
int i;
- snprintf(filename, sizeof(filename), "%s/postmaster.opts", DataDir);
+#define OPTS_FILE "postmaster.opts"
- if ((fp = fopen(filename, "w")) == NULL)
+ if ((fp = fopen(OPTS_FILE, "w")) == NULL)
{
- elog(LOG, "could not create file \"%s\": %m", filename);
+ elog(LOG, "could not create file \"%s\": %m", OPTS_FILE);
return false;
}
@@ -3546,7 +3543,7 @@ CreateOptsFile(int argc, char *argv[], char *fullprogname)
if (fclose(fp))
{
- elog(LOG, "could not write file \"%s\": %m", filename);
+ elog(LOG, "could not write file \"%s\": %m", OPTS_FILE);
return false;
}
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 1899d8f21a..c6f02520bf 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -18,7 +18,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.15 2005/04/19 03:13:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.16 2005/07/04 04:51:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -422,17 +422,9 @@ SysLogger_Start(void)
#endif
/*
- * create log directory if not present; ignore errors
+ * Create log directory if not present; ignore errors
*/
- if (is_absolute_path(Log_directory))
- mkdir(Log_directory, 0700);
- else
- {
- filename = palloc(MAXPGPATH);
- snprintf(filename, MAXPGPATH, "%s/%s", DataDir, Log_directory);
- mkdir(filename, 0700);
- pfree(filename);
- }
+ mkdir(Log_directory, 0700);
/*
* The initial logfile is created right in the postmaster, to verify
@@ -823,10 +815,7 @@ logfile_getname(pg_time_t timestamp)
filename = palloc(MAXPGPATH);
- if (is_absolute_path(Log_directory))
- snprintf(filename, MAXPGPATH, "%s/", Log_directory);
- else
- snprintf(filename, MAXPGPATH, "%s/%s/", DataDir, Log_directory);
+ snprintf(filename, MAXPGPATH, "%s/", Log_directory);
len = strlen(filename);