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

Commit3ccde31

Browse files
committed
Have autovacuum consider processing TOAST tables separately from their
main tables.This requires vacuum() to accept processing a toast table standalone, sothere's a user-visible change in that it's now possible (for a superuser) toexecute "VACUUM pg_toast.pg_toast_XXX".
1 parent010eebf commit3ccde31

File tree

4 files changed

+172
-141
lines changed

4 files changed

+172
-141
lines changed

‎src/backend/commands/vacuum.c

Lines changed: 22 additions & 15 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.375 2008/06/05 15:47:32 alvherre Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.376 2008/08/13 00:07:50 alvherre Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -213,8 +213,8 @@ static BufferAccessStrategy vac_strategy;
213213
staticList*get_rel_oids(Oidrelid,constRangeVar*vacrel,
214214
constchar*stmttype);
215215
staticvoidvac_truncate_clog(TransactionIdfrozenXID);
216-
staticvoidvacuum_rel(Oidrelid,VacuumStmt*vacstmt,charexpected_relkind,
217-
boolfor_wraparound);
216+
staticvoidvacuum_rel(Oidrelid,VacuumStmt*vacstmt,booldo_toast,
217+
boolfor_wraparound);
218218
staticvoidfull_vacuum_rel(Relationonerel,VacuumStmt*vacstmt);
219219
staticvoidscan_heap(VRelStats*vacrelstats,Relationonerel,
220220
VacPageListvacuum_pages,VacPageListfraged_pages);
@@ -268,6 +268,9 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
268268
* OID to be processed, and vacstmt->relation is ignored. (The non-invalid
269269
* case is currently only used by autovacuum.)
270270
*
271+
* do_toast is passed as FALSE by autovacuum, because it processes TOAST
272+
* tables separately.
273+
*
271274
* for_wraparound is used by autovacuum to let us know when it's forcing
272275
* a vacuum for wraparound, which should not be auto-cancelled.
273276
*
@@ -281,7 +284,7 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
281284
* at transaction commit.
282285
*/
283286
void
284-
vacuum(VacuumStmt*vacstmt,Oidrelid,
287+
vacuum(VacuumStmt*vacstmt,Oidrelid,booldo_toast,
285288
BufferAccessStrategybstrategy,boolfor_wraparound,boolisTopLevel)
286289
{
287290
constchar*stmttype=vacstmt->vacuum ?"VACUUM" :"ANALYZE";
@@ -433,7 +436,7 @@ vacuum(VacuumStmt *vacstmt, Oid relid,
433436
Oidrelid=lfirst_oid(cur);
434437

435438
if (vacstmt->vacuum)
436-
vacuum_rel(relid,vacstmt,RELKIND_RELATION,for_wraparound);
439+
vacuum_rel(relid,vacstmt,do_toast,for_wraparound);
437440

438441
if (vacstmt->analyze)
439442
{
@@ -975,8 +978,7 @@ vac_truncate_clog(TransactionId frozenXID)
975978
*At entry and exit, we are not inside a transaction.
976979
*/
977980
staticvoid
978-
vacuum_rel(Oidrelid,VacuumStmt*vacstmt,charexpected_relkind,
979-
boolfor_wraparound)
981+
vacuum_rel(Oidrelid,VacuumStmt*vacstmt,booldo_toast,boolfor_wraparound)
980982
{
981983
LOCKMODElmode;
982984
Relationonerel;
@@ -1013,8 +1015,8 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
10131015
* by autovacuum; it's used to avoid cancelling a vacuum that was
10141016
* invoked in an emergency.
10151017
*
1016-
* Note:this flag remains set until CommitTransaction or
1017-
* AbortTransaction. We don't want to clearit until we reset
1018+
* Note:these flags remain set until CommitTransaction or
1019+
* AbortTransaction. We don't want to clearthem until we reset
10181020
* MyProc->xid/xmin, else OldestXmin might appear to go backwards,
10191021
* which is probably Not Good.
10201022
*/
@@ -1087,10 +1089,11 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
10871089
}
10881090

10891091
/*
1090-
* Check that it's aplain table; we used to do this in get_rel_oids() but
1091-
* seems safer to check after we've locked the relation.
1092+
* Check that it's avacuumable table; we used to do this in get_rel_oids()
1093+
*butseems safer to check after we've locked the relation.
10921094
*/
1093-
if (onerel->rd_rel->relkind!=expected_relkind)
1095+
if (onerel->rd_rel->relkind!=RELKIND_RELATION&&
1096+
onerel->rd_rel->relkind!=RELKIND_TOASTVALUE)
10941097
{
10951098
ereport(WARNING,
10961099
(errmsg("skipping \"%s\" --- cannot vacuum indexes, views, or special system tables",
@@ -1132,9 +1135,13 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
11321135
LockRelationIdForSession(&onerelid,lmode);
11331136

11341137
/*
1135-
* Remember the relation's TOAST relation for later
1138+
* Remember the relation's TOAST relation for later, if the caller asked
1139+
* us to process it.
11361140
*/
1137-
toast_relid=onerel->rd_rel->reltoastrelid;
1141+
if (do_toast)
1142+
toast_relid=onerel->rd_rel->reltoastrelid;
1143+
else
1144+
toast_relid=InvalidOid;
11381145

11391146
/*
11401147
* Switch to the table owner's userid, so that any index functions are
@@ -1173,7 +1180,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
11731180
* totally unimportant for toast relations.
11741181
*/
11751182
if (toast_relid!=InvalidOid)
1176-
vacuum_rel(toast_relid,vacstmt,RELKIND_TOASTVALUE,for_wraparound);
1183+
vacuum_rel(toast_relid,vacstmt,false,for_wraparound);
11771184

11781185
/*
11791186
* Now release the session-level lock on the master table.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp