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

Commit349f40b

Browse files
committed
Rearrange backend startup sequence so that ShmemIndexLock can become
an LWLock instead of a spinlock. This hardly matters on Unix machinesbut should improve startup performance on Windows (or any port usingEXEC_BACKEND). Per previous discussion.
1 parente0078ea commit349f40b

File tree

15 files changed

+414
-259
lines changed

15 files changed

+414
-259
lines changed

‎src/backend/bootstrap/bootstrap.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.209 2005/11/22 18:17:07 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.210 2006/01/04 21:06:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -381,22 +381,19 @@ BootstrapMain(int argc, char *argv[])
381381
BaseInit();
382382

383383
/*
384-
* We aren't going to do the full InitPostgres pushups, but there are a
385-
* couple of things that need to get lit up even in a dummy process.
384+
* When we are a dummy process, we aren't going to do the full
385+
* InitPostgres pushups, but there are a couple of things that need
386+
* to get lit up even in a dummy process.
386387
*/
387388
if (IsUnderPostmaster)
388389
{
389-
/* set up proc.c to get use of LWLocks */
390-
switch (xlogop)
391-
{
392-
caseBS_XLOG_BGWRITER:
393-
InitDummyProcess(DUMMY_PROC_BGWRITER);
394-
break;
395-
396-
default:
397-
InitDummyProcess(DUMMY_PROC_DEFAULT);
398-
break;
399-
}
390+
/*
391+
* Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
392+
* this was already done by SubPostmasterMain().
393+
*/
394+
#ifndefEXEC_BACKEND
395+
InitDummyProcess();
396+
#endif
400397

401398
/* finish setting up bufmgr.c */
402399
InitBufferPoolBackend();
@@ -437,11 +434,17 @@ BootstrapMain(int argc, char *argv[])
437434
proc_exit(1);
438435
}
439436

437+
/*
438+
* We must be getting invoked for bootstrap mode
439+
*/
440+
Assert(!IsUnderPostmaster);
441+
440442
SetProcessingMode(BootstrapProcessing);
441443

442444
/*
443-
* backend initialization
445+
*Dobackend-like initialization for bootstrap mode
444446
*/
447+
InitProcess();
445448
(void)InitPostgres(dbname,NULL);
446449

447450
/*

‎src/backend/postmaster/autovacuum.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.8 2005/11/28 17:23:11 alvherre Exp $
13+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.9 2006/01/04 21:06:31 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -167,6 +167,9 @@ autovac_start(void)
167167
/* Close the postmaster's sockets */
168168
ClosePostmasterPorts(false);
169169

170+
/* Lose the postmaster's on-exit routines */
171+
on_exit_reset();
172+
170173
AutoVacMain(0,NULL);
171174
break;
172175
#endif
@@ -230,9 +233,6 @@ AutoVacMain(int argc, char *argv[])
230233
/* reset MyProcPid */
231234
MyProcPid=getpid();
232235

233-
/* Lose the postmaster's on-exit routines */
234-
on_exit_reset();
235-
236236
/* Identify myself via ps */
237237
init_ps_display("autovacuum process","","");
238238
set_ps_display("");
@@ -268,6 +268,16 @@ AutoVacMain(int argc, char *argv[])
268268
/* Early initialization */
269269
BaseInit();
270270

271+
/*
272+
* Create a per-backend PGPROC struct in shared memory, except in
273+
* the EXEC_BACKEND case where this was done in SubPostmasterMain.
274+
* We must do this before we can use LWLocks (and in the EXEC_BACKEND
275+
* case we already had to do some stuff with LWLocks).
276+
*/
277+
#ifndefEXEC_BACKEND
278+
InitProcess();
279+
#endif
280+
271281
/*
272282
* If an exception is encountered, processing resumes here.
273283
*

‎src/backend/postmaster/pgarch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*
2121
* IDENTIFICATION
22-
* $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.18 2005/10/15 02:49:23 momjian Exp $
22+
* $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.19 2006/01/04 21:06:31 tgl Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -158,6 +158,9 @@ pgarch_start(void)
158158
/* Close the postmaster's sockets */
159159
ClosePostmasterPorts(false);
160160

161+
/* Lose the postmaster's on-exit routines */
162+
on_exit_reset();
163+
161164
/* Drop our connection to postmaster's shared memory, as well */
162165
PGSharedMemoryDetach();
163166

@@ -219,9 +222,6 @@ PgArchiverMain(int argc, char *argv[])
219222

220223
MyProcPid=getpid();/* reset MyProcPid */
221224

