31
31
*
32
32
*
33
33
* IDENTIFICATION
34
- * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.34 2004/02/03 17:34:02 tgl Exp $
34
+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.35 2004/02/06 19:36:17 wieck Exp $
35
35
*
36
36
*-------------------------------------------------------------------------
37
37
*/
@@ -148,6 +148,11 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
148
148
vac_open_indexes (onerel , & nindexes , & Irel );
149
149
hasindex = (nindexes > 0 );
150
150
151
+ /* Turn on vacuum cost accounting */
152
+ if (VacuumCostNaptime > 0 )
153
+ VacuumCostActive = true;
154
+ VacuumCostBalance = 0 ;
155
+
151
156
/* Do the vacuuming */
152
157
lazy_scan_heap (onerel , vacrelstats , Irel , nindexes );
153
158
@@ -168,6 +173,9 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
168
173
/* Update shared free space map with final free space info */
169
174
lazy_update_fsm (onerel , vacrelstats );
170
175
176
+ /* Turn off vacuum cost accounting */
177
+ VacuumCostActive = false;
178
+
171
179
/* Update statistics in pg_class */
172
180
vac_update_relstats (RelationGetRelid (onerel ), vacrelstats -> rel_pages ,
173
181
vacrelstats -> rel_tuples , hasindex );
@@ -228,6 +236,25 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
228
236
229
237
CHECK_FOR_INTERRUPTS ();
230
238
239
+ /*
240
+ * Do the napping in a cost based vacuum.
241
+ */
242
+ if (VacuumCostActive && !InterruptPending &&
243
+ VacuumCostBalance >= VacuumCostLimit )
244
+ {
245
+ int msec ;
246
+
247
+ msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit ;
248
+ if (msec < VacuumCostNaptime * 4 )
249
+ PG_MSLEEP (msec );
250
+ else
251
+ PG_MSLEEP (VacuumCostNaptime * 4 );
252
+
253
+ VacuumCostBalance = 0 ;
254
+
255
+ CHECK_FOR_INTERRUPTS ();
256
+ }
257
+
231
258
/*
232
259
* If we are close to overrunning the available space for
233
260
* dead-tuple TIDs, pause and do a cycle of vacuuming before we
@@ -469,6 +496,25 @@ lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats)
469
496
470
497
CHECK_FOR_INTERRUPTS ();
471
498
499
+ /*
500
+ * Do the napping in a cost based vacuum.
501
+ */
502
+ if (VacuumCostActive && !InterruptPending &&
503
+ VacuumCostBalance >= VacuumCostLimit )
504
+ {
505
+ int msec ;
506
+
507
+ msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit ;
508
+ if (msec < VacuumCostNaptime * 4 )
509
+ PG_MSLEEP (msec );
510
+ else
511
+ PG_MSLEEP (VacuumCostNaptime * 4 );
512
+
513
+ VacuumCostBalance = 0 ;
514
+
515
+ CHECK_FOR_INTERRUPTS ();
516
+ }
517
+
472
518
tblk = ItemPointerGetBlockNumber (& vacrelstats -> dead_tuples [tupindex ]);
473
519
buf = ReadBuffer (onerel , tblk );
474
520
LockBufferForCleanup (buf );
@@ -800,6 +846,25 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
800
846
801
847
CHECK_FOR_INTERRUPTS ();
802
848
849
+ /*
850
+ * Do the napping in a cost based vacuum.
851
+ */
852
+ if (VacuumCostActive && !InterruptPending &&
853
+ VacuumCostBalance >= VacuumCostLimit )
854
+ {
855
+ int msec ;
856
+
857
+ msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit ;
858
+ if (msec < VacuumCostNaptime * 4 )
859
+ PG_MSLEEP (msec );
860
+ else
861
+ PG_MSLEEP (VacuumCostNaptime * 4 );
862
+
863
+ VacuumCostBalance = 0 ;
864
+
865
+ CHECK_FOR_INTERRUPTS ();
866
+ }
867
+
803
868
blkno -- ;
804
869
805
870
buf = ReadBuffer (onerel , blkno );
0 commit comments