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
346
347
348
349
351
352
359
360
365
366
367
368
369
370
371
372
373
374
375
376
377
379
380
381
382
383
384
385
386
387
388
390
391
392
393
394
395
396
397
398
399
401
402
403
404
405
406
407
408
409
412
413
414
416{
421
422
423
428 void *callback_private_data,
429 void *per_buffer_data);
451 double reltuples,
455 double reltuples,
456 bool estimated_count,
467
473 bool *all_frozen,
484
485
486
487
488
489
490
491
492
493
494static void
496{
502
503
504
505
506
507
509 vacrel->eager_scan_max_fails_per_region = 0;
510 vacrel->eager_scan_remaining_fails = 0;
511 vacrel->eager_scan_remaining_successes = 0;
512
513
515 return;
516
517
518
519
520
521
522
523
525 return;
526
527
528
529
530
531
532
533
535 return;
536
537
538
539
540
541
542
543
544
545
546
547
548
549
552 vacrel->cutoffs.FreezeLimit))
554
558 vacrel->cutoffs.MultiXactCutoff))
560
562 return;
563
564
565
566
567
568
569
571
572 vacrel->eager_scan_remaining_successes =
575
576
577 if (
vacrel->eager_scan_remaining_successes == 0)
578 return;
579
580
581
582
583
584
585
586
588
590
593
594 vacrel->eager_scan_max_fails_per_region =
597
598
599
600
601
604
605 vacrel->eager_scan_remaining_fails =
606 vacrel->eager_scan_max_fails_per_region *
608}
609
610
611
612
613
614
615
616
617
618
619
620
621void
624{
627 instrument,
628 skipwithvm,
644
648 if (instrument)
649 {
652 {
655 }
656 }
657
658
660
668 else
671
672
673
674
675
676
677
678
679
680
681
682
683
695
696
700 vacrel->bstrategy = bstrategy;
701 if (instrument &&
vacrel->nindexes > 0)
702 {
703
705 for (
int i = 0;
i <
vacrel->nindexes;
i++)
707 }
708
709
710
711
712
713
714
715
716
717
721
722
723
724
725
727 vacrel->consider_bypass_optimization =
true;
728 vacrel->do_index_vacuuming =
true;
729 vacrel->do_index_cleanup =
true;
732 {
733
734 vacrel->do_index_vacuuming =
false;
735 vacrel->do_index_cleanup =
false;
736 }
738 {
739
740 vacrel->consider_bypass_optimization =
false;
741 }
742 else
743 {
744
746 }
747
748
749 vacrel->scanned_pages = 0;
750 vacrel->eager_scanned_pages = 0;
751 vacrel->removed_pages = 0;
752 vacrel->new_frozen_tuple_pages = 0;
753 vacrel->lpdead_item_pages = 0;
754 vacrel->missed_dead_pages = 0;
755 vacrel->nonempty_pages = 0;
756
757
758
759 vacrel->new_rel_tuples = 0;
760 vacrel->new_live_tuples = 0;
763
764
765 vacrel->num_index_scans = 0;
766 vacrel->num_dead_items_resets = 0;
767 vacrel->total_dead_items_bytes = 0;
768 vacrel->tuples_deleted = 0;
769 vacrel->tuples_frozen = 0;
772 vacrel->recently_dead_tuples = 0;
773 vacrel->missed_dead_tuples = 0;
774
775 vacrel->new_all_visible_pages = 0;
776 vacrel->new_all_visible_all_frozen_pages = 0;
777 vacrel->new_all_frozen_pages = 0;
778
779 vacrel->worker_usage.vacuum.nlaunched = 0;
780 vacrel->worker_usage.vacuum.nplanned = 0;
781 vacrel->worker_usage.cleanup.nlaunched = 0;
782 vacrel->worker_usage.cleanup.nplanned = 0;
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
803
804
807
808
809
810
811
812
813 vacrel->skippedallvis =
false;
814 skipwithvm = true;
816 {
817
818
819
820
821 vacrel->aggressive =
true;
822 skipwithvm = false;
823 }
824
825 vacrel->skipwithvm = skipwithvm;
826
827
828
829
830
831
833
834
839
841 {
844 (
errmsg(
"aggressively vacuuming \"%s.%s.%s\"",
847 else
849 (
errmsg(
"vacuuming \"%s.%s.%s\"",
852 }
853
854
855
856
857
858
859
860
863
864
865
866
867
869
870
871
872
873
874
877
878
879
880
881
884
885
886
887
888
889
890
891 if (
vacrel->do_index_cleanup)
893
894
896
897
900
901
903
904
907
908
909
910
911
912
913
914
917 vacrel->cutoffs.relfrozenxid,
918 vacrel->NewRelfrozenXid));
921 vacrel->cutoffs.relminmxid,
923 if (
vacrel->skippedallvis)
924 {
925
926
927
928
929
933 }
934
935
936
937
938
943
944
945
946
947
948
951
952
953
954
955
956
957
958
964
965
966
967
968
969
970
971
972
973
974
977 vacrel->recently_dead_tuples +
978 vacrel->missed_dead_tuples,
979 starttime);
981
982 if (instrument)
983 {
985
989 {
1002
1008
1015
1018 {
1019
1020
1021
1022
1024 msgfmt =
_(
"finished vacuuming \"%s.%s.%s\": index scans: %d\n");
1025 }
1027 {
1028
1029
1030
1031
1032
1033
1035 msgfmt =
_(
"automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1036 else
1037 msgfmt =
_(
"automatic vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1038 }
1039 else
1040 {
1042 msgfmt =
_(
"automatic aggressive vacuum of table \"%s.%s.%s\": index scans: %d\n");
1043 else
1044 msgfmt =
_(
"automatic vacuum of table \"%s.%s.%s\": index scans: %d\n");
1045 }
1050 vacrel->num_index_scans);
1051 appendStringInfo(&
buf,
_(
"pages: %u removed, %u remain, %u scanned (%.2f%% of total), %u eagerly scanned\n"),
1056 100.0 *
vacrel->scanned_pages /
1058 vacrel->eager_scanned_pages);
1060 _(
"tuples: %" PRId64 " removed, %" PRId64 " remain, %" PRId64 " are dead but not yet removable\n"),
1063 vacrel->recently_dead_tuples);
1064 if (
vacrel->missed_dead_tuples > 0)
1066 _(
"tuples missed: %" PRId64 " dead from %u pages not removed due to cleanup lock contention\n"),
1067 vacrel->missed_dead_tuples,
1068 vacrel->missed_dead_pages);
1070 vacrel->cutoffs.OldestXmin);
1072 _(
"removable cutoff: %u, which was %d XIDs old when operation ended\n"),
1075 {
1077 vacrel->cutoffs.relfrozenxid);
1079 _(
"new relfrozenxid: %u, which is %d XIDs ahead of previous value\n"),
1081 }
1083 {
1085 vacrel->cutoffs.relminmxid);
1087 _(
"new relminmxid: %u, which is %d MXIDs ahead of previous value\n"),
1089 }
1091 vacrel->new_frozen_tuple_pages,
1093 100.0 *
vacrel->new_frozen_tuple_pages /
1096
1098 _(
"visibility map: %u pages set all-visible, %u pages set all-frozen (%u were all-visible)\n"),
1099 vacrel->new_all_visible_pages,
1100 vacrel->new_all_visible_all_frozen_pages +
1101 vacrel->new_all_frozen_pages,
1102 vacrel->new_all_frozen_pages);
1103 if (
vacrel->do_index_vacuuming)
1104 {
1105 if (
vacrel->nindexes == 0 ||
vacrel->num_index_scans == 0)
1107 else
1109
1110 msgfmt =
_(
"%u pages from table (%.2f%% of total) had %" PRId64 " dead item identifiers removed\n");
1111 }
1112 else
1113 {
1116 else
1118
1119 msgfmt =
_(
"%u pages from table (%.2f%% of total) have %" PRId64 " dead item identifiers\n");
1120 }
1122 vacrel->lpdead_item_pages,
1126
1127 if (
vacrel->worker_usage.vacuum.nplanned > 0)
1129 _(
"parallel workers: index vacuum: %d planned, %d launched in total\n"),
1130 vacrel->worker_usage.vacuum.nplanned,
1131 vacrel->worker_usage.vacuum.nlaunched);
1132
1133 if (
vacrel->worker_usage.cleanup.nplanned > 0)
1135 _(
"parallel workers: index cleanup: %d planned, %d launched\n"),
1136 vacrel->worker_usage.cleanup.nplanned,
1137 vacrel->worker_usage.cleanup.nlaunched);
1138
1139 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1140 {
1142
1143 if (!istat)
1144 continue;
1145
1147 _(
"index \"%s\": pages: %u in total, %u newly deleted, %u currently deleted, %u reusable\n"),
1153 }
1155 {
1156
1157
1158
1159
1160
1161
1164 }
1166 {
1169
1172 }
1174 {
1179 }
1194
1195
1196
1197
1198
1199
1200
1201
1202
1204 ngettext(
"memory usage: dead item storage %.2f MB accumulated across %d reset (limit %.2f MB each)\n",
1205 "memory usage: dead item storage %.2f MB accumulated across %d resets (limit %.2f MB each)\n",
1206 vacrel->num_dead_items_resets),
1207 (
double)
vacrel->total_dead_items_bytes / (1024 * 1024),
1208 vacrel->num_dead_items_resets,
1211
1215 }
1216 }
1217
1218
1219 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1220 {
1223
1224 if (instrument)
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
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265static void
1267{
1270 blkno = 0,
1273 vacrel->eager_scan_remaining_successes;
1279 };
1281
1282
1287
1288
1291 vacrel->next_unskippable_eager_scanned =
false;
1293
1294
1295
1296
1297
1298
1299
1306 sizeof(bool));
1307
1308 while (true)
1309 {
1313 int ndeleted = 0;
1315 void *per_buffer_data =
NULL;
1318
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330 if (
vacrel->scanned_pages > 0 &&
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342 if (
vacrel->dead_items_info->num_items > 0 &&
1344 {
1345
1346
1347
1348
1349
1350
1352 {
1355 }
1356
1357
1358 vacrel->consider_bypass_optimization =
false;
1360
1361
1362
1363
1364
1365
1367 blkno + 1);
1369
1370
1373 }
1374
1376
1377
1379 break;
1380
1385
1388 vacrel->eager_scanned_pages++;
1389
1390
1394
1395
1396
1397
1398
1399
1401
1402
1403
1404
1405
1406
1407
1409
1412
1413
1415 vmbuffer))
1416 {
1417
1418 continue;
1419 }
1420
1421
1422
1423
1424
1425
1426
1427
1428
1431 {
1432
1433
1434
1435
1440 }
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1457 vmbuffer,
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1475 {
1476
1478
1480 {
1481 if (
vacrel->eager_scan_remaining_successes > 0)
1482 vacrel->eager_scan_remaining_successes--;
1483
1484 if (
vacrel->eager_scan_remaining_successes == 0)
1485 {
1486
1487
1488
1489
1490
1491
1492
1493 if (
vacrel->eager_scan_max_fails_per_region > 0)
1495 (
errmsg(
"disabling eager scanning after freezing %u eagerly scanned blocks of relation \"%s.%s.%s\"",
1499
1500
1501
1502
1503
1504
1505 vacrel->eager_scan_remaining_fails = 0;
1507 vacrel->eager_scan_max_fails_per_region = 0;
1508 }
1509 }
1510 else if (
vacrel->eager_scan_remaining_fails > 0)
1511 vacrel->eager_scan_remaining_fails--;
1512 }
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533 if (
vacrel->nindexes == 0
1534 || !
vacrel->do_index_vacuuming
1536 {
1538
1541
1542
1543
1544
1545
1546
1547
1550 {
1552 blkno);
1554 }
1555 }
1556 else
1558 }
1559
1563
1564
1565
1566
1567
1569 rel_pages);
1570
1571
1575
1576
1577
1578
1579
1582 vacrel->missed_dead_tuples;
1583
1585
1586
1587
1588
1589
1590 if (
vacrel->dead_items_info->num_items > 0)
1592
1593
1594
1595
1596
1597
1598
1601
1602
1604
1605
1608}
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1636 void *callback_private_data,
1637 void *per_buffer_data)
1638{
1641
1642
1644
1645
1647 {
1649 {
1652 }
1654 }
1655
1656
1657
1658
1661 {
1662
1663
1664
1665
1666
1668
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1687 {
1690 vacrel->skippedallvis =
true;
1691 }
1692 }
1693
1694
1696 {
1697
1698
1699
1700
1701
1703
1704 *((bool *) per_buffer_data) = false;
1705 return vacrel->current_block;
1706 }
1707 else
1708 {
1709
1710
1711
1712
1714
1716 *((
bool *) per_buffer_data) =
vacrel->next_unskippable_eager_scanned;
1717 return vacrel->current_block;
1718 }
1719}
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734static void
1736{
1739 Buffer next_unskippable_vmbuffer =
vacrel->next_unskippable_vmbuffer;
1740 bool next_unskippable_eager_scanned = false;
1741
1743
1744 for (;; next_unskippable_block++)
1745 {
1747 next_unskippable_block,
1748 &next_unskippable_vmbuffer);
1749
1750
1751
1752
1753
1754
1755
1756
1757 if (next_unskippable_block >=
vacrel->next_eager_scan_region_start)
1758 {
1759 vacrel->eager_scan_remaining_fails =
1760 vacrel->eager_scan_max_fails_per_region;
1762 }
1763
1764
1765
1766
1767
1769 {
1771 break;
1772 }
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784 if (next_unskippable_block == rel_pages - 1)
1785 break;
1786
1787
1789 break;
1790
1791
1792
1793
1794
1796 continue;
1797
1798
1799
1800
1801
1803 break;
1804
1805
1806
1807
1808
1809
1810 if (
vacrel->eager_scan_remaining_fails > 0)
1811 {
1812 next_unskippable_eager_scanned = true;
1813 break;
1814 }
1815
1816
1817
1818
1819
1821 }
1822
1823
1824 vacrel->next_unskippable_block = next_unskippable_block;
1825 vacrel->next_unskippable_eager_scanned = next_unskippable_eager_scanned;
1826 vacrel->next_unskippable_vmbuffer = next_unskippable_vmbuffer;
1827}
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863static bool
1866{
1868
1870 {
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1891
1893 {
1895
1897 }
1898
1899 return true;
1900 }
1901
1903 {
1904
1905
1906
1907
1908
1910 {
1913
1915 {
1916
1917 return false;
1918 }
1919 }
1920 else
1921 {
1922
1923 }
1924
1925
1926
1927
1928
1930 {
1931
1933
1935
1936
1938
1942 vmbuffer,
1945 vacrel->rel->rd_locator);
1946
1947
1948
1949
1950
1953 vmbuffer,
1957 false,
1963
1965
1967
1968
1969 vacrel->new_all_visible_pages++;
1970 vacrel->new_all_visible_all_frozen_pages++;
1971 }
1972
1976 return true;
1977 }
1978
1979
1980 return false;
1981}
1982
1983
1984static int
1986{
1988}
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007static int
2015{
2019 .relation = rel,
2021 .vmbuffer = vmbuffer,
2024 .vistest =
vacrel->vistest,
2025 .cutoffs = &
vacrel->cutoffs,
2026 };
2027
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045 if (
vacrel->nindexes == 0)
2047
2048
2049
2050
2051
2052
2053
2054
2057
2062
2065
2067 {
2068
2069
2070
2071
2072
2073
2074 vacrel->new_frozen_tuple_pages++;
2075 }
2076
2077
2078
2079
2081 {
2082 vacrel->lpdead_item_pages++;
2083
2084
2085
2086
2087
2088
2089
2092
2094 }
2095
2096
2097 if (
presult.newly_all_visible)
2098 vacrel->new_all_visible_pages++;
2099 if (
presult.newly_all_visible_frozen)
2100 vacrel->new_all_visible_all_frozen_pages++;
2102 vacrel->new_all_frozen_pages++;
2103
2104
2107
2112 vacrel->recently_dead_tuples +=
presult.recently_dead_tuples;
2113
2114
2116 vacrel->nonempty_pages = blkno + 1;
2117
2118
2120
2122}
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144static bool
2150{
2152 maxoff;
2153 int lpdead_items,
2154 live_tuples,
2155 recently_dead_tuples,
2156 missed_dead_tuples;
2157 bool hastup;
2162
2164
2165 hastup = false;
2166
2167 lpdead_items = 0;
2168 live_tuples = 0;
2169 recently_dead_tuples = 0;
2170 missed_dead_tuples = 0;
2171
2174 offnum <= maxoff;
2176 {
2179
2182
2184 continue;
2185
2187 {
2188 hastup = true;
2189 continue;
2190 }
2191
2193 {
2194
2195
2196
2197
2198 deadoffsets[lpdead_items++] = offnum;
2199 continue;
2200 }
2201
2202 hastup = true;
2205 &NoFreezePageRelfrozenXid,
2206 &NoFreezePageRelminMxid))
2207 {
2208
2210 {
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2223 return false;
2224 }
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234 }
2235
2240
2243 {
2246
2247
2248
2249
2250 live_tuples++;
2251
2252 break;
2254
2255
2256
2257
2258
2259 missed_dead_tuples++;
2260 break;
2262
2263
2264
2265
2266 recently_dead_tuples++;
2267 break;
2269
2270
2271
2272
2273 break;
2274 default:
2275 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
2276 break;
2277 }
2278 }
2279
2281
2282
2283
2284
2285
2286
2287 vacrel->NewRelfrozenXid = NoFreezePageRelfrozenXid;
2288 vacrel->NewRelminMxid = NoFreezePageRelminMxid;
2289
2290
2291 if (
vacrel->nindexes == 0)
2292 {
2293
2294 if (lpdead_items > 0)
2295 {
2296
2297
2298
2299
2300
2301
2302
2303
2304 hastup = true;
2305 missed_dead_tuples += lpdead_items;
2306 }
2307 }
2308 else if (lpdead_items > 0)
2309 {
2310
2311
2312
2313
2314
2315 vacrel->lpdead_item_pages++;
2316
2318
2319 vacrel->lpdead_items += lpdead_items;
2320 }
2321
2322
2323
2324
2325 vacrel->live_tuples += live_tuples;
2326 vacrel->recently_dead_tuples += recently_dead_tuples;
2327 vacrel->missed_dead_tuples += missed_dead_tuples;
2328 if (missed_dead_tuples > 0)
2329 vacrel->missed_dead_pages++;
2330
2331
2332 if (hastup)
2333 vacrel->nonempty_pages = blkno + 1;
2334
2335
2337
2338
2339 return true;
2340}
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355static void
2357{
2359
2360
2363
2364 if (!
vacrel->do_index_vacuuming)
2365 {
2368 return;
2369 }
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2391 if (
vacrel->consider_bypass_optimization &&
vacrel->rel_pages > 0)
2392 {
2394
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2425 }
2426
2428 {
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439 vacrel->do_index_vacuuming =
false;
2440 }
2442 {
2443
2444
2445
2446
2448 }
2449 else
2450 {
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2463 }
2464
2465
2466
2467
2468
2470}
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480static bool
2482{
2488 };
2493 };
2496
2500
2501
2503 {
2504
2505 return false;
2506 }
2507
2508
2509
2510
2511
2515
2517 {
2519 {
2522
2526
2527
2530
2532 {
2533
2535 break;
2536 }
2537 }
2538 }
2539 else
2540 {
2541
2544 &(
vacrel->worker_usage.vacuum));
2545
2546
2547
2548
2549
2552 }
2553
2554
2555
2556
2557
2558
2559
2560
2562 vacrel->dead_items_info->num_items ==
vacrel->lpdead_items);
2564
2565
2566
2567
2568
2569
2570
2571
2572 vacrel->num_index_scans++;
2577
2579}
2580
2581
2582
2583
2584
2585
2586
2587
2590 void *callback_private_data,
2591 void *per_buffer_data)
2592{
2595
2599
2600
2601
2602
2603
2605
2607}
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626static void
2628{
2634
2638
2639
2642
2643
2647
2649
2650
2651
2652
2653
2654
2655
2656
2657
2664 iter,
2666
2667 while (true)
2668 {
2676
2678
2680
2681
2683 break;
2684
2686
2690
2691
2692
2693
2694
2695
2697
2698
2702
2703
2706
2710 }
2711
2714
2718
2719
2720
2721
2722
2724 (
vacrel->dead_items_info->num_items ==
vacrel->lpdead_items &&
2726
2728 (
errmsg(
"table \"%s\": removed %" PRId64 " dead item identifiers in %u pages",
2731
2732
2734}
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744static void
2748{
2751 int nunused = 0;
2754 bool all_frozen;
2757
2759
2761
2762
2766
2767
2768
2769
2770
2771
2772
2773
2774
2778 &all_frozen, &newest_live_xid,
2780 {
2782 if (all_frozen)
2783 {
2786 }
2787
2788
2789
2790
2791
2792
2794 }
2795
2797
2799 {
2802
2804
2807 unused[nunused++] =
toff;
2808 }
2809
2811
2812
2814
2816 {
2817
2818
2819
2820
2825 vacrel->rel->rd_locator);
2827 }
2828
2829
2830
2831
2833
2834
2836 {
2846 unused, nunused);
2847 }
2848
2850
2852 {
2853
2855 vacrel->new_all_visible_pages++;
2856 if (all_frozen)
2857 vacrel->new_all_visible_all_frozen_pages++;
2858 }
2859
2860
2862}
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876static bool
2878{
2879
2881 return true;
2882
2884 {
2889 };
2891
2893
2894
2895
2896
2897
2898
2900
2901
2902 vacrel->do_index_vacuuming =
false;
2903 vacrel->do_index_cleanup =
false;
2904 vacrel->do_rel_truncate =
false;
2905
2906
2908
2910 (
errmsg(
"bypassing nonessential maintenance of table \"%s.%s.%s\" as a failsafe after %d index scans",
2912 vacrel->num_index_scans),
2913 errdetail(
"The table's relfrozenxid or relminmxid is too far in the past."),
2914 errhint(
"Consider increasing configuration parameter \"maintenance_work_mem\" or \"autovacuum_work_mem\".\n"
2915 "You might also need to consider other ways for VACUUM to keep up with the allocation of transaction IDs.")));
2916
2917
2920
2921 return true;
2922 }
2923
2924 return false;
2925}
2926
2927
2928
2929
2930static void
2932{
2933 double reltuples =
vacrel->new_rel_tuples;
2934 bool estimated_count =
vacrel->scanned_pages <
vacrel->rel_pages;
2938 };
2942 };
2945
2948
2949
2950
2951
2952
2956
2958 {
2960 {
2963
2966 estimated_count,
vacrel);
2967
2968
2971 }
2972 }
2973 else
2974 {
2975
2978 estimated_count,
2979 &(
vacrel->worker_usage.cleanup));
2980 }
2981
2982
2984}
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
3002{
3005
3008 ivinfo.analyze_only =
false;
3009 ivinfo.report_progress =
false;
3010 ivinfo.estimated_count =
true;
3012 ivinfo.num_heap_tuples = reltuples;
3014
3015
3016
3017
3018
3019
3020
3026
3027
3029 vacrel->dead_items_info);
3030
3031
3035
3036 return istat;
3037}
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3050 double reltuples, bool estimated_count,
3052{
3055
3058 ivinfo.analyze_only =
false;
3059 ivinfo.report_progress =
false;
3060 ivinfo.estimated_count = estimated_count;
3062
3063 ivinfo.num_heap_tuples = reltuples;
3065
3066
3067
3068
3069
3070
3071
3077
3079
3080
3084
3085 return istat;
3086}
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108static bool
3110{
3112
3114 return false;
3115
3120 return true;
3121
3122 return false;
3123}
3124
3125
3126
3127
3128static void
3130{
3135
3136
3139
3140
3143
3144
3145
3146
3147 do
3148 {
3149
3150
3151
3152
3153
3154
3155
3158 while (true)
3159 {
3161 break;
3162
3163
3164
3165
3166
3168
3171 {
3172
3173
3174
3175
3177 (
errmsg(
"\"%s\": stopping truncate due to conflicting lock request",
3179 return;
3180 }
3181
3187 }
3188
3189
3190
3191
3192
3193
3196 {
3197
3198
3199
3200
3201
3202
3203
3205 return;
3206 }
3207
3208
3209
3210
3211
3212
3213
3216
3218 {
3219
3221 return;
3222 }
3223
3224
3225
3226
3228
3229
3230
3231
3232
3233
3234
3235
3237
3238
3239
3240
3241
3242
3245
3247 (
errmsg(
"table \"%s\": truncated %u to %u pages",
3252}
3253
3254
3255
3256
3257
3258
3261{
3263 "prefetch size must be power of 2");
3264
3268
3269
3271
3272
3273
3274
3275
3276
3277
3278 blkno =
vacrel->rel_pages;
3280 while (blkno >
vacrel->nonempty_pages)
3281 {
3285 maxoff;
3286 bool hastup;
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296 if ((blkno % 32) == 0)
3297 {
3300
3306 {
3308 {
3310 (
errmsg(
"table \"%s\": suspending truncate due to conflicting lock request",
3312
3314 return blkno;
3315 }
3317 }
3318 }
3319
3320
3321
3322
3323
3324
3326
3327 blkno--;
3328
3329
3331 {
3334
3337 {
3340 }
3342 }
3343
3346
3347
3349
3351
3353 {
3355 continue;
3356 }
3357
3358 hastup = false;
3361 offnum <= maxoff;
3363 {
3365
3367
3368
3369
3370
3371
3372
3374 {
3375 hastup = true;
3376 break;
3377 }
3378 }
3379
3381
3382
3383 if (hastup)
3384 return blkno + 1;
3385 }
3386
3387
3388
3389
3390
3391
3392 return vacrel->nonempty_pages;
3393}
3394
3395
3396
3397
3398
3399
3400
3401
3402static void
3404{
3409
3410
3411
3412
3413
3414
3415 if (nworkers >= 0 &&
vacrel->nindexes > 1 &&
vacrel->do_index_vacuuming)
3416 {
3417
3418
3419
3420
3422 {
3423
3424
3425
3426
3427 if (nworkers > 0)
3429 (
errmsg(
"disabling parallel option of vacuum on \"%s\" --- cannot vacuum temporary tables in parallel",
3431 }
3432 else
3434 vacrel->nindexes, nworkers,
3438
3439
3440
3441
3442
3444 {
3446 &
vacrel->dead_items_info);
3447 return;
3448 }
3449 }
3450
3451
3452
3453
3454
3455
3459 vacrel->dead_items_info = dead_items_info;
3460
3462}
3463
3464
3465
3466
3467static void
3470{
3474 };
3476
3479
3480
3484}
3485
3486
3487
3488
3489static void
3491{
3492
3493 vacrel->num_dead_items_resets++;
3495
3497 {
3500 &
vacrel->dead_items_info);
3501 return;
3502 }
3503
3504
3507
3508
3509 vacrel->dead_items_info->num_items = 0;
3510}
3511
3512
3513
3514
3515static void
3517{
3519 {
3520
3521 return;
3522 }
3523
3524
3527}
3528
3529#ifdef USE_ASSERT_CHECKING
3530
3531
3532
3533
3534
3535
3536bool
3539 bool *all_frozen,
3542{
3543
3544
3545
3546
3547
3548
3550 vistest, false,
3552 all_frozen,
3553 newest_live_xid,
3555}
3556#endif
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590static bool
3596 bool *all_frozen,
3599{
3603 maxoff;
3604 bool all_visible = true;
3606
3608 *all_frozen = true;
3609
3611
3612#ifdef USE_ASSERT_CHECKING
3613
3615 {
3617 Assert(deadoffsets[
i - 1] < deadoffsets[
i]);
3618 }
3619#endif
3620
3623 offnum <= maxoff && all_visible;
3625 {
3629
3630
3631
3632
3633
3636
3637
3639 continue;
3640
3642
3643
3644
3645
3646
3648 {
3649 if (!deadoffsets ||
3652 {
3653 *all_frozen = all_visible = false;
3654 break;
3655 }
3657 continue;
3658 }
3659
3661
3665
3666
3669 {
3671 {
3673
3674
3676 {
3677 all_visible = false;
3678 *all_frozen = false;
3679 break;
3680 }
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3694
3695
3698 *newest_live_xid = xmin;
3699
3700
3701 if (all_visible && *all_frozen &&
3703 *all_frozen = false;
3704 }
3705 break;
3706
3711 {
3712 all_visible = false;
3713 *all_frozen = false;
3714 break;
3715 }
3716 default:
3717 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
3718 break;
3719 }
3720 }
3721
3722
3723
3724
3725
3726
3727 if (all_visible &&
3731 {
3732 all_visible = false;
3733 *all_frozen = false;
3734 }
3735
3736
3738
3739 return all_visible;
3740}
3741
3742
3743
3744
3745static void
3747{
3749 int nindexes =
vacrel->nindexes;
3751
3753
3754 for (
int idx = 0;
idx < nindexes;
idx++)
3755 {
3758
3760 continue;
3761
3762
3766 0, 0,
3767 false,
3771 }
3772}
3773
3774
3775
3776
3777
3778
3779
3780static void
3782{
3784
3786 {
3789 {
3791 errcontext(
"while scanning block %u offset %u of relation \"%s.%s\"",
3793 else
3794 errcontext(
"while scanning block %u of relation \"%s.%s\"",
3796 }
3797 else
3798 errcontext(
"while scanning relation \"%s.%s\"",
3800 break;
3801
3804 {
3806 errcontext(
"while vacuuming block %u offset %u of relation \"%s.%s\"",
3808 else
3809 errcontext(
"while vacuuming block %u of relation \"%s.%s\"",
3811 }
3812 else
3813 errcontext(
"while vacuuming relation \"%s.%s\"",
3815 break;
3816
3818 errcontext(
"while vacuuming index \"%s\" of relation \"%s.%s\"",
3820 break;
3821
3823 errcontext(
"while cleaning up index \"%s\" of relation \"%s.%s\"",
3825 break;
3826
3829 errcontext(
"while truncating relation \"%s.%s\" to %u blocks",
3831 break;
3832
3834 default:
3835 return;
3836
3837 }
3838}
3839
3840
3841
3842
3843
3844static void
3847{
3849 {
3853 }
3854
3858}
3859
3860
3861
3862
3863static void
3866{
3870}
Datum idx(PG_FUNCTION_ARGS)
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
TimestampTz GetCurrentTimestamp(void)
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
void pgstat_progress_end_command(void)
@ PROGRESS_COMMAND_VACUUM
PgBackendStatus * MyBEEntry
#define InvalidBlockNumber
static bool BlockNumberIsValid(BlockNumber blockNumber)
void CheckBufferIsPinnedOnce(Buffer buffer)
BlockNumber BufferGetBlockNumber(Buffer buffer)
PrefetchBufferResult PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
void ReleaseBuffer(Buffer buffer)
void UnlockReleaseBuffer(Buffer buffer)
void MarkBufferDirty(Buffer buffer)
void LockBufferForCleanup(Buffer buffer)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
bool ConditionalLockBufferForCleanup(Buffer buffer)
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
static void LockBuffer(Buffer buffer, BufferLockMode mode)
static bool BufferIsValid(Buffer bufnum)
Size PageGetHeapFreeSpace(const PageData *page)
void PageTruncateLinePointerArray(Page page)
static bool PageIsEmpty(const PageData *page)
static bool PageIsAllVisible(const PageData *page)
static bool PageIsNew(const PageData *page)
#define SizeOfPageHeaderData
static void PageSetAllVisible(Page page)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static void * PageGetItem(PageData *page, const ItemIdData *itemId)
#define PageClearPrunable(page)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
#define ngettext(s, p, n)
#define Assert(condition)
TransactionId MultiXactId
#define StaticAssertDecl(condition, errmessage)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define palloc0_object(type)
void FreeSpaceMapVacuumRange(Relation rel, BlockNumber start, BlockNumber end)
Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk)
void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail)
volatile uint32 CritSectionCount
bool heap_tuple_needs_eventual_freeze(HeapTupleHeader tuple)
bool heap_tuple_should_freeze(HeapTupleHeader tuple, const struct VacuumCutoffs *cutoffs, TransactionId *NoFreezePageRelfrozenXid, MultiXactId *NoFreezePageRelminMxid)
#define HEAP_PAGE_PRUNE_FREEZE
#define HEAP_PAGE_PRUNE_ALLOW_FAST_PATH
@ HEAPTUPLE_RECENTLY_DEAD
@ HEAPTUPLE_INSERT_IN_PROGRESS
@ HEAPTUPLE_DELETE_IN_PROGRESS
#define HEAP_PAGE_PRUNE_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
uint32 pg_prng_uint32(pg_prng_state *state)
pg_prng_state pg_global_prng_state
const char * pg_rusage_show(const PGRUsage *ru0)
void pg_rusage_init(PGRUsage *ru0)
static char buf[DEFAULT_XLOG_SEG_SIZE]
PgStat_Counter pgStatBlockReadTime
PgStat_Counter pgStatBlockWriteTime
void pgstat_report_vacuum(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, TimestampTz starttime)
#define qsort(a, b, c, d)
GlobalVisState * GlobalVisTestFor(Relation rel)
bool GlobalVisTestXidConsideredRunning(GlobalVisState *state, TransactionId xid, bool allow_update)
#define PROGRESS_VACUUM_PHASE_FINAL_CLEANUP
#define PROGRESS_VACUUM_MODE
#define PROGRESS_VACUUM_MODE_NORMAL
#define PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM
#define PROGRESS_VACUUM_DEAD_TUPLE_BYTES
#define PROGRESS_VACUUM_PHASE_SCAN_HEAP
#define PROGRESS_VACUUM_TOTAL_HEAP_BLKS
#define PROGRESS_VACUUM_PHASE
#define PROGRESS_VACUUM_DELAY_TIME
#define PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM_WRAPAROUND
#define PROGRESS_VACUUM_NUM_INDEX_VACUUMS
#define PROGRESS_VACUUM_PHASE_VACUUM_HEAP
#define PROGRESS_VACUUM_NUM_DEAD_ITEM_IDS
#define PROGRESS_VACUUM_MAX_DEAD_TUPLE_BYTES
#define PROGRESS_VACUUM_STARTED_BY_MANUAL
#define PROGRESS_VACUUM_HEAP_BLKS_SCANNED
#define PROGRESS_VACUUM_STARTED_BY
#define PROGRESS_VACUUM_PHASE_INDEX_CLEANUP
#define PROGRESS_VACUUM_PHASE_VACUUM_INDEX
#define PROGRESS_VACUUM_MODE_FAILSAFE
#define PROGRESS_VACUUM_INDEXES_PROCESSED
#define PROGRESS_VACUUM_INDEXES_TOTAL
#define PROGRESS_VACUUM_MODE_AGGRESSIVE
#define PROGRESS_VACUUM_HEAP_BLKS_VACUUMED
#define PROGRESS_VACUUM_PHASE_TRUNCATE
void heap_page_prune_and_freeze(PruneFreezeParams *params, PruneFreezeResult *presult, OffsetNumber *off_loc, TransactionId *new_relfrozen_xid, MultiXactId *new_relmin_mxid)
void log_heap_prune_and_freeze(Relation relation, Buffer buffer, Buffer vmbuffer, uint8 vmflags, TransactionId conflict_xid, bool cleanup_lock, PruneReason reason, HeapTupleFreeze *frozen, int nfrozen, OffsetNumber *redirected, int nredirected, OffsetNumber *dead, int ndead, OffsetNumber *unused, int nunused)
Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
ReadStream * read_stream_begin_relation(int flags, BufferAccessStrategy strategy, Relation rel, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
void read_stream_end(ReadStream *stream)
#define READ_STREAM_MAINTENANCE
#define READ_STREAM_USE_BATCHING
#define RelationGetRelid(relation)
#define RelationGetRelationName(relation)
#define RelationNeedsWAL(relation)
#define RelationUsesLocalBuffers(relation)
#define RelationGetNamespace(relation)
void RelationTruncate(Relation rel, BlockNumber nblocks)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
int64 shared_blks_dirtied
struct ErrorContextCallback * previous
void(* callback)(void *arg)
BlockNumber pages_deleted
BlockNumber pages_newly_deleted
BlockNumber next_eager_scan_region_start
ParallelVacuumState * pvs
bool next_unskippable_eager_scanned
VacDeadItemsInfo * dead_items_info
PVWorkerUsage worker_usage
Buffer next_unskippable_vmbuffer
BlockNumber nonempty_pages
BlockNumber eager_scan_remaining_fails
BlockNumber scanned_pages
int num_dead_items_resets
BlockNumber new_frozen_tuple_pages
BlockNumber removed_pages
IndexBulkDeleteResult ** indstats
BlockNumber new_all_frozen_pages
BlockNumber new_all_visible_all_frozen_pages
BlockNumber new_all_visible_pages
TransactionId NewRelfrozenXid
bool consider_bypass_optimization
Size total_dead_items_bytes
BlockNumber next_unskippable_block
int64 recently_dead_tuples
BlockNumber missed_dead_pages
BlockNumber current_block
BufferAccessStrategy bstrategy
BlockNumber eager_scan_remaining_successes
BlockNumber lpdead_item_pages
BlockNumber eager_scanned_pages
MultiXactId NewRelminMxid
struct VacuumCutoffs cutoffs
BlockNumber eager_scan_max_fails_per_region
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
int log_vacuum_min_duration
VacOptValue index_cleanup
double max_eager_freeze_failure_rate
TidStoreIter * TidStoreBeginIterate(TidStore *ts)
void TidStoreEndIterate(TidStoreIter *iter)
TidStoreIterResult * TidStoreIterateNext(TidStoreIter *iter)
TidStore * TidStoreCreateLocal(size_t max_bytes, bool insert_only)
void TidStoreDestroy(TidStore *ts)
int TidStoreGetBlockOffsets(TidStoreIterResult *result, OffsetNumber *offsets, int max_offsets)
void TidStoreSetBlockOffsets(TidStore *ts, BlockNumber blkno, OffsetNumber *offsets, int num_offsets)
size_t TidStoreMemoryUsage(TidStore *ts)
static bool TransactionIdFollows(TransactionId id1, TransactionId id2)
static TransactionId ReadNextTransactionId(void)
#define InvalidTransactionId
static bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
#define TransactionIdIsValid(xid)
#define TransactionIdIsNormal(xid)
static bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
bool track_cost_delay_timing
void vac_open_indexes(Relation relation, LOCKMODE lockmode, int *nindexes, Relation **Irel)
IndexBulkDeleteResult * vac_cleanup_one_index(IndexVacuumInfo *ivinfo, IndexBulkDeleteResult *istat)
void vac_close_indexes(int nindexes, Relation *Irel, LOCKMODE lockmode)
void vacuum_delay_point(bool is_analyze)
bool vacuum_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 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)
#define EAGER_SCAN_REGION_SIZE
static void lazy_truncate_heap(LVRelState *vacrel)
static void lazy_vacuum(LVRelState *vacrel)
static void lazy_cleanup_all_indexes(LVRelState *vacrel)
#define MAX_EAGER_FREEZE_SUCCESS_RATE
static bool lazy_scan_noprune(LVRelState *vacrel, Buffer buf, BlockNumber blkno, Page page, bool *has_lpdead_items)
static BlockNumber vacuum_reap_lp_read_stream_next(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
#define REL_TRUNCATE_MINIMUM
static bool should_attempt_truncation(LVRelState *vacrel)
static bool lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf, BlockNumber blkno, Page page, bool sharelock, Buffer vmbuffer)
@ VACUUM_ERRCB_PHASE_SCAN_HEAP
@ VACUUM_ERRCB_PHASE_VACUUM_INDEX
@ VACUUM_ERRCB_PHASE_TRUNCATE
@ VACUUM_ERRCB_PHASE_INDEX_CLEANUP
@ VACUUM_ERRCB_PHASE_VACUUM_HEAP
@ VACUUM_ERRCB_PHASE_UNKNOWN
static void lazy_scan_heap(LVRelState *vacrel)
#define ParallelVacuumIsActive(vacrel)
static void restore_vacuum_error_info(LVRelState *vacrel, const LVSavedErrInfo *saved_vacrel)
static IndexBulkDeleteResult * lazy_vacuum_one_index(Relation indrel, IndexBulkDeleteResult *istat, double reltuples, LVRelState *vacrel)
static void find_next_unskippable_block(LVRelState *vacrel, bool *skipsallvis)
static void dead_items_reset(LVRelState *vacrel)
#define REL_TRUNCATE_FRACTION
static bool lazy_check_wraparound_failsafe(LVRelState *vacrel)
static IndexBulkDeleteResult * lazy_cleanup_one_index(Relation indrel, IndexBulkDeleteResult *istat, double reltuples, bool estimated_count, LVRelState *vacrel)
static void lazy_vacuum_heap_page(LVRelState *vacrel, BlockNumber blkno, Buffer buffer, OffsetNumber *deadoffsets, int num_offsets, Buffer vmbuffer)
static bool heap_page_would_be_all_visible(Relation rel, Buffer buf, GlobalVisState *vistest, bool allow_update_vistest, OffsetNumber *deadoffsets, int ndeadoffsets, bool *all_frozen, TransactionId *newest_live_xid, OffsetNumber *logging_offnum)
#define BYPASS_THRESHOLD_PAGES
static void dead_items_alloc(LVRelState *vacrel, int nworkers)
#define VACUUM_TRUNCATE_LOCK_TIMEOUT
static bool lazy_vacuum_all_indexes(LVRelState *vacrel)
static void update_vacuum_error_info(LVRelState *vacrel, LVSavedErrInfo *saved_vacrel, int phase, BlockNumber blkno, OffsetNumber offnum)
static BlockNumber count_nondeletable_pages(LVRelState *vacrel, bool *lock_waiter_detected)
#define SKIP_PAGES_THRESHOLD
#define FAILSAFE_EVERY_PAGES
#define VACUUM_TRUNCATE_LOCK_CHECK_INTERVAL
static int cmpOffsetNumbers(const void *a, const void *b)
static void lazy_vacuum_heap_rel(LVRelState *vacrel)
#define VACUUM_FSM_EVERY_PAGES
void parallel_vacuum_cleanup_all_indexes(ParallelVacuumState *pvs, long num_table_tuples, int num_index_scans, bool estimated_count, PVWorkerStats *wstats)
TidStore * parallel_vacuum_get_dead_items(ParallelVacuumState *pvs, VacDeadItemsInfo **dead_items_info_p)
void parallel_vacuum_bulkdel_all_indexes(ParallelVacuumState *pvs, long num_table_tuples, int num_index_scans, PVWorkerStats *wstats)
ParallelVacuumState * parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes, int nrequested_workers, int vac_work_mem, int elevel, BufferAccessStrategy bstrategy)
void parallel_vacuum_reset_dead_items(ParallelVacuumState *pvs)
void parallel_vacuum_end(ParallelVacuumState *pvs, IndexBulkDeleteResult **istats)
void visibilitymap_set(BlockNumber heapBlk, Buffer vmBuf, uint8 flags, const RelFileLocator rlocator)
void visibilitymap_pin(Relation rel, BlockNumber heapBlk, Buffer *vmbuf)
uint8 visibilitymap_get_status(Relation rel, BlockNumber heapBlk, Buffer *vmbuf)
void visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_frozen)
#define VISIBILITYMAP_VALID_BITS
#define VISIBILITYMAP_ALL_FROZEN
#define VISIBILITYMAP_ALL_VISIBLE
#define WL_EXIT_ON_PM_DEATH
bool IsInParallelMode(void)