Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb5949d

Browse files
committed
Arrange for the postmaster (and standalone backends, initdb, etc) to
chdir into PGDATA and subsequently use relative paths instead of absolutepaths to access all files under PGDATA. This seems to give a smallperformance improvement, and it should make the system more robustagainst naive DBAs doing things like moving a database directory thathas a live postmaster in it. Per recent discussion.
1 parent7504f0b commiteb5949d

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-
externDLLIMPORTchar*DataDir;
29-
3027
Datumpg_tablespace_size(PG_FUNCTION_ARGS);
3128
Datumpg_database_size(PG_FUNCTION_ARGS);
3229
Datumpg_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
structdirent*direntry;
135132

136133
if (tblspcOid==DEFAULTTABLESPACE_OID)
137-
snprintf(tblspcPath,MAXPGPATH,"%s/base",DataDir);
134+
snprintf(tblspcPath,MAXPGPATH,"base");
138135
elseif (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
elseif (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
#defineTwoPhaseFilePath(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
TransactionIdorigNextXid=ShmemVariableCache->nextXid;
14361436
TransactionIdresult=origNextXid;
1437-
chardir[MAXPGPATH];
14381437
DIR*cldir;
14391438
structdirent*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
structdirent*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)

[8]ページ先頭

©2009-2025 Movatter.jp