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

Commit3cff187

Browse files
committed
Aggressively freeze tables when CLUSTER or VACUUM FULL rewrites them.
We haven't wanted to do this in the past on the grounds that in rarecases the original xmin value will be needed for forensic purposes, butcommit37484ad removes that objection,so now we can.Per extensive discussion, among many people, on pgsql-hackers.
1 parent4cf81b7 commit3cff187

File tree

5 files changed

+22
-31
lines changed

5 files changed

+22
-31
lines changed

‎doc/src/sgml/ref/vacuum.sgml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ <replaceable class="PARAMETER">
102102
Specifying <literal>FREEZE</literal> is equivalent to performing
103103
<command>VACUUM</command> with the
104104
<xref linkend="guc-vacuum-freeze-min-age"> parameter
105-
set to zero.
105+
set to zero. Aggressive freezing is always performed when the
106+
table is rewritten, so this option is redundant when <literal>FULL</>
107+
is specified.
106108
</para>
107109
</listitem>
108110
</varlistentry>

‎src/backend/access/heap/rewriteheap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ rewrite_heap_tuple(RewriteState state,
345345

346346
/*
347347
* While we have our hands on the tuple, we may as well freeze any
348-
*very-old xmin or xmax, so that future VACUUM effort can be saved.
348+
*eligible xmin or xmax, so that future VACUUM effort can be saved.
349349
*/
350350
heap_freeze_tuple(new_tuple->t_data,state->rs_freeze_xid,
351351
state->rs_cutoff_multi);

‎src/backend/commands/cluster.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ typedef struct
6464
}RelToCluster;
6565

6666

67-
staticvoidrebuild_relation(RelationOldHeap,OidindexOid,
68-
intfreeze_min_age,intfreeze_table_age,boolverbose);
67+
staticvoidrebuild_relation(RelationOldHeap,OidindexOid,boolverbose);
6968
staticvoidcopy_heap_data(OidOIDNewHeap,OidOIDOldHeap,OidOIDOldIndex,
70-
intfreeze_min_age,intfreeze_table_age,boolverbose,
71-
bool*pSwapToastByContent,TransactionId*pFreezeXid,
72-
MultiXactId*pCutoffMulti);
69+
boolverbose,bool*pSwapToastByContent,
70+
TransactionId*pFreezeXid,MultiXactId*pCutoffMulti);
7371
staticList*get_tables_to_cluster(MemoryContextcluster_context);
7472
staticvoidreform_and_rewrite_tuple(HeapTupletuple,
7573
TupleDescoldTupDesc,TupleDescnewTupDesc,
@@ -176,11 +174,8 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
176174
/* close relation, keep lock till commit */
177175
heap_close(rel,NoLock);
178176

179-
/*
180-
* Do the job. We use a -1 freeze_min_age to avoid having CLUSTER
181-
* freeze tuples earlier than a plain VACUUM would.
182-
*/
183-
cluster_rel(tableOid,indexOid, false,stmt->verbose,-1,-1);
177+
/* Do the job. */
178+
cluster_rel(tableOid,indexOid, false,stmt->verbose);
184179
}
185180
else
186181
{
@@ -229,9 +224,8 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
229224
StartTransactionCommand();
230225
/* functions in indexes may want a snapshot set */
231226
PushActiveSnapshot(GetTransactionSnapshot());
232-
/* Do the job. As above, use a -1 freeze_min_age. */
233-
cluster_rel(rvtc->tableOid,rvtc->indexOid, true,stmt->verbose,
234-
-1,-1);
227+
/* Do the job. */
228+
cluster_rel(rvtc->tableOid,rvtc->indexOid, true,stmt->verbose);
235229
PopActiveSnapshot();
236230
CommitTransactionCommand();
237231
}
@@ -262,8 +256,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
262256
* and error messages should refer to the operation as VACUUM not CLUSTER.
263257
*/
264258
void
265-
cluster_rel(OidtableOid,OidindexOid,boolrecheck,boolverbose,
266-
intfreeze_min_age,intfreeze_table_age)
259+
cluster_rel(OidtableOid,OidindexOid,boolrecheck,boolverbose)
267260
{
268261
RelationOldHeap;
269262

@@ -407,8 +400,7 @@ cluster_rel(Oid tableOid, Oid indexOid, bool recheck, bool verbose,
407400
TransferPredicateLocksToHeapRelation(OldHeap);
408401

409402
/* rebuild_relation does all the dirty work */
410-
rebuild_relation(OldHeap,indexOid,freeze_min_age,freeze_table_age,
411-
verbose);
403+
rebuild_relation(OldHeap,indexOid,verbose);
412404

413405
/* NB: rebuild_relation does heap_close() on OldHeap */
414406
}
@@ -561,8 +553,7 @@ mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
561553
* NB: this routine closes OldHeap at the right time; caller should not.
562554
*/
563555
staticvoid
564-
rebuild_relation(RelationOldHeap,OidindexOid,
565-
intfreeze_min_age,intfreeze_table_age,boolverbose)
556+
rebuild_relation(RelationOldHeap,OidindexOid,boolverbose)
566557
{
567558
OidtableOid=RelationGetRelid(OldHeap);
568559
OidtableSpace=OldHeap->rd_rel->reltablespace;
@@ -587,8 +578,7 @@ rebuild_relation(Relation OldHeap, Oid indexOid,
587578
AccessExclusiveLock);
588579

589580
/* Copy the heap data into the new table in the desired order */
590-
copy_heap_data(OIDNewHeap,tableOid,indexOid,
591-
freeze_min_age,freeze_table_age,verbose,
581+
copy_heap_data(OIDNewHeap,tableOid,indexOid,verbose,
592582
&swap_toast_by_content,&frozenXid,&cutoffMulti);
593583

594584
/*
@@ -743,8 +733,7 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, bool forcetemp,
743733
* *pCutoffMulti receives the MultiXactId used as a cutoff point.
744734
*/
745735
staticvoid
746-
copy_heap_data(OidOIDNewHeap,OidOIDOldHeap,OidOIDOldIndex,
747-
intfreeze_min_age,intfreeze_table_age,boolverbose,
736+
copy_heap_data(OidOIDNewHeap,OidOIDOldHeap,OidOIDOldIndex,boolverbose,
748737
bool*pSwapToastByContent,TransactionId*pFreezeXid,
749738
MultiXactId*pCutoffMulti)
750739
{
@@ -857,10 +846,11 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex,
857846
*pSwapToastByContent= false;
858847

859848
/*
860-
* compute xids used to freeze and weed out dead tuples.
849+
* Compute xids used to freeze and weed out dead tuples and multixacts.
850+
* Since we're going to rewrite the whole table anyway, there's no reason
851+
* not to be aggressive about this.
861852
*/
862-
vacuum_set_xid_limits(freeze_min_age,freeze_table_age,
863-
OldHeap->rd_rel->relisshared,
853+
vacuum_set_xid_limits(0,0,OldHeap->rd_rel->relisshared,
864854
&OldestXmin,&FreezeXid,NULL,&MultiXactCutoff,
865855
NULL);
866856

‎src/backend/commands/vacuum.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, bool do_toast, bool for_wraparound)
11491149

11501150
/* VACUUM FULL is now a variant of CLUSTER; see cluster.c */
11511151
cluster_rel(relid,InvalidOid, false,
1152-
(vacstmt->options&VACOPT_VERBOSE)!=0,
1153-
vacstmt->freeze_min_age,vacstmt->freeze_table_age);
1152+
(vacstmt->options&VACOPT_VERBOSE)!=0);
11541153
}
11551154
else
11561155
lazy_vacuum_rel(onerel,vacstmt,vac_strategy);

‎src/include/commands/cluster.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
externvoidcluster(ClusterStmt*stmt,boolisTopLevel);
2222
externvoidcluster_rel(OidtableOid,OidindexOid,boolrecheck,
23-
boolverbose,intfreeze_min_age,intfreeze_table_age);
23+
boolverbose);
2424
externvoidcheck_index_is_clusterable(RelationOldHeap,OidindexOid,
2525
boolrecheck,LOCKMODElockmode);
2626
externvoidmark_index_clustered(Relationrel,OidindexOid,boolis_internal);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp