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

Commit8d675c8

Browse files
committed
pgstat's on-proc-exit hook has to execute after the last transaction commit
or abort within a backend; rearrange InitPostgres processing to make it so.Revealed by just-added Asserts along with ECPG regression tests (hm, I wonderwhy the core regression tests didn't expose it?). This possibly is anotherreason for missing stats updates ...
1 parent77947c5 commit8d675c8

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2007, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.156 2007/05/2703:50:39 tgl Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.157 2007/05/2705:37:49 tgl Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -1771,28 +1771,45 @@ CreateSharedBackendStatus(void)
17711771
}
17721772

17731773

1774+
/* ----------
1775+
* pgstat_initialize() -
1776+
*
1777+
*Initialize pgstats state, and set up our on-proc-exit hook.
1778+
*Called from InitPostgres. MyBackendId must be set,
1779+
*but we must not have started any transaction yet (since the
1780+
*exit hook must run after the last transaction exit).
1781+
* ----------
1782+
*/
1783+
void
1784+
pgstat_initialize(void)
1785+
{
1786+
/* Initialize MyBEEntry */
1787+
Assert(MyBackendId >=1&&MyBackendId <=MaxBackends);
1788+
MyBEEntry=&BackendStatusArray[MyBackendId-1];
1789+
1790+
/* Set up a process-exit hook to clean up */
1791+
on_shmem_exit(pgstat_beshutdown_hook,0);
1792+
}
1793+
17741794
/* ----------
17751795
* pgstat_bestart() -
17761796
*
1777-
*Initialize this backend's entry in the PgBackendStatus array,
1778-
*and set up an on-proc-exit hook that will clear it again.
1779-
*Called from InitPostgres. MyBackendId and MyDatabaseId must be set.
1797+
*Initialize this backend's entry in the PgBackendStatus array.
1798+
*Called from InitPostgres. MyDatabaseId and session userid must be set
1799+
*(hence, this cannot be combined with pgstat_initialize).
17801800
* ----------
17811801
*/
17821802
void
17831803
pgstat_bestart(void)
17841804
{
1785-
volatilePgBackendStatus*beentry;
17861805
TimestampTzproc_start_timestamp;
17871806
Oiduserid;
17881807
SockAddrclientaddr;
1789-
1790-
Assert(MyBackendId >=1&&MyBackendId <=MaxBackends);
1791-
MyBEEntry=&BackendStatusArray[MyBackendId-1];
1808+
volatilePgBackendStatus*beentry;
17921809

17931810
/*
1794-
* To minimize the time spent modifying the entry, fetch all the needed
1795-
* data first.
1811+
* To minimize the time spent modifying thePgBackendStatusentry,
1812+
*fetch all the neededdata first.
17961813
*
17971814
* If we have a MyProcPort, use its session start time (for consistency,
17981815
* and to save a kernel call).
@@ -1839,11 +1856,6 @@ pgstat_bestart(void)
18391856

18401857
beentry->st_changecount++;
18411858
Assert((beentry->st_changecount&1)==0);
1842-
1843-
/*
1844-
* Set up a process-exit hook to clean up.
1845-
*/
1846-
on_shmem_exit(pgstat_beshutdown_hook,0);
18471859
}
18481860

18491861
/*

‎src/backend/utils/init/postinit.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.175 2007/03/13 00:33:42 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.176 2007/05/27 05:37:49 tgl Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -435,6 +435,10 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
435435
/* Initialize portal manager */
436436
EnablePortalManager();
437437

438+
/* Initialize stats collection --- must happen before first xact */
439+
if (!bootstrap)
440+
pgstat_initialize();
441+
438442
/*
439443
* Set up process-exit callback to do pre-shutdown cleanup. This has to
440444
* be after we've initialized all the low-level modules like the buffer
@@ -587,7 +591,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
587591
/* initialize client encoding */
588592
InitializeClientEncoding();
589593

590-
/*initialize statistics collection for this backend */
594+
/*report this backend in the PgBackendStatus array */
591595
if (!bootstrap)
592596
pgstat_bestart();
593597

‎src/include/pgstat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*Copyright (c) 2001-2007, PostgreSQL Global Development Group
77
*
8-
*$PostgreSQL: pgsql/src/include/pgstat.h,v 1.59 2007/05/2703:50:39 tgl Exp $
8+
*$PostgreSQL: pgsql/src/include/pgstat.h,v 1.60 2007/05/2705:37:50 tgl Exp $
99
* ----------
1010
*/
1111
#ifndefPGSTAT_H
@@ -501,7 +501,9 @@ extern void pgstat_report_analyze(Oid tableoid, bool shared,
501501
PgStat_Counterlivetuples,
502502
PgStat_Counterdeadtuples);
503503

504+
externvoidpgstat_initialize(void);
504505
externvoidpgstat_bestart(void);
506+
505507
externvoidpgstat_report_activity(constchar*what);
506508
externvoidpgstat_report_txn_timestamp(TimestampTztstamp);
507509
externvoidpgstat_report_waiting(boolwaiting);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp