13
13
*
14
14
* Copyright (c) 2001-2009, PostgreSQL Global Development Group
15
15
*
16
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.190 2009/08/12 20:53:30 tgl Exp $
16
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.191 2009/09/04 22:32:33 tgl Exp $
17
17
* ----------
18
18
*/
19
19
#include "postgres.h"
@@ -246,6 +246,8 @@ static void pgstat_beshutdown_hook(int code, Datum arg);
246
246
static void pgstat_sighup_handler (SIGNAL_ARGS );
247
247
248
248
static PgStat_StatDBEntry * pgstat_get_db_entry (Oid databaseid , bool create );
249
+ static PgStat_StatTabEntry * pgstat_get_tab_entry (PgStat_StatDBEntry * dbentry ,
250
+ Oid tableoid , bool create );
249
251
static void pgstat_write_statsfile (bool permanent );
250
252
static HTAB * pgstat_read_statsfile (Oid onlydb , bool permanent );
251
253
static void backend_read_statsfile (void );
@@ -2940,6 +2942,52 @@ pgstat_get_db_entry(Oid databaseid, bool create)
2940
2942
}
2941
2943
2942
2944
2945
+ /*
2946
+ * Lookup the hash table entry for the specified table. If no hash
2947
+ * table entry exists, initialize it, if the create parameter is true.
2948
+ * Else, return NULL.
2949
+ */
2950
+ static PgStat_StatTabEntry *
2951
+ pgstat_get_tab_entry (PgStat_StatDBEntry * dbentry , Oid tableoid , bool create )
2952
+ {
2953
+ PgStat_StatTabEntry * result ;
2954
+ bool found ;
2955
+ HASHACTION action = (create ? HASH_ENTER : HASH_FIND );
2956
+
2957
+ /* Lookup or create the hash table entry for this table */
2958
+ result = (PgStat_StatTabEntry * ) hash_search (dbentry -> tables ,
2959
+ & tableoid ,
2960
+ action , & found );
2961
+
2962
+ if (!create && !found )
2963
+ return NULL ;
2964
+
2965
+ /* If not found, initialize the new one. */
2966
+ if (!found )
2967
+ {
2968
+ result -> numscans = 0 ;
2969
+ result -> tuples_returned = 0 ;
2970
+ result -> tuples_fetched = 0 ;
2971
+ result -> tuples_inserted = 0 ;
2972
+ result -> tuples_updated = 0 ;
2973
+ result -> tuples_deleted = 0 ;
2974
+ result -> tuples_hot_updated = 0 ;
2975
+ result -> n_live_tuples = 0 ;
2976
+ result -> n_dead_tuples = 0 ;
2977
+ result -> last_anl_tuples = 0 ;
2978
+ result -> blocks_fetched = 0 ;
2979
+ result -> blocks_hit = 0 ;
2980
+
2981
+ result -> vacuum_timestamp = 0 ;
2982
+ result -> autovac_vacuum_timestamp = 0 ;
2983
+ result -> analyze_timestamp = 0 ;
2984
+ result -> autovac_analyze_timestamp = 0 ;
2985
+ }
2986
+
2987
+ return result ;
2988
+ }
2989
+
2990
+
2943
2991
/* ----------
2944
2992
* pgstat_write_statsfile() -
2945
2993
*
@@ -3553,10 +3601,10 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
3553
3601
tabentry -> tuples_hot_updated = tabmsg [i ].t_counts .t_tuples_hot_updated ;
3554
3602
tabentry -> n_live_tuples = tabmsg [i ].t_counts .t_new_live_tuples ;
3555
3603
tabentry -> n_dead_tuples = tabmsg [i ].t_counts .t_new_dead_tuples ;
3604
+ tabentry -> last_anl_tuples = 0 ;
3556
3605
tabentry -> blocks_fetched = tabmsg [i ].t_counts .t_blocks_fetched ;
3557
3606
tabentry -> blocks_hit = tabmsg [i ].t_counts .t_blocks_hit ;
3558
3607
3559
- tabentry -> last_anl_tuples = 0 ;
3560
3608
tabentry -> vacuum_timestamp = 0 ;
3561
3609
tabentry -> autovac_vacuum_timestamp = 0 ;
3562
3610
tabentry -> analyze_timestamp = 0 ;
@@ -3734,19 +3782,10 @@ pgstat_recv_autovac(PgStat_MsgAutovacStart *msg, int len)
3734
3782
PgStat_StatDBEntry * dbentry ;
3735
3783
3736
3784
/*
3737
- * Lookup the database in the hashtable. Don't create the entry if it
3738
- * doesn't exist, because autovacuum may be processing a template
3739
- * database. If this isn't the case, the database is most likely to have
3740
- * an entry already. (If it doesn't, not much harm is done anyway --
3741
- * it'll get created as soon as somebody actually uses the database.)
3785
+ * Store the last autovacuum time in the database's hashtable entry.
3742
3786
*/
3743
- dbentry = pgstat_get_db_entry (msg -> m_databaseid , false);
3744
- if (dbentry == NULL )
3745
- return ;
3787
+ dbentry = pgstat_get_db_entry (msg -> m_databaseid , true);
3746
3788
3747
- /*
3748
- * Store the last autovacuum time in the database entry.
3749
- */
3750
3789
dbentry -> last_autovac_time = msg -> m_start_time ;
3751
3790
}
3752
3791
@@ -3763,18 +3802,11 @@ pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len)
3763
3802
PgStat_StatTabEntry * tabentry ;
3764
3803
3765
3804
/*
3766
- * Don't create either the database or table entry if it doesn't already
3767
- * exist. This avoids bloating the stats with entries for stuff that is
3768
- * only touched by vacuum and not by live operations.
3805
+ * Store the data in the table's hashtable entry.
3769
3806
*/
3770
- dbentry = pgstat_get_db_entry (msg -> m_databaseid , false);
3771
- if (dbentry == NULL )
3772
- return ;
3807
+ dbentry = pgstat_get_db_entry (msg -> m_databaseid , true);
3773
3808
3774
- tabentry = hash_search (dbentry -> tables , & (msg -> m_tableoid ),
3775
- HASH_FIND , NULL );
3776
- if (tabentry == NULL )
3777
- return ;
3809
+ tabentry = pgstat_get_tab_entry (dbentry , msg -> m_tableoid , true);
3778
3810
3779
3811
if (msg -> m_autovacuum )
3780
3812
tabentry -> autovac_vacuum_timestamp = msg -> m_vacuumtime ;
@@ -3821,18 +3853,11 @@ pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len)
3821
3853
PgStat_StatTabEntry * tabentry ;
3822
3854
3823
3855
/*
3824
- * Don't create either the database or table entry if it doesn't already
3825
- * exist. This avoids bloating the stats with entries for stuff that is
3826
- * only touched by analyze and not by live operations.
3856
+ * Store the data in the table's hashtable entry.
3827
3857
*/
3828
- dbentry = pgstat_get_db_entry (msg -> m_databaseid , false);
3829
- if (dbentry == NULL )
3830
- return ;
3858
+ dbentry = pgstat_get_db_entry (msg -> m_databaseid , true);
3831
3859
3832
- tabentry = hash_search (dbentry -> tables , & (msg -> m_tableoid ),
3833
- HASH_FIND , NULL );
3834
- if (tabentry == NULL )
3835
- return ;
3860
+ tabentry = pgstat_get_tab_entry (dbentry , msg -> m_tableoid , true);
3836
3861
3837
3862
if (msg -> m_autovacuum )
3838
3863
tabentry -> autovac_analyze_timestamp = msg -> m_analyzetime ;
0 commit comments