Skip to content

Commit 1832cef

Browse files
committed
Fix pgstat_report_waiting() to not dump core if called before
pgstat_bestart() has been called; else any lock-block occurring during InitPostgres() is disastrous. I believe this explains recent wasp regression failure; at least it explains the crash I got while trying to duplicate the problem. I also made pgstat_report_activity() safe against the same scenario, just in case. The report_waiting hazard was created by my patch of 19-Aug to include waiting status in pg_stat_activity.
1 parent ae28cfe commit 1832cef

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2006, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.137 2006/08/19 01:36:24 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.138 2006/08/28 19:38:09 tgl Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -1384,7 +1384,7 @@ pgstat_bestart(void)
13841384
static void
13851385
pgstat_beshutdown_hook(int code, Datum arg)
13861386
{
1387-
volatile PgBackendStatus *beentry;
1387+
volatile PgBackendStatus *beentry = MyBEEntry;
13881388

13891389
pgstat_report_tabstat();
13901390

@@ -1393,7 +1393,6 @@ pgstat_beshutdown_hook(int code, Datum arg)
13931393
* st_changecount before and after. We use a volatile pointer here
13941394
* to ensure the compiler doesn't try to get cute.
13951395
*/
1396-
beentry = MyBEEntry;
13971396
beentry->st_changecount++;
13981397

13991398
beentry->st_procpid = 0; /* mark invalid */
@@ -1413,11 +1412,11 @@ pgstat_beshutdown_hook(int code, Datum arg)
14131412
void
14141413
pgstat_report_activity(const char *cmd_str)
14151414
{
1416-
volatile PgBackendStatus *beentry;
1415+
volatile PgBackendStatus *beentry = MyBEEntry;
14171416
TimestampTz start_timestamp;
14181417
int len;
14191418

1420-
if (!pgstat_collect_querystring)
1419+
if (!pgstat_collect_querystring || !beentry)
14211420
return;
14221421

14231422
/*
@@ -1434,7 +1433,6 @@ pgstat_report_activity(const char *cmd_str)
14341433
* st_changecount before and after. We use a volatile pointer here
14351434
* to ensure the compiler doesn't try to get cute.
14361435
*/
1437-
beentry = MyBEEntry;
14381436
beentry->st_changecount++;
14391437

14401438
beentry->st_activity_start_timestamp = start_timestamp;
@@ -1450,23 +1448,24 @@ pgstat_report_activity(const char *cmd_str)
14501448
* pgstat_report_waiting() -
14511449
*
14521450
* Called from lock manager to report beginning or end of a lock wait.
1451+
*
1452+
* NB: this *must* be able to survive being called before MyBEEntry has been
1453+
* initialized.
14531454
* ----------
14541455
*/
14551456
void
14561457
pgstat_report_waiting(bool waiting)
14571458
{
1458-
volatile PgBackendStatus *beentry;
1459+
volatile PgBackendStatus *beentry = MyBEEntry;
14591460

1460-
if (!pgstat_collect_querystring)
1461+
if (!pgstat_collect_querystring || !beentry)
14611462
return;
14621463

14631464
/*
14641465
* Since this is a single-byte field in a struct that only this process
14651466
* may modify, there seems no need to bother with the st_changecount
14661467
* protocol. The update must appear atomic in any case.
14671468
*/
1468-
beentry = MyBEEntry;
1469-
14701469
beentry->st_waiting = waiting;
14711470
}
14721471

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy