223{
231
232
233
234
235
236
237
238
239#define MAX_EAGER_FREEZE_SUCCESS_RATE 0.2
240
241
242
243
244
245
246
247
248#define EAGER_SCAN_REGION_SIZE 4096
249
251{
252
256
257
260
261
263
265
267
268
272
273
276
280
281
290
291
292
293
294
295
296
297
298
299
300
303
306
307
308
309
310
312
315
316
318
319
320
321
322
323
324
325
327
328
330
334
335
338
340
341
345
352
353
358
359
360
361
362
363
364
365
366
367
368
369
370
372
373
374
375
376
377
378
379
380
381
383
384
385
386
387
388
389
390
391
392
394
395
396
397
398
399
400
401
402
405
406
407
409{
414
415
416
421 void *callback_private_data,
422 void *per_buffer_data);
449 double reltuples,
453 double reltuples,
454 bool estimated_count,
465
466#ifdef USE_ASSERT_CHECKING
469 bool *all_frozen,
472#endif
477 bool *all_frozen,
488
489
490
491
492
493
494
495
496
497
498static void
500{
506
507
508
509
510
511
513 vacrel->eager_scan_max_fails_per_region = 0;
514 vacrel->eager_scan_remaining_fails = 0;
515 vacrel->eager_scan_remaining_successes = 0;
516
517
519 return;
520
521
522
523
524
525
526
527
529 return;
530
531
532
533
534
535
536
537
539 return;
540
541
542
543
544
545
546
547
548
549
550
551
552
553
556 vacrel->cutoffs.FreezeLimit))
558
562 vacrel->cutoffs.MultiXactCutoff))
564
566 return;
567
568
569
570
571
572
573
575
576 vacrel->eager_scan_remaining_successes =
579
580
581 if (
vacrel->eager_scan_remaining_successes == 0)
582 return;
583
584
585
586
587
588
589
590
592
594
597
598 vacrel->eager_scan_max_fails_per_region =
601
602
603
604
605
608
609 vacrel->eager_scan_remaining_fails =
610 vacrel->eager_scan_max_fails_per_region *
612}
613
614
615
616
617
618
619
620
621
622
623
624
625void
628{
631 instrument,
632 skipwithvm,
648
652 if (instrument)
653 {
656 {
659 }
660 }
661
662
664
672 else
675
676
677
678
679
680
681
682
683
684
685
686
687
699
700
704 vacrel->bstrategy = bstrategy;
705 if (instrument &&
vacrel->nindexes > 0)
706 {
707
709 for (
int i = 0;
i <
vacrel->nindexes;
i++)
711 }
712
713
714
715
716
717
718
719
720
721
725
726
727
728
729
731 vacrel->consider_bypass_optimization =
true;
732 vacrel->do_index_vacuuming =
true;
733 vacrel->do_index_cleanup =
true;
736 {
737
738 vacrel->do_index_vacuuming =
false;
739 vacrel->do_index_cleanup =
false;
740 }
742 {
743
744 vacrel->consider_bypass_optimization =
false;
745 }
746 else
747 {
748
750 }
751
752
753 vacrel->scanned_pages = 0;
754 vacrel->eager_scanned_pages = 0;
755 vacrel->removed_pages = 0;
756 vacrel->new_frozen_tuple_pages = 0;
757 vacrel->lpdead_item_pages = 0;
758 vacrel->missed_dead_pages = 0;
759 vacrel->nonempty_pages = 0;
760
761
762
763 vacrel->new_rel_tuples = 0;
764 vacrel->new_live_tuples = 0;
767
768
769 vacrel->num_index_scans = 0;
770 vacrel->num_dead_items_resets = 0;
771 vacrel->total_dead_items_bytes = 0;
772 vacrel->tuples_deleted = 0;
773 vacrel->tuples_frozen = 0;
776 vacrel->recently_dead_tuples = 0;
777 vacrel->missed_dead_tuples = 0;
778
779 vacrel->new_all_visible_pages = 0;
780 vacrel->new_all_visible_all_frozen_pages = 0;
781 vacrel->new_all_frozen_pages = 0;
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
802
803
806
807
808
809
810
811
812 vacrel->skippedallvis =
false;
813 skipwithvm = true;
815 {
816
817
818
819
820 vacrel->aggressive =
true;
821 skipwithvm = false;
822 }
823
824 vacrel->skipwithvm = skipwithvm;
825
826
827
828
829
830
832
833
838
840 {
843 (
errmsg(
"aggressively vacuuming \"%s.%s.%s\"",
846 else
848 (
errmsg(
"vacuuming \"%s.%s.%s\"",
851 }
852
853
854
855
856
857
858
859
862
863
864
865
866
868
869
870
871
872
873
876
877
878
879
880
883
884
885
886
887
888
889
890 if (
vacrel->do_index_cleanup)
892
893
895
896
899
900
902
903
906
907
908
909
910
911
912
913
916 vacrel->cutoffs.relfrozenxid,
917 vacrel->NewRelfrozenXid));
920 vacrel->cutoffs.relminmxid,
922 if (
vacrel->skippedallvis)
923 {
924
925
926
927
928
932 }
933
934
935
936
937
942
943
944
945
946
947
950
951
952
953
954
955
956
957
963
964
965
966
967
968
969
970
971
972
973
976 vacrel->recently_dead_tuples +
977 vacrel->missed_dead_tuples,
978 starttime);
980
981 if (instrument)
982 {
984
988 {
1001
1007
1014
1017 {
1018
1019
1020
1021
1023 msgfmt =
_(
"finished vacuuming \"%s.%s.%s\": index scans: %d\n");
1024 }
1026 {
1027
1028
1029
1030
1031
1032
1034 msgfmt =
_(
"automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1035 else
1036 msgfmt =
_(
"automatic vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1037 }
1038 else
1039 {
1041 msgfmt =
_(
"automatic aggressive vacuum of table \"%s.%s.%s\": index scans: %d\n");
1042 else
1043 msgfmt =
_(
"automatic vacuum of table \"%s.%s.%s\": index scans: %d\n");
1044 }
1049 vacrel->num_index_scans);
1050 appendStringInfo(&
buf,
_(
"pages: %u removed, %u remain, %u scanned (%.2f%% of total), %u eagerly scanned\n"),
1055 100.0 *
vacrel->scanned_pages /
1057 vacrel->eager_scanned_pages);
1059 _(
"tuples: %" PRId64 " removed, %" PRId64 " remain, %" PRId64 " are dead but not yet removable\n"),
1062 vacrel->recently_dead_tuples);
1063 if (
vacrel->missed_dead_tuples > 0)
1065 _(
"tuples missed: %" PRId64 " dead from %u pages not removed due to cleanup lock contention\n"),
1066 vacrel->missed_dead_tuples,
1067 vacrel->missed_dead_pages);
1069 vacrel->cutoffs.OldestXmin);
1071 _(
"removable cutoff: %u, which was %d XIDs old when operation ended\n"),
1074 {
1076 vacrel->cutoffs.relfrozenxid);
1078 _(
"new relfrozenxid: %u, which is %d XIDs ahead of previous value\n"),
1080 }
1082 {
1084 vacrel->cutoffs.relminmxid);
1086 _(
"new relminmxid: %u, which is %d MXIDs ahead of previous value\n"),
1088 }
1090 vacrel->new_frozen_tuple_pages,
1092 100.0 *
vacrel->new_frozen_tuple_pages /
1095
1097 _(
"visibility map: %u pages set all-visible, %u pages set all-frozen (%u were all-visible)\n"),
1098 vacrel->new_all_visible_pages,
1099 vacrel->new_all_visible_all_frozen_pages +
1100 vacrel->new_all_frozen_pages,
1101 vacrel->new_all_frozen_pages);
1102 if (
vacrel->do_index_vacuuming)
1103 {
1104 if (
vacrel->nindexes == 0 ||
vacrel->num_index_scans == 0)
1106 else
1108
1109 msgfmt =
_(
"%u pages from table (%.2f%% of total) had %" PRId64 " dead item identifiers removed\n");
1110 }
1111 else
1112 {
1115 else
1117
1118 msgfmt =
_(
"%u pages from table (%.2f%% of total) have %" PRId64 " dead item identifiers\n");
1119 }
1121 vacrel->lpdead_item_pages,
1125 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1126 {
1128
1129 if (!istat)
1130 continue;
1131
1133 _(
"index \"%s\": pages: %u in total, %u newly deleted, %u currently deleted, %u reusable\n"),
1139 }
1141 {
1142
1143
1144
1145
1146
1147
1150 }
1152 {
1155
1158 }
1160 {
1165 }
1180
1181
1182
1183
1184
1185
1186
1187
1188
1190 ngettext(
"memory usage: dead item storage %.2f MB accumulated across %d reset (limit %.2f MB each)\n",
1191 "memory usage: dead item storage %.2f MB accumulated across %d resets (limit %.2f MB each)\n",
1192 vacrel->num_dead_items_resets),
1193 (
double)
vacrel->total_dead_items_bytes / (1024 * 1024),
1194 vacrel->num_dead_items_resets,
1197
1201 }
1202 }
1203
1204
1205 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1206 {
1209
1210 if (instrument)
1212 }
1213}
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251static void
1253{
1256 blkno = 0,
1259 vacrel->eager_scan_remaining_successes;
1265 };
1267
1268
1273
1274
1277 vacrel->next_unskippable_eager_scanned =
false;
1279
1280
1281
1282
1283
1284
1285
1292 sizeof(bool));
1293
1294 while (true)
1295 {
1299 int ndeleted = 0;
1301 void *per_buffer_data =
NULL;
1304
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316 if (
vacrel->scanned_pages > 0 &&
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328 if (
vacrel->dead_items_info->num_items > 0 &&
1330 {
1331
1332
1333
1334
1335
1336
1338 {
1341 }
1342
1343
1344 vacrel->consider_bypass_optimization =
false;
1346
1347
1348
1349
1350
1351
1353 blkno + 1);
1355
1356
1359 }
1360
1362
1363
1365 break;
1366
1371
1374 vacrel->eager_scanned_pages++;
1375
1376
1380
1381
1382
1383
1384
1385
1387
1388
1389
1390
1391
1392
1393
1395
1398
1399
1401 vmbuffer))
1402 {
1403
1404 continue;
1405 }
1406
1407
1408
1409
1410
1411
1412
1413
1414
1417 {
1418
1419
1420
1421
1426 }
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1443 vmbuffer,
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1461 {
1462
1464
1466 {
1467 if (
vacrel->eager_scan_remaining_successes > 0)
1468 vacrel->eager_scan_remaining_successes--;
1469
1470 if (
vacrel->eager_scan_remaining_successes == 0)
1471 {
1472
1473
1474
1475
1476
1477
1478
1479 if (
vacrel->eager_scan_max_fails_per_region > 0)
1481 (
errmsg(
"disabling eager scanning after freezing %u eagerly scanned blocks of relation \"%s.%s.%s\"",
1485
1486
1487
1488
1489
1490
1491 vacrel->eager_scan_remaining_fails = 0;
1493 vacrel->eager_scan_max_fails_per_region = 0;
1494 }
1495 }
1496 else if (
vacrel->eager_scan_remaining_fails > 0)
1497 vacrel->eager_scan_remaining_fails--;
1498 }
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519 if (
vacrel->nindexes == 0
1520 || !
vacrel->do_index_vacuuming
1522 {
1524
1527
1528
1529
1530
1531
1532
1533
1536 {
1538 blkno);
1540 }
1541 }
1542 else
1544 }
1545
1549
1550
1551
1552
1553
1555 rel_pages);
1556
1557
1561
1562
1563
1564
1565
1568 vacrel->missed_dead_tuples;
1569
1571
1572
1573
1574
1575
1576 if (
vacrel->dead_items_info->num_items > 0)
1578
1579
1580
1581
1582
1583
1584
1587
1588
1590
1591
1594}
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1622 void *callback_private_data,
1623 void *per_buffer_data)
1624{
1627
1628
1630
1631
1633 {
1635 {
1638 }
1640 }
1641
1642
1643
1644
1647 {
1648
1649
1650
1651
1652
1654
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1673 {
1676 vacrel->skippedallvis =
true;
1677 }
1678 }
1679
1680
1682 {
1683
1684
1685
1686
1687
1689
1690 *((bool *) per_buffer_data) = false;
1691 return vacrel->current_block;
1692 }
1693 else
1694 {
1695
1696
1697
1698
1700
1702 *((
bool *) per_buffer_data) =
vacrel->next_unskippable_eager_scanned;
1703 return vacrel->current_block;
1704 }
1705}
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720static void
1722{
1725 Buffer next_unskippable_vmbuffer =
vacrel->next_unskippable_vmbuffer;
1726 bool next_unskippable_eager_scanned = false;
1727
1729
1730 for (;; next_unskippable_block++)
1731 {
1733 next_unskippable_block,
1734 &next_unskippable_vmbuffer);
1735
1736
1737
1738
1739
1740
1741
1742
1743 if (next_unskippable_block >=
vacrel->next_eager_scan_region_start)
1744 {
1745 vacrel->eager_scan_remaining_fails =
1746 vacrel->eager_scan_max_fails_per_region;
1748 }
1749
1750
1751
1752
1753
1755 {
1757 break;
1758 }
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770 if (next_unskippable_block == rel_pages - 1)
1771 break;
1772
1773
1775 break;
1776
1777
1778
1779
1780
1782 continue;
1783
1784
1785
1786
1787
1789 break;
1790
1791
1792
1793
1794
1795
1796 if (
vacrel->eager_scan_remaining_fails > 0)
1797 {
1798 next_unskippable_eager_scanned = true;
1799 break;
1800 }
1801
1802
1803
1804
1805
1807 }
1808
1809
1810 vacrel->next_unskippable_block = next_unskippable_block;
1811 vacrel->next_unskippable_eager_scanned = next_unskippable_eager_scanned;
1812 vacrel->next_unskippable_vmbuffer = next_unskippable_vmbuffer;
1813}
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849static bool
1852{
1854
1856 {
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1877
1879 {
1881
1883 }
1884
1885 return true;
1886 }
1887
1889 {
1890
1891
1892
1893
1894
1896 {
1899
1901 {
1902
1903 return false;
1904 }
1905 }
1906 else
1907 {
1908
1909 }
1910
1911
1912
1913
1914
1916 {
1918
1919
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1934
1943
1944
1945 vacrel->new_all_visible_pages++;
1946 vacrel->new_all_visible_all_frozen_pages++;
1947 }
1948
1952 return true;
1953 }
1954
1955
1956 return false;
1957}
1958
1959
1960static int
1962{
1964}
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982static void
1988{
1990
1992
1993
1994
1995
1996
1997
1998
2001 {
2004 errmsg(
"page is not marked all-visible but visibility map bit is set in relation \"%s\" page %u",
2006
2010 }
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2027 {
2030 errmsg(
"page containing LP_DEAD items is marked as all-visible in relation \"%s\" page %u",
2032
2038 }
2039}
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058static int
2066{
2070 .relation = rel,
2074 .vistest =
vacrel->vistest,
2075 .cutoffs = &
vacrel->cutoffs,
2076 };
2079
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097 if (
vacrel->nindexes == 0)
2099
2104
2107
2109 {
2110
2111
2112
2113
2114
2115
2116 vacrel->new_frozen_tuple_pages++;
2117 }
2118
2119
2120
2121
2122
2123
2124
2125
2126#ifdef USE_ASSERT_CHECKING
2128 {
2131
2133
2137
2139
2142 }
2143#endif
2144
2145
2146
2147
2149 {
2150 vacrel->lpdead_item_pages++;
2151
2152
2153
2154
2155
2156
2157
2160
2162 }
2163
2164
2169 vacrel->recently_dead_tuples +=
presult.recently_dead_tuples;
2170
2171
2173 vacrel->nonempty_pages = blkno + 1;
2174
2175
2177
2180
2182
2184 presult.lpdead_items, vmbuffer,
2186
2189
2190
2192
2195
2196
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2215
2216
2217
2218
2219
2220
2223
2226 vmbuffer,
presult.vm_conflict_horizon,
2228
2229
2230
2231
2232
2234 {
2235 vacrel->new_all_visible_pages++;
2237 {
2238 vacrel->new_all_visible_all_frozen_pages++;
2240 }
2241 }
2244 {
2245 vacrel->new_all_frozen_pages++;
2247 }
2248
2250}
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272static bool
2278{
2280 maxoff;
2281 int lpdead_items,
2282 live_tuples,
2283 recently_dead_tuples,
2284 missed_dead_tuples;
2285 bool hastup;
2290
2292
2293 hastup = false;
2294
2295 lpdead_items = 0;
2296 live_tuples = 0;
2297 recently_dead_tuples = 0;
2298 missed_dead_tuples = 0;
2299
2302 offnum <= maxoff;
2304 {
2307
2310
2312 continue;
2313
2315 {
2316 hastup = true;
2317 continue;
2318 }
2319
2321 {
2322
2323
2324
2325
2326 deadoffsets[lpdead_items++] = offnum;
2327 continue;
2328 }
2329
2330 hastup = true;
2333 &NoFreezePageRelfrozenXid,
2334 &NoFreezePageRelminMxid))
2335 {
2336
2338 {
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2351 return false;
2352 }
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362 }
2363
2368
2371 {
2374
2375
2376
2377
2378 live_tuples++;
2379
2380 break;
2382
2383
2384
2385
2386
2387 missed_dead_tuples++;
2388 break;
2390
2391
2392
2393
2394 recently_dead_tuples++;
2395 break;
2397
2398
2399
2400
2401 break;
2402 default:
2403 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
2404 break;
2405 }
2406 }
2407
2409
2410
2411
2412
2413
2414
2415 vacrel->NewRelfrozenXid = NoFreezePageRelfrozenXid;
2416 vacrel->NewRelminMxid = NoFreezePageRelminMxid;
2417
2418
2419 if (
vacrel->nindexes == 0)
2420 {
2421
2422 if (lpdead_items > 0)
2423 {
2424
2425
2426
2427
2428
2429
2430
2431
2432 hastup = true;
2433 missed_dead_tuples += lpdead_items;
2434 }
2435 }
2436 else if (lpdead_items > 0)
2437 {
2438
2439
2440
2441
2442
2443 vacrel->lpdead_item_pages++;
2444
2446
2447 vacrel->lpdead_items += lpdead_items;
2448 }
2449
2450
2451
2452
2453 vacrel->live_tuples += live_tuples;
2454 vacrel->recently_dead_tuples += recently_dead_tuples;
2455 vacrel->missed_dead_tuples += missed_dead_tuples;
2456 if (missed_dead_tuples > 0)
2457 vacrel->missed_dead_pages++;
2458
2459
2460 if (hastup)
2461 vacrel->nonempty_pages = blkno + 1;
2462
2463
2465
2466
2467 return true;
2468}
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483static void
2485{
2487
2488
2491
2492 if (!
vacrel->do_index_vacuuming)
2493 {
2496 return;
2497 }
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2519 if (
vacrel->consider_bypass_optimization &&
vacrel->rel_pages > 0)
2520 {
2522
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2553 }
2554
2556 {
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567 vacrel->do_index_vacuuming =
false;
2568 }
2570 {
2571
2572
2573
2574
2576 }
2577 else
2578 {
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2591 }
2592
2593
2594
2595
2596
2598}
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608static bool
2610{
2616 };
2621 };
2624
2628
2629
2631 {
2632
2633 return false;
2634 }
2635
2636
2637
2638
2639
2643
2645 {
2647 {
2650
2654
2655
2658
2660 {
2661
2663 break;
2664 }
2665 }
2666 }
2667 else
2668 {
2669
2671 vacrel->num_index_scans);
2672
2673
2674
2675
2676
2679 }
2680
2681
2682
2683
2684
2685
2686
2687
2689 vacrel->dead_items_info->num_items ==
vacrel->lpdead_items);
2691
2692
2693
2694
2695
2696
2697
2698
2699 vacrel->num_index_scans++;
2704
2706}
2707
2708
2709
2710
2711
2712
2713
2714
2717 void *callback_private_data,
2718 void *per_buffer_data)
2719{
2722
2726
2727
2728
2729
2730
2732
2734}
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753static void
2755{
2761
2765
2766
2769
2770
2774
2776
2777
2778
2779
2780
2781
2782
2783
2784
2791 iter,
2793
2794 while (true)
2795 {
2803
2805
2807
2808
2810 break;
2811
2813
2817
2818
2819
2820
2821
2822
2824
2825
2829
2830
2833
2837 }
2838
2841
2845
2846
2847
2848
2849
2851 (
vacrel->dead_items_info->num_items ==
vacrel->lpdead_items &&
2853
2855 (
errmsg(
"table \"%s\": removed %" PRId64 " dead item identifiers in %u pages",
2858
2859
2861}
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871static void
2875{
2878 int nunused = 0;
2881 bool all_frozen;
2884
2886
2888
2889
2893
2894
2895
2896
2897
2898
2899
2900
2901
2903 vacrel->cutoffs.OldestXmin,
2905 &all_frozen, &visibility_cutoff_xid,
2907 {
2909 if (all_frozen)
2910 {
2913 }
2914
2915
2916
2917
2918
2919
2921 }
2922
2924
2926 {
2929
2931
2934 unused[nunused++] =
toff;
2935 }
2936
2938
2939
2941
2943 {
2944
2945
2946
2947
2952 vacrel->rel->rd_locator);
2954 }
2955
2956
2957
2958
2960
2961
2963 {
2973 unused, nunused);
2974 }
2975
2977
2979 {
2980
2982 vacrel->new_all_visible_pages++;
2983 if (all_frozen)
2984 vacrel->new_all_visible_all_frozen_pages++;
2985 }
2986
2987
2989}
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003static bool
3005{
3006
3008 return true;
3009
3011 {
3016 };
3018
3020
3021
3022
3023
3024
3025
3027
3028
3029 vacrel->do_index_vacuuming =
false;
3030 vacrel->do_index_cleanup =
false;
3031 vacrel->do_rel_truncate =
false;
3032
3033
3035
3037 (
errmsg(
"bypassing nonessential maintenance of table \"%s.%s.%s\" as a failsafe after %d index scans",
3039 vacrel->num_index_scans),
3040 errdetail(
"The table's relfrozenxid or relminmxid is too far in the past."),
3041 errhint(
"Consider increasing configuration parameter \"maintenance_work_mem\" or \"autovacuum_work_mem\".\n"
3042 "You might also need to consider other ways for VACUUM to keep up with the allocation of transaction IDs.")));
3043
3044
3047
3048 return true;
3049 }
3050
3051 return false;
3052}
3053
3054
3055
3056
3057static void
3059{
3060 double reltuples =
vacrel->new_rel_tuples;
3061 bool estimated_count =
vacrel->scanned_pages <
vacrel->rel_pages;
3065 };
3069 };
3072
3075
3076
3077
3078
3079
3083
3085 {
3087 {
3090
3093 estimated_count,
vacrel);
3094
3095
3098 }
3099 }
3100 else
3101 {
3102
3105 estimated_count);
3106 }
3107
3108
3110}
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3128{
3131
3134 ivinfo.analyze_only =
false;
3135 ivinfo.report_progress =
false;
3136 ivinfo.estimated_count =
true;
3138 ivinfo.num_heap_tuples = reltuples;
3140
3141
3142
3143
3144
3145
3146
3152
3153
3155 vacrel->dead_items_info);
3156
3157
3161
3162 return istat;
3163}
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3176 double reltuples, bool estimated_count,
3178{
3181
3184 ivinfo.analyze_only =
false;
3185 ivinfo.report_progress =
false;
3186 ivinfo.estimated_count = estimated_count;
3188
3189 ivinfo.num_heap_tuples = reltuples;
3191
3192
3193
3194
3195
3196
3197
3203
3205
3206
3210
3211 return istat;
3212}
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234static bool
3236{
3238
3240 return false;
3241
3246 return true;
3247
3248 return false;
3249}
3250
3251
3252
3253
3254static void
3256{
3261
3262
3265
3266
3269
3270
3271
3272
3273 do
3274 {
3275
3276
3277
3278
3279
3280
3281
3284 while (true)
3285 {
3287 break;
3288
3289
3290
3291
3292
3294
3297 {
3298
3299
3300
3301
3303 (
errmsg(
"\"%s\": stopping truncate due to conflicting lock request",
3305 return;
3306 }
3307
3313 }
3314
3315
3316
3317
3318
3319
3322 {
3323
3324
3325
3326
3327
3328
3329
3331 return;
3332 }
3333
3334
3335
3336
3337
3338
3339
3342
3344 {
3345
3347 return;
3348 }
3349
3350
3351
3352
3354
3355
3356
3357
3358
3359
3360
3361
3363
3364
3365
3366
3367
3368
3371
3373 (
errmsg(
"table \"%s\": truncated %u to %u pages",
3378}
3379
3380
3381
3382
3383
3384
3387{
3389 "prefetch size must be power of 2");
3390
3394
3395
3397
3398
3399
3400
3401
3402
3403
3404 blkno =
vacrel->rel_pages;
3406 while (blkno >
vacrel->nonempty_pages)
3407 {
3411 maxoff;
3412 bool hastup;
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422 if ((blkno % 32) == 0)
3423 {
3426
3432 {
3434 {
3436 (
errmsg(
"table \"%s\": suspending truncate due to conflicting lock request",
3438
3440 return blkno;
3441 }
3443 }
3444 }
3445
3446
3447
3448
3449
3450
3452
3453 blkno--;
3454
3455
3457 {
3460
3463 {
3466 }
3468 }
3469
3472
3473
3475
3477
3479 {
3481 continue;
3482 }
3483
3484 hastup = false;
3487 offnum <= maxoff;
3489 {
3491
3493
3494
3495
3496
3497
3498
3500 {
3501 hastup = true;
3502 break;
3503 }
3504 }
3505
3507
3508
3509 if (hastup)
3510 return blkno + 1;
3511 }
3512
3513
3514
3515
3516
3517
3518 return vacrel->nonempty_pages;
3519}
3520
3521
3522
3523
3524
3525
3526
3527
3528static void
3530{
3535
3536
3537
3538
3539
3540
3541 if (nworkers >= 0 &&
vacrel->nindexes > 1 &&
vacrel->do_index_vacuuming)
3542 {
3543
3544
3545
3546
3548 {
3549
3550
3551
3552
3553 if (nworkers > 0)
3555 (
errmsg(
"disabling parallel option of vacuum on \"%s\" --- cannot vacuum temporary tables in parallel",
3557 }
3558 else
3560 vacrel->nindexes, nworkers,
3564
3565
3566
3567
3568
3570 {
3572 &
vacrel->dead_items_info);
3573 return;
3574 }
3575 }
3576
3577
3578
3579
3580
3581
3585 vacrel->dead_items_info = dead_items_info;
3586
3588}
3589
3590
3591
3592
3593static void
3596{
3600 };
3602
3605
3606
3610}
3611
3612
3613
3614
3615static void
3617{
3618
3619 vacrel->num_dead_items_resets++;
3621
3623 {
3626 &
vacrel->dead_items_info);
3627 return;
3628 }
3629
3630
3633
3634
3635 vacrel->dead_items_info->num_items = 0;
3636}
3637
3638
3639
3640
3641static void
3643{
3645 {
3646
3647 return;
3648 }
3649
3650
3653}
3654
3655#ifdef USE_ASSERT_CHECKING
3656
3657
3658
3659
3660
3661
3662static bool
3665 bool *all_frozen,
3668{
3669
3671 OldestXmin,
3673 all_frozen,
3674 visibility_cutoff_xid,
3676}
3677#endif
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709static bool
3714 bool *all_frozen,
3717{
3721 maxoff;
3722 bool all_visible = true;
3724
3726 *all_frozen = true;
3727
3729
3730#ifdef USE_ASSERT_CHECKING
3731
3733 {
3735 Assert(deadoffsets[
i - 1] < deadoffsets[
i]);
3736 }
3737#endif
3738
3741 offnum <= maxoff && all_visible;
3743 {
3747
3748
3749
3750
3751
3754
3755
3757 continue;
3758
3760
3761
3762
3763
3764
3766 {
3767 if (!deadoffsets ||
3770 {
3771 *all_frozen = all_visible = false;
3772 break;
3773 }
3775 continue;
3776 }
3777
3779
3783
3784
3787 {
3789 {
3791
3792
3794 {
3795 all_visible = false;
3796 *all_frozen = false;
3797 break;
3798 }
3799
3800
3801
3802
3803
3806 {
3807 all_visible = false;
3808 *all_frozen = false;
3809 break;
3810 }
3811
3812
3815 *visibility_cutoff_xid = xmin;
3816
3817
3818 if (all_visible && *all_frozen &&
3820 *all_frozen = false;
3821 }
3822 break;
3823
3828 {
3829 all_visible = false;
3830 *all_frozen = false;
3831 break;
3832 }
3833 default:
3834 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
3835 break;
3836 }
3837 }
3838
3839
3841
3842 return all_visible;
3843}
3844
3845
3846
3847
3848static void
3850{
3852 int nindexes =
vacrel->nindexes;
3854
3856
3857 for (
int idx = 0;
idx < nindexes;
idx++)
3858 {
3861
3863 continue;
3864
3865
3869 0, 0,
3870 false,
3874 }
3875}
3876
3877
3878
3879
3880
3881
3882
3883static void
3885{
3887
3889 {
3892 {
3894 errcontext(
"while scanning block %u offset %u of relation \"%s.%s\"",
3896 else
3897 errcontext(
"while scanning block %u of relation \"%s.%s\"",
3899 }
3900 else
3901 errcontext(
"while scanning relation \"%s.%s\"",
3903 break;
3904
3907 {
3909 errcontext(
"while vacuuming block %u offset %u of relation \"%s.%s\"",
3911 else
3912 errcontext(
"while vacuuming block %u of relation \"%s.%s\"",
3914 }
3915 else
3916 errcontext(
"while vacuuming relation \"%s.%s\"",
3918 break;
3919
3921 errcontext(
"while vacuuming index \"%s\" of relation \"%s.%s\"",
3923 break;
3924
3926 errcontext(
"while cleaning up index \"%s\" of relation \"%s.%s\"",
3928 break;
3929
3932 errcontext(
"while truncating relation \"%s.%s\" to %u blocks",
3934 break;
3935
3937 default:
3938 return;
3939
3940 }
3941}
3942
3943
3944
3945
3946
3947static void
3950{
3952 {
3956 }
3957
3961}
3962
3963
3964
3965
3966static void
3969{
3973}
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)
bool BufferIsLockedByMeInMode(Buffer buffer, BufferLockMode mode)
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 void PageClearAllVisible(Page 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 XLogRecPtr PageGetLSN(const PageData *page)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
#define ngettext(s, p, n)
#define Assert(condition)
TransactionId MultiXactId
#define StaticAssertDecl(condition, errmessage)
ErrorContextCallback * error_context_stack
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
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
@ HEAPTUPLE_RECENTLY_DEAD
@ HEAPTUPLE_INSERT_IN_PROGRESS
@ HEAPTUPLE_DELETE_IN_PROGRESS
#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 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
#define ERRCODE_DATA_CORRUPTED
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)
#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
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_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)
bool vacuum_get_cutoffs(Relation rel, const VacuumParams params, struct VacuumCutoffs *cutoffs)
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 identify_and_fix_vm_corruption(Relation rel, Buffer heap_buffer, BlockNumber heap_blk, Page heap_page, int nlpdead_items, Buffer vmbuffer, uint8 *vmbits)
static void update_relstats_all_indexes(LVRelState *vacrel)
static void dead_items_add(LVRelState *vacrel, BlockNumber blkno, OffsetNumber *offsets, int num_offsets)
void heap_vacuum_rel(Relation rel, const VacuumParams params, BufferAccessStrategy bstrategy)
static BlockNumber heap_vac_scan_next_block(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
static void heap_vacuum_eager_scan_setup(LVRelState *vacrel, const VacuumParams params)
#define VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL
static void vacuum_error_callback(void *arg)
static bool heap_page_would_be_all_visible(Relation rel, Buffer buf, TransactionId OldestXmin, OffsetNumber *deadoffsets, int ndeadoffsets, bool *all_frozen, TransactionId *visibility_cutoff_xid, OffsetNumber *logging_offnum)
#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)
#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
TidStore * parallel_vacuum_get_dead_items(ParallelVacuumState *pvs, VacDeadItemsInfo **dead_items_info_p)
ParallelVacuumState * parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes, int nrequested_workers, int vac_work_mem, int elevel, BufferAccessStrategy bstrategy)
void parallel_vacuum_bulkdel_all_indexes(ParallelVacuumState *pvs, long num_table_tuples, int num_index_scans)
void parallel_vacuum_reset_dead_items(ParallelVacuumState *pvs)
void parallel_vacuum_cleanup_all_indexes(ParallelVacuumState *pvs, long num_table_tuples, int num_index_scans, bool estimated_count)
void parallel_vacuum_end(ParallelVacuumState *pvs, IndexBulkDeleteResult **istats)
void visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf, XLogRecPtr recptr, Buffer vmBuf, TransactionId cutoff_xid, uint8 flags)
bool visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf, uint8 flags)
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)
void visibilitymap_set_vmbits(BlockNumber heapBlk, Buffer vmBuf, uint8 flags, const RelFileLocator rlocator)
#define VISIBILITYMAP_VALID_BITS
#define VISIBILITYMAP_ALL_FROZEN
#define VISIBILITYMAP_ALL_VISIBLE
#define WL_EXIT_ON_PM_DEATH
bool IsInParallelMode(void)
#define XLogRecPtrIsValid(r)
#define InvalidXLogRecPtr
XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std)