Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d5db3ab

Browse files
committed
Modify pgstats code to reduce performance penalties from oversized stats data
files: avoid creating stats hashtable entries for tables that aren't being touched except by vacuum/analyze, ensure that entries for dropped tables are removed promptly, and tweak the data layout to avoid storing useless struct padding. Also improve the performance of pgstat_vacuum_tabstat(), and make sure that autovacuum invokes it exactly once per autovac cycle rather than multiple times or not at all. This should cure recent complaints about 8.1 showing much higher stats I/O volume than was seen in 8.0. It'd still be a good idea to revisit the design with an eye to not re-writing the entire stats dataset every half second ... but that would be too much to backpatch, I fear.
1 parent e1af35a commit d5db3ab

File tree

5 files changed

+216
-209
lines changed

5 files changed

+216
-209
lines changed

src/backend/commands/vacuum.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.320 2006/01/04 19:16:24 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.321 2006/01/18 20:35:05 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -35,6 +35,7 @@
3535
#include "commands/vacuum.h"
3636
#include "executor/executor.h"
3737
#include "miscadmin.h"
38+
#include "postmaster/autovacuum.h"
3839
#include "storage/freespace.h"
3940
#include "storage/procarray.h"
4041
#include "storage/smgr.h"
@@ -324,9 +325,10 @@ vacuum(VacuumStmt *vacstmt, List *relids)
324325
errhint("Use VACUUM FULL, then VACUUM FREEZE.")));
325326

326327
/*
327-
* Send info about dead objects to the statistics collector
328+
* Send info about dead objects to the statistics collector, unless
329+
* we are in autovacuum --- autovacuum.c does this for itself.
328330
*/
329-
if (vacstmt->vacuum)
331+
if (vacstmt->vacuum && !IsAutoVacuumProcess())
330332
pgstat_vacuum_tabstat();
331333

332334
/*

src/backend/postmaster/autovacuum.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.9 2006/01/04 21:06:31 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.10 2006/01/18 20:35:05 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -508,6 +508,11 @@ process_whole_db(void)
508508
/* functions in indexes may want a snapshot set */
509509
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
510510

511+
/*
512+
* Clean up any dead statistics collector entries for this DB.
513+
*/
514+
pgstat_vacuum_tabstat();
515+
511516
dbRel = heap_open(DatabaseRelationId, AccessShareLock);
512517

513518
/* Must use a table scan, since there's no syscache for pg_database */
@@ -572,6 +577,13 @@ do_autovacuum(PgStat_StatDBEntry *dbentry)
572577
/* functions in indexes may want a snapshot set */
573578
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
574579

580+
/*
581+
* Clean up any dead statistics collector entries for this DB.
582+
* We always want to do this exactly once per DB-processing cycle,
583+
* even if we find nothing worth vacuuming in the database.
584+
*/
585+
pgstat_vacuum_tabstat();
586+
575587
/*
576588
* StartTransactionCommand and CommitTransactionCommand will automatically
577589
* switch to other contexts. We need this one to keep the list of

0 commit comments

Comments
 (0)