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

Commitea4b9f1

Browse files
committed
I've run across a pretty serious problem with pg_autovacuum.
pg_autovacuum looses track of any table that's ever been truncated(possibly other situations too). When i truncate a table it gets anew relfilenode in pg_class. This is a problem because pg_autovacuumassumes pg_class.relfilenode will join to pg_stats_all_tables.relid.pg_stats_all_tables.relid is actallly the oid from pg_class, not therelfilenode. These two values start out equal so pg_autovacuum worksinitially, but it fails later on because of this incorrect assumption.This patch fixes that problem. Applied to HEAD and 7.4.X.Brian Hirt
1 parent2712ca7 commitea4b9f1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

‎contrib/pg_autovacuum/pg_autovacuum.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ init_table_info(PGresult *res, int row, db_info * dbi)
116116
atol(PQgetvalue(res,row,PQfnumber(res,"n_tup_upd"))));
117117
new_tbl->curr_vacuum_count=new_tbl->CountAtLastVacuum;
118118

119-
new_tbl->relfilenode=atoi(PQgetvalue(res,row,PQfnumber(res,"relfilenode")));
119+
new_tbl->relid=atoi(PQgetvalue(res,row,PQfnumber(res,"oid")));
120120
new_tbl->reltuples=atoi(PQgetvalue(res,row,PQfnumber(res,"reltuples")));
121121
new_tbl->relpages=atoi(PQgetvalue(res,row,PQfnumber(res,"relpages")));
122122

@@ -154,7 +154,7 @@ update_table_thresholds(db_info * dbi, tbl_info * tbl, int vacuum_type)
154154

155155
if (dbi->conn!=NULL)
156156
{
157-
snprintf(query,sizeof(query),PAGES_QUERY,tbl->relfilenode);
157+
snprintf(query,sizeof(query),PAGES_QUERY,tbl->relid);
158158
res=send_query(query,dbi);
159159
if (res!=NULL)
160160
{
@@ -237,7 +237,7 @@ update_table_list(db_info * dbi)
237237
for (i=0;i<t;i++)
238238
{/* loop through result set looking for a
239239
* match */
240-
if (tbl->relfilenode==atoi(PQgetvalue(res,i,PQfnumber(res,"relfilenode"))))
240+
if (tbl->relid==atoi(PQgetvalue(res,i,PQfnumber(res,"oid"))))
241241
{
242242
found_match=1;
243243
break;
@@ -267,7 +267,7 @@ update_table_list(db_info * dbi)
267267
while (tbl_elem!=NULL)
268268
{
269269
tbl= ((tbl_info*)DLE_VAL(tbl_elem));
270-
if (tbl->relfilenode==atoi(PQgetvalue(res,i,PQfnumber(res,"relfilenode"))))
270+
if (tbl->relid==atoi(PQgetvalue(res,i,PQfnumber(res,"oid"))))
271271
{
272272
found_match=1;
273273
break;
@@ -361,7 +361,7 @@ print_table_info(tbl_info * tbl)
361361
{
362362
sprintf(logbuffer," table name: %s.%s",tbl->dbi->dbname,tbl->table_name);
363363
log_entry(logbuffer);
364-
sprintf(logbuffer,"relfilenode: %i; relisshared: %i",tbl->relfilenode,tbl->relisshared);
364+
sprintf(logbuffer,"relid: %i; relisshared: %i",tbl->relid,tbl->relisshared);
365365
log_entry(logbuffer);
366366
sprintf(logbuffer," reltuples: %i; relpages: %i",tbl->reltuples,tbl->relpages);
367367
log_entry(logbuffer);
@@ -1072,7 +1072,7 @@ main(int argc, char *argv[])
10721072
{/* Loop through tables in list */
10731073
tbl= ((tbl_info*)DLE_VAL(tbl_elem));/* set tbl_info =
10741074
* current_table */
1075-
if (tbl->relfilenode==atoi(PQgetvalue(res,j,PQfnumber(res,"relfilenode"))))
1075+
if (tbl->relid==atoi(PQgetvalue(res,j,PQfnumber(res,"oid"))))
10761076
{
10771077
tbl->curr_analyze_count=
10781078
(atol(PQgetvalue(res,j,PQfnumber(res,"n_tup_ins")))+

‎contrib/pg_autovacuum/pg_autovacuum.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
#defineVACUUM_ANALYZE0
3535
#defineANALYZE_ONLY1
3636

37-
#defineTABLE_STATS_QUERY"select a.relfilenode,a.relname,a.relnamespace,a.relpages,a.relisshared,a.reltuples,b.schemaname,b.n_tup_ins,b.n_tup_upd,b.n_tup_del from pg_class a, pg_stat_all_tables b where a.relfilenode=b.relid and a.relkind = 'r'"
37+
#defineTABLE_STATS_QUERY"select a.oid,a.relname,a.relnamespace,a.relpages,a.relisshared,a.reltuples,b.schemaname,b.n_tup_ins,b.n_tup_upd,b.n_tup_del from pg_class a, pg_stat_all_tables b where a.oid=b.relid and a.relkind = 'r'"
3838

3939
#defineFRONTEND
40-
#definePAGES_QUERY "selectrelfilenode,reltuples,relpages from pg_class whererelfilenode=%i"
40+
#definePAGES_QUERY "selectoid,reltuples,relpages from pg_class whereoid=%i"
4141
#defineFROZENOID_QUERY "select oid,age(datfrozenxid) from pg_database where datname = 'template1'"
4242
#defineFROZENOID_QUERY2 "select oid,datname,age(datfrozenxid) from pg_database where datname!='template0'"
4343

@@ -84,7 +84,7 @@ struct tableinfo
8484
{
8585
char*schema_name,
8686
*table_name;
87-
intrelfilenode,
87+
intrelid,
8888
reltuples,
8989
relisshared,
9090
relpages;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp