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

Commit5d5f1a7

Browse files
committed
Clean up a number of autovacuum loose ends. Make the stats collector
track shared relations in a separate hashtable, so that operations donefrom different databases are counted correctly. Add proper support foranti-XID-wraparound vacuuming, even in databases that are never connectedto and so have no stats entries. Miscellaneous other bug fixes.Alvaro Herrera, some additional fixes by Tom Lane.
1 parent507b758 commit5d5f1a7

File tree

13 files changed

+423
-270
lines changed

13 files changed

+423
-270
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.212 2005/07/2903:25:53 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.213 2005/07/2919:29:59 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -4913,6 +4913,36 @@ GetRedoRecPtr(void)
49134913
returnRedoRecPtr;
49144914
}
49154915

4916+
/*
4917+
* GetRecentNextXid - get the nextXid value saved by the most recent checkpoint
4918+
*
4919+
* This is currently used only by the autovacuum daemon. To check for
4920+
* impending XID wraparound, autovac needs an approximate idea of the current
4921+
* XID counter, and it needs it before choosing which DB to attach to, hence
4922+
* before it sets up a PGPROC, hence before it can take any LWLocks. But it
4923+
* has attached to shared memory, and so we can let it reach into the shared
4924+
* ControlFile structure and pull out the last checkpoint nextXID.
4925+
*
4926+
* Since we don't take any sort of lock, we have to assume that reading a
4927+
* TransactionId is atomic ... but that assumption is made elsewhere, too,
4928+
* and in any case the worst possible consequence of a bogus result is that
4929+
* autovac issues an unnecessary database-wide VACUUM.
4930+
*
4931+
* Note: we could also choose to read ShmemVariableCache->nextXid in an
4932+
* unlocked fashion, thus getting a more up-to-date result; but since that
4933+
* changes far more frequently than the controlfile checkpoint copy, it would
4934+
* pose a far higher risk of bogus result if we did have a nonatomic-read
4935+
* problem.
4936+
*
4937+
* A (theoretically) completely safe answer is to read the actual pg_control
4938+
* file into local process memory, but that certainly seems like overkill.
4939+
*/
4940+
TransactionId
4941+
GetRecentNextXid(void)
4942+
{
4943+
returnControlFile->checkPointCopy.nextXid;
4944+
}
4945+
49164946
/*
49174947
* This must be called ONCE during postmaster or standalone-backend shutdown
49184948
*/

‎src/backend/commands/analyze.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.87 2005/07/14 05:13:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.88 2005/07/29 19:30:03 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -317,7 +317,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
317317
* a zero-column table.
318318
*/
319319
if (!vacstmt->vacuum)
320-
pgstat_report_analyze(RelationGetRelid(onerel),0,0);
320+
pgstat_report_analyze(RelationGetRelid(onerel),
321+
onerel->rd_rel->relisshared,
322+
0,0);
321323

322324
vac_close_indexes(nindexes,Irel,AccessShareLock);
323325
relation_close(onerel,AccessShareLock);
@@ -436,8 +438,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
436438
}
437439

438440
/* report results to the stats collector, too */
439-
pgstat_report_analyze(RelationGetRelid(onerel),totalrows,
440-
totaldeadrows);
441+
pgstat_report_analyze(RelationGetRelid(onerel),
442+
onerel->rd_rel->relisshared,
443+
totalrows,totaldeadrows);
441444
}
442445

443446
/* Done with indexes */

‎src/backend/commands/vacuum.c

Lines changed: 9 additions & 7 deletions
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.311 2005/07/14 05:13:39 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.312 2005/07/29 19:30:03 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -41,6 +41,7 @@
4141
#include"tcop/pquery.h"
4242
#include"utils/acl.h"
4343
#include"utils/builtins.h"
44+
#include"utils/flatfiles.h"
4445
#include"utils/fmgroids.h"
4546
#include"utils/inval.h"
4647
#include"utils/lsyscache.h"
@@ -490,7 +491,7 @@ vacuum(VacuumStmt *vacstmt, List *relids)
490491
* If it was a database-wide VACUUM, print FSM usage statistics
491492
* (we don't make you be superuser to see these).
492493
*/
493-
if (vacstmt->relation==NULL)
494+
if (all_rels)
494495
PrintFreeSpaceMapStatistics(elevel);
495496

496497
/*
@@ -712,7 +713,7 @@ vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples,
712713
*vac_update_dbstats() -- update statistics for one database
713714
*
714715
*Update the whole-database statistics that are kept in its pg_database
715-
*row.
716+
*row, and the flat-file copy of pg_database.
716717
*
717718
*We violate no-overwrite semantics here by storing new values for the
718719
*statistics columns directly into the tuple that's already on the page.
@@ -721,8 +722,6 @@ vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples,
721722
*
722723
*This routine is shared by full and lazy VACUUM. Note that it is only
723724
*applied after a database-wide VACUUM operation.
724-
*
725-
*Note that we don't bother to update the flat-file copy of pg_database.
726725
*/
727726
staticvoid
728727
vac_update_dbstats(Oiddbid,
@@ -768,6 +767,9 @@ vac_update_dbstats(Oid dbid,
768767
heap_endscan(scan);
769768

770769
heap_close(relation,RowExclusiveLock);
770+
771+
/* Mark the flat-file copy of pg_database for update at commit */
772+
database_file_update_needed();
771773
}
772774

773775

@@ -1165,8 +1167,8 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
11651167
vacrelstats->rel_tuples,vacrelstats->hasindex);
11661168

11671169
/* report results to the stats collector, too */
1168-
pgstat_report_vacuum(RelationGetRelid(onerel),vacstmt->analyze,
1169-
vacrelstats->rel_tuples);
1170+
pgstat_report_vacuum(RelationGetRelid(onerel),onerel->rd_rel->relisshared,
1171+
vacstmt->analyze,vacrelstats->rel_tuples);
11701172
}
11711173

11721174

‎src/backend/commands/vacuumlazy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
*
3333
* IDENTIFICATION
34-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.55 2005/07/14 05:13:40 tgl Exp $
34+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.56 2005/07/29 19:30:03 tgl Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -182,8 +182,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
182182
hasindex);
183183

184184
/* report results to the stats collector, too */
185-
pgstat_report_vacuum(RelationGetRelid(onerel),vacstmt->analyze,
186-
vacrelstats->rel_tuples);
185+
pgstat_report_vacuum(RelationGetRelid(onerel),onerel->rd_rel->relisshared,
186+
vacstmt->analyze,vacrelstats->rel_tuples);
187187
}
188188

189189

‎src/backend/libpq/hba.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.145 2005/07/28 15:30:55 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.146 2005/07/29 19:30:04 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -39,6 +39,7 @@
3939

4040

4141
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
42+
#defineatoxid(x) ((TransactionId) strtoul((x), NULL, 10))
4243

4344
/* Max size of username ident server can return */
4445
#defineIDENT_USERNAME_MAX 512
@@ -999,13 +1000,14 @@ load_hba(void)
9991000
*dbname: gets database name (must be of size NAMEDATALEN bytes)
10001001
*dboid: gets database OID
10011002
*dbtablespace: gets database's default tablespace's OID
1003+
*dbfrozenxid: gets database's frozen XID
10021004
*
10031005
* This is not much related to the other functions in hba.c, but we put it
10041006
* here because it uses the next_token() infrastructure.
10051007
*/
10061008
bool
1007-
read_pg_database_line(FILE*fp,char*dbname,
1008-
Oid*dboid,Oid*dbtablespace)
1009+
read_pg_database_line(FILE*fp,char*dbname,Oid*dboid,
1010+
Oid*dbtablespace,TransactionId*dbfrozenxid)
10091011
{
10101012
charbuf[MAX_TOKEN];
10111013

@@ -1024,10 +1026,10 @@ read_pg_database_line(FILE *fp, char *dbname,
10241026
if (!isdigit((unsignedchar)buf[0]))
10251027
elog(FATAL,"bad data in flat pg_database file");
10261028
*dbtablespace=atooid(buf);
1027-
/* discard datfrozenxid */
10281029
next_token(fp,buf,sizeof(buf));
10291030
if (!isdigit((unsignedchar)buf[0]))
10301031
elog(FATAL,"bad data in flat pg_database file");
1032+
*dbfrozenxid=atoxid(buf);
10311033
/* expect EOL next */
10321034
if (next_token(fp,buf,sizeof(buf)))
10331035
elog(FATAL,"bad data in flat pg_database file");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp