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

Commitdffb673

Browse files
committed
While changing Cygwin Python to build its core as a DLL (like Win32
Python) to support shared extension modules, I have learned that Guidoprefers the style of the attached patch to solve the above problem.I feel that this solution is particularly appropriate in this casebecause the following: PglargeType PgType PgQueryTypeare already being handled in the way that I am proposing for PgSourceType.Jason Tishler
1 parent3f7c542 commitdffb673

File tree

10 files changed

+210
-20
lines changed

10 files changed

+210
-20
lines changed

‎doc/src/sgml/ref/vacuum.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/vacuum.sgml,v 1.14 2001/05/07 00:43:15 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/vacuum.sgml,v 1.15 2001/05/25 15:34:49 momjian Exp $
33
Postgres documentation
44
-->
55

@@ -154,7 +154,8 @@ NOTICE: Index <replaceable class="PARAMETER">index</replaceable>: Pages 28;
154154

155155
<para>
156156
With no parameter, <command>VACUUM</command> processes every table in the
157-
current database. With a parameter, <command>VACUUM</command> processes
157+
current database. It also detects any extraneous files in the
158+
database directory. With a parameter, <command>VACUUM</command> processes
158159
only that table.
159160
</para>
160161

‎src/backend/access/transam/varsup.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2000, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.38 2001/03/22 03:59:17 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.39 2001/05/25 15:34:49 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -16,7 +16,10 @@
1616
#include"access/transam.h"
1717
#include"access/xlog.h"
1818
#include"storage/proc.h"
19+
#include"storage/sinval.h"
20+
#include"storage/sinvaladt.h"
1921

22+
externSISeg*shmInvalBuffer;
2023

2124
/* Number of XIDs and OIDs to prefetch (preallocate) per XLOG write */
2225
#defineVAR_XID_PREFETCH1024
@@ -143,3 +146,44 @@ CheckMaxObjectId(Oid assigned_oid)
143146

144147
SpinRelease(OidGenLockId);
145148
}
149+
150+
/*
151+
* GetMinBackendOid -- returns lowest oid stored on startup of
152+
* each backend.
153+
*/
154+
Oid
155+
GetMinStartupOid(void)
156+
{
157+
SISeg*segP=shmInvalBuffer;
158+
ProcState*stateP=segP->procState;
159+
intindex;
160+
Oidmin_oid;
161+
162+
/* prime with current oid, no need for lock */
163+
min_oid=ShmemVariableCache->nextOid;
164+
165+
SpinAcquire(SInvalLock);
166+
167+
for (index=0;index<segP->lastBackend;index++)
168+
{
169+
SHMEM_OFFSETpOffset=stateP[index].procStruct;
170+
171+
if (pOffset!=INVALID_OFFSET)
172+
{
173+
PROC*proc= (PROC*)MAKE_PTR(pOffset);
174+
Oidproc_oid;
175+
176+
proc_oid=proc->startOid;/* we don't use spin-locking in
177+
* AbortTransaction() ! */
178+
if (proc==MyProc||proc_oid <=BootstrapObjectIdData)
179+
continue;
180+
if (proc_oid<min_oid)
181+
min_oid=proc_oid;
182+
}
183+
}
184+
185+
SpinRelease(SInvalLock);
186+
returnmin_oid;
187+
}
188+
189+

‎src/backend/commands/vacuum.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.193 2001/05/18 21:24:18 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.194 2001/05/25 15:34:49 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include"postgres.h"
1616

1717
#include<fcntl.h>
1818
#include<unistd.h>
19+
#include<stdlib.h>
20+
#include<limits.h>
1921
#include<time.h>
2022
#include<sys/time.h>
2123
#include<sys/types.h>
24+
#include<dirent.h>
2225
#include<sys/file.h>
2326
#include<sys/stat.h>
2427

@@ -30,6 +33,7 @@
3033

3134
#include"access/genam.h"
3235
#include"access/heapam.h"
36+
#include"access/transam.h"
3337
#include"access/xlog.h"
3438
#include"catalog/catalog.h"
3539
#include"catalog/catname.h"
@@ -159,6 +163,7 @@ static intvac_cmp_vtlinks(const void *left, const void *right);
159163
staticboolenough_space(VacPagevacpage,Sizelen);
160164
staticvoidinit_rusage(VacRUsage*ru0);
161165
staticchar*show_rusage(VacRUsage*ru0);
166+
staticvoidreport_orphans(void);
162167

163168

164169
/*
@@ -236,6 +241,10 @@ vacuum(VacuumStmt *vacstmt)
236241

237242
/* clean up */
238243
vacuum_shutdown();
244+
245+
if (VacRelName==NULL)
246+
report_orphans();
247+
239248
}
240249

241250
/*
@@ -2646,3 +2655,74 @@ show_rusage(VacRUsage *ru0)
26462655

26472656
returnresult;
26482657
}
2658+
2659+
/*
2660+
* report_orphans
2661+
*
2662+
* Report files that are not referenced by any pg_class.relfilenode.
2663+
* Could be caused by backend crash no cleaning up.
2664+
*/
2665+
staticvoid
2666+
report_orphans(void)
2667+
{
2668+
DIR*db_dir;
2669+
structdirent*db_de;
2670+
Relationrel;
2671+
TupleDesctupdesc;
2672+
HeapScanDescscan;
2673+
HeapTupletuple;
2674+
Oiddir_file_oid;
2675+
Oidrel_file_oid;
2676+
Datumd;
2677+
booln;
2678+
boolmatch_found;
2679+
charcwd[MAXPGPATH];
2680+
2681+
getcwd(cwd,MAXPGPATH);
2682+
db_dir=opendir(".");
2683+
rel=heap_openr(RelationRelationName,AccessShareLock);
2684+
Assert(db_dir);
2685+
2686+
/*
2687+
* Cycle through directory and check each file against
2688+
* pg_class.relfilenode.
2689+
* XXX This is O(n^2). Is it too slow? bjm
2690+
*/
2691+
while ((db_de=readdir(db_dir))!=NULL)
2692+
{
2693+
if (strspn(db_de->d_name,"0123456789")==
2694+
strlen(db_de->d_name))
2695+
{
2696+
dir_file_oid= (Oid)strtoul((db_de->d_name),NULL,10);
2697+
2698+
if (dir_file_oid >=GetMinStartupOid()||
2699+
dir_file_oid <=BootstrapObjectIdData)
2700+
continue;
2701+
2702+
tupdesc=RelationGetDescr(rel);
2703+
2704+
match_found= false;
2705+
scan=heap_beginscan(rel, false,SnapshotNow,0, (ScanKey)NULL);
2706+
while (HeapTupleIsValid(tuple=heap_getnext(scan,0)))
2707+
{
2708+
d=heap_getattr(tuple,Anum_pg_class_relfilenode,tupdesc,&n);
2709+
rel_file_oid=DatumGetObjectId(d);
2710+
if (dir_file_oid==rel_file_oid)
2711+
{
2712+
match_found= true;
2713+
break;
2714+
}
2715+
}
2716+
heap_endscan(scan);
2717+
/* make sure there was no oid wrap-around during the scan */
2718+
if (!match_found&&dir_file_oid <=ShmemVariableCache->nextOid)
2719+
elog(NOTICE,
2720+
"Unreferenced file found in database directory:\n\t%s/%s",
2721+
cwd,db_de->d_name);
2722+
/* Maybe one day we can unlink too. bjm 2001-05-24 */
2723+
}
2724+
}
2725+
2726+
heap_close(rel,AccessShareLock);
2727+
closedir(db_dir);
2728+
}

‎src/backend/postmaster/postmaster.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
*
3030
* IDENTIFICATION
31-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.212 2001/04/19 19:09:23 petere Exp $
31+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.213 2001/05/25 15:34:50 momjian Exp $
3232
*
3333
* NOTES
3434
*
@@ -58,6 +58,7 @@
5858
#include<ctype.h>
5959
#include<sys/types.h>
6060
#include<sys/stat.h>
61+
#include<dirent.h>
6162
#include<sys/time.h>
6263
#include<sys/socket.h>
6364
#include<errno.h>
@@ -243,6 +244,7 @@ static void RandomSalt(char *salt);
243244
staticvoidSignalChildren(intsignal);
244245
staticintCountChildren(void);
245246
staticboolCreateOptsFile(intargc,char*argv[]);
247+
staticvoidRemovePgSorttemp(void);
246248

247249
staticpid_tSSDataBase(intxlop);
248250

@@ -595,6 +597,9 @@ PostmasterMain(int argc, char *argv[])
595597
if (!CreateDataDirLockFile(DataDir, true))
596598
ExitPostmaster(1);
597599

600+
/* Remove old sort files */
601+
RemovePgSorttemp();
602+
598603
/*
599604
* Establish input sockets.
600605
*/
@@ -2450,3 +2455,51 @@ CreateOptsFile(int argc, char *argv[])
24502455
fclose(fp);
24512456
return true;
24522457
}
2458+
2459+
2460+
/*
2461+
* Remove old sort files
2462+
*/
2463+
staticvoid
2464+
RemovePgSorttemp(void)
2465+
{
2466+
chardb_path[MAXPGPATH];
2467+
chartemp_path[MAXPGPATH];
2468+
charrm_path[MAXPGPATH];
2469+
DIR*db_dir;
2470+
DIR*temp_dir;
2471+
structdirent*db_de;
2472+
structdirent*temp_de;
2473+
2474+
/*
2475+
* Cycle through pg_tempsort for all databases and
2476+
* and remove old sort files.
2477+
*/
2478+
/* trailing slash forces symlink following */
2479+
snprintf(db_path,sizeof(db_path),"%s/base/",DataDir);
2480+
if ((db_dir=opendir(db_path))!=NULL)
2481+
{
2482+
while ((db_de=readdir(db_dir))!=NULL)
2483+
{
2484+
snprintf(temp_path,sizeof(temp_path),
2485+
"%s/%s/%s/",db_path,db_de->d_name,SORT_TEMP_DIR);
2486+
if ((temp_dir=opendir(temp_path))!=NULL)
2487+
{
2488+
while ((temp_de=readdir(temp_dir))!=NULL)
2489+
{
2490+
if (strspn(temp_de->d_name,"0123456789.")==
2491+
strlen(temp_de->d_name))
2492+
{
2493+
snprintf(rm_path,sizeof(temp_path),
2494+
"%s/%s/%s/%s",
2495+
db_path,db_de->d_name,
2496+
SORT_TEMP_DIR,temp_de->d_name);
2497+
unlink(rm_path);
2498+
}
2499+
}
2500+
closedir(temp_dir);
2501+
}
2502+
}
2503+
closedir(db_dir);
2504+
}
2505+
}

‎src/backend/storage/file/fd.c

Lines changed: 14 additions & 6 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-
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.76 2001/04/03 04:07:02 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.77 2001/05/25 15:34:50 momjian Exp $
1111
*
1212
* NOTES:
1313
*
@@ -742,21 +742,29 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
742742
File
743743
OpenTemporaryFile(void)
744744
{
745-
chartempfilename[64];
745+
chartempfilepath[128];
746746
Filefile;
747747

748748
/*
749749
* Generate a tempfile name that's unique within the current
750750
* transaction
751751
*/
752-
snprintf(tempfilename,sizeof(tempfilename),
753-
"pg_sorttemp%d.%ld",MyProcPid,tempFileCounter++);
752+
snprintf(tempfilepath,sizeof(tempfilepath),
753+
"%s%c%d.%ld",SORT_TEMP_DIR,SEP_CHAR,MyProcPid,
754+
tempFileCounter++);
754755

755756
/* Open the file */
756-
file=FileNameOpenFile(tempfilename,
757+
file=FileNameOpenFile(tempfilepath,
757758
O_RDWR |O_CREAT |O_TRUNC |PG_BINARY,0600);
758759
if (file <=0)
759-
elog(ERROR,"Failed to create temporary file %s",tempfilename);
760+
{
761+
/* mkdir could fail if some one else already created it */
762+
mkdir(SORT_TEMP_DIR,S_IRWXU);
763+
file=FileNameOpenFile(tempfilepath,
764+
O_RDWR |O_CREAT |O_TRUNC |PG_BINARY,0600);
765+
if (file <=0)
766+
elog(ERROR,"Failed to create temporary file %s",tempfilepath);
767+
}
760768

761769
/* Mark it for deletion at close or EOXact */
762770
VfdCache[file].fdstate |=FD_TEMPORARY;

‎src/backend/storage/lmgr/proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.100 2001/03/22 06:16:17 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.101 2001/05/25 15:34:50 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -261,6 +261,7 @@ InitProcess(void)
261261
MyProc->databaseId=MyDatabaseId;
262262
MyProc->xid=InvalidTransactionId;
263263
MyProc->xmin=InvalidTransactionId;
264+
MyProc->startOid=ShmemVariableCache->nextOid;
264265
MyProc->waitLock=NULL;
265266
MyProc->waitHolder=NULL;
266267
SHMQueueInit(&(MyProc->procHolders));

‎src/include/access/transam.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: transam.h,v 1.33 2001/05/14 20:30:21 momjian Exp $
10+
* $Id: transam.h,v 1.34 2001/05/25 15:34:50 momjian Exp $
1111
*
1212
* NOTES
1313
*Transaction System Version 101 now support proper oid
@@ -133,6 +133,7 @@ extern void GetNewTransactionId(TransactionId *xid);
133133
externvoidReadNewTransactionId(TransactionId*xid);
134134
externvoidGetNewObjectId(Oid*oid_return);
135135
externvoidCheckMaxObjectId(Oidassigned_oid);
136+
externOidGetMinStartupOid(void);
136137

137138
/* ----------------
138139
*global variable extern declarations

‎src/include/storage/fd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: fd.h,v 1.27 2001/02/18 04:39:42 tgl Exp $
10+
* $Id: fd.h,v 1.28 2001/05/25 15:34:50 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -39,6 +39,8 @@
3939
* FileSeek uses the standard UNIX lseek(2) flags.
4040
*/
4141

42+
#defineSORT_TEMP_DIR "pg_sorttemp"
43+
4244
typedefchar*FileName;
4345

4446
typedefintFile;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp