221{
229
230
231
232
233
234
235
236
237#define MAX_EAGER_FREEZE_SUCCESS_RATE 0.2
238
239
240
241
242
243
244
245
246#define EAGER_SCAN_REGION_SIZE 4096
247
249{
250
254
255
258
259
261
263
265
266
270
271
274
278
279
288
289
290
291
292
293
294
295
296
297
298
301
304
305
306
307
308
310
313
314
316
317
318
319
320
321
322
324
325
327
331
332
335
337
338
342
349
350
355
356
357
358
359
360
361
362
363
364
365
366
367
369
370
371
372
373
374
375
376
377
378
380
381
382
383
384
385
386
387
388
389
391
392
393
394
395
396
397
398
399
402
403
404
406{
411
412
413
418 void *callback_private_data,
419 void *per_buffer_data);
446 double reltuples,
450 double reltuples,
451 bool estimated_count,
462
463#ifdef USE_ASSERT_CHECKING
466 bool *all_frozen,
469#endif
474 bool *all_frozen,
485
486
487
488
489
490
491
492
493
494
495static void
497{
503
504
505
506
507
508
510 vacrel->eager_scan_max_fails_per_region = 0;
511 vacrel->eager_scan_remaining_fails = 0;
512 vacrel->eager_scan_remaining_successes = 0;
513
514
516 return;
517
518
519
520
521
522
523
524
526 return;
527
528
529
530
531
532
533
534
536 return;
537
538
539
540
541
542
543
544
545
546
547
548
549
550
553 vacrel->cutoffs.FreezeLimit))
555
559 vacrel->cutoffs.MultiXactCutoff))
561
563 return;
564
565
566
567
568
569
570
572
573 vacrel->eager_scan_remaining_successes =
576
577
578 if (
vacrel->eager_scan_remaining_successes == 0)
579 return;
580
581
582
583
584
585
586
587
589
591
594
595 vacrel->eager_scan_max_fails_per_region =
598
599
600
601
602
605
606 vacrel->eager_scan_remaining_fails =
607 vacrel->eager_scan_max_fails_per_region *
609}
610
611
612
613
614
615
616
617
618
619
620
621
622void
625{
628 instrument,
629 skipwithvm,
645
649 if (instrument)
650 {
653 {
656 }
657 }
658
659
661
669 else
672
673
674
675
676
677
678
679
680
681
682
683
684
696
697
701 vacrel->bstrategy = bstrategy;
702 if (instrument &&
vacrel->nindexes > 0)
703 {
704
706 for (
int i = 0;
i <
vacrel->nindexes;
i++)
708 }
709
710
711
712
713
714
715
716
717
718
722
723
724
725
726
728 vacrel->consider_bypass_optimization =
true;
729 vacrel->do_index_vacuuming =
true;
730 vacrel->do_index_cleanup =
true;
733 {
734
735 vacrel->do_index_vacuuming =
false;
736 vacrel->do_index_cleanup =
false;
737 }
739 {
740
741 vacrel->consider_bypass_optimization =
false;
742 }
743 else
744 {
745
747 }
748
749
750 vacrel->scanned_pages = 0;
751 vacrel->eager_scanned_pages = 0;
752 vacrel->removed_pages = 0;
753 vacrel->new_frozen_tuple_pages = 0;
754 vacrel->lpdead_item_pages = 0;
755 vacrel->missed_dead_pages = 0;
756 vacrel->nonempty_pages = 0;
757
758
759
760 vacrel->new_rel_tuples = 0;
761 vacrel->new_live_tuples = 0;
764
765
766 vacrel->num_index_scans = 0;
767 vacrel->num_dead_items_resets = 0;
768 vacrel->total_dead_items_bytes = 0;
769 vacrel->tuples_deleted = 0;
770 vacrel->tuples_frozen = 0;
773 vacrel->recently_dead_tuples = 0;
774 vacrel->missed_dead_tuples = 0;
775
776 vacrel->vm_new_visible_pages = 0;
777 vacrel->vm_new_visible_frozen_pages = 0;
778 vacrel->vm_new_frozen_pages = 0;
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
799
800
803
804
805
806
807
808
809 vacrel->skippedallvis =
false;
810 skipwithvm = true;
812 {
813
814
815
816
817 vacrel->aggressive =
true;
818 skipwithvm = false;
819 }
820
821 vacrel->skipwithvm = skipwithvm;
822
823
824
825
826
827
829
830
835
837 {
840 (
errmsg(
"aggressively vacuuming \"%s.%s.%s\"",
843 else
845 (
errmsg(
"vacuuming \"%s.%s.%s\"",
848 }
849
850
851
852
853
854
855
856
859
860
861
862
863
865
866
867
868
869
870
873
874
875
876
877
880
881
882
883
884
885
886
887 if (
vacrel->do_index_cleanup)
889
890
892
893
896
897
899
900
903
904
905
906
907
908
909
910
913 vacrel->cutoffs.relfrozenxid,
914 vacrel->NewRelfrozenXid));
917 vacrel->cutoffs.relminmxid,
919 if (
vacrel->skippedallvis)
920 {
921
922
923
924
925
929 }
930
931
932
933
934
939
940
941
942
943
944
947
948
949
950
951
952
953
954
960
961
962
963
964
965
966
967
968
969
970
973 vacrel->recently_dead_tuples +
974 vacrel->missed_dead_tuples,
975 starttime);
977
978 if (instrument)
979 {
981
985 {
998
1004
1011
1014 {
1015
1016
1017
1018
1020 msgfmt =
_(
"finished vacuuming \"%s.%s.%s\": index scans: %d\n");
1021 }
1023 {
1024
1025
1026
1027
1028
1029
1031 msgfmt =
_(
"automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1032 else
1033 msgfmt =
_(
"automatic vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1034 }
1035 else
1036 {
1038 msgfmt =
_(
"automatic aggressive vacuum of table \"%s.%s.%s\": index scans: %d\n");
1039 else
1040 msgfmt =
_(
"automatic vacuum of table \"%s.%s.%s\": index scans: %d\n");
1041 }
1046 vacrel->num_index_scans);
1047 appendStringInfo(&
buf,
_(
"pages: %u removed, %u remain, %u scanned (%.2f%% of total), %u eagerly scanned\n"),
1052 100.0 *
vacrel->scanned_pages /
1054 vacrel->eager_scanned_pages);
1056 _(
"tuples: %" PRId64 " removed, %" PRId64 " remain, %" PRId64 " are dead but not yet removable\n"),
1059 vacrel->recently_dead_tuples);
1060 if (
vacrel->missed_dead_tuples > 0)
1062 _(
"tuples missed: %" PRId64 " dead from %u pages not removed due to cleanup lock contention\n"),
1063 vacrel->missed_dead_tuples,
1064 vacrel->missed_dead_pages);
1066 vacrel->cutoffs.OldestXmin);
1068 _(
"removable cutoff: %u, which was %d XIDs old when operation ended\n"),
1071 {
1073 vacrel->cutoffs.relfrozenxid);
1075 _(
"new relfrozenxid: %u, which is %d XIDs ahead of previous value\n"),
1077 }
1079 {
1081 vacrel->cutoffs.relminmxid);
1083 _(
"new relminmxid: %u, which is %d MXIDs ahead of previous value\n"),
1085 }
1087 vacrel->new_frozen_tuple_pages,
1089 100.0 *
vacrel->new_frozen_tuple_pages /
1092
1094 _(
"visibility map: %u pages set all-visible, %u pages set all-frozen (%u were all-visible)\n"),
1095 vacrel->vm_new_visible_pages,
1096 vacrel->vm_new_visible_frozen_pages +
1097 vacrel->vm_new_frozen_pages,
1098 vacrel->vm_new_frozen_pages);
1099 if (
vacrel->do_index_vacuuming)
1100 {
1101 if (
vacrel->nindexes == 0 ||
vacrel->num_index_scans == 0)
1103 else
1105
1106 msgfmt =
_(
"%u pages from table (%.2f%% of total) had %" PRId64 " dead item identifiers removed\n");
1107 }
1108 else
1109 {
1112 else
1114
1115 msgfmt =
_(
"%u pages from table (%.2f%% of total) have %" PRId64 " dead item identifiers\n");
1116 }
1118 vacrel->lpdead_item_pages,
1122 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1123 {
1125
1126 if (!istat)
1127 continue;
1128
1130 _(
"index \"%s\": pages: %u in total, %u newly deleted, %u currently deleted, %u reusable\n"),
1136 }
1138 {
1139
1140
1141
1142
1143
1144
1147 }
1149 {
1152
1155 }
1157 {
1162 }
1177
1178
1179
1180
1181
1182
1183
1184
1185
1187 ngettext(
"memory usage: dead item storage %.2f MB accumulated across %d reset (limit %.2f MB each)\n",
1188 "memory usage: dead item storage %.2f MB accumulated across %d resets (limit %.2f MB each)\n",
1189 vacrel->num_dead_items_resets),
1190 (
double)
vacrel->total_dead_items_bytes / (1024 * 1024),
1191 vacrel->num_dead_items_resets,
1194
1198 }
1199 }
1200
1201
1202 for (
int i = 0;
i <
vacrel->nindexes;
i++)
1203 {
1206
1207 if (instrument)
1209 }
1210}
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
1248static void
1250{
1253 blkno = 0,
1256 vacrel->eager_scan_remaining_successes;
1262 };
1264
1265
1270
1271
1274 vacrel->next_unskippable_eager_scanned =
false;
1276
1277
1278
1279
1280
1281
1282
1289 sizeof(bool));
1290
1291 while (true)
1292 {
1296 int ndeleted = 0;
1298 void *per_buffer_data =
NULL;
1301
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313 if (
vacrel->scanned_pages > 0 &&
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325 if (
vacrel->dead_items_info->num_items > 0 &&
1327 {
1328
1329
1330
1331
1332
1333
1335 {
1338 }
1339
1340
1341 vacrel->consider_bypass_optimization =
false;
1343
1344
1345
1346
1347
1348
1350 blkno + 1);
1352
1353
1356 }
1357
1359
1360
1362 break;
1363
1368
1371 vacrel->eager_scanned_pages++;
1372
1373
1377
1378
1379
1380
1381
1382
1384
1385
1386
1387
1388
1389
1390
1392
1395
1396
1398 vmbuffer))
1399 {
1400
1401 continue;
1402 }
1403
1404
1405
1406
1407
1408
1409
1410
1411
1414 {
1415
1416
1417
1418
1423 }
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1440 vmbuffer,
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1458 {
1459
1461
1463 {
1464 if (
vacrel->eager_scan_remaining_successes > 0)
1465 vacrel->eager_scan_remaining_successes--;
1466
1467 if (
vacrel->eager_scan_remaining_successes == 0)
1468 {
1469
1470
1471
1472
1473
1474
1475
1476 if (
vacrel->eager_scan_max_fails_per_region > 0)
1478 (
errmsg(
"disabling eager scanning after freezing %u eagerly scanned blocks of relation \"%s.%s.%s\"",
1482
1483
1484
1485
1486
1487
1488 vacrel->eager_scan_remaining_fails = 0;
1490 vacrel->eager_scan_max_fails_per_region = 0;
1491 }
1492 }
1493 else if (
vacrel->eager_scan_remaining_fails > 0)
1494 vacrel->eager_scan_remaining_fails--;
1495 }
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516 if (
vacrel->nindexes == 0
1517 || !
vacrel->do_index_vacuuming
1519 {
1521
1524
1525
1526
1527
1528
1529
1530
1533 {
1535 blkno);
1537 }
1538 }
1539 else
1541 }
1542
1546
1547
1548
1549
1550
1552 rel_pages);
1553
1554
1558
1559
1560
1561
1562
1565 vacrel->missed_dead_tuples;
1566
1568
1569
1570
1571
1572
1573 if (
vacrel->dead_items_info->num_items > 0)
1575
1576
1577
1578
1579
1580
1581
1584
1585
1587
1588
1591}
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1619 void *callback_private_data,
1620 void *per_buffer_data)
1621{
1624
1625
1627
1628
1630 {
1632 {
1635 }
1637 }
1638
1639
1640
1641
1644 {
1645
1646
1647
1648
1649
1651
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1670 {
1673 vacrel->skippedallvis =
true;
1674 }
1675 }
1676
1677
1679 {
1680
1681
1682
1683
1684
1686
1687 *((bool *) per_buffer_data) = false;
1688 return vacrel->current_block;
1689 }
1690 else
1691 {
1692
1693
1694
1695
1697
1699 *((
bool *) per_buffer_data) =
vacrel->next_unskippable_eager_scanned;
1700 return vacrel->current_block;
1701 }
1702}
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717static void
1719{
1722 Buffer next_unskippable_vmbuffer =
vacrel->next_unskippable_vmbuffer;
1723 bool next_unskippable_eager_scanned = false;
1724
1726
1727 for (;; next_unskippable_block++)
1728 {
1730 next_unskippable_block,
1731 &next_unskippable_vmbuffer);
1732
1733
1734
1735
1736
1737
1738
1739
1740 if (next_unskippable_block >=
vacrel->next_eager_scan_region_start)
1741 {
1742 vacrel->eager_scan_remaining_fails =
1743 vacrel->eager_scan_max_fails_per_region;
1745 }
1746
1747
1748
1749
1750
1752 {
1754 break;
1755 }
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767 if (next_unskippable_block == rel_pages - 1)
1768 break;
1769
1770
1772 break;
1773
1774
1775
1776
1777
1779 continue;
1780
1781
1782
1783
1784
1786 break;
1787
1788
1789
1790
1791
1792
1793 if (
vacrel->eager_scan_remaining_fails > 0)
1794 {
1795 next_unskippable_eager_scanned = true;
1796 break;
1797 }
1798
1799
1800
1801
1802
1804 }
1805
1806
1807 vacrel->next_unskippable_block = next_unskippable_block;
1808 vacrel->next_unskippable_eager_scanned = next_unskippable_eager_scanned;
1809 vacrel->next_unskippable_vmbuffer = next_unskippable_vmbuffer;
1810}
1811
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
1846static bool
1849{
1851
1853 {
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1874
1876 {
1878
1880 }
1881
1882 return true;
1883 }
1884
1886 {
1887
1888
1889
1890
1891
1893 {
1896
1898 {
1899
1900 return false;
1901 }
1902 }
1903 else
1904 {
1905
1906 }
1907
1908
1909
1910
1911
1913 {
1915
1916
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1931
1939
1940
1941 vacrel->vm_new_visible_pages++;
1942 vacrel->vm_new_visible_frozen_pages++;
1943 }
1944
1948 return true;
1949 }
1950
1951
1952 return false;
1953}
1954
1955
1956static int
1958{
1960}
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978static void
1984{
1986
1988
1989
1990
1991
1992
1993
1994
1997 {
2000 errmsg(
"page is not marked all-visible but visibility map bit is set in relation \"%s\" page %u",
2002
2006 }
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2023 {
2026 errmsg(
"page containing LP_DEAD items is marked as all-visible in relation \"%s\" page %u",
2028
2034 }
2035}
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054static int
2062{
2066 .relation = rel,
2070 .vistest =
vacrel->vistest,
2071 .cutoffs = &
vacrel->cutoffs,
2072 };
2075
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093 if (
vacrel->nindexes == 0)
2095
2100
2103
2105 {
2106
2107
2108
2109
2110
2111
2112 vacrel->new_frozen_tuple_pages++;
2113 }
2114
2115
2116
2117
2118
2119
2120
2121
2122#ifdef USE_ASSERT_CHECKING
2124 {
2127
2129
2133
2135
2138 }
2139#endif
2140
2141
2142
2143
2145 {
2146 vacrel->lpdead_item_pages++;
2147
2148
2149
2150
2151
2152
2153
2156
2158 }
2159
2160
2165 vacrel->recently_dead_tuples +=
presult.recently_dead_tuples;
2166
2167
2169 vacrel->nonempty_pages = blkno + 1;
2170
2171
2173
2176
2178
2180 presult.lpdead_items, vmbuffer,
2182
2185
2186
2188
2191
2192
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2210
2211
2212
2213
2214
2215
2218
2221 vmbuffer,
presult.vm_conflict_horizon,
2223
2224
2225
2226
2227
2229 {
2230 vacrel->vm_new_visible_pages++;
2232 {
2233 vacrel->vm_new_visible_frozen_pages++;
2235 }
2236 }
2239 {
2240 vacrel->vm_new_frozen_pages++;
2242 }
2243
2245}
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267static bool
2273{
2275 maxoff;
2276 int lpdead_items,
2277 live_tuples,
2278 recently_dead_tuples,
2279 missed_dead_tuples;
2280 bool hastup;
2285
2287
2288 hastup = false;
2289
2290 lpdead_items = 0;
2291 live_tuples = 0;
2292 recently_dead_tuples = 0;
2293 missed_dead_tuples = 0;
2294
2297 offnum <= maxoff;
2299 {
2302
2305
2307 continue;
2308
2310 {
2311 hastup = true;
2312 continue;
2313 }
2314
2316 {
2317
2318
2319
2320
2321 deadoffsets[lpdead_items++] = offnum;
2322 continue;
2323 }
2324
2325 hastup = true;
2328 &NoFreezePageRelfrozenXid,
2329 &NoFreezePageRelminMxid))
2330 {
2331
2333 {
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2346 return false;
2347 }
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357 }
2358
2363
2366 {
2369
2370
2371
2372
2373 live_tuples++;
2374
2375 break;
2377
2378
2379
2380
2381
2382 missed_dead_tuples++;
2383 break;
2385
2386
2387
2388
2389 recently_dead_tuples++;
2390 break;
2392
2393
2394
2395
2396 break;
2397 default:
2398 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
2399 break;
2400 }
2401 }
2402
2404
2405
2406
2407
2408
2409
2410 vacrel->NewRelfrozenXid = NoFreezePageRelfrozenXid;
2411 vacrel->NewRelminMxid = NoFreezePageRelminMxid;
2412
2413
2414 if (
vacrel->nindexes == 0)
2415 {
2416
2417 if (lpdead_items > 0)
2418 {
2419
2420
2421
2422
2423
2424
2425
2426
2427 hastup = true;
2428 missed_dead_tuples += lpdead_items;
2429 }
2430 }
2431 else if (lpdead_items > 0)
2432 {
2433
2434
2435
2436
2437
2438 vacrel->lpdead_item_pages++;
2439
2441
2442 vacrel->lpdead_items += lpdead_items;
2443 }
2444
2445
2446
2447
2448 vacrel->live_tuples += live_tuples;
2449 vacrel->recently_dead_tuples += recently_dead_tuples;
2450 vacrel->missed_dead_tuples += missed_dead_tuples;
2451 if (missed_dead_tuples > 0)
2452 vacrel->missed_dead_pages++;
2453
2454
2455 if (hastup)
2456 vacrel->nonempty_pages = blkno + 1;
2457
2458
2460
2461
2462 return true;
2463}
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478static void
2480{
2482
2483
2486
2487 if (!
vacrel->do_index_vacuuming)
2488 {
2491 return;
2492 }
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2514 if (
vacrel->consider_bypass_optimization &&
vacrel->rel_pages > 0)
2515 {
2517
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2548 }
2549
2551 {
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562 vacrel->do_index_vacuuming =
false;
2563 }
2565 {
2566
2567
2568
2569
2571 }
2572 else
2573 {
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2586 }
2587
2588
2589
2590
2591
2593}
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603static bool
2605{
2611 };
2616 };
2619
2623
2624
2626 {
2627
2628 return false;
2629 }
2630
2631
2632
2633
2634
2638
2640 {
2642 {
2645
2649
2650
2653
2655 {
2656
2658 break;
2659 }
2660 }
2661 }
2662 else
2663 {
2664
2666 vacrel->num_index_scans);
2667
2668
2669
2670
2671
2674 }
2675
2676
2677
2678
2679
2680
2681
2682
2684 vacrel->dead_items_info->num_items ==
vacrel->lpdead_items);
2686
2687
2688
2689
2690
2691
2692
2693
2694 vacrel->num_index_scans++;
2699
2701}
2702
2703
2704
2705
2706
2707
2708
2709
2712 void *callback_private_data,
2713 void *per_buffer_data)
2714{
2717
2721
2722
2723
2724
2725
2727
2729}
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748static void
2750{
2756
2760
2761
2764
2765
2769
2771
2772
2773
2774
2775
2776
2777
2778
2779
2786 iter,
2788
2789 while (true)
2790 {
2798
2800
2802
2803
2805 break;
2806
2808
2812
2813
2814
2815
2816
2817
2819
2820
2824
2825
2828
2832 }
2833
2836
2840
2841
2842
2843
2844
2846 (
vacrel->dead_items_info->num_items ==
vacrel->lpdead_items &&
2848
2850 (
errmsg(
"table \"%s\": removed %" PRId64 " dead item identifiers in %u pages",
2853
2854
2856}
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866static void
2870{
2873 int nunused = 0;
2876 bool all_frozen;
2879
2881
2883
2884
2888
2889
2890
2891
2892
2893
2894
2895
2896
2898 vacrel->cutoffs.OldestXmin,
2900 &all_frozen, &visibility_cutoff_xid,
2902 {
2904 if (all_frozen)
2905 {
2908 }
2909
2910
2911
2912
2913
2914
2916 }
2917
2919
2921 {
2924
2926
2929 unused[nunused++] =
toff;
2930 }
2931
2933
2934
2936
2938 {
2939
2940
2941
2942
2946 vacrel->rel->rd_locator);
2948 }
2949
2950
2951
2952
2954
2955
2957 {
2967 unused, nunused);
2968 }
2969
2971
2973 {
2974
2976 vacrel->vm_new_visible_pages++;
2977 if (all_frozen)
2978 vacrel->vm_new_visible_frozen_pages++;
2979 }
2980
2981
2983}
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997static bool
2999{
3000
3002 return true;
3003
3005 {
3010 };
3012
3014
3015
3016
3017
3018
3019
3021
3022
3023 vacrel->do_index_vacuuming =
false;
3024 vacrel->do_index_cleanup =
false;
3025 vacrel->do_rel_truncate =
false;
3026
3027
3029
3031 (
errmsg(
"bypassing nonessential maintenance of table \"%s.%s.%s\" as a failsafe after %d index scans",
3033 vacrel->num_index_scans),
3034 errdetail(
"The table's relfrozenxid or relminmxid is too far in the past."),
3035 errhint(
"Consider increasing configuration parameter \"maintenance_work_mem\" or \"autovacuum_work_mem\".\n"
3036 "You might also need to consider other ways for VACUUM to keep up with the allocation of transaction IDs.")));
3037
3038
3041
3042 return true;
3043 }
3044
3045 return false;
3046}
3047
3048
3049
3050
3051static void
3053{
3054 double reltuples =
vacrel->new_rel_tuples;
3055 bool estimated_count =
vacrel->scanned_pages <
vacrel->rel_pages;
3059 };
3063 };
3066
3069
3070
3071
3072
3073
3077
3079 {
3081 {
3084
3087 estimated_count,
vacrel);
3088
3089
3092 }
3093 }
3094 else
3095 {
3096
3099 estimated_count);
3100 }
3101
3102
3104}
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3122{
3125
3128 ivinfo.analyze_only =
false;
3129 ivinfo.report_progress =
false;
3130 ivinfo.estimated_count =
true;
3132 ivinfo.num_heap_tuples = reltuples;
3134
3135
3136
3137
3138
3139
3140
3146
3147
3149 vacrel->dead_items_info);
3150
3151
3155
3156 return istat;
3157}
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3170 double reltuples, bool estimated_count,
3172{
3175
3178 ivinfo.analyze_only =
false;
3179 ivinfo.report_progress =
false;
3180 ivinfo.estimated_count = estimated_count;
3182
3183 ivinfo.num_heap_tuples = reltuples;
3185
3186
3187
3188
3189
3190
3191
3197
3199
3200
3204
3205 return istat;
3206}
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228static bool
3230{
3232
3234 return false;
3235
3240 return true;
3241
3242 return false;
3243}
3244
3245
3246
3247
3248static void
3250{
3255
3256
3259
3260
3263
3264
3265
3266
3267 do
3268 {
3269
3270
3271
3272
3273
3274
3275
3278 while (true)
3279 {
3281 break;
3282
3283
3284
3285
3286
3288
3291 {
3292
3293
3294
3295
3297 (
errmsg(
"\"%s\": stopping truncate due to conflicting lock request",
3299 return;
3300 }
3301
3307 }
3308
3309
3310
3311
3312
3313
3316 {
3317
3318
3319
3320
3321
3322
3323
3325 return;
3326 }
3327
3328
3329
3330
3331
3332
3333
3336
3338 {
3339
3341 return;
3342 }
3343
3344
3345
3346
3348
3349
3350
3351
3352
3353
3354
3355
3357
3358
3359
3360
3361
3362
3365
3367 (
errmsg(
"table \"%s\": truncated %u to %u pages",
3372}
3373
3374
3375
3376
3377
3378
3381{
3383 "prefetch size must be power of 2");
3384
3388
3389
3391
3392
3393
3394
3395
3396
3397
3398 blkno =
vacrel->rel_pages;
3400 while (blkno >
vacrel->nonempty_pages)
3401 {
3405 maxoff;
3406 bool hastup;
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416 if ((blkno % 32) == 0)
3417 {
3420
3426 {
3428 {
3430 (
errmsg(
"table \"%s\": suspending truncate due to conflicting lock request",
3432
3434 return blkno;
3435 }
3437 }
3438 }
3439
3440
3441
3442
3443
3444
3446
3447 blkno--;
3448
3449
3451 {
3454
3457 {
3460 }
3462 }
3463
3466
3467
3469
3471
3473 {
3475 continue;
3476 }
3477
3478 hastup = false;
3481 offnum <= maxoff;
3483 {
3485
3487
3488
3489
3490
3491
3492
3494 {
3495 hastup = true;
3496 break;
3497 }
3498 }
3499
3501
3502
3503 if (hastup)
3504 return blkno + 1;
3505 }
3506
3507
3508
3509
3510
3511
3512 return vacrel->nonempty_pages;
3513}
3514
3515
3516
3517
3518
3519
3520
3521
3522static void
3524{
3529
3530
3531
3532
3533
3534
3535 if (nworkers >= 0 &&
vacrel->nindexes > 1 &&
vacrel->do_index_vacuuming)
3536 {
3537
3538
3539
3540
3542 {
3543
3544
3545
3546
3547 if (nworkers > 0)
3549 (
errmsg(
"disabling parallel option of vacuum on \"%s\" --- cannot vacuum temporary tables in parallel",
3551 }
3552 else
3554 vacrel->nindexes, nworkers,
3558
3559
3560
3561
3562
3564 {
3566 &
vacrel->dead_items_info);
3567 return;
3568 }
3569 }
3570
3571
3572
3573
3574
3575
3579 vacrel->dead_items_info = dead_items_info;
3580
3582}
3583
3584
3585
3586
3587static void
3590{
3594 };
3596
3599
3600
3604}
3605
3606
3607
3608
3609static void
3611{
3612
3613 vacrel->num_dead_items_resets++;
3615
3617 {
3620 &
vacrel->dead_items_info);
3621 return;
3622 }
3623
3624
3627
3628
3629 vacrel->dead_items_info->num_items = 0;
3630}
3631
3632
3633
3634
3635static void
3637{
3639 {
3640
3641 return;
3642 }
3643
3644
3647}
3648
3649#ifdef USE_ASSERT_CHECKING
3650
3651
3652
3653
3654
3655
3656static bool
3659 bool *all_frozen,
3662{
3663
3665 OldestXmin,
3667 all_frozen,
3668 visibility_cutoff_xid,
3670}
3671#endif
3672
3673
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
3703static bool
3708 bool *all_frozen,
3711{
3715 maxoff;
3716 bool all_visible = true;
3718
3720 *all_frozen = true;
3721
3723
3724#ifdef USE_ASSERT_CHECKING
3725
3727 {
3729 Assert(deadoffsets[
i - 1] < deadoffsets[
i]);
3730 }
3731#endif
3732
3735 offnum <= maxoff && all_visible;
3737 {
3740
3741
3742
3743
3744
3747
3748
3750 continue;
3751
3753
3754
3755
3756
3757
3759 {
3760 if (!deadoffsets ||
3763 {
3764 *all_frozen = all_visible = false;
3765 break;
3766 }
3768 continue;
3769 }
3770
3772
3776
3777
3780 {
3782 {
3784
3785
3787 {
3788 all_visible = false;
3789 *all_frozen = false;
3790 break;
3791 }
3792
3793
3794
3795
3796
3799 {
3800 all_visible = false;
3801 *all_frozen = false;
3802 break;
3803 }
3804
3805
3808 *visibility_cutoff_xid = xmin;
3809
3810
3811 if (all_visible && *all_frozen &&
3813 *all_frozen = false;
3814 }
3815 break;
3816
3821 {
3822 all_visible = false;
3823 *all_frozen = false;
3824 break;
3825 }
3826 default:
3827 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
3828 break;
3829 }
3830 }
3831
3832
3834
3835 return all_visible;
3836}
3837
3838
3839
3840
3841static void
3843{
3845 int nindexes =
vacrel->nindexes;
3847
3849
3850 for (
int idx = 0;
idx < nindexes;
idx++)
3851 {
3854
3856 continue;
3857
3858
3862 0, 0,
3863 false,
3867 }
3868}
3869
3870
3871
3872
3873
3874
3875
3876static void
3878{
3880
3882 {
3885 {
3887 errcontext(
"while scanning block %u offset %u of relation \"%s.%s\"",
3889 else
3890 errcontext(
"while scanning block %u of relation \"%s.%s\"",
3892 }
3893 else
3894 errcontext(
"while scanning relation \"%s.%s\"",
3896 break;
3897
3900 {
3902 errcontext(
"while vacuuming block %u offset %u of relation \"%s.%s\"",
3904 else
3905 errcontext(
"while vacuuming block %u of relation \"%s.%s\"",
3907 }
3908 else
3909 errcontext(
"while vacuuming relation \"%s.%s\"",
3911 break;
3912
3914 errcontext(
"while vacuuming index \"%s\" of relation \"%s.%s\"",
3916 break;
3917
3919 errcontext(
"while cleaning up index \"%s\" of relation \"%s.%s\"",
3921 break;
3922
3925 errcontext(
"while truncating relation \"%s.%s\" to %u blocks",
3927 break;
3928
3930 default:
3931 return;
3932
3933 }
3934}
3935
3936
3937
3938
3939
3940static void
3943{
3945 {
3949 }
3950
3954}
3955
3956
3957
3958
3959static void
3962{
3966}
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)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#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 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
BlockNumber vm_new_frozen_pages
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
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 vm_new_visible_pages
BlockNumber eager_scan_max_fails_per_region
BlockNumber vm_new_visible_frozen_pages
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)