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.
This commit is contained in:
Tom Lane 2007-07-08 22:23:16 +00:00
parent 8331c11f3f
commit b09cb0cf12
3 changed files with 13 additions and 11 deletions

View File

@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.160 2007/06/28 00:02:38 tgl Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.161 2007/07/08 22:23:16 tgl Exp $
* ----------
*/
#include "postgres.h"
@ -964,8 +964,12 @@ pgstat_drop_database(Oid databaseid)
* Tell the collector that we just dropped a relation.
* (If the message gets lost, we will still clean the dead entry eventually
* via future invocations of pgstat_vacuum_tabstat().)
*
* Currently not used for lack of any good place to call it; we rely
* entirely on pgstat_vacuum_tabstat() to clean out stats for dead rels.
* ----------
*/
#ifdef NOT_USED
void
pgstat_drop_relation(Oid relid)
{
@ -984,6 +988,7 @@ pgstat_drop_relation(Oid relid)
msg.m_databaseid = MyDatabaseId;
pgstat_send(&msg, len);
}
#endif /* NOT_USED */
/* ----------

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.103 2007/01/05 22:19:39 momjian Exp $
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.104 2007/07/08 22:23:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -20,11 +20,11 @@
#include "access/xact.h"
#include "access/xlogutils.h"
#include "commands/tablespace.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/freespace.h"
#include "storage/ipc.h"
#include "storage/smgr.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
@ -452,13 +452,11 @@ smgr_internal_unlink(RelFileNode rnode, int which, bool isTemp, bool isRedo)
FreeSpaceMapForgetRel(&rnode);
/*
* Tell the stats collector to forget it immediately, too. Skip this in
* recovery mode, since the stats collector likely isn't running (and if
* it is, pgstat.c will get confused because we aren't a real backend
* process).
* It'd be nice to tell the stats collector to forget it immediately, too.
* But we can't because we don't know the OID (and in cases involving
* relfilenode swaps, it's not always clear which table OID to forget,
* anyway).
*/
if (!InRecovery)
pgstat_drop_relation(rnode.relNode);
/*
* And delete the physical files.

View File

@ -5,7 +5,7 @@
*
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.63 2007/06/28 00:02:40 tgl Exp $
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.64 2007/07/08 22:23:16 tgl Exp $
* ----------
*/
#ifndef PGSTAT_H
@ -486,7 +486,6 @@ extern void pgstat_ping(void);
extern void pgstat_report_tabstat(bool force);
extern void pgstat_vacuum_tabstat(void);
extern void pgstat_drop_database(Oid databaseid);
extern void pgstat_drop_relation(Oid relid);
extern void pgstat_clear_snapshot(void);
extern void pgstat_reset_counters(void);