222-
/* Lose the postmaster's on-exit routines */
223-
on_exit_reset();
224-
225225
/*
226226
* Ignore all signals usually bound to some action in the postmaster,
227227
* except for SIGHUP, SIGUSR1 and SIGQUIT.

‎src/backend/postmaster/pgstat.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2005, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.118 2006/01/03 19:54:08 momjian Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.119 2006/01/04 21:06:31 tgl Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -147,6 +147,7 @@ static intpgStatNumBackends = 0;
147147

148148
staticvolatileboolneed_statwrite;
149149

150+
150151
/* ----------
151152
* Local function forward declarations
152153
* ----------
@@ -608,6 +609,9 @@ pgstat_start(void)
608609
/* Close the postmaster's sockets */
609610
ClosePostmasterPorts(false);
610611

612+
/* Lose the postmaster's on-exit routines */
613+
on_exit_reset();
614+
611615
/* Drop our connection to postmaster's shared memory, as well */
612616
PGSharedMemoryDetach();
613617

@@ -1465,9 +1469,6 @@ PgstatBufferMain(int argc, char *argv[])
14651469

14661470
MyProcPid=getpid();/* reset MyProcPid */
14671471

1468-
/* Lose the postmaster's on-exit routines */
1469-
on_exit_reset();
1470-
14711472
/*
14721473
* Ignore all signals usually bound to some action in the postmaster,
14731474
* except for SIGCHLD and SIGQUIT --- see pgstat_recvbuffer.
@@ -1551,10 +1552,10 @@ PgstatCollectorMain(int argc, char *argv[])
15511552
fd_setrfds;
15521553
intreadPipe;
15531554
intlen=0;
1554-
structitimervaltimeval;
1555+
structitimervaltimeout;
15551556
HASHCTLhash_ctl;
15561557
boolneed_timer= false;
1557-
1558+
15581559
MyProcPid=getpid();/* reset MyProcPid */
15591560

15601561
/*
@@ -1597,11 +1598,15 @@ PgstatCollectorMain(int argc, char *argv[])
15971598
init_ps_display("stats collector process","","");
15981599
set_ps_display("");
15991600

1601+
/*
1602+
* Arrange to write the initial status file right away
1603+
*/
16001604
need_statwrite= true;
16011605

1602-
MemSet(&timeval,0,sizeof(structitimerval));
1603-
timeval.it_value.tv_sec=PGSTAT_STAT_INTERVAL /1000;
1604-
timeval.it_value.tv_usec=PGSTAT_STAT_INTERVAL %1000;
1606+
/* Preset the delay between status file writes */
1607+
MemSet(&timeout,0,sizeof(structitimerval));
1608+
timeout.it_value.tv_sec=PGSTAT_STAT_INTERVAL /1000;
1609+
timeout.it_value.tv_usec=PGSTAT_STAT_INTERVAL %1000;
16051610

16061611
/*
16071612
* Read in an existing statistics stats file or initialize the stats to
@@ -1634,6 +1639,12 @@ PgstatCollectorMain(int argc, char *argv[])
16341639
*/
16351640
for (;;)
16361641
{
1642+
/*
1643+
* If time to write the stats file, do so. Note that the alarm
1644+
* interrupt isn't re-enabled immediately, but only after we next
1645+
* receive a stats message; so no cycles are wasted when there is
1646+
* nothing going on.
1647+
*/
16371648
if (need_statwrite)
16381649
{
16391650
pgstat_write_statsfile();
@@ -1776,11 +1787,16 @@ PgstatCollectorMain(int argc, char *argv[])
17761787
*/
17771788
pgStatNumMessages++;
17781789

1790+
/*
1791+
* If this is the first message after we wrote the stats file the
1792+
* last time, enable the alarm interrupt to make it be written
1793+
* again later.
1794+
*/
17791795
if (need_timer)
17801796
{
1781-
if (setitimer(ITIMER_REAL,&timeval,NULL))
1797+
if (setitimer(ITIMER_REAL,&timeout,NULL))
17821798
ereport(ERROR,
1783-
(errmsg("unable to set statistics collector timer: %m")));
1799+
(errmsg("could not set statistics collector timer: %m")));
17841800
need_timer= false;
17851801
}
17861802
}
@@ -1806,6 +1822,7 @@ PgstatCollectorMain(int argc, char *argv[])
18061822
}
18071823

18081824

1825+
/* SIGALRM signal handler for collector process */
18091826
staticvoid
18101827
force_statwrite(SIGNAL_ARGS)
18111828
{
@@ -1913,8 +1930,10 @@ pgstat_recvbuffer(void)
19131930
/*
19141931
* Wait for some work to do; but not for more than 10 seconds. (This
19151932
* determines how quickly we will shut down after an ungraceful
1916-
* postmaster termination; so it needn't be very fast.) struct timeout
1917-
* is modified by some operating systems.
1933+
* postmaster termination; so it needn't be very fast.)
1934+
*
1935+
* struct timeout is modified by select() on some operating systems,
1936+
* so re-fill it each time.
19181937
*/
19191938
timeout.tv_sec=10;
19201939
timeout.tv_usec=0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp