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

Commit76668e6

Browse files
committed
Check the file system on postmaster startup and report any unreferenced
files in the server log.Heikki Linnakangas
1 parentb656150 commit76668e6

File tree

9 files changed

+302
-26
lines changed

9 files changed

+302
-26
lines changed

‎doc/src/sgml/maintenance.sgml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.41 2005/02/20 02:21:26 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.42 2005/05/02 18:26:52 momjian Exp $
33
-->
44

55
<chapter id="maintenance">
@@ -474,6 +474,23 @@ HINT: Stop the postmaster and use a standalone backend to VACUUM in "mydb".
474474
</para>
475475
</sect1>
476476

477+
<sect1 id="check-files-after-crash">
478+
<title>Check files after crash</title>
479+
480+
<indexterm zone="check-files-after-crash">
481+
<primary>stale file</primary>
482+
</indexterm>
483+
484+
<para>
485+
<productname>PostgreSQL</productname> recovers automatically after crash
486+
using the write-ahead log (see <xref linkend="wal">) and no manual
487+
operations are normally needed. However, if there was a transaction running
488+
when the crash occured that created or dropped a relation, the
489+
transaction might have left a stale file in the data directory. If this
490+
happens, you will get a notice in the log file stating which files can be
491+
deleted.
492+
</para>
493+
</sect1>
477494

478495
<sect1 id="logfile-maintenance">
479496
<title>Log File Maintenance</title>

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.189 2005/04/28 21:47:10 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.190 2005/05/02 18:26:52 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -43,6 +43,7 @@
4343
#include"utils/builtins.h"
4444
#include"utils/guc.h"
4545
#include"utils/relcache.h"
46+
#include"utils/flatfiles.h"
4647

4748

4849
/*
@@ -4525,6 +4526,8 @@ StartupXLOG(void)
45254526

45264527
CreateCheckPoint(true, true);
45274528

4529+
CheckStaleRelFiles();
4530+
45284531
/*
45294532
* Close down recovery environment
45304533
*/
@@ -4536,6 +4539,12 @@ StartupXLOG(void)
45364539
*/
45374540
remove_backup_label();
45384541
}
4542+
else
4543+
{
4544+
XLogInitRelationCache();
4545+
CheckStaleRelFiles();
4546+
XLogCloseRelationCache();
4547+
}
45394548

45404549
/*
45414550
* Preallocate additional log files, if wanted.

‎src/backend/catalog/catalog.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.59 2005/04/14 20:03:23 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.60 2005/05/02 18:26:53 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -106,6 +106,39 @@ GetDatabasePath(Oid dbNode, Oid spcNode)
106106
returnpath;
107107
}
108108

109+
/*
110+
* GetTablespacePath- construct path to a tablespace symbolic link
111+
*
112+
* Result is a palloc'd string.
113+
*
114+
* XXX this must agree with relpath and GetDatabasePath!
115+
*/
116+
char*
117+
GetTablespacePath(OidspcNode)
118+
{
119+
intpathlen;
120+
char*path;
121+
122+
Assert(spcNode!=GLOBALTABLESPACE_OID);
123+
124+
if (spcNode==DEFAULTTABLESPACE_OID)
125+
{
126+
/* The default tablespace is {datadir}/base */
127+
pathlen=strlen(DataDir)+5+1;
128+
path= (char*)palloc(pathlen);
129+
snprintf(path,pathlen,"%s/base",
130+
DataDir);
131+
}
132+
else
133+
{
134+
/* All other tablespaces have symlinks in pg_tblspc */
135+
pathlen=strlen(DataDir)+11+OIDCHARS+1;
136+
path= (char*)palloc(pathlen);
137+
snprintf(path,pathlen,"%s/pg_tblspc/%u",
138+
DataDir,spcNode);
139+
}
140+
returnpath;
141+
}
109142

110143
/*
111144
* IsSystemRelation

‎src/backend/commands/tablespace.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.17 2005/04/14 20:03:24 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.18 2005/05/02 18:26:53 momjian Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -341,8 +341,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
341341
/*
342342
* All seems well, create the symlink
343343
*/
344-
linkloc= (char*)palloc(strlen(DataDir)+11+10+1);
345-
sprintf(linkloc,"%s/pg_tblspc/%u",DataDir,tablespaceoid);
344+
linkloc=GetTablespacePath(tablespaceoid);
346345

347346
if (symlink(location,linkloc)<0)
348347
ereport(ERROR,
@@ -495,8 +494,7 @@ remove_tablespace_directories(Oid tablespaceoid, bool redo)
495494
char*subfile;
496495
structstatst;
497496

498-
location= (char*)palloc(strlen(DataDir)+11+10+1);
499-
sprintf(location,"%s/pg_tblspc/%u",DataDir,tablespaceoid);
497+
location=GetTablespacePath(tablespaceoid);
500498

501499
/*
502500
* Check if the tablespace still contains any files. We try to rmdir
@@ -1036,8 +1034,7 @@ tblspc_redo(XLogRecPtr lsn, XLogRecord *record)
10361034
set_short_version(location);
10371035

10381036
/* Create the symlink if not already present */
1039-
linkloc= (char*)palloc(strlen(DataDir)+11+10+1);
1040-
sprintf(linkloc,"%s/pg_tblspc/%u",DataDir,xlrec->ts_id);
1037+
linkloc=GetTablespacePath(xlrec->ts_id);
10411038

10421039
if (symlink(location,linkloc)<0)
10431040
{

‎src/backend/utils/adt/misc.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.40 2004/12/31 22:01:22 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.41 2005/05/02 18:26:53 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -26,6 +26,7 @@
2626
#include"funcapi.h"
2727
#include"catalog/pg_type.h"
2828
#include"catalog/pg_tablespace.h"
29+
#include"catalog/catalog.h"
2930

3031
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
3132

@@ -144,11 +145,6 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
144145

145146
fctx=palloc(sizeof(ts_db_fctx));
146147

147-
/*
148-
* size = path length + tablespace dirname length + 2 dir sep
149-
* chars + oid + terminator
150-
*/
151-
fctx->location= (char*)palloc(strlen(DataDir)+11+10+1);
152148
if (tablespaceOid==GLOBALTABLESPACE_OID)
153149
{
154150
fctx->dirdesc=NULL;
@@ -157,12 +153,7 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
157153
}
158154
else
159155
{
160-
if (tablespaceOid==DEFAULTTABLESPACE_OID)
161-
sprintf(fctx->location,"%s/base",DataDir);
162-
else
163-
sprintf(fctx->location,"%s/pg_tblspc/%u",DataDir,
164-
tablespaceOid);
165-
156+
fctx->location=GetTablespacePath(tablespaceOid);
166157
fctx->dirdesc=AllocateDir(fctx->location);
167158

168159
if (!fctx->dirdesc)

‎src/backend/utils/init/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Makefile for utils/init
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/utils/init/Makefile,v 1.18 2005/02/20 02:22:00 tgl Exp $
7+
# $PostgreSQL: pgsql/src/backend/utils/init/Makefile,v 1.19 2005/05/02 18:26:53 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/utils/init
1212
top_builddir = ../../../..
1313
include$(top_builddir)/src/Makefile.global
1414

15-
OBJS = flatfiles.o globals.o miscinit.o postinit.o
15+
OBJS = flatfiles.o globals.o miscinit.o postinit.o checkfiles.o
1616

1717
all: SUBSYS.o
1818

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp