224{
232
233
234
235
236
237
238
239
240#define MAX_EAGER_FREEZE_SUCCESS_RATE 0.2
241
242
243
244
245
246
247
248
249#define EAGER_SCAN_REGION_SIZE 4096
250
252{
253
257
258
261
262
264
266
268
269
273
274
277
281
282
291
292
293
294
295
296
297
298
299
300
301
304
307
308
309
310
311
313
316
317
319
320
321
322
323
324
325
326
328
329
331
335
336
339
341
342
346
347
348
349
350
352
353
360
361
366
367
368
369
370
371
372
373
374
375
376
377
378
380
381
382
383
384
385
386
387
388
389
391
392
393
394
395
396
397
398
399
400
402
403
404
405
406
407
408
409
410
413
414
415
417{
422
423
424
429 void *callback_private_data,
430 void *per_buffer_data);
452 double reltuples,
456 double reltuples,
457 bool estimated_count,
468
474 bool *all_frozen,
485
486
487
488
489
490
491
492
493
494
495static void
497{
503
504
505
506
507
508
510 vacrel->eager_scan_max_fails_per_region = 0;
511 vacrel->eager_scan_remaining_fails = 0;
512 vacrel->eager_scan_remaining_successes = 0;
513
514
516 return;
517
518
519
520
521
522
523
524
526 return;
527
528
529
530
531
532
533
534
536 return;
537
538
539
540
541
542
543
544
545
546
547
548
549
550
553 vacrel->cutoffs.FreezeLimit))
555
559 vacrel->cutoffs.MultiXactCutoff))
561
563 return;
564
565
566
567
568
569
570
572
573 vacrel->eager_scan_remaining_successes =
576
577
578 if (
vacrel->eager_scan_remaining_successes == 0)
579 return;
580
581
582
583
584
585
586
587
589
591
594
595 vacrel->eager_scan_max_fails_per_region =
598
599
600
601
602
605
606 vacrel->eager_scan_remaining_fails =
607 vacrel->eager_scan_max_fails_per_region *
609}
610
611
612
613
614
615
616
617
618
619
620
621
622void
625{
628 instrument,
629 skipwithvm,
645
649 if (instrument)
650 {
653 {
656 }
657 }
658
659
661
669 else
672
673
674
675
676
677
678
679
680
681
682
683
684
696
697
701 vacrel->bstrategy = bstrategy;
702 if (instrument &&
vacrel->nindexes > 0)
703 {
704
706 for (
int i = 0;
i <
vacrel->nindexes;
i++)
708 }
709
710
711
712
713
714
715
716
717
718
722
723
724
725
726
728 vacrel->consider_bypass_optimization =
true;
729 vacrel->do_index_vacuuming =
true;
730 vacrel->do_index_cleanup =
true;
733 {
734
735 vacrel->do_index_vacuuming =
false;
736 vacrel->do_index_cleanup =
false;
737 }
739 {
740
741 vacrel->consider_bypass_optimization =
false;
742 }
743 else
744 {
745
747 }
748
749
750 vacrel->scanned_pages = 0;
751 vacrel->eager_scanned_pages = 0;
752 vacrel->removed_pages = 0;
753 vacrel->new_frozen_tuple_pages = 0;
754 vacrel->lpdead_item_pages = 0;
755 vacrel->missed_dead_pages = 0;
756 vacrel->nonempty_pages = 0;
757
758
759
760 vacrel->new_rel_tuples = 0;
761 vacrel->new_live_tuples = 0;
764
765
766 vacrel->num_index_scans = 0;
767 vacrel->num_dead_items_resets = 0;
768 vacrel->total_dead_items_bytes = 0;
769 vacrel->tuples_deleted = 0;
770 vacrel->tuples_frozen = 0;
773 vacrel->recently_dead_tuples = 0;
774 vacrel->missed_dead_tuples = 0;
775
776 vacrel->new_all_visible_pages = 0;
777 vacrel->new_all_visible_all_frozen_pages = 0;
778 vacrel->new_all_frozen_pages = 0;
779
780 vacrel->worker_usage.vacuum.nlaunched = 0;
781 vacrel->worker_usage.vacuum.nplanned = 0;
782 vacrel->worker_usage.cleanup.nlaunched = 0;
783 vacrel->worker_usage.cleanup.nplanned = 0;
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
804
805
808
809
810
811
812
813
814 vacrel->skippedallvis =
false;
815 skipwithvm = true;
817 {
818
819
820
821
822 vacrel->aggressive =
true;
823 skipwithvm = false;
824 }
825
826 vacrel->skipwithvm = skipwithvm;
827
828
829
830
831
832
834
835
840
842 {
845 (
errmsg(
"aggressively vacuuming \"%s.%s.%s\"",
848 else
850 (
errmsg(
"vacuuming \"%s.%s.%s\"",
853 }
854
855
856
857
858
859
860
861
864
865#ifdef USE_INJECTION_POINTS
866
867
868
869
870
871
874#endif
875
876
877
878
879
881
882
883
884
885
886
889
890
891
892
893
896
897
898
899
900
901
902
903 if (
vacrel->do_index_cleanup)
905
906
908
909
912
913
915
916
919
920
921
922
923
924
925
926
929 vacrel->cutoffs.relfrozenxid,
930 vacrel->NewRelfrozenXid));
933 vacrel->cutoffs.relminmxid,
935 if (
vacrel->skippedallvis)
936 {
937
938
939
940
941
945 }
946
947
948
949
950
955
956
957
958
959
960
963
964
965
966
967
968
969
970
976
977
978
979
980
981
982
983
984
985
986
989 vacrel->recently_dead_tuples +
990 vacrel->missed_dead_tuples,
991 starttime);
993
994 if (instrument)
995 {
997
1001 {
1014
1020
1027
1030 {
1031
1032
1033
1034
1036 msgfmt =
_(
"finished vacuuming \"%s.%s.%s\": index scans: %d\n");
1037 }
1039 {
1040
1041
1042
1043
1044
1045
1047 msgfmt =
_(
"automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1048 else
1049 msgfmt =
_(
"automatic vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1050 }
1051 else
1052 {
1054 msgfmt =
_(
"automatic aggressive vacuum of table \"%s.%s.%s\": index scans: %d\n");
1055 else
1056 msgfmt =
_(
"automatic vacuum of table \"%s.%s.%s\": index scans: %d\n");
1057 }
1062 vacrel->num_index_scans);
1063 appendStringInfo(&
buf,
_(
"pages: %u removed, %u remain, %u scanned (%.2f%% of total), %u eagerly scanned\n"),
1068 100.0 *
vacrel->scanned_pages /
1070 vacrel->eager_scanned_pages);
1072 _(
"tuples: %" PRId64 " removed, %" PRId64 " remain, %" PRId64 " are dead but not yet removable\n"),
1075 vacrel->recently_dead_tuples);
1076 if (
vacrel->missed_dead_tuples > 0)
1078 _(
"tuples missed: %" PRId64 " dead from %u pages not removed due to cleanup lock contention\n"),
1079 vacrel->missed_dead_tuples,
1080 vacrel->missed_dead_pages);
1082 vacrel->cutoffs.OldestXmin);
1084 _(
"removable cutoff: %u, which was %d XIDs old when operation ended\n"),
1087 {
1089 vacrel->cutoffs.relfrozenxid);
1091 _(
"new relfrozenxid: %u, which is %d XIDs ahead of previous value\n"),
1093 }
1095 {
1097 vacrel->cutoffs.relminmxid);
1099 _(
"new relminmxid: %u, which is %d MXIDs ahead of previous value\n"),
1101 }
1103 vacrel->new_frozen_tuple_pages,
1105 100.0 *
vacrel->new_frozen_tuple_pages /
1108
1110 _(
"visibility map: %u pages set all-visible, %u pages set all-frozen (%u were all-visible)\n"),
1111 vacrel->new_all_visible_pages,
1112 vacrel->new_all_visible_all_frozen_pages +
1113 vacrel->new_all_frozen_pages,
1114 vacrel->new_all_frozen_pages);
1115 if (
vacrel->do_index_vacuuming)
1116 {
1117 if (
vacrel->nindexes == 0 ||
vacrel->num_index_scans == 0)
1119 else
1121
1122 msgfmt =
_(
"%u pages from table (%.2f%% of total) had %" PRId64 " dead item identifiers removed\n");
1123 }
1124 else
1125 {
1128 else
1130
1131 msgfmt =
_(
"%u pages from table (%.2f%% of total) have %" PRId64 " dead item identifiers\n");
1132 }
1134 vacrel->lpdead_item_pages,
1138
1139 if (
vacrel->worker_usage.vacuum.nplanned > 0)
1141 _(
"parallel workers: index vacuum: %d planned, %d launched in total\n"),
1142 vacrel->worker_usage.vacuum.nplanned,
1143 vacrel->worker_usage.vacuum.nlaunched);
1144
1145 if (
vacrel->worker_usage.cleanup.nplanned > 0)
1147 _(
"parallel workers: index cleanup: %d planned, %d launched\n"),
1148 vacrel->worker_usage.cleanup.nplanned,
1149 vacrel->worker_usage.cleanup.nlaunched);
1150
1151 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1152 {
1154
1155 if (!istat)
1156 continue;
1157
1159 _(
"index \"%s\": pages: %u in total, %u newly deleted, %u currently deleted, %u reusable\n"),
1165 }
1167 {
1168
1169
1170
1171
1172
1173
1176 }
1178 {
1181
1184 }
1186 {
1191 }
1206
1207
1208
1209
1210
1211
1212
1213
1214
1216 ngettext(
"memory usage: dead item storage %.2f MB accumulated across %d reset (limit %.2f MB each)\n",
1217 "memory usage: dead item storage %.2f MB accumulated across %d resets (limit %.2f MB each)\n",
1218 vacrel->num_dead_items_resets),
1219 (
double)
vacrel->total_dead_items_bytes / (1024 * 1024),
1220 vacrel->num_dead_items_resets,
1223
1227 }
1228 }
1229
1230
1231 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1232 {
1235
1236 if (instrument)
1238 }
1239}
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277static void
1279{
1282 blkno = 0,
1285 vacrel->eager_scan_remaining_successes;
1291 };
1293
1294
1299
1300
1303 vacrel->next_unskippable_eager_scanned =
false;
1305
1306
1307
1308
1309
1310
1311
1318 sizeof(bool));
1319
1320 while (true)
1321 {
1325 int ndeleted = 0;
1327 void *per_buffer_data =
NULL;
1330
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342 if (
vacrel->scanned_pages > 0 &&
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354 if (
vacrel->dead_items_info->num_items > 0 &&
1356 {
1357
1358
1359
1360
1361
1362
1364 {
1367 }
1368
1369
1370 vacrel->consider_bypass_optimization =
false;
1372
1373
1374
1375
1376
1377
1379 blkno + 1);
1381
1382
1385 }
1386
1388
1389
1391 break;
1392
1397
1400 vacrel->eager_scanned_pages++;
1401
1402
1406
1407
1408
1409
1410
1411
1413
1414
1415
1416
1417
1418
1419
1421
1424
1425
1427 vmbuffer))
1428 {
1429
1430 continue;
1431 }
1432
1433
1434
1435
1436
1437
1438
1439
1440
1443 {
1444
1445
1446
1447
1452 }
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1469 vmbuffer,
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1487 {
1488
1490
1492 {
1493 if (
vacrel->eager_scan_remaining_successes > 0)
1494 vacrel->eager_scan_remaining_successes--;
1495
1496 if (
vacrel->eager_scan_remaining_successes == 0)
1497 {
1498
1499
1500
1501
1502
1503
1504
1505 if (
vacrel->eager_scan_max_fails_per_region > 0)
1507 (
errmsg(
"disabling eager scanning after freezing %u eagerly scanned blocks of relation \"%s.%s.%s\"",
1511
1512
1513
1514
1515
1516
1517 vacrel->eager_scan_remaining_fails = 0;
1519 vacrel->eager_scan_max_fails_per_region = 0;
1520 }
1521 }
1522 else if (
vacrel->eager_scan_remaining_fails > 0)
1523 vacrel->eager_scan_remaining_fails--;
1524 }
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545 if (
vacrel->nindexes == 0
1546 || !
vacrel->do_index_vacuuming
1548 {
1550
1553
1554
1555
1556
1557
1558
1559
1562 {
1564 blkno);
1566 }
1567 }
1568 else
1570 }
1571
1575
1576
1577
1578
1579
1581 rel_pages);
1582
1583
1587
1588
1589
1590
1591
1594 vacrel->missed_dead_tuples;
1595
1597
1598
1599
1600
1601
1602 if (
vacrel->dead_items_info->num_items > 0)
1604
1605
1606
1607
1608
1609
1610
1613
1614
1616
1617
1620}
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1648 void *callback_private_data,
1649 void *per_buffer_data)
1650{
1653
1654
1656
1657
1659 {
1661 {
1664 }
1666 }
1667
1668
1669
1670
1673 {
1674
1675
1676
1677
1678
1680
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1699 {
1702 vacrel->skippedallvis =
true;
1703 }
1704 }
1705
1706
1708 {
1709
1710
1711
1712
1713
1715
1716 *((bool *) per_buffer_data) = false;
1717 return vacrel->current_block;
1718 }
1719 else
1720 {
1721
1722
1723
1724
1726
1728 *((
bool *) per_buffer_data) =
vacrel->next_unskippable_eager_scanned;
1729 return vacrel->current_block;
1730 }
1731}
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746static void
1748{
1751 Buffer next_unskippable_vmbuffer =
vacrel->next_unskippable_vmbuffer;
1752 bool next_unskippable_eager_scanned = false;
1753
1755
1756 for (;; next_unskippable_block++)
1757 {
1759 next_unskippable_block,
1760 &next_unskippable_vmbuffer);
1761
1762
1763
1764
1765
1766
1767
1768
1769 if (next_unskippable_block >=
vacrel->next_eager_scan_region_start)
1770 {
1771 vacrel->eager_scan_remaining_fails =
1772 vacrel->eager_scan_max_fails_per_region;
1774 }
1775
1776
1777
1778
1779
1781 {
1783 break;
1784 }
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796 if (next_unskippable_block == rel_pages - 1)
1797 break;
1798
1799
1801 break;
1802
1803
1804
1805
1806
1808 continue;
1809
1810
1811
1812
1813
1815 break;
1816
1817
1818
1819
1820
1821
1822 if (
vacrel->eager_scan_remaining_fails > 0)
1823 {
1824 next_unskippable_eager_scanned = true;
1825 break;
1826 }
1827
1828
1829
1830
1831
1833 }
1834
1835
1836 vacrel->next_unskippable_block = next_unskippable_block;
1837 vacrel->next_unskippable_eager_scanned = next_unskippable_eager_scanned;
1838 vacrel->next_unskippable_vmbuffer = next_unskippable_vmbuffer;
1839}
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875static bool
1878{
1880
1882 {
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1903
1905 {
1907
1909 }
1910
1911 return true;
1912 }
1913
1915 {
1916
1917
1918
1919
1920
1922 {
1925
1927 {
1928
1929 return false;
1930 }
1931 }
1932 else
1933 {
1934
1935 }
1936
1937
1938
1939
1940
1942 {
1943
1945
1947
1948
1950
1954 vmbuffer,
1957 vacrel->rel->rd_locator);
1958
1959
1960
1961
1962
1965 vmbuffer,
1969 false,
1975
1977
1979
1980
1981 vacrel->new_all_visible_pages++;
1982 vacrel->new_all_visible_all_frozen_pages++;
1983 }
1984
1988 return true;
1989 }
1990
1991
1992 return false;
1993}
1994
1995
1996static int
1998{
2000}
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019static int
2027{
2031 .relation = rel,
2033 .vmbuffer = vmbuffer,
2036 .vistest =
vacrel->vistest,
2037 .cutoffs = &
vacrel->cutoffs,
2038 };
2039
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057 if (
vacrel->nindexes == 0)
2059
2060
2061
2062
2063
2064
2065
2066
2069
2074
2077
2079 {
2080
2081
2082
2083
2084
2085
2086 vacrel->new_frozen_tuple_pages++;
2087 }
2088
2089
2090
2091
2093 {
2094 vacrel->lpdead_item_pages++;
2095
2096
2097
2098
2099
2100
2101
2104
2106 }
2107
2108
2109 if (
presult.newly_all_visible)
2110 vacrel->new_all_visible_pages++;
2111 if (
presult.newly_all_visible_frozen)
2112 vacrel->new_all_visible_all_frozen_pages++;
2114 vacrel->new_all_frozen_pages++;
2115
2116
2119
2124 vacrel->recently_dead_tuples +=
presult.recently_dead_tuples;
2125
2126
2128 vacrel->nonempty_pages = blkno + 1;
2129
2130
2132
2134}
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156static bool
2162{
2164 maxoff;
2165 int lpdead_items,
2166 live_tuples,
2167 recently_dead_tuples,
2168 missed_dead_tuples;
2169 bool hastup;
2174
2176
2177 hastup = false;
2178
2179 lpdead_items = 0;
2180 live_tuples = 0;
2181 recently_dead_tuples = 0;
2182 missed_dead_tuples = 0;
2183
2186 offnum <= maxoff;
2188 {
2191
2194
2196 continue;
2197
2199 {
2200 hastup = true;
2201 continue;
2202 }
2203
2205 {
2206
2207
2208
2209
2210 deadoffsets[lpdead_items++] = offnum;
2211 continue;
2212 }
2213
2214 hastup = true;
2217 &NoFreezePageRelfrozenXid,
2218 &NoFreezePageRelminMxid))
2219 {
2220
2222 {
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2235 return false;
2236 }
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246 }
2247
2252
2255 {
2258
2259
2260
2261
2262 live_tuples++;
2263
2264 break;
2266
2267
2268
2269
2270
2271 missed_dead_tuples++;
2272 break;
2274
2275
2276
2277
2278 recently_dead_tuples++;
2279 break;
2281
2282
2283
2284
2285 break;
2286 default:
2287 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
2288 break;
2289 }
2290 }
2291
2293
2294
2295
2296
2297
2298
2299 vacrel->NewRelfrozenXid = NoFreezePageRelfrozenXid;
2300 vacrel->NewRelminMxid = NoFreezePageRelminMxid;
2301
2302
2303 if (
vacrel->nindexes == 0)
2304 {
2305
2306 if (lpdead_items > 0)
2307 {
2308
2309
2310
2311
2312
2313
2314
2315
2316 hastup = true;
2317 missed_dead_tuples += lpdead_items;
2318 }
2319 }
2320 else if (lpdead_items > 0)
2321 {
2322
2323
2324
2325
2326
2327 vacrel->lpdead_item_pages++;
2328
2330
2331 vacrel->lpdead_items += lpdead_items;
2332 }
2333
2334
2335
2336
2337 vacrel->live_tuples += live_tuples;
2338 vacrel->recently_dead_tuples += recently_dead_tuples;
2339 vacrel->missed_dead_tuples += missed_dead_tuples;
2340 if (missed_dead_tuples > 0)
2341 vacrel->missed_dead_pages++;
2342
2343
2344 if (hastup)
2345 vacrel->nonempty_pages = blkno + 1;
2346
2347
2349
2350
2351 return true;
2352}
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367static void
2369{
2371
2372
2375
2376 if (!
vacrel->do_index_vacuuming)
2377 {
2380 return;
2381 }
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2403 if (
vacrel->consider_bypass_optimization &&
vacrel->rel_pages > 0)
2404 {
2406
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2437 }
2438
2440 {
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451 vacrel->do_index_vacuuming =
false;
2452 }
2454 {
2455
2456
2457
2458
2460 }
2461 else
2462 {
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2475 }
2476
2477
2478
2479
2480
2482}
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492static bool
2494{
2500 };
2505 };
2508
2512
2513
2515 {
2516
2517 return false;
2518 }
2519
2520
2521
2522
2523
2527
2529 {
2531 {
2534
2538
2539
2542
2544 {
2545
2547 break;
2548 }
2549 }
2550 }
2551 else
2552 {
2553
2556 &(
vacrel->worker_usage.vacuum));
2557
2558
2559
2560
2561
2564 }
2565
2566
2567
2568
2569
2570
2571
2572
2574 vacrel->dead_items_info->num_items ==
vacrel->lpdead_items);
2576
2577
2578
2579
2580
2581
2582
2583
2584 vacrel->num_index_scans++;
2589
2591}
2592
2593
2594
2595
2596
2597
2598
2599
2602 void *callback_private_data,
2603 void *per_buffer_data)
2604{
2607
2611
2612
2613
2614
2615
2617
2619}
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638static void
2640{
2646
2650
2651
2654
2655
2659
2661
2662
2663
2664
2665
2666
2667
2668
2669
2676 iter,
2678
2679 while (true)
2680 {
2688
2690
2692
2693
2695 break;
2696
2698
2702
2703
2704
2705
2706
2707
2709
2710
2714
2715
2718
2722 }
2723
2726
2730
2731
2732
2733
2734
2736 (
vacrel->dead_items_info->num_items ==
vacrel->lpdead_items &&
2738
2740 (
errmsg(
"table \"%s\": removed %" PRId64 " dead item identifiers in %u pages",
2743
2744
2746}
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756static void
2760{
2763 int nunused = 0;
2766 bool all_frozen;
2769
2771
2773
2774
2778
2779
2780
2781
2782
2783
2784
2785
2786
2790 &all_frozen, &newest_live_xid,
2792 {
2794 if (all_frozen)
2795 {
2798 }
2799
2800
2801
2802
2803
2804
2806 }
2807
2809
2811 {
2814
2816
2819 unused[nunused++] =
toff;
2820 }
2821
2823
2824
2826
2828 {
2829
2830
2831
2832
2837 vacrel->rel->rd_locator);
2839 }
2840
2841
2842
2843
2845
2846
2848 {
2858 unused, nunused);
2859 }
2860
2862
2864 {
2865
2867 vacrel->new_all_visible_pages++;
2868 if (all_frozen)
2869 vacrel->new_all_visible_all_frozen_pages++;
2870 }
2871
2872
2874}
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888static bool
2890{
2891
2893 return true;
2894
2896 {
2901 };
2903
2905
2906
2907
2908
2909
2910
2912
2913
2914 vacrel->do_index_vacuuming =
false;
2915 vacrel->do_index_cleanup =
false;
2916 vacrel->do_rel_truncate =
false;
2917
2918
2920
2922 (
errmsg(
"bypassing nonessential maintenance of table \"%s.%s.%s\" as a failsafe after %d index scans",
2924 vacrel->num_index_scans),
2925 errdetail(
"The table's relfrozenxid or relminmxid is too far in the past."),
2926 errhint(
"Consider increasing configuration parameter \"maintenance_work_mem\" or \"autovacuum_work_mem\".\n"
2927 "You might also need to consider other ways for VACUUM to keep up with the allocation of transaction IDs.")));
2928
2929
2932
2933 return true;
2934 }
2935
2936 return false;
2937}
2938
2939
2940
2941
2942static void
2944{
2945 double reltuples =
vacrel->new_rel_tuples;
2946 bool estimated_count =
vacrel->scanned_pages <
vacrel->rel_pages;
2950 };
2954 };
2957
2960
2961
2962
2963
2964
2968
2970 {
2972 {
2975
2978 estimated_count,
vacrel);
2979
2980
2983 }
2984 }
2985 else
2986 {
2987
2990 estimated_count,
2991 &(
vacrel->worker_usage.cleanup));
2992 }
2993
2994
2996}
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3014{
3017
3020 ivinfo.analyze_only =
false;
3021 ivinfo.report_progress =
false;
3022 ivinfo.estimated_count =
true;
3024 ivinfo.num_heap_tuples = reltuples;
3026
3027
3028
3029
3030
3031
3032
3038
3039
3041 vacrel->dead_items_info);
3042
3043
3047
3048 return istat;
3049}
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3062 double reltuples, bool estimated_count,
3064{
3067
3070 ivinfo.analyze_only =
false;
3071 ivinfo.report_progress =
false;
3072 ivinfo.estimated_count = estimated_count;
3074
3075 ivinfo.num_heap_tuples = reltuples;
3077
3078
3079
3080
3081
3082
3083
3089
3091
3092
3096
3097 return istat;
3098}
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120static bool
3122{
3124
3126 return false;
3127
3132 return true;
3133
3134 return false;
3135}
3136
3137
3138
3139
3140static void
3142{
3147
3148
3151
3152
3155
3156
3157
3158
3159 do
3160 {
3161
3162
3163
3164
3165
3166
3167
3170 while (true)
3171 {
3173 break;
3174
3175
3176
3177
3178
3180
3183 {
3184
3185
3186
3187
3189 (
errmsg(
"\"%s\": stopping truncate due to conflicting lock request",
3191 return;
3192 }
3193
3199 }
3200
3201
3202
3203
3204
3205
3208 {
3209
3210
3211
3212
3213
3214
3215
3217 return;
3218 }
3219
3220
3221
3222
3223
3224
3225
3228
3230 {
3231
3233 return;
3234 }
3235
3236
3237
3238
3240
3241
3242
3243
3244
3245
3246
3247
3249
3250
3251
3252
3253
3254
3257
3259 (
errmsg(
"table \"%s\": truncated %u to %u pages",
3264}
3265
3266
3267
3268
3269
3270
3273{
3275 "prefetch size must be power of 2");
3276
3280
3281
3283
3284
3285
3286
3287
3288
3289
3290 blkno =
vacrel->rel_pages;
3292 while (blkno >
vacrel->nonempty_pages)
3293 {
3297 maxoff;
3298 bool hastup;
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308 if ((blkno % 32) == 0)
3309 {
3312
3318 {
3320 {
3322 (
errmsg(
"table \"%s\": suspending truncate due to conflicting lock request",
3324
3326 return blkno;
3327 }
3329 }
3330 }
3331
3332
3333
3334
3335
3336
3338
3339 blkno--;
3340
3341
3343 {
3346
3349 {
3352 }
3354 }
3355
3358
3359
3361
3363
3365 {
3367 continue;
3368 }
3369
3370 hastup = false;
3373 offnum <= maxoff;
3375 {
3377
3379
3380
3381
3382
3383
3384
3386 {
3387 hastup = true;
3388 break;
3389 }
3390 }
3391
3393
3394
3395 if (hastup)
3396 return blkno + 1;
3397 }
3398
3399
3400
3401
3402
3403
3404 return vacrel->nonempty_pages;
3405}
3406
3407
3408
3409
3410
3411
3412
3413
3414static void
3416{
3421
3422
3423
3424
3425
3426
3427 if (nworkers >= 0 &&
vacrel->nindexes > 1 &&
vacrel->do_index_vacuuming)
3428 {
3429
3430
3431
3432
3434 {
3435
3436
3437
3438
3439 if (nworkers > 0)
3441 (
errmsg(
"disabling parallel option of vacuum on \"%s\" --- cannot vacuum temporary tables in parallel",
3443 }
3444 else
3446 vacrel->nindexes, nworkers,
3450
3451
3452
3453
3454
3456 {
3458 &
vacrel->dead_items_info);
3459 return;
3460 }
3461 }
3462
3463
3464
3465
3466
3467
3471 vacrel->dead_items_info = dead_items_info;
3472
3474}
3475
3476
3477
3478
3479static void
3482{
3486 };
3488
3491
3492
3496}
3497
3498
3499
3500
3501static void
3503{
3504
3505 vacrel->num_dead_items_resets++;
3507
3509 {
3512 &
vacrel->dead_items_info);
3513 return;
3514 }
3515
3516
3519
3520
3521 vacrel->dead_items_info->num_items = 0;
3522}
3523
3524
3525
3526
3527static void
3529{
3531 {
3532
3533 return;
3534 }
3535
3536
3539}
3540
3541#ifdef USE_ASSERT_CHECKING
3542
3543
3544
3545
3546
3547
3548bool
3551 bool *all_frozen,
3554{
3555
3556
3557
3558
3559
3560
3562 vistest, false,
3564 all_frozen,
3565 newest_live_xid,
3567}
3568#endif
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602static bool
3608 bool *all_frozen,
3611{
3615 maxoff;
3616 bool all_visible = true;
3618
3620 *all_frozen = true;
3621
3623
3624#ifdef USE_ASSERT_CHECKING
3625
3627 {
3629 Assert(deadoffsets[
i - 1] < deadoffsets[
i]);
3630 }
3631#endif
3632
3635 offnum <= maxoff && all_visible;
3637 {
3641
3642
3643
3644
3645
3648
3649
3651 continue;
3652
3654
3655
3656
3657
3658
3660 {
3661 if (!deadoffsets ||
3664 {
3665 *all_frozen = all_visible = false;
3666 break;
3667 }
3669 continue;
3670 }
3671
3673
3677
3678
3681 {
3683 {
3685
3686
3688 {
3689 all_visible = false;
3690 *all_frozen = false;
3691 break;
3692 }
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3706
3707
3710 *newest_live_xid = xmin;
3711
3712
3713 if (all_visible && *all_frozen &&
3715 *all_frozen = false;
3716 }
3717 break;
3718
3723 {
3724 all_visible = false;
3725 *all_frozen = false;
3726 break;
3727 }
3728 default:
3729 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
3730 break;
3731 }
3732 }
3733
3734
3735
3736
3737
3738
3739 if (all_visible &&
3743 {
3744 all_visible = false;
3745 *all_frozen = false;
3746 }
3747
3748
3750
3751 return all_visible;
3752}
3753
3754
3755
3756
3757static void
3759{
3761 int nindexes =
vacrel->nindexes;
3763
3765
3766 for (
int idx = 0;
idx < nindexes;
idx++)
3767 {
3770
3772 continue;
3773
3774
3778 0, 0,
3779 false,
3783 }
3784}
3785
3786
3787
3788
3789
3790
3791
3792static void
3794{
3796
3798 {
3801 {
3803 errcontext(
"while scanning block %u offset %u of relation \"%s.%s\"",
3805 else
3806 errcontext(
"while scanning block %u of relation \"%s.%s\"",
3808 }
3809 else
3810 errcontext(
"while scanning relation \"%s.%s\"",
3812 break;
3813
3816 {
3818 errcontext(
"while vacuuming block %u offset %u of relation \"%s.%s\"",
3820 else
3821 errcontext(
"while vacuuming block %u of relation \"%s.%s\"",
3823 }
3824 else
3825 errcontext(
"while vacuuming relation \"%s.%s\"",
3827 break;
3828
3830 errcontext(
"while vacuuming index \"%s\" of relation \"%s.%s\"",
3832 break;
3833
3835 errcontext(
"while cleaning up index \"%s\" of relation \"%s.%s\"",
3837 break;
3838
3841 errcontext(
"while truncating relation \"%s.%s\" to %u blocks",
3843 break;
3844
3846 default:
3847 return;
3848
3849 }
3850}
3851
3852
3853
3854
3855
3856static void
3859{
3861 {
3865 }
3866
3870}
3871
3872
3873
3874
3875static void
3878{
3882}
Datum idx(PG_FUNCTION_ARGS)
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
TimestampTz GetCurrentTimestamp(void)
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
void pgstat_progress_end_command(void)
@ PROGRESS_COMMAND_VACUUM
PgBackendStatus * MyBEEntry
#define InvalidBlockNumber
static bool BlockNumberIsValid(BlockNumber blockNumber)
void CheckBufferIsPinnedOnce(Buffer buffer)
BlockNumber BufferGetBlockNumber(Buffer buffer)
PrefetchBufferResult PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
void ReleaseBuffer(Buffer buffer)
void UnlockReleaseBuffer(Buffer buffer)
void MarkBufferDirty(Buffer buffer)
void LockBufferForCleanup(Buffer buffer)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
bool ConditionalLockBufferForCleanup(Buffer buffer)
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
static void LockBuffer(Buffer buffer, BufferLockMode mode)
static bool BufferIsValid(Buffer bufnum)
Size PageGetHeapFreeSpace(const PageData *page)
void PageTruncateLinePointerArray(Page page)
static bool PageIsEmpty(const PageData *page)
static bool PageIsAllVisible(const PageData *page)
static bool PageIsNew(const PageData *page)
#define SizeOfPageHeaderData
static void PageSetAllVisible(Page page)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static void * PageGetItem(PageData *page, const ItemIdData *itemId)
#define PageClearPrunable(page)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
#define ngettext(s, p, n)
#define Assert(condition)
TransactionId MultiXactId
#define StaticAssertDecl(condition, errmessage)
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define palloc0_object(type)
void FreeSpaceMapVacuumRange(Relation rel, BlockNumber start, BlockNumber end)
Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk)
void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail)
volatile uint32 CritSectionCount
bool heap_tuple_needs_eventual_freeze(HeapTupleHeader tuple)
bool heap_tuple_should_freeze(HeapTupleHeader tuple, const struct VacuumCutoffs *cutoffs, TransactionId *NoFreezePageRelfrozenXid, MultiXactId *NoFreezePageRelminMxid)
#define HEAP_PAGE_PRUNE_FREEZE
#define HEAP_PAGE_PRUNE_ALLOW_FAST_PATH
@ HEAPTUPLE_RECENTLY_DEAD
@ HEAPTUPLE_INSERT_IN_PROGRESS
@ HEAPTUPLE_DELETE_IN_PROGRESS
#define HEAP_PAGE_PRUNE_SET_VM
#define HEAP_PAGE_PRUNE_MARK_UNUSED_NOW
HTSV_Result HeapTupleSatisfiesVacuumHorizon(HeapTuple htup, Buffer buffer, TransactionId *dead_after)
HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin, Buffer buffer)
HeapTupleHeaderData * HeapTupleHeader
static TransactionId HeapTupleHeaderGetXmin(const HeapTupleHeaderData *tup)
#define MaxHeapTuplesPerPage
static bool HeapTupleHeaderXminCommitted(const HeapTupleHeaderData *tup)
#define INJECTION_POINT(name, arg)
#define INSTR_TIME_SET_CURRENT(t)
#define INSTR_TIME_SUBTRACT(x, y)
#define INSTR_TIME_GET_MICROSEC(t)
void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
BufferUsage pgBufferUsage
void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
static int pg_cmp_u16(uint16 a, uint16 b)
#define ItemIdGetLength(itemId)
#define ItemIdIsNormal(itemId)
#define ItemIdIsDead(itemId)
#define ItemIdIsUsed(itemId)
#define ItemIdSetUnused(itemId)
#define ItemIdIsRedirected(itemId)
#define ItemIdHasStorage(itemId)
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
void UnlockRelation(Relation relation, LOCKMODE lockmode)
bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode)
bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode)
#define AccessExclusiveLock
char * get_database_name(Oid dbid)
char * get_namespace_name(Oid nspid)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
#define AmAutoVacuumWorkerProcess()
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define END_CRIT_SECTION()
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
bool MultiXactIdPrecedesOrEquals(MultiXactId multi1, MultiXactId multi2)
#define MultiXactIdIsValid(multi)
#define InvalidMultiXactId
#define InvalidOffsetNumber
#define OffsetNumberIsValid(offsetNumber)
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
uint32 pg_prng_uint32(pg_prng_state *state)
pg_prng_state pg_global_prng_state
const char * pg_rusage_show(const PGRUsage *ru0)
void pg_rusage_init(PGRUsage *ru0)
static char buf[DEFAULT_XLOG_SEG_SIZE]
PgStat_Counter pgStatBlockReadTime
PgStat_Counter pgStatBlockWriteTime
void pgstat_report_vacuum(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, TimestampTz starttime)
#define qsort(a, b, c, d)
GlobalVisState * GlobalVisTestFor(Relation rel)
bool GlobalVisTestXidConsideredRunning(GlobalVisState *state, TransactionId xid, bool allow_update)
#define PROGRESS_VACUUM_PHASE_FINAL_CLEANUP
#define PROGRESS_VACUUM_MODE
#define PROGRESS_VACUUM_MODE_NORMAL
#define PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM
#define PROGRESS_VACUUM_DEAD_TUPLE_BYTES
#define PROGRESS_VACUUM_PHASE_SCAN_HEAP
#define PROGRESS_VACUUM_TOTAL_HEAP_BLKS
#define PROGRESS_VACUUM_PHASE
#define PROGRESS_VACUUM_DELAY_TIME
#define PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM_WRAPAROUND
#define PROGRESS_VACUUM_NUM_INDEX_VACUUMS
#define PROGRESS_VACUUM_PHASE_VACUUM_HEAP
#define PROGRESS_VACUUM_NUM_DEAD_ITEM_IDS
#define PROGRESS_VACUUM_MAX_DEAD_TUPLE_BYTES
#define PROGRESS_VACUUM_STARTED_BY_MANUAL
#define PROGRESS_VACUUM_HEAP_BLKS_SCANNED
#define PROGRESS_VACUUM_STARTED_BY
#define PROGRESS_VACUUM_PHASE_INDEX_CLEANUP
#define PROGRESS_VACUUM_PHASE_VACUUM_INDEX
#define PROGRESS_VACUUM_MODE_FAILSAFE
#define PROGRESS_VACUUM_INDEXES_PROCESSED
#define PROGRESS_VACUUM_INDEXES_TOTAL
#define PROGRESS_VACUUM_MODE_AGGRESSIVE
#define PROGRESS_VACUUM_HEAP_BLKS_VACUUMED
#define PROGRESS_VACUUM_PHASE_TRUNCATE
void heap_page_prune_and_freeze(PruneFreezeParams *params, PruneFreezeResult *presult, OffsetNumber *off_loc, TransactionId *new_relfrozen_xid, MultiXactId *new_relmin_mxid)
void log_heap_prune_and_freeze(Relation relation, Buffer buffer, Buffer vmbuffer, uint8 vmflags, TransactionId conflict_xid, bool cleanup_lock, PruneReason reason, HeapTupleFreeze *frozen, int nfrozen, OffsetNumber *redirected, int nredirected, OffsetNumber *dead, int ndead, OffsetNumber *unused, int nunused)
Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
ReadStream * read_stream_begin_relation(int flags, BufferAccessStrategy strategy, Relation rel, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
void read_stream_end(ReadStream *stream)
#define READ_STREAM_MAINTENANCE
#define READ_STREAM_USE_BATCHING
#define RelationGetRelid(relation)
#define RelationGetRelationName(relation)
#define RelationNeedsWAL(relation)
#define RelationUsesLocalBuffers(relation)
#define RelationGetNamespace(relation)
void RelationTruncate(Relation rel, BlockNumber nblocks)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
int64 shared_blks_dirtied
struct ErrorContextCallback * previous
void(* callback)(void *arg)
BlockNumber pages_deleted
BlockNumber pages_newly_deleted
BlockNumber next_eager_scan_region_start
ParallelVacuumState * pvs
bool next_unskippable_eager_scanned
VacDeadItemsInfo * dead_items_info
PVWorkerUsage worker_usage
Buffer next_unskippable_vmbuffer
BlockNumber nonempty_pages
BlockNumber eager_scan_remaining_fails
BlockNumber scanned_pages
int num_dead_items_resets
BlockNumber new_frozen_tuple_pages
BlockNumber removed_pages
IndexBulkDeleteResult ** indstats
BlockNumber new_all_frozen_pages
BlockNumber new_all_visible_all_frozen_pages
BlockNumber new_all_visible_pages
TransactionId NewRelfrozenXid
bool consider_bypass_optimization
Size total_dead_items_bytes
BlockNumber next_unskippable_block
int64 recently_dead_tuples
BlockNumber missed_dead_pages
BlockNumber current_block
BufferAccessStrategy bstrategy
BlockNumber eager_scan_remaining_successes
BlockNumber lpdead_item_pages
BlockNumber eager_scanned_pages
MultiXactId NewRelminMxid
struct VacuumCutoffs cutoffs
BlockNumber eager_scan_max_fails_per_region
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
int log_vacuum_min_duration
VacOptValue index_cleanup
double max_eager_freeze_failure_rate
TidStoreIter * TidStoreBeginIterate(TidStore *ts)
void TidStoreEndIterate(TidStoreIter *iter)
TidStoreIterResult * TidStoreIterateNext(TidStoreIter *iter)
TidStore * TidStoreCreateLocal(size_t max_bytes, bool insert_only)
void TidStoreDestroy(TidStore *ts)
int TidStoreGetBlockOffsets(TidStoreIterResult *result, OffsetNumber *offsets, int max_offsets)
void TidStoreSetBlockOffsets(TidStore *ts, BlockNumber blkno, OffsetNumber *offsets, int num_offsets)
size_t TidStoreMemoryUsage(TidStore *ts)
static bool TransactionIdFollows(TransactionId id1, TransactionId id2)
static TransactionId ReadNextTransactionId(void)
#define InvalidTransactionId
static bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
#define TransactionIdIsValid(xid)
#define TransactionIdIsNormal(xid)
static bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
bool track_cost_delay_timing
void vac_open_indexes(Relation relation, LOCKMODE lockmode, int *nindexes, Relation **Irel)
IndexBulkDeleteResult * vac_cleanup_one_index(IndexVacuumInfo *ivinfo, IndexBulkDeleteResult *istat)
void vac_close_indexes(int nindexes, Relation *Irel, LOCKMODE lockmode)
void vacuum_delay_point(bool is_analyze)
bool vacuum_get_cutoffs(Relation rel, const VacuumParams *params, struct VacuumCutoffs *cutoffs)
bool vacuum_xid_failsafe_check(const struct VacuumCutoffs *cutoffs)
bool VacuumFailsafeActive
double vac_estimate_reltuples(Relation relation, BlockNumber total_pages, BlockNumber scanned_pages, double scanned_tuples)
void vac_update_relstats(Relation relation, BlockNumber num_pages, double num_tuples, BlockNumber num_all_visible_pages, BlockNumber num_all_frozen_pages, bool hasindex, TransactionId frozenxid, MultiXactId minmulti, bool *frozenxid_updated, bool *minmulti_updated, bool in_outer_xact)
IndexBulkDeleteResult * vac_bulkdel_one_index(IndexVacuumInfo *ivinfo, IndexBulkDeleteResult *istat, TidStore *dead_items, VacDeadItemsInfo *dead_items_info)
@ VACOPTVALUE_UNSPECIFIED
#define VACOPT_DISABLE_PAGE_SKIPPING
static int lazy_scan_prune(LVRelState *vacrel, Buffer buf, BlockNumber blkno, Page page, Buffer vmbuffer, bool *has_lpdead_items, bool *vm_page_frozen)
static void dead_items_cleanup(LVRelState *vacrel)
static void update_relstats_all_indexes(LVRelState *vacrel)
static void dead_items_add(LVRelState *vacrel, BlockNumber blkno, OffsetNumber *offsets, int num_offsets)
static BlockNumber heap_vac_scan_next_block(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
#define VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL
static void vacuum_error_callback(void *arg)
#define EAGER_SCAN_REGION_SIZE
static void lazy_truncate_heap(LVRelState *vacrel)
static void lazy_vacuum(LVRelState *vacrel)
static void lazy_cleanup_all_indexes(LVRelState *vacrel)
#define MAX_EAGER_FREEZE_SUCCESS_RATE
static bool lazy_scan_noprune(LVRelState *vacrel, Buffer buf, BlockNumber blkno, Page page, bool *has_lpdead_items)
static BlockNumber vacuum_reap_lp_read_stream_next(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
#define REL_TRUNCATE_MINIMUM
static bool should_attempt_truncation(LVRelState *vacrel)
static bool lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf, BlockNumber blkno, Page page, bool sharelock, Buffer vmbuffer)
@ VACUUM_ERRCB_PHASE_SCAN_HEAP
@ VACUUM_ERRCB_PHASE_VACUUM_INDEX
@ VACUUM_ERRCB_PHASE_TRUNCATE
@ VACUUM_ERRCB_PHASE_INDEX_CLEANUP
@ VACUUM_ERRCB_PHASE_VACUUM_HEAP
@ VACUUM_ERRCB_PHASE_UNKNOWN
static void lazy_scan_heap(LVRelState *vacrel)
#define ParallelVacuumIsActive(vacrel)
static void restore_vacuum_error_info(LVRelState *vacrel, const LVSavedErrInfo *saved_vacrel)
static IndexBulkDeleteResult * lazy_vacuum_one_index(Relation indrel, IndexBulkDeleteResult *istat, double reltuples, LVRelState *vacrel)
static void find_next_unskippable_block(LVRelState *vacrel, bool *skipsallvis)
static void dead_items_reset(LVRelState *vacrel)
#define REL_TRUNCATE_FRACTION
static bool lazy_check_wraparound_failsafe(LVRelState *vacrel)
static IndexBulkDeleteResult * lazy_cleanup_one_index(Relation indrel, IndexBulkDeleteResult *istat, double reltuples, bool estimated_count, LVRelState *vacrel)
static void lazy_vacuum_heap_page(LVRelState *vacrel, BlockNumber blkno, Buffer buffer, OffsetNumber *deadoffsets, int num_offsets, Buffer vmbuffer)
static void heap_vacuum_eager_scan_setup(LVRelState *vacrel, const VacuumParams *params)
static bool heap_page_would_be_all_visible(Relation rel, Buffer buf, GlobalVisState *vistest, bool allow_update_vistest, OffsetNumber *deadoffsets, int ndeadoffsets, bool *all_frozen, TransactionId *newest_live_xid, OffsetNumber *logging_offnum)
void heap_vacuum_rel(Relation rel, const VacuumParams *params, BufferAccessStrategy bstrategy)
#define BYPASS_THRESHOLD_PAGES
static void dead_items_alloc(LVRelState *vacrel, int nworkers)
#define VACUUM_TRUNCATE_LOCK_TIMEOUT
static bool lazy_vacuum_all_indexes(LVRelState *vacrel)
static void update_vacuum_error_info(LVRelState *vacrel, LVSavedErrInfo *saved_vacrel, int phase, BlockNumber blkno, OffsetNumber offnum)
static BlockNumber count_nondeletable_pages(LVRelState *vacrel, bool *lock_waiter_detected)
#define SKIP_PAGES_THRESHOLD
#define FAILSAFE_EVERY_PAGES
#define VACUUM_TRUNCATE_LOCK_CHECK_INTERVAL
static int cmpOffsetNumbers(const void *a, const void *b)
static void lazy_vacuum_heap_rel(LVRelState *vacrel)
#define VACUUM_FSM_EVERY_PAGES
void parallel_vacuum_cleanup_all_indexes(ParallelVacuumState *pvs, long num_table_tuples, int num_index_scans, bool estimated_count, PVWorkerStats *wstats)
TidStore * parallel_vacuum_get_dead_items(ParallelVacuumState *pvs, VacDeadItemsInfo **dead_items_info_p)
void parallel_vacuum_bulkdel_all_indexes(ParallelVacuumState *pvs, long num_table_tuples, int num_index_scans, PVWorkerStats *wstats)
ParallelVacuumState * parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes, int nrequested_workers, int vac_work_mem, int elevel, BufferAccessStrategy bstrategy)
void parallel_vacuum_reset_dead_items(ParallelVacuumState *pvs)
void parallel_vacuum_end(ParallelVacuumState *pvs, IndexBulkDeleteResult **istats)
void visibilitymap_set(BlockNumber heapBlk, Buffer vmBuf, uint8 flags, const RelFileLocator rlocator)
void visibilitymap_pin(Relation rel, BlockNumber heapBlk, Buffer *vmbuf)
uint8 visibilitymap_get_status(Relation rel, BlockNumber heapBlk, Buffer *vmbuf)
void visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_frozen)
#define VISIBILITYMAP_VALID_BITS
#define VISIBILITYMAP_ALL_FROZEN
#define VISIBILITYMAP_ALL_VISIBLE
#define WL_EXIT_ON_PM_DEATH
bool IsInParallelMode(void)