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

Commit04011cc

Browse files
committed
Allow backends to start up without use of the flat-file copy of pg_database.
To make this work in the base case, pg_database now has a nailed-in-cacherelation descriptor that is initialized using hardwired knowledge inrelcache.c. This means pg_database is added to the set of relations thatneed to have a Schema_pg_xxx macro maintained in pg_attribute.h. When thispath is taken, we'll have to do a seqscan of pg_database to find the rowwe need.In the normal case, we are able to do an indexscan to find the database's rowby name. This is made possible by storing a global relcache init file thatdescribes only the shared catalogs and their indexes (and therefore is usableby all backends in any database). A new backend loads this cache file,finds its database OID after an indexscan on pg_database, and then loadsthe local relcache init file for that database.This change should effectively eliminate number of databases as a factorin backend startup time, even with large numbers of databases. However,the real reason for doing it is as a first step towards getting rid ofthe flat files altogether. There are still several other sub-projectsto be tackled before that can happen.
1 parenta1f0c9b commit04011cc

File tree

13 files changed

+606
-354
lines changed

13 files changed

+606
-354
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, 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.347 2009/08/08 16:39:17 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.348 2009/08/12 20:53:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -5249,6 +5249,16 @@ StartupXLOG(void)
52495249
*/
52505250
ValidateXLOGDirectoryStructure();
52515251

5252+
/*
5253+
* Clear out any old relcache cache files. This is *necessary* if we
5254+
* do any WAL replay, since that would probably result in the cache files
5255+
* being out of sync with database reality. In theory we could leave
5256+
* them in place if the database had been cleanly shut down, but it
5257+
* seems safest to just remove them always and let them be rebuilt
5258+
* during the first backend startup.
5259+
*/
5260+
RelationCacheInitFileRemove();
5261+
52525262
/*
52535263
* Initialize on the assumption we want to recover to the same timeline
52545264
* that's active according to pg_control.

‎src/backend/postmaster/autovacuum.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
*
5757
* IDENTIFICATION
58-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.100 2009/07/31 20:26:22 tgl Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.101 2009/08/12 20:53:30 tgl Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -1602,7 +1602,7 @@ AutoVacWorkerMain(int argc, char *argv[])
16021602

16031603
if (OidIsValid(dbid))
16041604
{
1605-
char*dbname;
1605+
chardbname[NAMEDATALEN];
16061606

16071607
/*
16081608
* Report autovac startup to the stats collector. We deliberately do
@@ -1620,7 +1620,7 @@ AutoVacWorkerMain(int argc, char *argv[])
16201620
* Note: if we have selected a just-deleted database (due to using
16211621
* stale stats info), we'll fail and exit here.
16221622
*/
1623-
InitPostgres(NULL,dbid,NULL,&dbname);
1623+
InitPostgres(NULL,dbid,NULL,dbname);
16241624
SetProcessingMode(NormalProcessing);
16251625
set_ps_display(dbname, false);
16261626
ereport(DEBUG1,

‎src/backend/postmaster/pgstat.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2009, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.189 2009/06/11 14:49:01 momjian Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.190 2009/08/12 20:53:30 tgl Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -2138,6 +2138,7 @@ CreateSharedBackendStatus(void)
21382138
*Called from InitPostgres. MyBackendId must be set,
21392139
*but we must not have started any transaction yet (since the
21402140
*exit hook must run after the last transaction exit).
2141+
*NOTE: MyDatabaseId isn't set yet; so the shutdown hook has to be careful.
21412142
* ----------
21422143
*/
21432144
void
@@ -2232,7 +2233,14 @@ pgstat_beshutdown_hook(int code, Datum arg)
22322233
{
22332234
volatilePgBackendStatus*beentry=MyBEEntry;
22342235

2235-
pgstat_report_stat(true);
2236+
/*
2237+
* If we got as far as discovering our own database ID, we can report
2238+
* what we did to the collector. Otherwise, we'd be sending an invalid
2239+
* database ID, so forget it. (This means that accesses to pg_database
2240+
* during failed backend starts might never get counted.)
2241+
*/
2242+
if (OidIsValid(MyDatabaseId))
2243+
pgstat_report_stat(true);
22362244

22372245
/*
22382246
* Clear my status entry, following the protocol of bumping st_changecount

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.207 2009/06/11 14:49:02 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.208 2009/08/12 20:53:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -332,22 +332,14 @@ InitProcess(void)
332332
* InitProcessPhase2 -- make MyProc visible in the shared ProcArray.
333333
*
334334
* This is separate from InitProcess because we can't acquire LWLocks until
335-
* we've created a PGPROC, but in the EXEC_BACKEND casethere is a good deal
336-
*of stuff to be donebefore this step that will require LWLock access.
335+
* we've created a PGPROC, but in the EXEC_BACKEND caseProcArrayAdd won't
336+
*work until after we've doneCreateSharedMemoryAndSemaphores.
337337
*/
338338
void
339339
InitProcessPhase2(void)
340340
{
341341
Assert(MyProc!=NULL);
342342

343-
/*
344-
* We should now know what database we're in, so advertise that. (We need
345-
* not do any locking here, since no other backend can yet see our
346-
* PGPROC.)
347-
*/
348-
Assert(OidIsValid(MyDatabaseId));
349-
MyProc->databaseId=MyDatabaseId;
350-
351343
/*
352344
* Add our PGPROC to the PGPROC array in shared memory.
353345
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp