Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b09cb0c

Browse files
committed
Remove the pgstat_drop_relation() call from smgr_internal_unlink(), because
we don't know at that point which relation OID to tell pgstat to forget. The code was passing the relfilenode, which is incorrect, and could possibly cause some other relation's stats to be zeroed out. While we could try to clean this up, it seems much simpler and more reliable to let the next invocation of pgstat_vacuum_tabstat() fix things; which indeed is how it worked before I introduced the buggy code into 8.1.3 and later :-(. Problem noticed by Itagaki Takahiro, fix is per subsequent discussion.
1 parent 8331c11 commit b09cb0c

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/backend/postmaster/pgstat.c

+6-1
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.160 2007/06/28 00:02:38 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.161 2007/07/08 22:23:16 tgl Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -964,8 +964,12 @@ pgstat_drop_database(Oid databaseid)
964964
* Tell the collector that we just dropped a relation.
965965
* (If the message gets lost, we will still clean the dead entry eventually
966966
* via future invocations of pgstat_vacuum_tabstat().)
967+
*
968+
* Currently not used for lack of any good place to call it; we rely
969+
* entirely on pgstat_vacuum_tabstat() to clean out stats for dead rels.
967970
* ----------
968971
*/
972+
#ifdef NOT_USED
969973
void
970974
pgstat_drop_relation(Oid relid)
971975
{
@@ -984,6 +988,7 @@ pgstat_drop_relation(Oid relid)
984988
msg.m_databaseid = MyDatabaseId;
985989
pgstat_send(&msg, len);
986990
}
991+
#endif /* NOT_USED */
987992

988993

989994
/* ----------

src/backend/storage/smgr/smgr.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.103 2007/01/05 22:19:39 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.104 2007/07/08 22:23:16 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -20,11 +20,11 @@
2020
#include "access/xact.h"
2121
#include "access/xlogutils.h"
2222
#include "commands/tablespace.h"
23-
#include "pgstat.h"
2423
#include "storage/bufmgr.h"
2524
#include "storage/freespace.h"
2625
#include "storage/ipc.h"
2726
#include "storage/smgr.h"
27+
#include "utils/hsearch.h"
2828
#include "utils/memutils.h"
2929

3030

@@ -452,13 +452,11 @@ smgr_internal_unlink(RelFileNode rnode, int which, bool isTemp, bool isRedo)
452452
FreeSpaceMapForgetRel(&rnode);
453453

454454
/*
455-
* Tell the stats collector to forget it immediately, too. Skip this in
456-
* recovery mode, since the stats collector likely isn't running (and if
457-
* it is, pgstat.c will get confused because we aren't a real backend
458-
* process).
455+
* It'd be nice to tell the stats collector to forget it immediately, too.
456+
* But we can't because we don't know the OID (and in cases involving
457+
* relfilenode swaps, it's not always clear which table OID to forget,
458+
* anyway).
459459
*/
460-
if (!InRecovery)
461-
pgstat_drop_relation(rnode.relNode);
462460

463461
/*
464462
* And delete the physical files.

src/include/pgstat.h

+1-2
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.63 2007/06/28 00:02:40 tgl Exp $
8+
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.64 2007/07/08 22:23:16 tgl Exp $
99
* ----------
1010
*/
1111
#ifndef PGSTAT_H
@@ -486,7 +486,6 @@ extern void pgstat_ping(void);
486486
extern void pgstat_report_tabstat(bool force);
487487
extern void pgstat_vacuum_tabstat(void);
488488
extern void pgstat_drop_database(Oid databaseid);
489-
extern void pgstat_drop_relation(Oid relid);
490489

491490
extern void pgstat_clear_snapshot(void);
492491
extern void pgstat_reset_counters(void);

0 commit comments

Comments
 (0)