Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit47ef623

Browse files
committed
Remove pgstat's discrimination against MsgVacuum and MsgAnalyze messages.
Formerly, these message types would be discarded unless there was alreadya stats hash table entry for the target table. However, the intent ofsaving hash table space for unused tables was subverted by the fact thatthe physical I/O done by the vacuum or analyze would result in an immediatelyfollowing tabstat message, which would create the hash table entry anyway.All that we had left was surprising loss of statistical data, as in a recentcomplaint from Jaime Casanova.It seems unlikely that a real database would have many tables that go totallyuntouched over the long haul, so the consensus is that this "optimization"serves little purpose anyhow. Remove it, and just create the hash tableentry on demand in all cases.
1 parent7be39bb commit47ef623

File tree

1 file changed

+58
-33
lines changed

1 file changed

+58
-33
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2009, PostgreSQL Global Development Group
1515
*
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 $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -246,6 +246,8 @@ static void pgstat_beshutdown_hook(int code, Datum arg);
246246
staticvoidpgstat_sighup_handler(SIGNAL_ARGS);
247247

248248
staticPgStat_StatDBEntry*pgstat_get_db_entry(Oiddatabaseid,boolcreate);
249+
staticPgStat_StatTabEntry*pgstat_get_tab_entry(PgStat_StatDBEntry*dbentry,
250+
Oidtableoid,boolcreate);
249251
staticvoidpgstat_write_statsfile(boolpermanent);
250252
staticHTAB*pgstat_read_statsfile(Oidonlydb,boolpermanent);
251253
staticvoidbackend_read_statsfile(void);
@@ -2940,6 +2942,52 @@ pgstat_get_db_entry(Oid databaseid, bool create)
29402942
}
29412943

29422944

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+
staticPgStat_StatTabEntry*
2951+
pgstat_get_tab_entry(PgStat_StatDBEntry*dbentry,Oidtableoid,boolcreate)
2952+
{
2953+
PgStat_StatTabEntry*result;
2954+
boolfound;
2955+
HASHACTIONaction= (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+
returnNULL;
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+
returnresult;
2988+
}
2989+
2990+
29432991
/* ----------
29442992
* pgstat_write_statsfile() -
29452993
*
@@ -3553,10 +3601,10 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
35533601
tabentry->tuples_hot_updated=tabmsg[i].t_counts.t_tuples_hot_updated;
35543602
tabentry->n_live_tuples=tabmsg[i].t_counts.t_new_live_tuples;
35553603
tabentry->n_dead_tuples=tabmsg[i].t_counts.t_new_dead_tuples;
3604+
tabentry->last_anl_tuples=0;
35563605
tabentry->blocks_fetched=tabmsg[i].t_counts.t_blocks_fetched;
35573606
tabentry->blocks_hit=tabmsg[i].t_counts.t_blocks_hit;
35583607

3559-
tabentry->last_anl_tuples=0;
35603608
tabentry->vacuum_timestamp=0;
35613609
tabentry->autovac_vacuum_timestamp=0;
35623610
tabentry->analyze_timestamp=0;
@@ -3734,19 +3782,10 @@ pgstat_recv_autovac(PgStat_MsgAutovacStart *msg, int len)
37343782
PgStat_StatDBEntry*dbentry;
37353783

37363784
/*
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.
37423786
*/
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);
37463788

3747-
/*
3748-
* Store the last autovacuum time in the database entry.
3749-
*/
37503789
dbentry->last_autovac_time=msg->m_start_time;
37513790
}
37523791

@@ -3763,18 +3802,11 @@ pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len)
37633802
PgStat_StatTabEntry*tabentry;
37643803

37653804
/*
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.
37693806
*/
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);
37733808

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);
37783810

37793811
if (msg->m_autovacuum)
37803812
tabentry->autovac_vacuum_timestamp=msg->m_vacuumtime;
@@ -3821,18 +3853,11 @@ pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len)
38213853
PgStat_StatTabEntry*tabentry;
38223854

38233855
/*
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.
38273857
*/
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);
38313859

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);
38363861

38373862
if (msg->m_autovacuum)
38383863
tabentry->autovac_analyze_timestamp=msg->m_analyzetime;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp