Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit eb5949d

Browse files
committed
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.
1 parent 7504f0b commit eb5949d

File tree

27 files changed

+364
-474
lines changed

27 files changed

+364
-474
lines changed

contrib/dbsize/dbsize.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
66
*
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.18 2005/06/19 21:34:00 tgl Exp $
8+
* $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.19 2005/07/04 04:51:43 tgl Exp $
99
*
1010
*/
1111

@@ -24,9 +24,6 @@
2424
#include "utils/syscache.h"
2525

2626

27-
/* hack to make it compile under Win32 */
28-
extern DLLIMPORT char *DataDir;
29-
3027
Datum pg_tablespace_size(PG_FUNCTION_ARGS);
3128
Datum pg_database_size(PG_FUNCTION_ARGS);
3229
Datum pg_relation_size(PG_FUNCTION_ARGS);
@@ -91,11 +88,11 @@ calculate_database_size(Oid dbOid)
9188
/* Shared storage in pg_global is not counted */
9289

9390
/* Include pg_default storage */
94-
snprintf(pathname, MAXPGPATH, "%s/base/%u", DataDir, dbOid);
91+
snprintf(pathname, MAXPGPATH, "base/%u", dbOid);
9592
totalsize += db_dir_size(pathname);
9693

9794
/* Scan the non-default tablespaces */
98-
snprintf(pathname, MAXPGPATH, "%s/pg_tblspc", DataDir);
95+
snprintf(pathname, MAXPGPATH, "pg_tblspc");
9996
dirdesc = AllocateDir(pathname);
10097

10198
while ((direntry = ReadDir(dirdesc, pathname)) != NULL)
@@ -104,8 +101,8 @@ calculate_database_size(Oid dbOid)
104101
strcmp(direntry->d_name, "..") == 0)
105102
continue;
106103

107-
snprintf(pathname, MAXPGPATH, "%s/pg_tblspc/%s/%u",
108-
DataDir, direntry->d_name, dbOid);
104+
snprintf(pathname, MAXPGPATH, "pg_tblspc/%s/%u",
105+
direntry->d_name, dbOid);
109106
totalsize += db_dir_size(pathname);
110107
}
111108

@@ -134,11 +131,11 @@ pg_tablespace_size(PG_FUNCTION_ARGS)
134131
struct dirent *direntry;
135132

136133
if (tblspcOid == DEFAULTTABLESPACE_OID)
137-
snprintf(tblspcPath, MAXPGPATH, "%s/base", DataDir);
134+
snprintf(tblspcPath, MAXPGPATH, "base");
138135
else if (tblspcOid == GLOBALTABLESPACE_OID)
139-
snprintf(tblspcPath, MAXPGPATH, "%s/global", DataDir);
136+
snprintf(tblspcPath, MAXPGPATH, "global");
140137
else
141-
snprintf(tblspcPath, MAXPGPATH, "%s/pg_tblspc/%u", DataDir, tblspcOid);
138+
snprintf(tblspcPath, MAXPGPATH, "pg_tblspc/%u", tblspcOid);
142139

143140
dirdesc = AllocateDir(tblspcPath);
144141

@@ -208,12 +205,12 @@ calculate_relation_size(Oid tblspcOid, Oid relnodeOid)
208205
tblspcOid = MyDatabaseTableSpace;
209206

210207
if (tblspcOid == DEFAULTTABLESPACE_OID)
211-
snprintf(dirpath, MAXPGPATH, "%s/base/%u", DataDir, MyDatabaseId);
208+
snprintf(dirpath, MAXPGPATH, "base/%u", MyDatabaseId);
212209
else if (tblspcOid == GLOBALTABLESPACE_OID)
213-
snprintf(dirpath, MAXPGPATH, "%s/global", DataDir);
210+
snprintf(dirpath, MAXPGPATH, "global");
214211
else
215-
snprintf(dirpath, MAXPGPATH, "%s/pg_tblspc/%u/%u",
216-
DataDir, tblspcOid, MyDatabaseId);
212+
snprintf(dirpath, MAXPGPATH, "pg_tblspc/%u/%u",
213+
tblspcOid, MyDatabaseId);
217214

218215
for (segcount = 0 ;; segcount++)
219216
{

src/backend/access/transam/slru.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
4949
* Portions Copyright (c) 1994, Regents of the University of California
5050
*
51-
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.25 2005/06/19 21:34:01 tgl Exp $
51+
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.26 2005/07/04 04:51:44 tgl Exp $
5252
*
5353
*-------------------------------------------------------------------------
5454
*/
@@ -190,7 +190,7 @@ SimpleLruInit(SlruCtl ctl, const char *name,
190190
*/
191191
ctl->shared = shared;
192192
ctl->do_fsync = true; /* default behavior */
193-
snprintf(ctl->Dir, MAXPGPATH, "%s/%s", DataDir, subdir);
193+
StrNCpy(ctl->Dir, subdir, sizeof(ctl->Dir));
194194
}
195195

196196
/*

src/backend/access/transam/twophase.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.7 2005/06/28 05:08:51 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.8 2005/07/04 04:51:44 tgl Exp $
1111
*
1212
* NOTES
1313
* Each global transaction is associated with a global transaction
@@ -661,7 +661,7 @@ TwoPhaseGetDummyProc(TransactionId xid)
661661
/************************************************************************/
662662

663663
#define TwoPhaseFilePath(path, xid) \
664-
snprintf(path, MAXPGPATH, "%s/%s/%08X", DataDir, TWOPHASE_DIR, xid)
664+
snprintf(path, MAXPGPATH, TWOPHASE_DIR "/%08X", xid)
665665

666666
/*
667667
* 2PC state file format:
@@ -1434,14 +1434,11 @@ PrescanPreparedTransactions(void)
14341434
{
14351435
TransactionId origNextXid = ShmemVariableCache->nextXid;
14361436
TransactionId result = origNextXid;
1437-
char dir[MAXPGPATH];
14381437
DIR *cldir;
14391438
struct dirent *clde;
14401439

1441-
snprintf(dir, MAXPGPATH, "%s/%s", DataDir, TWOPHASE_DIR);
1442-
1443-
cldir = AllocateDir(dir);
1444-
while ((clde = ReadDir(cldir, dir)) != NULL)
1440+
cldir = AllocateDir(TWOPHASE_DIR);
1441+
while ((clde = ReadDir(cldir, TWOPHASE_DIR)) != NULL)
14451442
{
14461443
if (strlen(clde->d_name) == 8 &&
14471444
strspn(clde->d_name, "0123456789ABCDEF") == 8)
@@ -1540,7 +1537,7 @@ RecoverPreparedTransactions(void)
15401537
DIR *cldir;
15411538
struct dirent *clde;
15421539

1543-
snprintf(dir, MAXPGPATH, "%s/%s", DataDir, TWOPHASE_DIR);
1540+
snprintf(dir, MAXPGPATH, "%s", TWOPHASE_DIR);
15441541

15451542
cldir = AllocateDir(dir);
15461543
while ((clde = ReadDir(cldir, dir)) != NULL)

0 commit comments

Comments
 (0)