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

Commit87d95ca

Browse files
committed
Arrange for VACUUM to delete the init file that relcache.c uses
to save a little bit of backend startup time. This way, the firstbackend started after a VACUUM will rebuild the init file with up-to-datestatistics for the critical system indexes.
1 parentf7d25d2 commit87d95ca

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

‎src/backend/commands/vacuum.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.99 1999/04/12 16:56:36 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.100 1999/05/01 19:09:46 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -46,6 +46,7 @@
4646
#include"utils/inval.h"
4747
#include"utils/mcxt.h"
4848
#include"utils/portal.h"
49+
#include"utils/relcache.h"
4950
#include"utils/syscache.h"
5051

5152
#ifndefHAVE_GETRUSAGE
@@ -219,7 +220,20 @@ vc_init()
219220
staticvoid
220221
vc_shutdown()
221222
{
222-
/* on entry, not in a transaction */
223+
/* on entry, we are not in a transaction */
224+
225+
/* Flush the init file that relcache.c uses to save startup time.
226+
* The next backend startup will rebuild the init file with up-to-date
227+
* information from pg_class. This lets the optimizer see the stats that
228+
* we've collected for certain critical system indexes. See relcache.c
229+
* for more details.
230+
*
231+
* Ignore any failure to unlink the file, since it might not be there
232+
* if no backend has been started since the last vacuum...
233+
*/
234+
unlink(RELCACHE_INIT_FILENAME);
235+
236+
/* remove the vacuum cleaner lock file */
223237
if (unlink("pg_vlock")<0)
224238
elog(ERROR,"vacuum: can't destroy lock file!");
225239

‎src/backend/utils/cache/relcache.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.59 1999/02/21 03:49:36 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.60 1999/05/01 19:09:44 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -77,7 +77,6 @@
7777
#include"utils/memutils.h"
7878
#include"utils/rel.h"
7979
#include"utils/relcache.h"
80-
#include"utils/relcache.h"
8180
#include"utils/syscache.h"
8281

8382

@@ -87,13 +86,6 @@ static Relation RelationNameCacheGetRelation(char *relationName);
8786
staticvoidinit_irels(void);
8887
staticvoidwrite_irels(void);
8988

90-
/* ----------------
91-
*defines
92-
* ----------------
93-
*/
94-
#defineprivate static
95-
#defineINIT_FILENAME"pg_internal.init"
96-
9789
/* ----------------
9890
*externs
9991
* ----------------
@@ -1826,11 +1818,20 @@ RelCheckFetch(Relation relation)
18261818
* from an initialization file in the data/base/... directory.
18271819
*
18281820
* + If the initialization file isn't there, then we create the
1829-
* relationdescriptor using sequential scans and writeit to
1821+
* relationdescriptors using sequential scans and write'em to
18301822
* the initialization file for use by subsequent backends.
18311823
*
1832-
*This is complicated and interferes with system changes, but
1833-
*performance is so bad that we're willing to pay the tax.
1824+
*We could dispense with the initialization file and just build the
1825+
*critical reldescs the hard way on every backend startup, but that
1826+
*slows down backend startup noticeably if pg_class is large.
1827+
*
1828+
*As of v6.5, vacuum.c deletes the initialization file at completion
1829+
*of a VACUUM, so that it will be rebuilt at the next backend startup.
1830+
*This ensures that vacuum-collected stats for the system indexes
1831+
*will eventually get used by the optimizer --- otherwise the relcache
1832+
*entries for these indexes will show zero sizes forever, since the
1833+
*relcache entries are pinned in memory and will never be reloaded
1834+
*from pg_class.
18341835
*/
18351836

18361837
/* pg_attnumind, pg_classnameind, pg_classoidind */
@@ -1852,9 +1853,9 @@ init_irels(void)
18521853
intrelno;
18531854

18541855
#ifndef__CYGWIN32__
1855-
if ((fd=FileNameOpenFile(INIT_FILENAME,O_RDONLY,0600))<0)
1856+
if ((fd=FileNameOpenFile(RELCACHE_INIT_FILENAME,O_RDONLY,0600))<0)
18561857
#else
1857-
if ((fd=FileNameOpenFile(INIT_FILENAME,O_RDONLY |O_BINARY,0600))<0)
1858+
if ((fd=FileNameOpenFile(RELCACHE_INIT_FILENAME,O_RDONLY |O_BINARY,0600))<0)
18581859
#endif
18591860
{
18601861
write_irels();
@@ -2017,12 +2018,12 @@ write_irels(void)
20172018
RelationBuildDescInfobi;
20182019

20192020
#ifndef__CYGWIN32__
2020-
fd=FileNameOpenFile(INIT_FILENAME,O_WRONLY |O_CREAT |O_TRUNC,0600);
2021+
fd=FileNameOpenFile(RELCACHE_INIT_FILENAME,O_WRONLY |O_CREAT |O_TRUNC,0600);
20212022
#else
2022-
fd=FileNameOpenFile(INIT_FILENAME,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY,0600);
2023+
fd=FileNameOpenFile(RELCACHE_INIT_FILENAME,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY,0600);
20232024
#endif
20242025
if (fd<0)
2025-
elog(FATAL,"cannot create init file %s",INIT_FILENAME);
2026+
elog(FATAL,"cannot create init file %s",RELCACHE_INIT_FILENAME);
20262027

20272028
FileSeek(fd,0L,SEEK_SET);
20282029

‎src/include/utils/relcache.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: relcache.h,v 1.11 1999/02/13 23:22:31 momjian Exp $
9+
* $Id: relcache.h,v 1.12 1999/05/01 19:09:43 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -34,4 +34,10 @@ extern void RelationRegisterRelation(Relation relation);
3434
externvoidRelationPurgeLocalRelation(boolxactComitted);
3535
externvoidRelationInitialize(void);
3636

37+
/*
38+
* both vacuum.c and relcache.c need to know the name of the relcache init file
39+
*/
40+
41+
#defineRELCACHE_INIT_FILENAME"pg_internal.init"
42+
3743
#endif/* RELCACHE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp