From eb5949d190e80360386113fde0f05854f0c9824d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 4 Jul 2005 04:51:52 +0000 Subject: 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. --- contrib/dbsize/dbsize.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'contrib/dbsize/dbsize.c') diff --git a/contrib/dbsize/dbsize.c b/contrib/dbsize/dbsize.c index 903de97b374..ac5e4c74ea8 100644 --- a/contrib/dbsize/dbsize.c +++ b/contrib/dbsize/dbsize.c @@ -5,7 +5,7 @@ * Copyright (c) 2002-2005, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.18 2005/06/19 21:34:00 tgl Exp $ + * $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.19 2005/07/04 04:51:43 tgl Exp $ * */ @@ -24,9 +24,6 @@ #include "utils/syscache.h" -/* hack to make it compile under Win32 */ -extern DLLIMPORT char *DataDir; - Datum pg_tablespace_size(PG_FUNCTION_ARGS); Datum pg_database_size(PG_FUNCTION_ARGS); Datum pg_relation_size(PG_FUNCTION_ARGS); @@ -91,11 +88,11 @@ calculate_database_size(Oid dbOid) /* Shared storage in pg_global is not counted */ /* Include pg_default storage */ - snprintf(pathname, MAXPGPATH, "%s/base/%u", DataDir, dbOid); + snprintf(pathname, MAXPGPATH, "base/%u", dbOid); totalsize += db_dir_size(pathname); /* Scan the non-default tablespaces */ - snprintf(pathname, MAXPGPATH, "%s/pg_tblspc", DataDir); + snprintf(pathname, MAXPGPATH, "pg_tblspc"); dirdesc = AllocateDir(pathname); while ((direntry = ReadDir(dirdesc, pathname)) != NULL) @@ -104,8 +101,8 @@ calculate_database_size(Oid dbOid) strcmp(direntry->d_name, "..") == 0) continue; - snprintf(pathname, MAXPGPATH, "%s/pg_tblspc/%s/%u", - DataDir, direntry->d_name, dbOid); + snprintf(pathname, MAXPGPATH, "pg_tblspc/%s/%u", + direntry->d_name, dbOid); totalsize += db_dir_size(pathname); } @@ -134,11 +131,11 @@ pg_tablespace_size(PG_FUNCTION_ARGS) struct dirent *direntry; if (tblspcOid == DEFAULTTABLESPACE_OID) - snprintf(tblspcPath, MAXPGPATH, "%s/base", DataDir); + snprintf(tblspcPath, MAXPGPATH, "base"); else if (tblspcOid == GLOBALTABLESPACE_OID) - snprintf(tblspcPath, MAXPGPATH, "%s/global", DataDir); + snprintf(tblspcPath, MAXPGPATH, "global"); else - snprintf(tblspcPath, MAXPGPATH, "%s/pg_tblspc/%u", DataDir, tblspcOid); + snprintf(tblspcPath, MAXPGPATH, "pg_tblspc/%u", tblspcOid); dirdesc = AllocateDir(tblspcPath); @@ -208,12 +205,12 @@ calculate_relation_size(Oid tblspcOid, Oid relnodeOid) tblspcOid = MyDatabaseTableSpace; if (tblspcOid == DEFAULTTABLESPACE_OID) - snprintf(dirpath, MAXPGPATH, "%s/base/%u", DataDir, MyDatabaseId); + snprintf(dirpath, MAXPGPATH, "base/%u", MyDatabaseId); else if (tblspcOid == GLOBALTABLESPACE_OID) - snprintf(dirpath, MAXPGPATH, "%s/global", DataDir); + snprintf(dirpath, MAXPGPATH, "global"); else - snprintf(dirpath, MAXPGPATH, "%s/pg_tblspc/%u/%u", - DataDir, tblspcOid, MyDatabaseId); + snprintf(dirpath, MAXPGPATH, "pg_tblspc/%u/%u", + tblspcOid, MyDatabaseId); for (segcount = 0 ;; segcount++) { -- cgit v1.2.3