Remove the pgstat_drop_relation() call from smgr_internal_unlink(), because
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 8 Jul 2007 22:23:25 +0000 (22:23 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 8 Jul 2007 22:23:25 +0000 (22:23 +0000)
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.

src/backend/postmaster/pgstat.c
src/backend/storage/smgr/smgr.c
src/include/pgstat.h

index ffeb9b584c6b8e65f067b0f7e4c9cc6feacdbcde..9c11f0df5d28d1f716a564f9352e04ffac273daf 100644 (file)
@@ -841,8 +841,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)
 {
@@ -861,6 +865,7 @@ pgstat_drop_relation(Oid relid)
        msg.m_databaseid = MyDatabaseId;
        pgstat_send(&msg, len);
 }
+#endif /* NOT_USED */
 
 
 /* ----------
index 14bc295b8abfa7a37423928c20018c0a138a15b0..79e93df12aadf1f1d0ba53c66b360eb422ccfd59 100644 (file)
 #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"
 
 
@@ -471,13 +471,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.
index 631a25933d702703e41fdcecd40000b8f887c939..c279ab797779267f485c4dbc11e2688c872e0d60 100644 (file)
@@ -377,7 +377,6 @@ extern void pgstat_ping(void);
 
 extern void pgstat_report_tabstat(void);
 extern void pgstat_vacuum_tabstat(void);
-extern void pgstat_drop_relation(Oid relid);
 
 extern void pgstat_reset_counters(void);