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
1941
1942
1943 vacrel->new_all_visible_pages++;
1944 vacrel->new_all_visible_all_frozen_pages++;
1945 }
1946
1950 return true;
1951 }
1952
1953
1954 return false;
1955}
1956
1957
1958static int
1960{
1962}
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980static void
1986{
1988
1990
1991
1992
1993
1994
1995
1996
1999 {
2002 errmsg(
"page is not marked all-visible but visibility map bit is set in relation \"%s\" page %u",
2004
2008 }
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2025 {
2028 errmsg(
"page containing LP_DEAD items is marked as all-visible in relation \"%s\" page %u",
2030
2036 }
2037}
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056static int
2064{
2068 .relation = rel,
2072 .vistest =
vacrel->vistest,
2073 .cutoffs = &
vacrel->cutoffs,
2074 };
2077
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095 if (
vacrel->nindexes == 0)
2097
2102
2105
2107 {
2108
2109
2110
2111
2112
2113
2114 vacrel->new_frozen_tuple_pages++;
2115 }
2116
2117
2118
2119
2120
2121
2122
2123
2124#ifdef USE_ASSERT_CHECKING
2126 {
2129
2131
2135
2137
2140 }
2141#endif
2142
2143
2144
2145
2147 {
2148 vacrel->lpdead_item_pages++;
2149
2150
2151
2152
2153
2154
2155
2158
2160 }
2161
2162
2167 vacrel->recently_dead_tuples +=
presult.recently_dead_tuples;
2168
2169
2171 vacrel->nonempty_pages = blkno + 1;
2172
2173
2175
2178
2180
2182 presult.lpdead_items, vmbuffer,
2184
2187
2188
2190
2193
2194
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2212
2213
2214
2215
2216
2217
2220
2223 vmbuffer,
presult.vm_conflict_horizon,
2225
2226
2227
2228
2229
2231 {
2232 vacrel->new_all_visible_pages++;
2234 {
2235 vacrel->new_all_visible_all_frozen_pages++;
2237 }
2238 }
2241 {
2242 vacrel->new_all_frozen_pages++;
2244 }
2245
2247}
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269static bool
2275{
2277 maxoff;
2278 int lpdead_items,
2279 live_tuples,
2280 recently_dead_tuples,
2281 missed_dead_tuples;
2282 bool hastup;
2287
2289
2290 hastup = false;
2291
2292 lpdead_items = 0;
2293 live_tuples = 0;
2294 recently_dead_tuples = 0;
2295 missed_dead_tuples = 0;
2296
2299 offnum <= maxoff;
2301 {
2304
2307
2309 continue;
2310
2312 {
2313 hastup = true;
2314 continue;
2315 }
2316
2318 {
2319
2320
2321
2322
2323 deadoffsets[lpdead_items++] = offnum;
2324 continue;
2325 }
2326
2327 hastup = true;
2330 &NoFreezePageRelfrozenXid,
2331 &NoFreezePageRelminMxid))
2332 {
2333
2335 {
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2348 return false;
2349 }
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359 }
2360
2365
2368 {
2371
2372
2373
2374
2375 live_tuples++;
2376
2377 break;
2379
2380
2381
2382
2383
2384 missed_dead_tuples++;
2385 break;
2387
2388
2389
2390
2391 recently_dead_tuples++;
2392 break;
2394
2395
2396
2397
2398 break;
2399 default:
2400 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
2401 break;
2402 }
2403 }
2404
2406
2407
2408
2409
2410
2411
2412 vacrel->NewRelfrozenXid = NoFreezePageRelfrozenXid;
2413 vacrel->NewRelminMxid = NoFreezePageRelminMxid;
2414
2415
2416 if (
vacrel->nindexes == 0)
2417 {
2418
2419 if (lpdead_items > 0)
2420 {
2421
2422
2423
2424
2425
2426
2427
2428
2429 hastup = true;
2430 missed_dead_tuples += lpdead_items;
2431 }
2432 }
2433 else if (lpdead_items > 0)
2434 {
2435
2436
2437
2438
2439
2440 vacrel->lpdead_item_pages++;
2441
2443
2444 vacrel->lpdead_items += lpdead_items;
2445 }
2446
2447
2448
2449
2450 vacrel->live_tuples += live_tuples;
2451 vacrel->recently_dead_tuples += recently_dead_tuples;
2452 vacrel->missed_dead_tuples += missed_dead_tuples;
2453 if (missed_dead_tuples > 0)
2454 vacrel->missed_dead_pages++;
2455
2456
2457 if (hastup)
2458 vacrel->nonempty_pages = blkno + 1;
2459
2460
2462
2463
2464 return true;
2465}
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480static void
2482{
2484
2485
2488
2489 if (!
vacrel->do_index_vacuuming)
2490 {
2493 return;
2494 }
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2516 if (
vacrel->consider_bypass_optimization &&
vacrel->rel_pages > 0)
2517 {
2519
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2550 }
2551
2553 {
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564 vacrel->do_index_vacuuming =
false;
2565 }
2567 {
2568
2569
2570
2571
2573 }
2574 else
2575 {
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2588 }
2589
2590
2591
2592
2593
2595}
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605static bool
2607{
2613 };
2618 };
2621
2625
2626
2628 {
2629
2630 return false;
2631 }
2632
2633
2634
2635
2636
2640
2642 {
2644 {
2647
2651
2652
2655
2657 {
2658
2660 break;
2661 }
2662 }
2663 }
2664 else
2665 {
2666
2668 vacrel->num_index_scans);
2669
2670
2671
2672
2673
2676 }
2677
2678
2679
2680
2681
2682
2683
2684
2686 vacrel->dead_items_info->num_items ==
vacrel->lpdead_items);
2688
2689
2690
2691
2692
2693
2694
2695
2696 vacrel->num_index_scans++;
2701
2703}
2704
2705
2706
2707
2708
2709
2710
2711
2714 void *callback_private_data,
2715 void *per_buffer_data)
2716{
2719
2723
2724
2725
2726
2727
2729
2731}
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750static void
2752{
2758
2762
2763
2766
2767
2771
2773
2774
2775
2776
2777
2778
2779
2780
2781
2788 iter,
2790
2791 while (true)
2792 {
2800
2802
2804
2805
2807 break;
2808
2810
2814
2815
2816
2817
2818
2819
2821
2822
2826
2827
2830
2834 }
2835
2838
2842
2843
2844
2845
2846
2848 (
vacrel->dead_items_info->num_items ==
vacrel->lpdead_items &&
2850
2852 (
errmsg(
"table \"%s\": removed %" PRId64 " dead item identifiers in %u pages",
2855
2856
2858}
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868static void
2872{
2875 int nunused = 0;
2878 bool all_frozen;
2881
2883
2885
2886
2890
2891
2892
2893
2894
2895
2896
2897
2898
2900 vacrel->cutoffs.OldestXmin,
2902 &all_frozen, &visibility_cutoff_xid,
2904 {
2906 if (all_frozen)
2907 {
2910 }
2911
2912
2913
2914
2915
2916
2918 }
2919
2921
2923 {
2926
2928
2931 unused[nunused++] =
toff;
2932 }
2933
2935
2936
2938
2940 {
2941
2942
2943
2944
2948 vacrel->rel->rd_locator);
2950 }
2951
2952
2953
2954
2956
2957
2959 {
2969 unused, nunused);
2970 }
2971
2973
2975 {
2976
2978 vacrel->new_all_visible_pages++;
2979 if (all_frozen)
2980 vacrel->new_all_visible_all_frozen_pages++;
2981 }
2982
2983
2985}
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999static bool
3001{
3002
3004 return true;
3005
3007 {
3012 };
3014
3016
3017
3018
3019
3020
3021
3023
3024
3025 vacrel->do_index_vacuuming =
false;
3026 vacrel->do_index_cleanup =
false;
3027 vacrel->do_rel_truncate =
false;
3028
3029
3031
3033 (
errmsg(
"bypassing nonessential maintenance of table \"%s.%s.%s\" as a failsafe after %d index scans",
3035 vacrel->num_index_scans),
3036 errdetail(
"The table's relfrozenxid or relminmxid is too far in the past."),
3037 errhint(
"Consider increasing configuration parameter \"maintenance_work_mem\" or \"autovacuum_work_mem\".\n"
3038 "You might also need to consider other ways for VACUUM to keep up with the allocation of transaction IDs.")));
3039
3040
3043
3044 return true;
3045 }
3046
3047 return false;
3048}
3049
3050
3051
3052
3053static void
3055{
3056 double reltuples =
vacrel->new_rel_tuples;
3057 bool estimated_count =
vacrel->scanned_pages <
vacrel->rel_pages;
3061 };
3065 };
3068
3071
3072
3073
3074
3075
3079
3081 {
3083 {
3086
3089 estimated_count,
vacrel);
3090
3091
3094 }
3095 }
3096 else
3097 {
3098
3101 estimated_count);
3102 }
3103
3104
3106}
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3124{
3127
3130 ivinfo.analyze_only =
false;
3131 ivinfo.report_progress =
false;
3132 ivinfo.estimated_count =
true;
3134 ivinfo.num_heap_tuples = reltuples;
3136
3137
3138
3139
3140
3141
3142
3148
3149
3151 vacrel->dead_items_info);
3152
3153
3157
3158 return istat;
3159}
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3172 double reltuples, bool estimated_count,
3174{
3177
3180 ivinfo.analyze_only =
false;
3181 ivinfo.report_progress =
false;
3182 ivinfo.estimated_count = estimated_count;
3184
3185 ivinfo.num_heap_tuples = reltuples;
3187
3188
3189
3190
3191
3192
3193
3199
3201
3202
3206
3207 return istat;
3208}
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230static bool
3232{
3234
3236 return false;
3237
3242 return true;
3243
3244 return false;
3245}
3246
3247
3248
3249
3250static void
3252{
3257
3258
3261
3262
3265
3266
3267
3268
3269 do
3270 {
3271
3272
3273
3274
3275
3276
3277
3280 while (true)
3281 {
3283 break;
3284
3285
3286
3287
3288
3290
3293 {
3294
3295
3296
3297
3299 (
errmsg(
"\"%s\": stopping truncate due to conflicting lock request",
3301 return;
3302 }
3303
3309 }
3310
3311
3312
3313
3314
3315
3318 {
3319
3320
3321
3322
3323
3324
3325
3327 return;
3328 }
3329
3330
3331
3332
3333
3334
3335
3338
3340 {
3341
3343 return;
3344 }
3345
3346
3347
3348
3350
3351
3352
3353
3354
3355
3356
3357
3359
3360
3361
3362
3363
3364
3367
3369 (
errmsg(
"table \"%s\": truncated %u to %u pages",
3374}
3375
3376
3377
3378
3379
3380
3383{
3385 "prefetch size must be power of 2");
3386
3390
3391
3393
3394
3395
3396
3397
3398
3399
3400 blkno =
vacrel->rel_pages;
3402 while (blkno >
vacrel->nonempty_pages)
3403 {
3407 maxoff;
3408 bool hastup;
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418 if ((blkno % 32) == 0)
3419 {
3422
3428 {
3430 {
3432 (
errmsg(
"table \"%s\": suspending truncate due to conflicting lock request",
3434
3436 return blkno;
3437 }
3439 }
3440 }
3441
3442
3443
3444
3445
3446
3448
3449 blkno--;
3450
3451
3453 {
3456
3459 {
3462 }
3464 }
3465
3468
3469
3471
3473
3475 {
3477 continue;
3478 }
3479
3480 hastup = false;
3483 offnum <= maxoff;
3485 {
3487
3489
3490
3491
3492
3493
3494
3496 {
3497 hastup = true;
3498 break;
3499 }
3500 }
3501
3503
3504
3505 if (hastup)
3506 return blkno + 1;
3507 }
3508
3509
3510
3511
3512
3513
3514 return vacrel->nonempty_pages;
3515}
3516
3517
3518
3519
3520
3521
3522
3523
3524static void
3526{
3531
3532
3533
3534
3535
3536
3537 if (nworkers >= 0 &&
vacrel->nindexes > 1 &&
vacrel->do_index_vacuuming)
3538 {
3539
3540
3541
3542
3544 {
3545
3546
3547
3548
3549 if (nworkers > 0)
3551 (
errmsg(
"disabling parallel option of vacuum on \"%s\" --- cannot vacuum temporary tables in parallel",
3553 }
3554 else
3556 vacrel->nindexes, nworkers,
3560
3561
3562
3563
3564
3566 {
3568 &
vacrel->dead_items_info);
3569 return;
3570 }
3571 }
3572
3573
3574
3575
3576
3577
3581 vacrel->dead_items_info = dead_items_info;
3582
3584}
3585
3586
3587
3588
3589static void
3592{
3596 };
3598
3601
3602
3606}
3607
3608
3609
3610
3611static void
3613{
3614
3615 vacrel->num_dead_items_resets++;
3617
3619 {
3622 &
vacrel->dead_items_info);
3623 return;
3624 }
3625
3626
3629
3630
3631 vacrel->dead_items_info->num_items = 0;
3632}
3633
3634
3635
3636
3637static void
3639{
3641 {
3642
3643 return;
3644 }
3645
3646
3649}
3650
3651#ifdef USE_ASSERT_CHECKING
3652
3653
3654
3655
3656
3657
3658static bool
3661 bool *all_frozen,
3664{
3665
3667 OldestXmin,
3669 all_frozen,
3670 visibility_cutoff_xid,
3672}
3673#endif
3674
3675
3676
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
3705static bool
3710 bool *all_frozen,
3713{
3717 maxoff;
3718 bool all_visible = true;
3720
3722 *all_frozen = true;
3723
3725
3726#ifdef USE_ASSERT_CHECKING
3727
3729 {
3731 Assert(deadoffsets[
i - 1] < deadoffsets[
i]);
3732 }
3733#endif
3734
3737 offnum <= maxoff && all_visible;
3739 {
3743
3744
3745
3746
3747
3750
3751
3753 continue;
3754
3756
3757
3758
3759
3760
3762 {
3763 if (!deadoffsets ||
3766 {
3767 *all_frozen = all_visible = false;
3768 break;
3769 }
3771 continue;
3772 }
3773
3775
3779
3780
3783 {
3785 {
3787
3788
3790 {
3791 all_visible = false;
3792 *all_frozen = false;
3793 break;
3794 }
3795
3796
3797
3798
3799
3802 {
3803 all_visible = false;
3804 *all_frozen = false;
3805 break;
3806 }
3807
3808
3811 *visibility_cutoff_xid = xmin;
3812
3813
3814 if (all_visible && *all_frozen &&
3816 *all_frozen = false;
3817 }
3818 break;
3819
3824 {
3825 all_visible = false;
3826 *all_frozen = false;
3827 break;
3828 }
3829 default:
3830 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
3831 break;
3832 }
3833 }
3834
3835
3837
3838 return all_visible;
3839}
3840
3841
3842
3843
3844static void
3846{
3848 int nindexes =
vacrel->nindexes;
3850
3852
3853 for (
int idx = 0;
idx < nindexes;
idx++)
3854 {
3857
3859 continue;
3860
3861
3865 0, 0,
3866 false,
3870 }
3871}
3872
3873
3874
3875
3876
3877
3878
3879static void
3881{
3883
3885 {
3888 {
3890 errcontext(
"while scanning block %u offset %u of relation \"%s.%s\"",
3892 else
3893 errcontext(
"while scanning block %u of relation \"%s.%s\"",
3895 }
3896 else
3897 errcontext(
"while scanning relation \"%s.%s\"",
3899 break;
3900
3903 {
3905 errcontext(
"while vacuuming block %u offset %u of relation \"%s.%s\"",
3907 else
3908 errcontext(
"while vacuuming block %u of relation \"%s.%s\"",
3910 }
3911 else
3912 errcontext(
"while vacuuming relation \"%s.%s\"",
3914 break;
3915
3917 errcontext(
"while vacuuming index \"%s\" of relation \"%s.%s\"",
3919 break;
3920
3922 errcontext(
"while cleaning up index \"%s\" of relation \"%s.%s\"",
3924 break;
3925
3928 errcontext(
"while truncating relation \"%s.%s\" to %u blocks",
3930 break;
3931
3933 default:
3934 return;
3935
3936 }
3937}
3938
3939
3940
3941
3942
3943static void
3946{
3948 {
3952 }
3953
3957}
3958
3959
3960
3961
3962static void
3965{
3969}
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)
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)