222{
230
231
232
233
234
235
236
237
238#define MAX_EAGER_FREEZE_SUCCESS_RATE 0.2
239
240
241
242
243
244
245
246
247#define EAGER_SCAN_REGION_SIZE 4096
248
250{
251
255
256
259
260
262
264
266
267
271
272
275
279
280
289
290
291
292
293
294
295
296
297
298
299
302
305
306
307
308
309
311
314
315
317
318
319
320
321
322
323
324
326
327
329
333
334
337
339
340
344
351
352
357
358
359
360
361
362
363
364
365
366
367
368
369
371
372
373
374
375
376
377
378
379
380
382
383
384
385
386
387
388
389
390
391
393
394
395
396
397
398
399
400
401
404
405
406
408{
413
414
415
420 void *callback_private_data,
421 void *per_buffer_data);
448 double reltuples,
452 double reltuples,
453 bool estimated_count,
464
465#ifdef USE_ASSERT_CHECKING
468 bool *all_frozen,
471#endif
476 bool *all_frozen,
487
488
489
490
491
492
493
494
495
496
497static void
499{
505
506
507
508
509
510
512 vacrel->eager_scan_max_fails_per_region = 0;
513 vacrel->eager_scan_remaining_fails = 0;
514 vacrel->eager_scan_remaining_successes = 0;
515
516
518 return;
519
520
521
522
523
524
525
526
528 return;
529
530
531
532
533
534
535
536
538 return;
539
540
541
542
543
544
545
546
547
548
549
550
551
552
555 vacrel->cutoffs.FreezeLimit))
557
561 vacrel->cutoffs.MultiXactCutoff))
563
565 return;
566
567
568
569
570
571
572
574
575 vacrel->eager_scan_remaining_successes =
578
579
580 if (
vacrel->eager_scan_remaining_successes == 0)
581 return;
582
583
584
585
586
587
588
589
591
593
596
597 vacrel->eager_scan_max_fails_per_region =
600
601
602
603
604
607
608 vacrel->eager_scan_remaining_fails =
609 vacrel->eager_scan_max_fails_per_region *
611}
612
613
614
615
616
617
618
619
620
621
622
623
624void
627{
630 instrument,
631 skipwithvm,
647
651 if (instrument)
652 {
655 {
658 }
659 }
660
661
663
671 else
674
675
676
677
678
679
680
681
682
683
684
685
686
698
699
703 vacrel->bstrategy = bstrategy;
704 if (instrument &&
vacrel->nindexes > 0)
705 {
706
708 for (
int i = 0;
i <
vacrel->nindexes;
i++)
710 }
711
712
713
714
715
716
717
718
719
720
724
725
726
727
728
730 vacrel->consider_bypass_optimization =
true;
731 vacrel->do_index_vacuuming =
true;
732 vacrel->do_index_cleanup =
true;
735 {
736
737 vacrel->do_index_vacuuming =
false;
738 vacrel->do_index_cleanup =
false;
739 }
741 {
742
743 vacrel->consider_bypass_optimization =
false;
744 }
745 else
746 {
747
749 }
750
751
752 vacrel->scanned_pages = 0;
753 vacrel->eager_scanned_pages = 0;
754 vacrel->removed_pages = 0;
755 vacrel->new_frozen_tuple_pages = 0;
756 vacrel->lpdead_item_pages = 0;
757 vacrel->missed_dead_pages = 0;
758 vacrel->nonempty_pages = 0;
759
760
761
762 vacrel->new_rel_tuples = 0;
763 vacrel->new_live_tuples = 0;
766
767
768 vacrel->num_index_scans = 0;
769 vacrel->num_dead_items_resets = 0;
770 vacrel->total_dead_items_bytes = 0;
771 vacrel->tuples_deleted = 0;
772 vacrel->tuples_frozen = 0;
775 vacrel->recently_dead_tuples = 0;
776 vacrel->missed_dead_tuples = 0;
777
778 vacrel->new_all_visible_pages = 0;
779 vacrel->new_all_visible_all_frozen_pages = 0;
780 vacrel->new_all_frozen_pages = 0;
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
801
802
805
806
807
808
809
810
811 vacrel->skippedallvis =
false;
812 skipwithvm = true;
814 {
815
816
817
818
819 vacrel->aggressive =
true;
820 skipwithvm = false;
821 }
822
823 vacrel->skipwithvm = skipwithvm;
824
825
826
827
828
829
831
832
837
839 {
842 (
errmsg(
"aggressively vacuuming \"%s.%s.%s\"",
845 else
847 (
errmsg(
"vacuuming \"%s.%s.%s\"",
850 }
851
852
853
854
855
856
857
858
861
862
863
864
865
867
868
869
870
871
872
875
876
877
878
879
882
883
884
885
886
887
888
889 if (
vacrel->do_index_cleanup)
891
892
894
895
898
899
901
902
905
906
907
908
909
910
911
912
915 vacrel->cutoffs.relfrozenxid,
916 vacrel->NewRelfrozenXid));
919 vacrel->cutoffs.relminmxid,
921 if (
vacrel->skippedallvis)
922 {
923
924
925
926
927
931 }
932
933
934
935
936
941
942
943
944
945
946
949
950
951
952
953
954
955
956
962
963
964
965
966
967
968
969
970
971
972
975 vacrel->recently_dead_tuples +
976 vacrel->missed_dead_tuples,
977 starttime);
979
980 if (instrument)
981 {
983
987 {
1000
1006
1013
1016 {
1017
1018
1019
1020
1022 msgfmt =
_(
"finished vacuuming \"%s.%s.%s\": index scans: %d\n");
1023 }
1025 {
1026
1027
1028
1029
1030
1031
1033 msgfmt =
_(
"automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1034 else
1035 msgfmt =
_(
"automatic vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1036 }
1037 else
1038 {
1040 msgfmt =
_(
"automatic aggressive vacuum of table \"%s.%s.%s\": index scans: %d\n");
1041 else
1042 msgfmt =
_(
"automatic vacuum of table \"%s.%s.%s\": index scans: %d\n");
1043 }
1048 vacrel->num_index_scans);
1049 appendStringInfo(&
buf,
_(
"pages: %u removed, %u remain, %u scanned (%.2f%% of total), %u eagerly scanned\n"),
1054 100.0 *
vacrel->scanned_pages /
1056 vacrel->eager_scanned_pages);
1058 _(
"tuples: %" PRId64 " removed, %" PRId64 " remain, %" PRId64 " are dead but not yet removable\n"),
1061 vacrel->recently_dead_tuples);
1062 if (
vacrel->missed_dead_tuples > 0)
1064 _(
"tuples missed: %" PRId64 " dead from %u pages not removed due to cleanup lock contention\n"),
1065 vacrel->missed_dead_tuples,
1066 vacrel->missed_dead_pages);
1068 vacrel->cutoffs.OldestXmin);
1070 _(
"removable cutoff: %u, which was %d XIDs old when operation ended\n"),
1073 {
1075 vacrel->cutoffs.relfrozenxid);
1077 _(
"new relfrozenxid: %u, which is %d XIDs ahead of previous value\n"),
1079 }
1081 {
1083 vacrel->cutoffs.relminmxid);
1085 _(
"new relminmxid: %u, which is %d MXIDs ahead of previous value\n"),
1087 }
1089 vacrel->new_frozen_tuple_pages,
1091 100.0 *
vacrel->new_frozen_tuple_pages /
1094
1096 _(
"visibility map: %u pages set all-visible, %u pages set all-frozen (%u were all-visible)\n"),
1097 vacrel->new_all_visible_pages,
1098 vacrel->new_all_visible_all_frozen_pages +
1099 vacrel->new_all_frozen_pages,
1100 vacrel->new_all_frozen_pages);
1101 if (
vacrel->do_index_vacuuming)
1102 {
1103 if (
vacrel->nindexes == 0 ||
vacrel->num_index_scans == 0)
1105 else
1107
1108 msgfmt =
_(
"%u pages from table (%.2f%% of total) had %" PRId64 " dead item identifiers removed\n");
1109 }
1110 else
1111 {
1114 else
1116
1117 msgfmt =
_(
"%u pages from table (%.2f%% of total) have %" PRId64 " dead item identifiers\n");
1118 }
1120 vacrel->lpdead_item_pages,
1124 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1125 {
1127
1128 if (!istat)
1129 continue;
1130
1132 _(
"index \"%s\": pages: %u in total, %u newly deleted, %u currently deleted, %u reusable\n"),
1138 }
1140 {
1141
1142
1143
1144
1145
1146
1149 }
1151 {
1154
1157 }
1159 {
1164 }
1179
1180
1181
1182
1183
1184
1185
1186
1187
1189 ngettext(
"memory usage: dead item storage %.2f MB accumulated across %d reset (limit %.2f MB each)\n",
1190 "memory usage: dead item storage %.2f MB accumulated across %d resets (limit %.2f MB each)\n",
1191 vacrel->num_dead_items_resets),
1192 (
double)
vacrel->total_dead_items_bytes / (1024 * 1024),
1193 vacrel->num_dead_items_resets,
1196
1200 }
1201 }
1202
1203
1204 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1205 {
1208
1209 if (instrument)
1211 }
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
1250static void
1252{
1255 blkno = 0,
1258 vacrel->eager_scan_remaining_successes;
1264 };
1266
1267
1272
1273
1276 vacrel->next_unskippable_eager_scanned =
false;
1278
1279
1280
1281
1282
1283
1284
1291 sizeof(bool));
1292
1293 while (true)
1294 {
1298 int ndeleted = 0;
1300 void *per_buffer_data =
NULL;
1303
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315 if (
vacrel->scanned_pages > 0 &&
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327 if (
vacrel->dead_items_info->num_items > 0 &&
1329 {
1330
1331
1332
1333
1334
1335
1337 {
1340 }
1341
1342
1343 vacrel->consider_bypass_optimization =
false;
1345
1346
1347
1348
1349
1350
1352 blkno + 1);
1354
1355
1358 }
1359
1361
1362
1364 break;
1365
1370
1373 vacrel->eager_scanned_pages++;
1374
1375
1379
1380
1381
1382
1383
1384
1386
1387
1388
1389
1390
1391
1392
1394
1397
1398
1400 vmbuffer))
1401 {
1402
1403 continue;
1404 }
1405
1406
1407
1408
1409
1410
1411
1412
1413
1416 {
1417
1418
1419
1420
1425 }
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1442 vmbuffer,
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1460 {
1461
1463
1465 {
1466 if (
vacrel->eager_scan_remaining_successes > 0)
1467 vacrel->eager_scan_remaining_successes--;
1468
1469 if (
vacrel->eager_scan_remaining_successes == 0)
1470 {
1471
1472
1473
1474
1475
1476
1477
1478 if (
vacrel->eager_scan_max_fails_per_region > 0)
1480 (
errmsg(
"disabling eager scanning after freezing %u eagerly scanned blocks of relation \"%s.%s.%s\"",
1484
1485
1486
1487
1488
1489
1490 vacrel->eager_scan_remaining_fails = 0;
1492 vacrel->eager_scan_max_fails_per_region = 0;
1493 }
1494 }
1495 else if (
vacrel->eager_scan_remaining_fails > 0)
1496 vacrel->eager_scan_remaining_fails--;
1497 }
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518 if (
vacrel->nindexes == 0
1519 || !
vacrel->do_index_vacuuming
1521 {
1523
1526
1527
1528
1529
1530
1531
1532
1535 {
1537 blkno);
1539 }
1540 }
1541 else
1543 }
1544
1548
1549
1550
1551
1552
1554 rel_pages);
1555
1556
1560
1561
1562
1563
1564
1567 vacrel->missed_dead_tuples;
1568
1570
1571
1572
1573
1574
1575 if (
vacrel->dead_items_info->num_items > 0)
1577
1578
1579
1580
1581
1582
1583
1586
1587
1589
1590
1593}
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
1621 void *callback_private_data,
1622 void *per_buffer_data)
1623{
1626
1627
1629
1630
1632 {
1634 {
1637 }
1639 }
1640
1641
1642
1643
1646 {
1647
1648
1649
1650
1651
1653
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1672 {
1675 vacrel->skippedallvis =
true;
1676 }
1677 }
1678
1679
1681 {
1682
1683
1684
1685
1686
1688
1689 *((bool *) per_buffer_data) = false;
1690 return vacrel->current_block;
1691 }
1692 else
1693 {
1694
1695
1696
1697
1699
1701 *((
bool *) per_buffer_data) =
vacrel->next_unskippable_eager_scanned;
1702 return vacrel->current_block;
1703 }
1704}
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719static void
1721{
1724 Buffer next_unskippable_vmbuffer =
vacrel->next_unskippable_vmbuffer;
1725 bool next_unskippable_eager_scanned = false;
1726
1728
1729 for (;; next_unskippable_block++)
1730 {
1732 next_unskippable_block,
1733 &next_unskippable_vmbuffer);
1734
1735
1736
1737
1738
1739
1740
1741
1742 if (next_unskippable_block >=
vacrel->next_eager_scan_region_start)
1743 {
1744 vacrel->eager_scan_remaining_fails =
1745 vacrel->eager_scan_max_fails_per_region;
1747 }
1748
1749
1750
1751
1752
1754 {
1756 break;
1757 }
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769 if (next_unskippable_block == rel_pages - 1)
1770 break;
1771
1772
1774 break;
1775
1776
1777
1778
1779
1781 continue;
1782
1783
1784
1785
1786
1788 break;
1789
1790
1791
1792
1793
1794
1795 if (
vacrel->eager_scan_remaining_fails > 0)
1796 {
1797 next_unskippable_eager_scanned = true;
1798 break;
1799 }
1800
1801
1802
1803
1804
1806 }
1807
1808
1809 vacrel->next_unskippable_block = next_unskippable_block;
1810 vacrel->next_unskippable_eager_scanned = next_unskippable_eager_scanned;
1811 vacrel->next_unskippable_vmbuffer = next_unskippable_vmbuffer;
1812}
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
1848static bool
1851{
1853
1855 {
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1876
1878 {
1880
1882 }
1883
1884 return true;
1885 }
1886
1888 {
1889
1890
1891
1892
1893
1895 {
1898
1900 {
1901
1902 return false;
1903 }
1904 }
1905 else
1906 {
1907
1908 }
1909
1910
1911
1912
1913
1915 {
1917
1918
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1933
1942
1943
1944 vacrel->new_all_visible_pages++;
1945 vacrel->new_all_visible_all_frozen_pages++;
1946 }
1947
1951 return true;
1952 }
1953
1954
1955 return false;
1956}
1957
1958
1959static int
1961{
1963}
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981static void
1987{
1989
1991
1992
1993
1994
1995
1996
1997
2000 {
2003 errmsg(
"page is not marked all-visible but visibility map bit is set in relation \"%s\" page %u",
2005
2009 }
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2026 {
2029 errmsg(
"page containing LP_DEAD items is marked as all-visible in relation \"%s\" page %u",
2031
2037 }
2038}
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057static int
2065{
2069 .relation = rel,
2073 .vistest =
vacrel->vistest,
2074 .cutoffs = &
vacrel->cutoffs,
2075 };
2078
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096 if (
vacrel->nindexes == 0)
2098
2103
2106
2108 {
2109
2110
2111
2112
2113
2114
2115 vacrel->new_frozen_tuple_pages++;
2116 }
2117
2118
2119
2120
2121
2122
2123
2124
2125#ifdef USE_ASSERT_CHECKING
2127 {
2130
2132
2136
2138
2141 }
2142#endif
2143
2144
2145
2146
2148 {
2149 vacrel->lpdead_item_pages++;
2150
2151
2152
2153
2154
2155
2156
2159
2161 }
2162
2163
2168 vacrel->recently_dead_tuples +=
presult.recently_dead_tuples;
2169
2170
2172 vacrel->nonempty_pages = blkno + 1;
2173
2174
2176
2179
2181
2183 presult.lpdead_items, vmbuffer,
2185
2188
2189
2191
2194
2195
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2214
2215
2216
2217
2218
2219
2222
2225 vmbuffer,
presult.vm_conflict_horizon,
2227
2228
2229
2230
2231
2233 {
2234 vacrel->new_all_visible_pages++;
2236 {
2237 vacrel->new_all_visible_all_frozen_pages++;
2239 }
2240 }
2243 {
2244 vacrel->new_all_frozen_pages++;
2246 }
2247
2249}
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271static bool
2277{
2279 maxoff;
2280 int lpdead_items,
2281 live_tuples,
2282 recently_dead_tuples,
2283 missed_dead_tuples;
2284 bool hastup;
2289
2291
2292 hastup = false;
2293
2294 lpdead_items = 0;
2295 live_tuples = 0;
2296 recently_dead_tuples = 0;
2297 missed_dead_tuples = 0;
2298
2301 offnum <= maxoff;
2303 {
2306
2309
2311 continue;
2312
2314 {
2315 hastup = true;
2316 continue;
2317 }
2318
2320 {
2321
2322
2323
2324
2325 deadoffsets[lpdead_items++] = offnum;
2326 continue;
2327 }
2328
2329 hastup = true;
2332 &NoFreezePageRelfrozenXid,
2333 &NoFreezePageRelminMxid))
2334 {
2335
2337 {
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2350 return false;
2351 }
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361 }
2362
2367
2370 {
2373
2374
2375
2376
2377 live_tuples++;
2378
2379 break;
2381
2382
2383
2384
2385
2386 missed_dead_tuples++;
2387 break;
2389
2390
2391
2392
2393 recently_dead_tuples++;
2394 break;
2396
2397
2398
2399
2400 break;
2401 default:
2402 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
2403 break;
2404 }
2405 }
2406
2408
2409
2410
2411
2412
2413
2414 vacrel->NewRelfrozenXid = NoFreezePageRelfrozenXid;
2415 vacrel->NewRelminMxid = NoFreezePageRelminMxid;
2416
2417
2418 if (
vacrel->nindexes == 0)
2419 {
2420
2421 if (lpdead_items > 0)
2422 {
2423
2424
2425
2426
2427
2428
2429
2430
2431 hastup = true;
2432 missed_dead_tuples += lpdead_items;
2433 }
2434 }
2435 else if (lpdead_items > 0)
2436 {
2437
2438
2439
2440
2441
2442 vacrel->lpdead_item_pages++;
2443
2445
2446 vacrel->lpdead_items += lpdead_items;
2447 }
2448
2449
2450
2451
2452 vacrel->live_tuples += live_tuples;
2453 vacrel->recently_dead_tuples += recently_dead_tuples;
2454 vacrel->missed_dead_tuples += missed_dead_tuples;
2455 if (missed_dead_tuples > 0)
2456 vacrel->missed_dead_pages++;
2457
2458
2459 if (hastup)
2460 vacrel->nonempty_pages = blkno + 1;
2461
2462
2464
2465
2466 return true;
2467}
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482static void
2484{
2486
2487
2490
2491 if (!
vacrel->do_index_vacuuming)
2492 {
2495 return;
2496 }
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2518 if (
vacrel->consider_bypass_optimization &&
vacrel->rel_pages > 0)
2519 {
2521
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2552 }
2553
2555 {
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566 vacrel->do_index_vacuuming =
false;
2567 }
2569 {
2570
2571
2572
2573
2575 }
2576 else
2577 {
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2590 }
2591
2592
2593
2594
2595
2597}
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607static bool
2609{
2615 };
2620 };
2623
2627
2628
2630 {
2631
2632 return false;
2633 }
2634
2635
2636
2637
2638
2642
2644 {
2646 {
2649
2653
2654
2657
2659 {
2660
2662 break;
2663 }
2664 }
2665 }
2666 else
2667 {
2668
2670 vacrel->num_index_scans);
2671
2672
2673
2674
2675
2678 }
2679
2680
2681
2682
2683
2684
2685
2686
2688 vacrel->dead_items_info->num_items ==
vacrel->lpdead_items);
2690
2691
2692
2693
2694
2695
2696
2697
2698 vacrel->num_index_scans++;
2703
2705}
2706
2707
2708
2709
2710
2711
2712
2713
2716 void *callback_private_data,
2717 void *per_buffer_data)
2718{
2721
2725
2726
2727
2728
2729
2731
2733}
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752static void
2754{
2760
2764
2765
2768
2769
2773
2775
2776
2777
2778
2779
2780
2781
2782
2783
2790 iter,
2792
2793 while (true)
2794 {
2802
2804
2806
2807
2809 break;
2810
2812
2816
2817
2818
2819
2820
2821
2823
2824
2828
2829
2832
2836 }
2837
2840
2844
2845
2846
2847
2848
2850 (
vacrel->dead_items_info->num_items ==
vacrel->lpdead_items &&
2852
2854 (
errmsg(
"table \"%s\": removed %" PRId64 " dead item identifiers in %u pages",
2857
2858
2860}
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870static void
2874{
2877 int nunused = 0;
2880 bool all_frozen;
2883
2885
2887
2888
2892
2893
2894
2895
2896
2897
2898
2899
2900
2902 vacrel->cutoffs.OldestXmin,
2904 &all_frozen, &visibility_cutoff_xid,
2906 {
2908 if (all_frozen)
2909 {
2912 }
2913
2914
2915
2916
2917
2918
2920 }
2921
2923
2925 {
2928
2930
2933 unused[nunused++] =
toff;
2934 }
2935
2937
2938
2940
2942 {
2943
2944
2945
2946
2951 vacrel->rel->rd_locator);
2953 }
2954
2955
2956
2957
2959
2960
2962 {
2972 unused, nunused);
2973 }
2974
2976
2978 {
2979
2981 vacrel->new_all_visible_pages++;
2982 if (all_frozen)
2983 vacrel->new_all_visible_all_frozen_pages++;
2984 }
2985
2986
2988}
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002static bool
3004{
3005
3007 return true;
3008
3010 {
3015 };
3017
3019
3020
3021
3022
3023
3024
3026
3027
3028 vacrel->do_index_vacuuming =
false;
3029 vacrel->do_index_cleanup =
false;
3030 vacrel->do_rel_truncate =
false;
3031
3032
3034
3036 (
errmsg(
"bypassing nonessential maintenance of table \"%s.%s.%s\" as a failsafe after %d index scans",
3038 vacrel->num_index_scans),
3039 errdetail(
"The table's relfrozenxid or relminmxid is too far in the past."),
3040 errhint(
"Consider increasing configuration parameter \"maintenance_work_mem\" or \"autovacuum_work_mem\".\n"
3041 "You might also need to consider other ways for VACUUM to keep up with the allocation of transaction IDs.")));
3042
3043
3046
3047 return true;
3048 }
3049
3050 return false;
3051}
3052
3053
3054
3055
3056static void
3058{
3059 double reltuples =
vacrel->new_rel_tuples;
3060 bool estimated_count =
vacrel->scanned_pages <
vacrel->rel_pages;
3064 };
3068 };
3071
3074
3075
3076
3077
3078
3082
3084 {
3086 {
3089
3092 estimated_count,
vacrel);
3093
3094
3097 }
3098 }
3099 else
3100 {
3101
3104 estimated_count);
3105 }
3106
3107
3109}
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3127{
3130
3133 ivinfo.analyze_only =
false;
3134 ivinfo.report_progress =
false;
3135 ivinfo.estimated_count =
true;
3137 ivinfo.num_heap_tuples = reltuples;
3139
3140
3141
3142
3143
3144
3145
3151
3152
3154 vacrel->dead_items_info);
3155
3156
3160
3161 return istat;
3162}
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3175 double reltuples, bool estimated_count,
3177{
3180
3183 ivinfo.analyze_only =
false;
3184 ivinfo.report_progress =
false;
3185 ivinfo.estimated_count = estimated_count;
3187
3188 ivinfo.num_heap_tuples = reltuples;
3190
3191
3192
3193
3194
3195
3196
3202
3204
3205
3209
3210 return istat;
3211}
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233static bool
3235{
3237
3239 return false;
3240
3245 return true;
3246
3247 return false;
3248}
3249
3250
3251
3252
3253static void
3255{
3260
3261
3264
3265
3268
3269
3270
3271
3272 do
3273 {
3274
3275
3276
3277
3278
3279
3280
3283 while (true)
3284 {
3286 break;
3287
3288
3289
3290
3291
3293
3296 {
3297
3298
3299
3300
3302 (
errmsg(
"\"%s\": stopping truncate due to conflicting lock request",
3304 return;
3305 }
3306
3312 }
3313
3314
3315
3316
3317
3318
3321 {
3322
3323
3324
3325
3326
3327
3328
3330 return;
3331 }
3332
3333
3334
3335
3336
3337
3338
3341
3343 {
3344
3346 return;
3347 }
3348
3349
3350
3351
3353
3354
3355
3356
3357
3358
3359
3360
3362
3363
3364
3365
3366
3367
3370
3372 (
errmsg(
"table \"%s\": truncated %u to %u pages",
3377}
3378
3379
3380
3381
3382
3383
3386{
3388 "prefetch size must be power of 2");
3389
3393
3394
3396
3397
3398
3399
3400
3401
3402
3403 blkno =
vacrel->rel_pages;
3405 while (blkno >
vacrel->nonempty_pages)
3406 {
3410 maxoff;
3411 bool hastup;
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421 if ((blkno % 32) == 0)
3422 {
3425
3431 {
3433 {
3435 (
errmsg(
"table \"%s\": suspending truncate due to conflicting lock request",
3437
3439 return blkno;
3440 }
3442 }
3443 }
3444
3445
3446
3447
3448
3449
3451
3452 blkno--;
3453
3454
3456 {
3459
3462 {
3465 }
3467 }
3468
3471
3472
3474
3476
3478 {
3480 continue;
3481 }
3482
3483 hastup = false;
3486 offnum <= maxoff;
3488 {
3490
3492
3493
3494
3495
3496
3497
3499 {
3500 hastup = true;
3501 break;
3502 }
3503 }
3504
3506
3507
3508 if (hastup)
3509 return blkno + 1;
3510 }
3511
3512
3513
3514
3515
3516
3517 return vacrel->nonempty_pages;
3518}
3519
3520
3521
3522
3523
3524
3525
3526
3527static void
3529{
3534
3535
3536
3537
3538
3539
3540 if (nworkers >= 0 &&
vacrel->nindexes > 1 &&
vacrel->do_index_vacuuming)
3541 {
3542
3543
3544
3545
3547 {
3548
3549
3550
3551
3552 if (nworkers > 0)
3554 (
errmsg(
"disabling parallel option of vacuum on \"%s\" --- cannot vacuum temporary tables in parallel",
3556 }
3557 else
3559 vacrel->nindexes, nworkers,
3563
3564
3565
3566
3567
3569 {
3571 &
vacrel->dead_items_info);
3572 return;
3573 }
3574 }
3575
3576
3577
3578
3579
3580
3584 vacrel->dead_items_info = dead_items_info;
3585
3587}
3588
3589
3590
3591
3592static void
3595{
3599 };
3601
3604
3605
3609}
3610
3611
3612
3613
3614static void
3616{
3617
3618 vacrel->num_dead_items_resets++;
3620
3622 {
3625 &
vacrel->dead_items_info);
3626 return;
3627 }
3628
3629
3632
3633
3634 vacrel->dead_items_info->num_items = 0;
3635}
3636
3637
3638
3639
3640static void
3642{
3644 {
3645
3646 return;
3647 }
3648
3649
3652}
3653
3654#ifdef USE_ASSERT_CHECKING
3655
3656
3657
3658
3659
3660
3661static bool
3664 bool *all_frozen,
3667{
3668
3670 OldestXmin,
3672 all_frozen,
3673 visibility_cutoff_xid,
3675}
3676#endif
3677
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
3708static bool
3713 bool *all_frozen,
3716{
3720 maxoff;
3721 bool all_visible = true;
3723
3725 *all_frozen = true;
3726
3728
3729#ifdef USE_ASSERT_CHECKING
3730
3732 {
3734 Assert(deadoffsets[
i - 1] < deadoffsets[
i]);
3735 }
3736#endif
3737
3740 offnum <= maxoff && all_visible;
3742 {
3746
3747
3748
3749
3750
3753
3754
3756 continue;
3757
3759
3760
3761
3762
3763
3765 {
3766 if (!deadoffsets ||
3769 {
3770 *all_frozen = all_visible = false;
3771 break;
3772 }
3774 continue;
3775 }
3776
3778
3782
3783
3786 {
3788 {
3790
3791
3793 {
3794 all_visible = false;
3795 *all_frozen = false;
3796 break;
3797 }
3798
3799
3800
3801
3802
3805 {
3806 all_visible = false;
3807 *all_frozen = false;
3808 break;
3809 }
3810
3811
3814 *visibility_cutoff_xid = xmin;
3815
3816
3817 if (all_visible && *all_frozen &&
3819 *all_frozen = false;
3820 }
3821 break;
3822
3827 {
3828 all_visible = false;
3829 *all_frozen = false;
3830 break;
3831 }
3832 default:
3833 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
3834 break;
3835 }
3836 }
3837
3838
3840
3841 return all_visible;
3842}
3843
3844
3845
3846
3847static void
3849{
3851 int nindexes =
vacrel->nindexes;
3853
3855
3856 for (
int idx = 0;
idx < nindexes;
idx++)
3857 {
3860
3862 continue;
3863
3864
3868 0, 0,
3869 false,
3873 }
3874}
3875
3876
3877
3878
3879
3880
3881
3882static void
3884{
3886
3888 {
3891 {
3893 errcontext(
"while scanning block %u offset %u of relation \"%s.%s\"",
3895 else
3896 errcontext(
"while scanning block %u of relation \"%s.%s\"",
3898 }
3899 else
3900 errcontext(
"while scanning relation \"%s.%s\"",
3902 break;
3903
3906 {
3908 errcontext(
"while vacuuming block %u offset %u of relation \"%s.%s\"",
3910 else
3911 errcontext(
"while vacuuming block %u of relation \"%s.%s\"",
3913 }
3914 else
3915 errcontext(
"while vacuuming relation \"%s.%s\"",
3917 break;
3918
3920 errcontext(
"while vacuuming index \"%s\" of relation \"%s.%s\"",
3922 break;
3923
3925 errcontext(
"while cleaning up index \"%s\" of relation \"%s.%s\"",
3927 break;
3928
3931 errcontext(
"while truncating relation \"%s.%s\" to %u blocks",
3933 break;
3934
3936 default:
3937 return;
3938
3939 }
3940}
3941
3942
3943
3944
3945
3946static void
3949{
3951 {
3955 }
3956
3960}
3961
3962
3963
3964
3965static void
3968{
3972}
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)