1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
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
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
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
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
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
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
|
<sect1 id="functions-admin">
<title>System Administration Functions</title>
<para>
The functions described in this section are used to control and
monitor a <productname>PostgreSQL</productname> installation.
</para>
<sect2 id="functions-admin-set">
<title>Configuration Settings Functions</title>
<indexterm>
<primary>SET</primary>
</indexterm>
<indexterm>
<primary>SHOW</primary>
</indexterm>
<indexterm>
<primary>configuration</primary>
<secondary sortas="server">of the server</secondary>
<tertiary>functions</tertiary>
</indexterm>
<para>
<xref linkend="functions-admin-set-table"/> shows the functions
available to query and alter run-time configuration parameters.
</para>
<table id="functions-admin-set-table">
<title>Configuration Settings Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para>
<para>
Example(s)
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>current_setting</primary>
</indexterm>
<function>current_setting</function> ( <parameter>setting_name</parameter> <type>text</type> <optional>, <parameter>missing_ok</parameter> <type>boolean</type> </optional> )
<returnvalue>text</returnvalue>
</para>
<para>
Returns the current value of the
setting <parameter>setting_name</parameter>. If there is no such
setting, <function>current_setting</function> throws an error
unless <parameter>missing_ok</parameter> is supplied and
is <literal>true</literal> (in which case NULL is returned).
This function corresponds to
the <acronym>SQL</acronym> command <xref linkend="sql-show"/>.
</para>
<para>
<literal>current_setting('datestyle')</literal>
<returnvalue>ISO, MDY</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>set_config</primary>
</indexterm>
<function>set_config</function> (
<parameter>setting_name</parameter> <type>text</type>,
<parameter>new_value</parameter> <type>text</type>,
<parameter>is_local</parameter> <type>boolean</type> )
<returnvalue>text</returnvalue>
</para>
<para>
Sets the parameter <parameter>setting_name</parameter>
to <parameter>new_value</parameter>, and returns that value.
If <parameter>is_local</parameter> is <literal>true</literal>, the new
value will only apply during the current transaction. If you want the
new value to apply for the rest of the current session,
use <literal>false</literal> instead. This function corresponds to
the SQL command <xref linkend="sql-set"/>.
</para>
<para>
<function>set_config</function> accepts the NULL value for
<parameter>new_value</parameter>, but as settings cannot be null, it
is interpreted as a request to reset the setting to its default value.
</para>
<para>
<literal>set_config('log_statement_stats', 'off', false)</literal>
<returnvalue>off</returnvalue>
</para></entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
<sect2 id="functions-admin-signal">
<title>Server Signaling Functions</title>
<indexterm>
<primary>signal</primary>
<secondary sortas="backend">backend processes</secondary>
</indexterm>
<para>
The functions shown in <xref
linkend="functions-admin-signal-table"/> send control signals to
other server processes. Use of these functions is restricted to
superusers by default but access may be granted to others using
<command>GRANT</command>, with noted exceptions.
</para>
<para>
Each of these functions returns <literal>true</literal> if
the signal was successfully sent and <literal>false</literal>
if sending the signal failed.
</para>
<table id="functions-admin-signal-table">
<title>Server Signaling Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_cancel_backend</primary>
</indexterm>
<function>pg_cancel_backend</function> ( <parameter>pid</parameter> <type>integer</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Cancels the current query of the session whose backend process has the
specified process ID. This is also allowed if the
calling role is a member of the role whose backend is being canceled or
the calling role has privileges of <literal>pg_signal_backend</literal>,
however only superusers can cancel superuser backends.
As an exception, roles with privileges of
<literal>pg_signal_autovacuum_worker</literal> are permitted to
cancel autovacuum worker processes, which are otherwise considered
superuser backends.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_log_backend_memory_contexts</primary>
</indexterm>
<function>pg_log_backend_memory_contexts</function> ( <parameter>pid</parameter> <type>integer</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Requests to log the memory contexts of the backend with the
specified process ID. This function can send the request to
backends and auxiliary processes except logger. These memory contexts
will be logged at
<literal>LOG</literal> message level. They will appear in
the server log based on the log configuration set
(see <xref linkend="runtime-config-logging"/> for more information),
but will not be sent to the client regardless of
<xref linkend="guc-client-min-messages"/>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_reload_conf</primary>
</indexterm>
<function>pg_reload_conf</function> ()
<returnvalue>boolean</returnvalue>
</para>
<para>
Causes all processes of the <productname>PostgreSQL</productname>
server to reload their configuration files. (This is initiated by
sending a <systemitem>SIGHUP</systemitem> signal to the postmaster
process, which in turn sends <systemitem>SIGHUP</systemitem> to each
of its children.) You can use the
<link linkend="view-pg-file-settings"><structname>pg_file_settings</structname></link>,
<link linkend="view-pg-hba-file-rules"><structname>pg_hba_file_rules</structname></link> and
<link linkend="view-pg-ident-file-mappings"><structname>pg_ident_file_mappings</structname></link> views
to check the configuration files for possible errors, before reloading.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_rotate_logfile</primary>
</indexterm>
<function>pg_rotate_logfile</function> ()
<returnvalue>boolean</returnvalue>
</para>
<para>
Signals the log-file manager to switch to a new output file
immediately. This works only when the built-in log collector is
running, since otherwise there is no log-file manager subprocess.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_terminate_backend</primary>
</indexterm>
<function>pg_terminate_backend</function> ( <parameter>pid</parameter> <type>integer</type>, <parameter>timeout</parameter> <type>bigint</type> <literal>DEFAULT</literal> <literal>0</literal> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Terminates the session whose backend process has the
specified process ID. This is also allowed if the calling role
is a member of the role whose backend is being terminated or the
calling role has privileges of <literal>pg_signal_backend</literal>,
however only superusers can terminate superuser backends.
As an exception, roles with privileges of
<literal>pg_signal_autovacuum_worker</literal> are permitted to
terminate autovacuum worker processes, which are otherwise considered
superuser backends.
</para>
<para>
If <parameter>timeout</parameter> is not specified or zero, this
function returns <literal>true</literal> whether the process actually
terminates or not, indicating only that the sending of the signal was
successful. If the <parameter>timeout</parameter> is specified (in
milliseconds) and greater than zero, the function waits until the
process is actually terminated or until the given time has passed. If
the process is terminated, the function
returns <literal>true</literal>. On timeout, a warning is emitted and
<literal>false</literal> is returned.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<function>pg_cancel_backend</function> and <function>pg_terminate_backend</function>
send signals (<systemitem>SIGINT</systemitem> or <systemitem>SIGTERM</systemitem>
respectively) to backend processes identified by process ID.
The process ID of an active backend can be found from
the <structfield>pid</structfield> column of the
<structname>pg_stat_activity</structname> view, or by listing the
<command>postgres</command> processes on the server (using
<application>ps</application> on Unix or the <application>Task
Manager</application> on <productname>Windows</productname>).
The role of an active backend can be found from the
<structfield>usename</structfield> column of the
<structname>pg_stat_activity</structname> view.
</para>
<para>
<function>pg_log_backend_memory_contexts</function> can be used
to log the memory contexts of a backend process. For example:
<programlisting>
postgres=# SELECT pg_log_backend_memory_contexts(pg_backend_pid());
pg_log_backend_memory_contexts
--------------------------------
t
(1 row)
</programlisting>
One message for each memory context will be logged. For example:
<screen>
LOG: logging memory contexts of PID 10377
STATEMENT: SELECT pg_log_backend_memory_contexts(pg_backend_pid());
LOG: level: 1; TopMemoryContext: 80800 total in 6 blocks; 14432 free (5 chunks); 66368 used
LOG: level: 2; pgstat TabStatusArray lookup hash table: 8192 total in 1 blocks; 1408 free (0 chunks); 6784 used
LOG: level: 2; TopTransactionContext: 8192 total in 1 blocks; 7720 free (1 chunks); 472 used
LOG: level: 2; RowDescriptionContext: 8192 total in 1 blocks; 6880 free (0 chunks); 1312 used
LOG: level: 2; MessageContext: 16384 total in 2 blocks; 5152 free (0 chunks); 11232 used
LOG: level: 2; Operator class cache: 8192 total in 1 blocks; 512 free (0 chunks); 7680 used
LOG: level: 2; smgr relation table: 16384 total in 2 blocks; 4544 free (3 chunks); 11840 used
LOG: level: 2; TransactionAbortContext: 32768 total in 1 blocks; 32504 free (0 chunks); 264 used
...
LOG: level: 2; ErrorContext: 8192 total in 1 blocks; 7928 free (3 chunks); 264 used
LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560 used
</screen>
If there are more than 100 child contexts under the same parent, the first
100 child contexts are logged, along with a summary of the remaining contexts.
Note that frequent calls to this function could incur significant overhead,
because it may generate a large number of log messages.
</para>
</sect2>
<sect2 id="functions-admin-backup">
<title>Backup Control Functions</title>
<indexterm>
<primary>backup</primary>
</indexterm>
<para>
The functions shown in <xref
linkend="functions-admin-backup-table"/> assist in making on-line backups.
These functions cannot be executed during recovery (except
<function>pg_backup_start</function>,
<function>pg_backup_stop</function>,
and <function>pg_wal_lsn_diff</function>).
</para>
<para>
For details about proper usage of these functions, see
<xref linkend="continuous-archiving"/>.
</para>
<table id="functions-admin-backup-table">
<title>Backup Control Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_create_restore_point</primary>
</indexterm>
<function>pg_create_restore_point</function> ( <parameter>name</parameter> <type>text</type> )
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Creates a named marker record in the write-ahead log that can later be
used as a recovery target, and returns the corresponding write-ahead
log location. The given name can then be used with
<xref linkend="guc-recovery-target-name"/> to specify the point up to
which recovery will proceed. Avoid creating multiple restore points
with the same name, since recovery will stop at the first one whose
name matches the recovery target.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_current_wal_flush_lsn</primary>
</indexterm>
<function>pg_current_wal_flush_lsn</function> ()
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Returns the current write-ahead log flush location (see notes below).
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_current_wal_insert_lsn</primary>
</indexterm>
<function>pg_current_wal_insert_lsn</function> ()
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Returns the current write-ahead log insert location (see notes below).
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_current_wal_lsn</primary>
</indexterm>
<function>pg_current_wal_lsn</function> ()
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Returns the current write-ahead log write location (see notes below).
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_backup_start</primary>
</indexterm>
<function>pg_backup_start</function> (
<parameter>label</parameter> <type>text</type>
<optional>, <parameter>fast</parameter> <type>boolean</type>
</optional> )
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Prepares the server to begin an on-line backup. The only required
parameter is an arbitrary user-defined label for the backup.
(Typically this would be the name under which the backup dump file
will be stored.)
If the optional second parameter is given as <literal>true</literal>,
it specifies executing <function>pg_backup_start</function> as quickly
as possible. This forces a fast checkpoint which will cause a
spike in I/O operations, slowing any concurrently executing queries.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_backup_stop</primary>
</indexterm>
<function>pg_backup_stop</function> (
<optional><parameter>wait_for_archive</parameter> <type>boolean</type>
</optional> )
<returnvalue>record</returnvalue>
( <parameter>lsn</parameter> <type>pg_lsn</type>,
<parameter>labelfile</parameter> <type>text</type>,
<parameter>spcmapfile</parameter> <type>text</type> )
</para>
<para>
Finishes performing an on-line backup. The desired contents of the
backup label file and the tablespace map file are returned as part of
the result of the function and must be written to files in the
backup area. These files must not be written to the live data directory
(doing so will cause PostgreSQL to fail to restart in the event of a
crash).
</para>
<para>
There is an optional parameter of type <type>boolean</type>.
If false, the function will return immediately after the backup is
completed, without waiting for WAL to be archived. This behavior is
only useful with backup software that independently monitors WAL
archiving. Otherwise, WAL required to make the backup consistent might
be missing and make the backup useless. By default or when this
parameter is true, <function>pg_backup_stop</function> will wait for
WAL to be archived when archiving is enabled. (On a standby, this
means that it will wait only when <varname>archive_mode</varname> =
<literal>always</literal>. If write activity on the primary is low,
it may be useful to run <function>pg_switch_wal</function> on the
primary in order to trigger an immediate segment switch.)
</para>
<para>
When executed on a primary, this function also creates a backup
history file in the write-ahead log archive area. The history file
includes the label given to <function>pg_backup_start</function>, the
starting and ending write-ahead log locations for the backup, and the
starting and ending times of the backup. After recording the ending
location, the current write-ahead log insertion point is automatically
advanced to the next write-ahead log file, so that the ending
write-ahead log file can be archived immediately to complete the
backup.
</para>
<para>
The result of the function is a single record.
The <parameter>lsn</parameter> column holds the backup's ending
write-ahead log location (which again can be ignored). The second
column returns the contents of the backup label file, and the third
column returns the contents of the tablespace map file. These must be
stored as part of the backup and are required as part of the restore
process.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_switch_wal</primary>
</indexterm>
<function>pg_switch_wal</function> ()
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Forces the server to switch to a new write-ahead log file, which
allows the current file to be archived (assuming you are using
continuous archiving). The result is the ending write-ahead log
location plus 1 within the just-completed write-ahead log file. If
there has been no write-ahead log activity since the last write-ahead
log switch, <function>pg_switch_wal</function> does nothing and
returns the start location of the write-ahead log file currently in
use.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_walfile_name</primary>
</indexterm>
<function>pg_walfile_name</function> ( <parameter>lsn</parameter> <type>pg_lsn</type> )
<returnvalue>text</returnvalue>
</para>
<para>
Converts a write-ahead log location to the name of the WAL file
holding that location.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_walfile_name_offset</primary>
</indexterm>
<function>pg_walfile_name_offset</function> ( <parameter>lsn</parameter> <type>pg_lsn</type> )
<returnvalue>record</returnvalue>
( <parameter>file_name</parameter> <type>text</type>,
<parameter>file_offset</parameter> <type>integer</type> )
</para>
<para>
Converts a write-ahead log location to a WAL file name and byte offset
within that file.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_split_walfile_name</primary>
</indexterm>
<function>pg_split_walfile_name</function> ( <parameter>file_name</parameter> <type>text</type> )
<returnvalue>record</returnvalue>
( <parameter>segment_number</parameter> <type>numeric</type>,
<parameter>timeline_id</parameter> <type>bigint</type> )
</para>
<para>
Extracts the sequence number and timeline ID from a WAL file
name.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_wal_lsn_diff</primary>
</indexterm>
<function>pg_wal_lsn_diff</function> ( <parameter>lsn1</parameter> <type>pg_lsn</type>, <parameter>lsn2</parameter> <type>pg_lsn</type> )
<returnvalue>numeric</returnvalue>
</para>
<para>
Calculates the difference in bytes (<parameter>lsn1</parameter> - <parameter>lsn2</parameter>) between two write-ahead log
locations. This can be used
with <structname>pg_stat_replication</structname> or some of the
functions shown in <xref linkend="functions-admin-backup-table"/> to
get the replication lag.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<function>pg_current_wal_lsn</function> displays the current write-ahead
log write location in the same format used by the above functions.
Similarly, <function>pg_current_wal_insert_lsn</function> displays the
current write-ahead log insertion location
and <function>pg_current_wal_flush_lsn</function> displays the current
write-ahead log flush location. The insertion location is
the <quote>logical</quote> end of the write-ahead log at any instant,
while the write location is the end of what has actually been written out
from the server's internal buffers, and the flush location is the last
location known to be written to durable storage. The write location is the
end of what can be examined from outside the server, and is usually what
you want if you are interested in archiving partially-complete write-ahead
log files. The insertion and flush locations are made available primarily
for server debugging purposes. These are all read-only operations and do
not require superuser permissions.
</para>
<para>
You can use <function>pg_walfile_name_offset</function> to extract the
corresponding write-ahead log file name and byte offset from
a <type>pg_lsn</type> value. For example:
<programlisting>
postgres=# SELECT * FROM pg_walfile_name_offset((pg_backup_stop()).lsn);
file_name | file_offset
--------------------------+-------------
00000001000000000000000D | 4039624
(1 row)
</programlisting>
Similarly, <function>pg_walfile_name</function> extracts just the write-ahead log file name.
</para>
<para>
<function>pg_split_walfile_name</function> is useful to compute a
<acronym>LSN</acronym> from a file offset and WAL file name, for example:
<programlisting>
postgres=# \set file_name '000000010000000100C000AB'
postgres=# \set offset 256
postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset AS lsn
FROM pg_split_walfile_name(:'file_name') pd,
pg_show_all_settings() ps
WHERE ps.name = 'wal_segment_size';
lsn
---------------
C001/AB000100
(1 row)
</programlisting>
</para>
</sect2>
<sect2 id="functions-recovery-control">
<title>Recovery Control Functions</title>
<para>
The functions shown in <xref
linkend="functions-recovery-info-table"/> provide information
about the current status of a standby server.
These functions may be executed both during recovery and in normal running.
</para>
<table id="functions-recovery-info-table">
<title>Recovery Information Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_is_in_recovery</primary>
</indexterm>
<function>pg_is_in_recovery</function> ()
<returnvalue>boolean</returnvalue>
</para>
<para>
Returns true if recovery is still in progress.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_last_wal_receive_lsn</primary>
</indexterm>
<function>pg_last_wal_receive_lsn</function> ()
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Returns the last write-ahead log location that has been received and
synced to disk by streaming replication. While streaming replication
is in progress this will increase monotonically. If recovery has
completed then this will remain static at the location of the last WAL
record received and synced to disk during recovery. If streaming
replication is disabled, or if it has not yet started, the function
returns <literal>NULL</literal>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_last_wal_replay_lsn</primary>
</indexterm>
<function>pg_last_wal_replay_lsn</function> ()
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Returns the last write-ahead log location that has been replayed
during recovery. If recovery is still in progress this will increase
monotonically. If recovery has completed then this will remain
static at the location of the last WAL record applied during recovery.
When the server has been started normally without recovery, the
function returns <literal>NULL</literal>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_last_xact_replay_timestamp</primary>
</indexterm>
<function>pg_last_xact_replay_timestamp</function> ()
<returnvalue>timestamp with time zone</returnvalue>
</para>
<para>
Returns the time stamp of the last transaction replayed during
recovery. This is the time at which the commit or abort WAL record
for that transaction was generated on the primary. If no transactions
have been replayed during recovery, the function
returns <literal>NULL</literal>. Otherwise, if recovery is still in
progress this will increase monotonically. If recovery has completed
then this will remain static at the time of the last transaction
applied during recovery. When the server has been started normally
without recovery, the function returns <literal>NULL</literal>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_get_wal_resource_managers</primary>
</indexterm>
<function>pg_get_wal_resource_managers</function> ()
<returnvalue>setof record</returnvalue>
( <parameter>rm_id</parameter> <type>integer</type>,
<parameter>rm_name</parameter> <type>text</type>,
<parameter>rm_builtin</parameter> <type>boolean</type> )
</para>
<para>
Returns the currently-loaded WAL resource managers in the system. The
column <parameter>rm_builtin</parameter> indicates whether it's a
built-in resource manager, or a custom resource manager loaded by an
extension.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
The functions shown in <xref
linkend="functions-recovery-control-table"/> control the progress of recovery.
These functions may be executed only during recovery.
</para>
<table id="functions-recovery-control-table">
<title>Recovery Control Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_is_wal_replay_paused</primary>
</indexterm>
<function>pg_is_wal_replay_paused</function> ()
<returnvalue>boolean</returnvalue>
</para>
<para>
Returns true if recovery pause is requested.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_get_wal_replay_pause_state</primary>
</indexterm>
<function>pg_get_wal_replay_pause_state</function> ()
<returnvalue>text</returnvalue>
</para>
<para>
Returns recovery pause state. The return values are <literal>
not paused</literal> if pause is not requested, <literal>
pause requested</literal> if pause is requested but recovery is
not yet paused, and <literal>paused</literal> if the recovery is
actually paused.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_promote</primary>
</indexterm>
<function>pg_promote</function> ( <parameter>wait</parameter> <type>boolean</type> <literal>DEFAULT</literal> <literal>true</literal>, <parameter>wait_seconds</parameter> <type>integer</type> <literal>DEFAULT</literal> <literal>60</literal> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Promotes a standby server to primary status.
With <parameter>wait</parameter> set to <literal>true</literal> (the
default), the function waits until promotion is completed
or <parameter>wait_seconds</parameter> seconds have passed, and
returns <literal>true</literal> if promotion is successful
and <literal>false</literal> otherwise.
If <parameter>wait</parameter> is set to <literal>false</literal>, the
function returns <literal>true</literal> immediately after sending a
<literal>SIGUSR1</literal> signal to the postmaster to trigger
promotion.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_wal_replay_pause</primary>
</indexterm>
<function>pg_wal_replay_pause</function> ()
<returnvalue>void</returnvalue>
</para>
<para>
Request to pause recovery. A request doesn't mean that recovery stops
right away. If you want a guarantee that recovery is actually paused,
you need to check for the recovery pause state returned by
<function>pg_get_wal_replay_pause_state()</function>. Note that
<function>pg_is_wal_replay_paused()</function> returns whether a request
is made. While recovery is paused, no further database changes are applied.
If hot standby is active, all new queries will see the same consistent
snapshot of the database, and no further query conflicts will be generated
until recovery is resumed.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_wal_replay_resume</primary>
</indexterm>
<function>pg_wal_replay_resume</function> ()
<returnvalue>void</returnvalue>
</para>
<para>
Restarts recovery if it was paused.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<function>pg_wal_replay_pause</function> and
<function>pg_wal_replay_resume</function> cannot be executed while
a promotion is ongoing. If a promotion is triggered while recovery
is paused, the paused state ends and promotion continues.
</para>
<para>
If streaming replication is disabled, the paused state may continue
indefinitely without a problem. If streaming replication is in
progress then WAL records will continue to be received, which will
eventually fill available disk space, depending upon the duration of
the pause, the rate of WAL generation and available disk space.
</para>
</sect2>
<sect2 id="functions-snapshot-synchronization">
<title>Snapshot Synchronization Functions</title>
<para>
<productname>PostgreSQL</productname> allows database sessions to synchronize their
snapshots. A <firstterm>snapshot</firstterm> determines which data is visible to the
transaction that is using the snapshot. Synchronized snapshots are
necessary when two or more sessions need to see identical content in the
database. If two sessions just start their transactions independently,
there is always a possibility that some third transaction commits
between the executions of the two <command>START TRANSACTION</command> commands,
so that one session sees the effects of that transaction and the other
does not.
</para>
<para>
To solve this problem, <productname>PostgreSQL</productname> allows a transaction to
<firstterm>export</firstterm> the snapshot it is using. As long as the exporting
transaction remains open, other transactions can <firstterm>import</firstterm> its
snapshot, and thereby be guaranteed that they see exactly the same view
of the database that the first transaction sees. But note that any
database changes made by any one of these transactions remain invisible
to the other transactions, as is usual for changes made by uncommitted
transactions. So the transactions are synchronized with respect to
pre-existing data, but act normally for changes they make themselves.
</para>
<para>
Snapshots are exported with the <function>pg_export_snapshot</function> function,
shown in <xref linkend="functions-snapshot-synchronization-table"/>, and
imported with the <xref linkend="sql-set-transaction"/> command.
</para>
<table id="functions-snapshot-synchronization-table">
<title>Snapshot Synchronization Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_export_snapshot</primary>
</indexterm>
<function>pg_export_snapshot</function> ()
<returnvalue>text</returnvalue>
</para>
<para>
Saves the transaction's current snapshot and returns
a <type>text</type> string identifying the snapshot. This string must
be passed (outside the database) to clients that want to import the
snapshot. The snapshot is available for import only until the end of
the transaction that exported it.
</para>
<para>
A transaction can export more than one snapshot, if needed. Note that
doing so is only useful in <literal>READ COMMITTED</literal>
transactions, since in <literal>REPEATABLE READ</literal> and higher
isolation levels, transactions use the same snapshot throughout their
lifetime. Once a transaction has exported any snapshots, it cannot be
prepared with <xref linkend="sql-prepare-transaction"/>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_log_standby_snapshot</primary>
</indexterm>
<function>pg_log_standby_snapshot</function> ()
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Take a snapshot of running transactions and write it to WAL, without
having to wait for bgwriter or checkpointer to log one. This is useful
for logical decoding on standby, as logical slot creation has to wait
until such a record is replayed on the standby.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
<sect2 id="functions-replication">
<title>Replication Management Functions</title>
<para>
The functions shown
in <xref linkend="functions-replication-table"/> are for
controlling and interacting with replication features.
See <xref linkend="streaming-replication"/>,
<xref linkend="streaming-replication-slots"/>, and
<xref linkend="replication-origins"/>
for information about the underlying features.
Use of functions for replication origin is only allowed to the
superuser by default, but may be allowed to other users by using the
<literal>GRANT</literal> command.
Use of functions for replication slots is restricted to superusers
and users having <literal>REPLICATION</literal> privilege.
</para>
<para>
Many of these functions have equivalent commands in the replication
protocol; see <xref linkend="protocol-replication"/>.
</para>
<para>
The functions described in
<xref linkend="functions-admin-backup"/>,
<xref linkend="functions-recovery-control"/>, and
<xref linkend="functions-snapshot-synchronization"/>
are also relevant for replication.
</para>
<table id="functions-replication-table">
<title>Replication Management Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_create_physical_replication_slot</primary>
</indexterm>
<function>pg_create_physical_replication_slot</function> ( <parameter>slot_name</parameter> <type>name</type> <optional>, <parameter>immediately_reserve</parameter> <type>boolean</type>, <parameter>temporary</parameter> <type>boolean</type> </optional> )
<returnvalue>record</returnvalue>
( <parameter>slot_name</parameter> <type>name</type>,
<parameter>lsn</parameter> <type>pg_lsn</type> )
</para>
<para>
Creates a new physical replication slot named
<parameter>slot_name</parameter>. The name cannot be
<literal>pg_conflict_detection</literal> as it is reserved for the
conflict detection slot. The optional second parameter,
when <literal>true</literal>, specifies that the <acronym>LSN</acronym> for this
replication slot be reserved immediately; otherwise
the <acronym>LSN</acronym> is reserved on first connection from a streaming
replication client. Streaming changes from a physical slot is only
possible with the streaming-replication protocol —
see <xref linkend="protocol-replication"/>. The optional third
parameter, <parameter>temporary</parameter>, when set to true, specifies that
the slot should not be permanently stored to disk and is only meant
for use by the current session. Temporary slots are also
released upon any error. This function corresponds
to the replication protocol command <literal>CREATE_REPLICATION_SLOT
... PHYSICAL</literal>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_drop_replication_slot</primary>
</indexterm>
<function>pg_drop_replication_slot</function> ( <parameter>slot_name</parameter> <type>name</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Drops the physical or logical replication slot
named <parameter>slot_name</parameter>. Same as replication protocol
command <literal>DROP_REPLICATION_SLOT</literal>.
</para></entry>
</row>
<row>
<entry id="pg-create-logical-replication-slot" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_create_logical_replication_slot</primary>
</indexterm>
<function>pg_create_logical_replication_slot</function> ( <parameter>slot_name</parameter> <type>name</type>, <parameter>plugin</parameter> <type>name</type> <optional>, <parameter>temporary</parameter> <type>boolean</type>, <parameter>twophase</parameter> <type>boolean</type>, <parameter>failover</parameter> <type>boolean</type> </optional> )
<returnvalue>record</returnvalue>
( <parameter>slot_name</parameter> <type>name</type>,
<parameter>lsn</parameter> <type>pg_lsn</type> )
</para>
<para>
Creates a new logical (decoding) replication slot named
<parameter>slot_name</parameter> using the output plugin
<parameter>plugin</parameter>. The name cannot be
<literal>pg_conflict_detection</literal> as it is reserved for
the conflict detection slot. The optional third
parameter, <parameter>temporary</parameter>, when set to true, specifies that
the slot should not be permanently stored to disk and is only meant
for use by the current session. Temporary slots are also
released upon any error. The optional fourth parameter,
<parameter>twophase</parameter>, when set to true, specifies
that the decoding of prepared transactions is enabled for this
slot. The optional fifth parameter,
<parameter>failover</parameter>, when set to true,
specifies that this slot is enabled to be synced to the
standbys so that logical replication can be resumed after
failover. A call to this function has the same effect as
the replication protocol command
<literal>CREATE_REPLICATION_SLOT ... LOGICAL</literal>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_copy_physical_replication_slot</primary>
</indexterm>
<function>pg_copy_physical_replication_slot</function> ( <parameter>src_slot_name</parameter> <type>name</type>, <parameter>dst_slot_name</parameter> <type>name</type> <optional>, <parameter>temporary</parameter> <type>boolean</type> </optional> )
<returnvalue>record</returnvalue>
( <parameter>slot_name</parameter> <type>name</type>,
<parameter>lsn</parameter> <type>pg_lsn</type> )
</para>
<para>
Copies an existing physical replication slot named <parameter>src_slot_name</parameter>
to a physical replication slot named <parameter>dst_slot_name</parameter>.
The new slot name cannot be <literal>pg_conflict_detection</literal>,
as it is reserved for the conflict detection.
The copied physical slot starts to reserve WAL from the same <acronym>LSN</acronym> as the
source slot.
<parameter>temporary</parameter> is optional. If <parameter>temporary</parameter>
is omitted, the same value as the source slot is used. Copy of an
invalidated slot is not allowed.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_copy_logical_replication_slot</primary>
</indexterm>
<function>pg_copy_logical_replication_slot</function> ( <parameter>src_slot_name</parameter> <type>name</type>, <parameter>dst_slot_name</parameter> <type>name</type> <optional>, <parameter>temporary</parameter> <type>boolean</type> <optional>, <parameter>plugin</parameter> <type>name</type> </optional></optional> )
<returnvalue>record</returnvalue>
( <parameter>slot_name</parameter> <type>name</type>,
<parameter>lsn</parameter> <type>pg_lsn</type> )
</para>
<para>
Copies an existing logical replication slot
named <parameter>src_slot_name</parameter> to a logical replication
slot named <parameter>dst_slot_name</parameter>, optionally changing
the output plugin and persistence. The new slot name cannot be
<literal>pg_conflict_detection</literal> as it is reserved for
the conflict detection. The copied logical slot starts from the same
<acronym>LSN</acronym> as the source logical slot. Both
<parameter>temporary</parameter> and <parameter>plugin</parameter> are
optional; if they are omitted, the values of the source slot are used.
The <literal>failover</literal> option of the source logical slot
is not copied and is set to <literal>false</literal> by default. This
is to avoid the risk of being unable to continue logical replication
after failover to standby where the slot is being synchronized. Copy of
an invalidated slot is not allowed.
</para></entry>
</row>
<row>
<entry id="pg-logical-slot-get-changes" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_logical_slot_get_changes</primary>
</indexterm>
<function>pg_logical_slot_get_changes</function> ( <parameter>slot_name</parameter> <type>name</type>, <parameter>upto_lsn</parameter> <type>pg_lsn</type>, <parameter>upto_nchanges</parameter> <type>integer</type>, <literal>VARIADIC</literal> <parameter>options</parameter> <type>text[]</type> )
<returnvalue>setof record</returnvalue>
( <parameter>lsn</parameter> <type>pg_lsn</type>,
<parameter>xid</parameter> <type>xid</type>,
<parameter>data</parameter> <type>text</type> )
</para>
<para>
Returns changes in the slot <parameter>slot_name</parameter>, starting
from the point from which changes have been consumed last. If
<parameter>upto_lsn</parameter>
and <parameter>upto_nchanges</parameter> are NULL,
logical decoding will continue until end of WAL. If
<parameter>upto_lsn</parameter> is non-NULL, decoding will include only
those transactions which commit prior to the specified LSN. If
<parameter>upto_nchanges</parameter> is non-NULL, decoding will
stop when the number of rows produced by decoding exceeds
the specified value. Note, however, that the actual number of
rows returned may be larger, since this limit is only checked after
adding the rows produced when decoding each new transaction commit.
If the specified slot is a logical failover slot then the function will
not return until all physical slots specified in
<link linkend="guc-synchronized-standby-slots"><varname>synchronized_standby_slots</varname></link>
have confirmed WAL receipt.
</para></entry>
</row>
<row>
<entry id="pg-logical-slot-peek-changes" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_logical_slot_peek_changes</primary>
</indexterm>
<function>pg_logical_slot_peek_changes</function> ( <parameter>slot_name</parameter> <type>name</type>, <parameter>upto_lsn</parameter> <type>pg_lsn</type>, <parameter>upto_nchanges</parameter> <type>integer</type>, <literal>VARIADIC</literal> <parameter>options</parameter> <type>text[]</type> )
<returnvalue>setof record</returnvalue>
( <parameter>lsn</parameter> <type>pg_lsn</type>,
<parameter>xid</parameter> <type>xid</type>,
<parameter>data</parameter> <type>text</type> )
</para>
<para>
Behaves just like
the <function>pg_logical_slot_get_changes()</function> function,
except that changes are not consumed; that is, they will be returned
again on future calls.
</para></entry>
</row>
<row>
<entry id="pg-logical-slot-get-binary-changes" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_logical_slot_get_binary_changes</primary>
</indexterm>
<function>pg_logical_slot_get_binary_changes</function> ( <parameter>slot_name</parameter> <type>name</type>, <parameter>upto_lsn</parameter> <type>pg_lsn</type>, <parameter>upto_nchanges</parameter> <type>integer</type>, <literal>VARIADIC</literal> <parameter>options</parameter> <type>text[]</type> )
<returnvalue>setof record</returnvalue>
( <parameter>lsn</parameter> <type>pg_lsn</type>,
<parameter>xid</parameter> <type>xid</type>,
<parameter>data</parameter> <type>bytea</type> )
</para>
<para>
Behaves just like
the <function>pg_logical_slot_get_changes()</function> function,
except that changes are returned as <type>bytea</type>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_logical_slot_peek_binary_changes</primary>
</indexterm>
<function>pg_logical_slot_peek_binary_changes</function> ( <parameter>slot_name</parameter> <type>name</type>, <parameter>upto_lsn</parameter> <type>pg_lsn</type>, <parameter>upto_nchanges</parameter> <type>integer</type>, <literal>VARIADIC</literal> <parameter>options</parameter> <type>text[]</type> )
<returnvalue>setof record</returnvalue>
( <parameter>lsn</parameter> <type>pg_lsn</type>,
<parameter>xid</parameter> <type>xid</type>,
<parameter>data</parameter> <type>bytea</type> )
</para>
<para>
Behaves just like
the <function>pg_logical_slot_peek_changes()</function> function,
except that changes are returned as <type>bytea</type>.
</para></entry>
</row>
<row>
<entry id="pg-replication-slot-advance" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_slot_advance</primary>
</indexterm>
<function>pg_replication_slot_advance</function> ( <parameter>slot_name</parameter> <type>name</type>, <parameter>upto_lsn</parameter> <type>pg_lsn</type> )
<returnvalue>record</returnvalue>
( <parameter>slot_name</parameter> <type>name</type>,
<parameter>end_lsn</parameter> <type>pg_lsn</type> )
</para>
<para>
Advances the current confirmed position of a replication slot named
<parameter>slot_name</parameter>. The slot will not be moved backwards,
and it will not be moved beyond the current insert location. Returns
the name of the slot and the actual position that it was advanced to.
The updated slot position information is written out at the next
checkpoint if any advancing is done. So in the event of a crash, the
slot may return to an earlier position. If the specified slot is a
logical failover slot then the function will not return until all
physical slots specified in
<link linkend="guc-synchronized-standby-slots"><varname>synchronized_standby_slots</varname></link>
have confirmed WAL receipt.
</para></entry>
</row>
<row>
<entry id="pg-replication-origin-create" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_create</primary>
</indexterm>
<function>pg_replication_origin_create</function> ( <parameter>node_name</parameter> <type>text</type> )
<returnvalue>oid</returnvalue>
</para>
<para>
Creates a replication origin with the given external
name, and returns the internal ID assigned to it.
The name must be no longer than 512 bytes.
</para></entry>
</row>
<row>
<entry id="pg-replication-origin-drop" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_drop</primary>
</indexterm>
<function>pg_replication_origin_drop</function> ( <parameter>node_name</parameter> <type>text</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Deletes a previously-created replication origin, including any
associated replay progress.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_oid</primary>
</indexterm>
<function>pg_replication_origin_oid</function> ( <parameter>node_name</parameter> <type>text</type> )
<returnvalue>oid</returnvalue>
</para>
<para>
Looks up a replication origin by name and returns the internal ID. If
no such replication origin is found, <literal>NULL</literal> is
returned.
</para></entry>
</row>
<row>
<entry id="pg-replication-origin-session-setup" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_session_setup</primary>
</indexterm>
<function>pg_replication_origin_session_setup</function> ( <parameter>node_name</parameter> <type>text</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Marks the current session as replaying from the given
origin, allowing replay progress to be tracked.
Can only be used if no origin is currently selected.
Use <function>pg_replication_origin_session_reset</function> to undo.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_session_reset</primary>
</indexterm>
<function>pg_replication_origin_session_reset</function> ()
<returnvalue>void</returnvalue>
</para>
<para>
Cancels the effects
of <function>pg_replication_origin_session_setup()</function>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_session_is_setup</primary>
</indexterm>
<function>pg_replication_origin_session_is_setup</function> ()
<returnvalue>boolean</returnvalue>
</para>
<para>
Returns true if a replication origin has been selected in the
current session.
</para></entry>
</row>
<row>
<entry id="pg-replication-origin-session-progress" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_session_progress</primary>
</indexterm>
<function>pg_replication_origin_session_progress</function> ( <parameter>flush</parameter> <type>boolean</type> )
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Returns the replay location for the replication origin selected in
the current session. The parameter <parameter>flush</parameter>
determines whether the corresponding local transaction will be
guaranteed to have been flushed to disk or not.
</para></entry>
</row>
<row>
<entry id="pg-replication-origin-xact-setup" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_xact_setup</primary>
</indexterm>
<function>pg_replication_origin_xact_setup</function> ( <parameter>origin_lsn</parameter> <type>pg_lsn</type>, <parameter>origin_timestamp</parameter> <type>timestamp with time zone</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Marks the current transaction as replaying a transaction that has
committed at the given <acronym>LSN</acronym> and timestamp. Can
only be called when a replication origin has been selected
using <function>pg_replication_origin_session_setup</function>.
</para></entry>
</row>
<row>
<entry id="pg-replication-origin-xact-reset" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_xact_reset</primary>
</indexterm>
<function>pg_replication_origin_xact_reset</function> ()
<returnvalue>void</returnvalue>
</para>
<para>
Cancels the effects of
<function>pg_replication_origin_xact_setup()</function>.
</para></entry>
</row>
<row>
<entry id="pg-replication-origin-advance" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_advance</primary>
</indexterm>
<function>pg_replication_origin_advance</function> ( <parameter>node_name</parameter> <type>text</type>, <parameter>lsn</parameter> <type>pg_lsn</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Sets replication progress for the given node to the given
location. This is primarily useful for setting up the initial
location, or setting a new location after configuration changes and
similar. Be aware that careless use of this function can lead to
inconsistently replicated data.
</para></entry>
</row>
<row>
<entry id="pg-replication-origin-progress" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_replication_origin_progress</primary>
</indexterm>
<function>pg_replication_origin_progress</function> ( <parameter>node_name</parameter> <type>text</type>, <parameter>flush</parameter> <type>boolean</type> )
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Returns the replay location for the given replication origin. The
parameter <parameter>flush</parameter> determines whether the
corresponding local transaction will be guaranteed to have been
flushed to disk or not.
</para></entry>
</row>
<row>
<entry id="pg-logical-emit-message" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_logical_emit_message</primary>
</indexterm>
<function>pg_logical_emit_message</function> ( <parameter>transactional</parameter> <type>boolean</type>, <parameter>prefix</parameter> <type>text</type>, <parameter>content</parameter> <type>text</type> <optional>, <parameter>flush</parameter> <type>boolean</type> <literal>DEFAULT</literal> <literal>false</literal></optional> )
<returnvalue>pg_lsn</returnvalue>
</para>
<para role="func_signature">
<function>pg_logical_emit_message</function> ( <parameter>transactional</parameter> <type>boolean</type>, <parameter>prefix</parameter> <type>text</type>, <parameter>content</parameter> <type>bytea</type> <optional>, <parameter>flush</parameter> <type>boolean</type> <literal>DEFAULT</literal> <literal>false</literal></optional> )
<returnvalue>pg_lsn</returnvalue>
</para>
<para>
Emits a logical decoding message. This can be used to pass generic
messages to logical decoding plugins through
WAL. The <parameter>transactional</parameter> parameter specifies if
the message should be part of the current transaction, or if it should
be written immediately and decoded as soon as the logical decoder
reads the record. The <parameter>prefix</parameter> parameter is a
textual prefix that can be used by logical decoding plugins to easily
recognize messages that are interesting for them.
The <parameter>content</parameter> parameter is the content of the
message, given either in text or binary form.
The <parameter>flush</parameter> parameter (default set to
<literal>false</literal>) controls if the message is immediately
flushed to WAL or not. <parameter>flush</parameter> has no effect
with <parameter>transactional</parameter>, as the message's WAL
record is flushed along with its transaction.
</para></entry>
</row>
<row>
<entry id="pg-sync-replication-slots" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_sync_replication_slots</primary>
</indexterm>
<function>pg_sync_replication_slots</function> ()
<returnvalue>void</returnvalue>
</para>
<para>
Synchronize the logical failover replication slots from the primary
server to the standby server. This function can only be executed on the
standby server. Temporary synced slots, if any, cannot be used for
logical decoding and must be dropped after promotion. See
<xref linkend="logicaldecoding-replication-slots-synchronization"/> for details.
Note that this function is primarily intended for testing and
debugging purposes and should be used with caution. Additionally,
this function cannot be executed if
<link linkend="guc-sync-replication-slots"><varname>
sync_replication_slots</varname></link> is enabled and the slotsync
worker is already running to perform the synchronization of slots.
</para>
<caution>
<para>
If, after executing the function,
<link linkend="guc-hot-standby-feedback">
<varname>hot_standby_feedback</varname></link> is disabled on
the standby or the physical slot configured in
<link linkend="guc-primary-slot-name">
<varname>primary_slot_name</varname></link> is
removed, then it is possible that the necessary rows of the
synchronized slot will be removed by the VACUUM process on the primary
server, resulting in the synchronized slot becoming invalidated.
</para>
</caution>
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
<sect2 id="functions-admin-dbobject">
<title>Database Object Management Functions</title>
<para>
The functions shown in <xref linkend="functions-admin-dbsize"/> calculate
the disk space usage of database objects, or assist in presentation
or understanding of usage results. <literal>bigint</literal> results
are measured in bytes. If an OID that does
not represent an existing object is passed to one of these
functions, <literal>NULL</literal> is returned.
</para>
<table id="functions-admin-dbsize">
<title>Database Object Size Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_column_size</primary>
</indexterm>
<function>pg_column_size</function> ( <type>"any"</type> )
<returnvalue>integer</returnvalue>
</para>
<para>
Shows the number of bytes used to store any individual data value. If
applied directly to a table column value, this reflects any
compression that was done.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_column_compression</primary>
</indexterm>
<function>pg_column_compression</function> ( <type>"any"</type> )
<returnvalue>text</returnvalue>
</para>
<para>
Shows the compression algorithm that was used to compress
an individual variable-length value. Returns <literal>NULL</literal>
if the value is not compressed.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_column_toast_chunk_id</primary>
</indexterm>
<function>pg_column_toast_chunk_id</function> ( <type>"any"</type> )
<returnvalue>oid</returnvalue>
</para>
<para>
Shows the <structfield>chunk_id</structfield> of an on-disk
<acronym>TOAST</acronym>ed value. Returns <literal>NULL</literal>
if the value is un-<acronym>TOAST</acronym>ed or not on-disk. See
<xref linkend="storage-toast"/> for more information about
<acronym>TOAST</acronym>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_database_size</primary>
</indexterm>
<function>pg_database_size</function> ( <type>name</type> )
<returnvalue>bigint</returnvalue>
</para>
<para role="func_signature">
<function>pg_database_size</function> ( <type>oid</type> )
<returnvalue>bigint</returnvalue>
</para>
<para>
Computes the total disk space used by the database with the specified
name or OID. To use this function, you must
have <literal>CONNECT</literal> privilege on the specified database
(which is granted by default) or have privileges of
the <literal>pg_read_all_stats</literal> role.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_indexes_size</primary>
</indexterm>
<function>pg_indexes_size</function> ( <type>regclass</type> )
<returnvalue>bigint</returnvalue>
</para>
<para>
Computes the total disk space used by indexes attached to the
specified table.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_relation_size</primary>
</indexterm>
<function>pg_relation_size</function> ( <parameter>relation</parameter> <type>regclass</type> <optional>, <parameter>fork</parameter> <type>text</type> </optional> )
<returnvalue>bigint</returnvalue>
</para>
<para>
Computes the disk space used by one <quote>fork</quote> of the
specified relation. (Note that for most purposes it is more
convenient to use the higher-level
functions <function>pg_total_relation_size</function>
or <function>pg_table_size</function>, which sum the sizes of all
forks.) With one argument, this returns the size of the main data
fork of the relation. The second argument can be provided to specify
which fork to examine:
<itemizedlist spacing="compact">
<listitem>
<para>
<literal>main</literal> returns the size of the main
data fork of the relation.
</para>
</listitem>
<listitem>
<para>
<literal>fsm</literal> returns the size of the Free Space Map
(see <xref linkend="storage-fsm"/>) associated with the relation.
</para>
</listitem>
<listitem>
<para>
<literal>vm</literal> returns the size of the Visibility Map
(see <xref linkend="storage-vm"/>) associated with the relation.
</para>
</listitem>
<listitem>
<para>
<literal>init</literal> returns the size of the initialization
fork, if any, associated with the relation.
</para>
</listitem>
</itemizedlist>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_size_bytes</primary>
</indexterm>
<function>pg_size_bytes</function> ( <type>text</type> )
<returnvalue>bigint</returnvalue>
</para>
<para>
Converts a size in human-readable format (as returned
by <function>pg_size_pretty</function>) into bytes. Valid units are
<literal>bytes</literal>, <literal>B</literal>, <literal>kB</literal>,
<literal>MB</literal>, <literal>GB</literal>, <literal>TB</literal>,
and <literal>PB</literal>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_size_pretty</primary>
</indexterm>
<function>pg_size_pretty</function> ( <type>bigint</type> )
<returnvalue>text</returnvalue>
</para>
<para role="func_signature">
<function>pg_size_pretty</function> ( <type>numeric</type> )
<returnvalue>text</returnvalue>
</para>
<para>
Converts a size in bytes into a more easily human-readable format with
size units (bytes, kB, MB, GB, TB, or PB as appropriate). Note that the
units are powers of 2 rather than powers of 10, so 1kB is 1024 bytes,
1MB is 1024<superscript>2</superscript> = 1048576 bytes, and so on.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_table_size</primary>
</indexterm>
<function>pg_table_size</function> ( <type>regclass</type> )
<returnvalue>bigint</returnvalue>
</para>
<para>
Computes the disk space used by the specified table, excluding indexes
(but including its TOAST table if any, free space map, and visibility
map).
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_tablespace_size</primary>
</indexterm>
<function>pg_tablespace_size</function> ( <type>name</type> )
<returnvalue>bigint</returnvalue>
</para>
<para role="func_signature">
<function>pg_tablespace_size</function> ( <type>oid</type> )
<returnvalue>bigint</returnvalue>
</para>
<para>
Computes the total disk space used in the tablespace with the
specified name or OID. To use this function, you must
have <literal>CREATE</literal> privilege on the specified tablespace
or have privileges of the <literal>pg_read_all_stats</literal> role,
unless it is the default tablespace for the current database.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_total_relation_size</primary>
</indexterm>
<function>pg_total_relation_size</function> ( <type>regclass</type> )
<returnvalue>bigint</returnvalue>
</para>
<para>
Computes the total disk space used by the specified table, including
all indexes and <acronym>TOAST</acronym> data. The result is
equivalent to <function>pg_table_size</function>
<literal>+</literal> <function>pg_indexes_size</function>.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
The functions above that operate on tables or indexes accept a
<type>regclass</type> argument, which is simply the OID of the table or index
in the <structname>pg_class</structname> system catalog. You do not have to look up
the OID by hand, however, since the <type>regclass</type> data type's input
converter will do the work for you. See <xref linkend="datatype-oid"/>
for details.
</para>
<para>
The functions shown in <xref linkend="functions-admin-dblocation"/> assist
in identifying the specific disk files associated with database objects.
</para>
<table id="functions-admin-dblocation">
<title>Database Object Location Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_relation_filenode</primary>
</indexterm>
<function>pg_relation_filenode</function> ( <parameter>relation</parameter> <type>regclass</type> )
<returnvalue>oid</returnvalue>
</para>
<para>
Returns the <quote>filenode</quote> number currently assigned to the
specified relation. The filenode is the base component of the file
name(s) used for the relation (see
<xref linkend="storage-file-layout"/> for more information).
For most relations the result is the same as
<structname>pg_class</structname>.<structfield>relfilenode</structfield>,
but for certain system catalogs <structfield>relfilenode</structfield>
is zero and this function must be used to get the correct value. The
function returns NULL if passed a relation that does not have storage,
such as a view.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_relation_filepath</primary>
</indexterm>
<function>pg_relation_filepath</function> ( <parameter>relation</parameter> <type>regclass</type> )
<returnvalue>text</returnvalue>
</para>
<para>
Returns the entire file path name (relative to the database cluster's
data directory, <varname>PGDATA</varname>) of the relation.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_filenode_relation</primary>
</indexterm>
<function>pg_filenode_relation</function> ( <parameter>tablespace</parameter> <type>oid</type>, <parameter>filenode</parameter> <type>oid</type> )
<returnvalue>regclass</returnvalue>
</para>
<para>
Returns a relation's OID given the tablespace OID and filenode it is
stored under. This is essentially the inverse mapping of
<function>pg_relation_filepath</function>. For a relation in the
database's default tablespace, the tablespace can be specified as zero.
Returns <literal>NULL</literal> if no relation in the current database
is associated with the given values.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<xref linkend="functions-admin-collation"/> lists functions used to manage
collations.
</para>
<table id="functions-admin-collation">
<title>Collation Management Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_collation_actual_version</primary>
</indexterm>
<function>pg_collation_actual_version</function> ( <type>oid</type> )
<returnvalue>text</returnvalue>
</para>
<para>
Returns the actual version of the collation object as it is currently
installed in the operating system. If this is different from the
value in
<structname>pg_collation</structname>.<structfield>collversion</structfield>,
then objects depending on the collation might need to be rebuilt. See
also <xref linkend="sql-altercollation"/>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_database_collation_actual_version</primary>
</indexterm>
<function>pg_database_collation_actual_version</function> ( <type>oid</type> )
<returnvalue>text</returnvalue>
</para>
<para>
Returns the actual version of the database's collation as it is currently
installed in the operating system. If this is different from the
value in
<structname>pg_database</structname>.<structfield>datcollversion</structfield>,
then objects depending on the collation might need to be rebuilt. See
also <xref linkend="sql-alterdatabase"/>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_import_system_collations</primary>
</indexterm>
<function>pg_import_system_collations</function> ( <parameter>schema</parameter> <type>regnamespace</type> )
<returnvalue>integer</returnvalue>
</para>
<para>
Adds collations to the system
catalog <structname>pg_collation</structname> based on all the locales
it finds in the operating system. This is
what <command>initdb</command> uses; see
<xref linkend="collation-managing"/> for more details. If additional
locales are installed into the operating system later on, this
function can be run again to add collations for the new locales.
Locales that match existing entries
in <structname>pg_collation</structname> will be skipped. (But
collation objects based on locales that are no longer present in the
operating system are not removed by this function.)
The <parameter>schema</parameter> parameter would typically
be <literal>pg_catalog</literal>, but that is not a requirement; the
collations could be installed into some other schema as well. The
function returns the number of new collation objects it created.
Use of this function is restricted to superusers.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<xref linkend="functions-admin-statsmod"/> lists functions used to
manipulate statistics.
These functions cannot be executed during recovery.
<warning>
<para>
Changes made by these statistics manipulation functions are likely to be
overwritten by <link linkend="autovacuum">autovacuum</link> (or manual
<command>VACUUM</command> or <command>ANALYZE</command>) and should be
considered temporary.
</para>
</warning>
</para>
<table id="functions-admin-statsmod">
<title>Database Object Statistics Manipulation Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_restore_relation_stats</primary>
</indexterm>
<function>pg_restore_relation_stats</function> (
<literal>VARIADIC</literal> <parameter>kwargs</parameter> <type>"any"</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Updates table-level statistics. Ordinarily, these statistics are
collected automatically or updated as a part of <xref
linkend="sql-vacuum"/> or <xref linkend="sql-analyze"/>, so it's not
necessary to call this function. However, it is useful after a
restore to enable the optimizer to choose better plans if
<command>ANALYZE</command> has not been run yet.
</para>
<para>
The tracked statistics may change from version to version, so
arguments are passed as pairs of <replaceable>argname</replaceable>
and <replaceable>argvalue</replaceable> in the form:
<programlisting>
SELECT pg_restore_relation_stats(
'<replaceable>arg1name</replaceable>', '<replaceable>arg1value</replaceable>'::<replaceable>arg1type</replaceable>,
'<replaceable>arg2name</replaceable>', '<replaceable>arg2value</replaceable>'::<replaceable>arg2type</replaceable>,
'<replaceable>arg3name</replaceable>', '<replaceable>arg3value</replaceable>'::<replaceable>arg3type</replaceable>);
</programlisting>
</para>
<para>
For example, to set the <structfield>relpages</structfield> and
<structfield>reltuples</structfield> values for the table
<structname>mytable</structname>:
<programlisting>
SELECT pg_restore_relation_stats(
'schemaname', 'myschema',
'relname', 'mytable',
'relpages', 173::integer,
'reltuples', 10000::real);
</programlisting>
</para>
<para>
The arguments <literal>schemaname</literal> and
<literal>relname</literal> are required, and specify the table. Other
arguments are the names and values of statistics corresponding to
certain columns in <link
linkend="catalog-pg-class"><structname>pg_class</structname></link>.
The currently-supported relation statistics are
<literal>relpages</literal> with a value of type
<type>integer</type>, <literal>reltuples</literal> with a value of
type <type>real</type>, <literal>relallvisible</literal> with a value
of type <type>integer</type>, and <literal>relallfrozen</literal>
with a value of type <type>integer</type>.
</para>
<para>
Additionally, this function accepts argument name
<literal>version</literal> of type <type>integer</type>, which
specifies the server version from which the statistics originated.
This is anticipated to be helpful in porting statistics from older
versions of <productname>PostgreSQL</productname>.
</para>
<para>
Minor errors are reported as a <literal>WARNING</literal> and
ignored, and remaining statistics will still be restored. If all
specified statistics are successfully restored, returns
<literal>true</literal>, otherwise <literal>false</literal>.
</para>
<para>
The caller must have the <literal>MAINTAIN</literal> privilege on the
table or be the owner of the database.
</para>
</entry>
</row>
<row>
<entry role="func_table_entry">
<para role="func_signature">
<indexterm>
<primary>pg_clear_relation_stats</primary>
</indexterm>
<function>pg_clear_relation_stats</function> ( <parameter>schemaname</parameter> <type>text</type>, <parameter>relname</parameter> <type>text</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Clears table-level statistics for the given relation, as though the
table was newly created.
</para>
<para>
The caller must have the <literal>MAINTAIN</literal> privilege on the
table or be the owner of the database.
</para>
</entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_restore_attribute_stats</primary>
</indexterm>
<function>pg_restore_attribute_stats</function> (
<literal>VARIADIC</literal> <parameter>kwargs</parameter> <type>"any"</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Creates or updates column-level statistics. Ordinarily, these
statistics are collected automatically or updated as a part of <xref
linkend="sql-vacuum"/> or <xref linkend="sql-analyze"/>, so it's not
necessary to call this function. However, it is useful after a
restore to enable the optimizer to choose better plans if
<command>ANALYZE</command> has not been run yet.
</para>
<para>
The tracked statistics may change from version to version, so
arguments are passed as pairs of <replaceable>argname</replaceable>
and <replaceable>argvalue</replaceable> in the form:
<programlisting>
SELECT pg_restore_attribute_stats(
'<replaceable>arg1name</replaceable>', '<replaceable>arg1value</replaceable>'::<replaceable>arg1type</replaceable>,
'<replaceable>arg2name</replaceable>', '<replaceable>arg2value</replaceable>'::<replaceable>arg2type</replaceable>,
'<replaceable>arg3name</replaceable>', '<replaceable>arg3value</replaceable>'::<replaceable>arg3type</replaceable>);
</programlisting>
</para>
<para>
For example, to set the <structfield>avg_width</structfield> and
<structfield>null_frac</structfield> values for the attribute
<structfield>col1</structfield> of the table
<structname>mytable</structname>:
<programlisting>
SELECT pg_restore_attribute_stats(
'schemaname', 'myschema',
'relname', 'mytable',
'attname', 'col1',
'inherited', false,
'avg_width', 125::integer,
'null_frac', 0.5::real);
</programlisting>
</para>
<para>
The required arguments are <literal>schemaname</literal> and
<literal>relname</literal> with a value of type <type>text</type>
which specify the table; either <literal>attname</literal> with a
value of type <type>text</type> or <literal>attnum</literal> with a
value of type <type>smallint</type>, which specifies the column; and
<literal>inherited</literal>, which specifies whether the statistics
include values from child tables. Other arguments are the names and
values of statistics corresponding to columns in <link
linkend="view-pg-stats"><structname>pg_stats</structname></link>.
</para>
<para>
Additionally, this function accepts argument name
<literal>version</literal> of type <type>integer</type>, which
specifies the server version from which the statistics originated.
This is anticipated to be helpful in porting statistics from older
versions of <productname>PostgreSQL</productname>.
</para>
<para>
Minor errors are reported as a <literal>WARNING</literal> and
ignored, and remaining statistics will still be restored. If all
specified statistics are successfully restored, returns
<literal>true</literal>, otherwise <literal>false</literal>.
</para>
<para>
The caller must have the <literal>MAINTAIN</literal> privilege on the
table or be the owner of the database.
</para>
</entry>
</row>
<row>
<entry role="func_table_entry">
<para role="func_signature">
<indexterm>
<primary>pg_clear_attribute_stats</primary>
</indexterm>
<function>pg_clear_attribute_stats</function> (
<parameter>schemaname</parameter> <type>text</type>,
<parameter>relname</parameter> <type>text</type>,
<parameter>attname</parameter> <type>text</type>,
<parameter>inherited</parameter> <type>boolean</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Clears column-level statistics for the given relation and
attribute, as though the table was newly created.
</para>
<para>
The caller must have the <literal>MAINTAIN</literal> privilege on
the table or be the owner of the database.
</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<xref linkend="functions-info-partition"/> lists functions that provide
information about the structure of partitioned tables.
</para>
<table id="functions-info-partition">
<title>Partitioning Information Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_partition_tree</primary>
</indexterm>
<function>pg_partition_tree</function> ( <type>regclass</type> )
<returnvalue>setof record</returnvalue>
( <parameter>relid</parameter> <type>regclass</type>,
<parameter>parentrelid</parameter> <type>regclass</type>,
<parameter>isleaf</parameter> <type>boolean</type>,
<parameter>level</parameter> <type>integer</type> )
</para>
<para>
Lists the tables or indexes in the partition tree of the
given partitioned table or partitioned index, with one row for each
partition. Information provided includes the OID of the partition,
the OID of its immediate parent, a boolean value telling if the
partition is a leaf, and an integer telling its level in the hierarchy.
The level value is 0 for the input table or index, 1 for its
immediate child partitions, 2 for their partitions, and so on.
Returns no rows if the relation does not exist or is not a partition
or partitioned table.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_partition_ancestors</primary>
</indexterm>
<function>pg_partition_ancestors</function> ( <type>regclass</type> )
<returnvalue>setof regclass</returnvalue>
</para>
<para>
Lists the ancestor relations of the given partition,
including the relation itself. Returns no rows if the relation
does not exist or is not a partition or partitioned table.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_partition_root</primary>
</indexterm>
<function>pg_partition_root</function> ( <type>regclass</type> )
<returnvalue>regclass</returnvalue>
</para>
<para>
Returns the top-most parent of the partition tree to which the given
relation belongs. Returns <literal>NULL</literal> if the relation
does not exist or is not a partition or partitioned table.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
For example, to check the total size of the data contained in a
partitioned table <structname>measurement</structname>, one could use the
following query:
<programlisting>
SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size
FROM pg_partition_tree('measurement');
</programlisting>
</para>
</sect2>
<sect2 id="functions-admin-index">
<title>Index Maintenance Functions</title>
<para>
<xref linkend="functions-admin-index-table"/> shows the functions
available for index maintenance tasks. (Note that these maintenance
tasks are normally done automatically by autovacuum; use of these
functions is only required in special cases.)
These functions cannot be executed during recovery.
Use of these functions is restricted to superusers and the owner
of the given index.
</para>
<table id="functions-admin-index-table">
<title>Index Maintenance Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>brin_summarize_new_values</primary>
</indexterm>
<function>brin_summarize_new_values</function> ( <parameter>index</parameter> <type>regclass</type> )
<returnvalue>integer</returnvalue>
</para>
<para>
Scans the specified BRIN index to find page ranges in the base table
that are not currently summarized by the index; for any such range it
creates a new summary index tuple by scanning those table pages.
Returns the number of new page range summaries that were inserted
into the index.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>brin_summarize_range</primary>
</indexterm>
<function>brin_summarize_range</function> ( <parameter>index</parameter> <type>regclass</type>, <parameter>blockNumber</parameter> <type>bigint</type> )
<returnvalue>integer</returnvalue>
</para>
<para>
Summarizes the page range covering the given block, if not already
summarized. This is
like <function>brin_summarize_new_values</function> except that it
only processes the page range that covers the given table block number.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>brin_desummarize_range</primary>
</indexterm>
<function>brin_desummarize_range</function> ( <parameter>index</parameter> <type>regclass</type>, <parameter>blockNumber</parameter> <type>bigint</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Removes the BRIN index tuple that summarizes the page range covering
the given table block, if there is one.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>gin_clean_pending_list</primary>
</indexterm>
<function>gin_clean_pending_list</function> ( <parameter>index</parameter> <type>regclass</type> )
<returnvalue>bigint</returnvalue>
</para>
<para>
Cleans up the <quote>pending</quote> list of the specified GIN index
by moving entries in it, in bulk, to the main GIN data structure.
Returns the number of pages removed from the pending list.
If the argument is a GIN index built with
the <literal>fastupdate</literal> option disabled, no cleanup happens
and the result is zero, because the index doesn't have a pending list.
See <xref linkend="gin-fast-update"/> and <xref linkend="gin-tips"/>
for details about the pending list and <literal>fastupdate</literal>
option.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
<sect2 id="functions-admin-genfile">
<title>Generic File Access Functions</title>
<para>
The functions shown in <xref
linkend="functions-admin-genfile-table"/> provide native access to
files on the machine hosting the server. Only files within the
database cluster directory and the <varname>log_directory</varname> can be
accessed, unless the user is a superuser or is granted the role
<literal>pg_read_server_files</literal>. Use a relative path for files in
the cluster directory, and a path matching the <varname>log_directory</varname>
configuration setting for log files.
</para>
<para>
Note that granting users the EXECUTE privilege on
<function>pg_read_file()</function>, or related functions, allows them the
ability to read any file on the server that the database server process can
read; these functions bypass all in-database privilege checks. This means
that, for example, a user with such access is able to read the contents of
the <structname>pg_authid</structname> table where authentication
information is stored, as well as read any table data in the database.
Therefore, granting access to these functions should be carefully
considered.
</para>
<para>
When granting privilege on these functions, note that the table entries
showing optional parameters are mostly implemented as several physical
functions with different parameter lists. Privilege must be granted
separately on each such function, if it is to be
used. <application>psql</application>'s <command>\df</command> command
can be useful to check what the actual function signatures are.
</para>
<para>
Some of these functions take an optional <parameter>missing_ok</parameter>
parameter, which specifies the behavior when the file or directory does
not exist. If <literal>true</literal>, the function
returns <literal>NULL</literal> or an empty result set, as appropriate.
If <literal>false</literal>, an error is raised. (Failure conditions
other than <quote>file not found</quote> are reported as errors in any
case.) The default is <literal>false</literal>.
</para>
<table id="functions-admin-genfile-table">
<title>Generic File Access Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_dir</primary>
</indexterm>
<function>pg_ls_dir</function> ( <parameter>dirname</parameter> <type>text</type> <optional>, <parameter>missing_ok</parameter> <type>boolean</type>, <parameter>include_dot_dirs</parameter> <type>boolean</type> </optional> )
<returnvalue>setof text</returnvalue>
</para>
<para>
Returns the names of all files (and directories and other special
files) in the specified
directory. The <parameter>include_dot_dirs</parameter> parameter
indicates whether <quote>.</quote> and <quote>..</quote> are to be
included in the result set; the default is to exclude them. Including
them can be useful when <parameter>missing_ok</parameter>
is <literal>true</literal>, to distinguish an empty directory from a
non-existent directory.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_logdir</primary>
</indexterm>
<function>pg_ls_logdir</function> ()
<returnvalue>setof record</returnvalue>
( <parameter>name</parameter> <type>text</type>,
<parameter>size</parameter> <type>bigint</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type> )
</para>
<para>
Returns the name, size, and last modification time (mtime) of each
ordinary file in the server's log directory. Filenames beginning with
a dot, directories, and other special files are excluded.
</para>
<para>
This function is restricted to superusers and roles with privileges of
the <literal>pg_monitor</literal> role by default, but other users can
be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_waldir</primary>
</indexterm>
<function>pg_ls_waldir</function> ()
<returnvalue>setof record</returnvalue>
( <parameter>name</parameter> <type>text</type>,
<parameter>size</parameter> <type>bigint</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type> )
</para>
<para>
Returns the name, size, and last modification time (mtime) of each
ordinary file in the server's write-ahead log (WAL) directory.
Filenames beginning with a dot, directories, and other special files
are excluded.
</para>
<para>
This function is restricted to superusers and roles with privileges of
the <literal>pg_monitor</literal> role by default, but other users can
be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_logicalmapdir</primary>
</indexterm>
<function>pg_ls_logicalmapdir</function> ()
<returnvalue>setof record</returnvalue>
( <parameter>name</parameter> <type>text</type>,
<parameter>size</parameter> <type>bigint</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type> )
</para>
<para>
Returns the name, size, and last modification time (mtime) of each
ordinary file in the server's <filename>pg_logical/mappings</filename>
directory. Filenames beginning with a dot, directories, and other
special files are excluded.
</para>
<para>
This function is restricted to superusers and members of
the <literal>pg_monitor</literal> role by default, but other users can
be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_logicalsnapdir</primary>
</indexterm>
<function>pg_ls_logicalsnapdir</function> ()
<returnvalue>setof record</returnvalue>
( <parameter>name</parameter> <type>text</type>,
<parameter>size</parameter> <type>bigint</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type> )
</para>
<para>
Returns the name, size, and last modification time (mtime) of each
ordinary file in the server's <filename>pg_logical/snapshots</filename>
directory. Filenames beginning with a dot, directories, and other
special files are excluded.
</para>
<para>
This function is restricted to superusers and members of
the <literal>pg_monitor</literal> role by default, but other users can
be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_replslotdir</primary>
</indexterm>
<function>pg_ls_replslotdir</function> ( <parameter>slot_name</parameter> <type>text</type> )
<returnvalue>setof record</returnvalue>
( <parameter>name</parameter> <type>text</type>,
<parameter>size</parameter> <type>bigint</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type> )
</para>
<para>
Returns the name, size, and last modification time (mtime) of each
ordinary file in the server's <filename>pg_replslot/slot_name</filename>
directory, where <parameter>slot_name</parameter> is the name of the
replication slot provided as input of the function. Filenames beginning
with a dot, directories, and other special files are excluded.
</para>
<para>
This function is restricted to superusers and members of
the <literal>pg_monitor</literal> role by default, but other users can
be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_summariesdir</primary>
</indexterm>
<function>pg_ls_summariesdir</function> ()
<returnvalue>setof record</returnvalue>
( <parameter>name</parameter> <type>text</type>,
<parameter>size</parameter> <type>bigint</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type> )
</para>
<para>
Returns the name, size, and last modification time (mtime) of each
ordinary file in the server's WAL summaries directory
(<filename>pg_wal/summaries</filename>). Filenames beginning
with a dot, directories, and other special files are excluded.
</para>
<para>
This function is restricted to superusers and members of
the <literal>pg_monitor</literal> role by default, but other users can
be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_archive_statusdir</primary>
</indexterm>
<function>pg_ls_archive_statusdir</function> ()
<returnvalue>setof record</returnvalue>
( <parameter>name</parameter> <type>text</type>,
<parameter>size</parameter> <type>bigint</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type> )
</para>
<para>
Returns the name, size, and last modification time (mtime) of each
ordinary file in the server's WAL archive status directory
(<filename>pg_wal/archive_status</filename>). Filenames beginning
with a dot, directories, and other special files are excluded.
</para>
<para>
This function is restricted to superusers and members of
the <literal>pg_monitor</literal> role by default, but other users can
be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_ls_tmpdir</primary>
</indexterm>
<function>pg_ls_tmpdir</function> ( <optional> <parameter>tablespace</parameter> <type>oid</type> </optional> )
<returnvalue>setof record</returnvalue>
( <parameter>name</parameter> <type>text</type>,
<parameter>size</parameter> <type>bigint</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type> )
</para>
<para>
Returns the name, size, and last modification time (mtime) of each
ordinary file in the temporary file directory for the
specified <parameter>tablespace</parameter>.
If <parameter>tablespace</parameter> is not provided,
the <literal>pg_default</literal> tablespace is examined. Filenames
beginning with a dot, directories, and other special files are
excluded.
</para>
<para>
This function is restricted to superusers and members of
the <literal>pg_monitor</literal> role by default, but other users can
be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_read_file</primary>
</indexterm>
<function>pg_read_file</function> ( <parameter>filename</parameter> <type>text</type> <optional>, <parameter>offset</parameter> <type>bigint</type>, <parameter>length</parameter> <type>bigint</type> </optional> <optional>, <parameter>missing_ok</parameter> <type>boolean</type> </optional> )
<returnvalue>text</returnvalue>
</para>
<para>
Returns all or part of a text file, starting at the
given byte <parameter>offset</parameter>, returning at
most <parameter>length</parameter> bytes (less if the end of file is
reached first). If <parameter>offset</parameter> is negative, it is
relative to the end of the file. If <parameter>offset</parameter>
and <parameter>length</parameter> are omitted, the entire file is
returned. The bytes read from the file are interpreted as a string in
the database's encoding; an error is thrown if they are not valid in
that encoding.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_read_binary_file</primary>
</indexterm>
<function>pg_read_binary_file</function> ( <parameter>filename</parameter> <type>text</type> <optional>, <parameter>offset</parameter> <type>bigint</type>, <parameter>length</parameter> <type>bigint</type> </optional> <optional>, <parameter>missing_ok</parameter> <type>boolean</type> </optional> )
<returnvalue>bytea</returnvalue>
</para>
<para>
Returns all or part of a file. This function is identical to
<function>pg_read_file</function> except that it can read arbitrary
binary data, returning the result as <type>bytea</type>
not <type>text</type>; accordingly, no encoding checks are performed.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para>
<para>
In combination with the <function>convert_from</function> function,
this function can be used to read a text file in a specified encoding
and convert to the database's encoding:
<programlisting>
SELECT convert_from(pg_read_binary_file('file_in_utf8.txt'), 'UTF8');
</programlisting>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_stat_file</primary>
</indexterm>
<function>pg_stat_file</function> ( <parameter>filename</parameter> <type>text</type> <optional>, <parameter>missing_ok</parameter> <type>boolean</type> </optional> )
<returnvalue>record</returnvalue>
( <parameter>size</parameter> <type>bigint</type>,
<parameter>access</parameter> <type>timestamp with time zone</type>,
<parameter>modification</parameter> <type>timestamp with time zone</type>,
<parameter>change</parameter> <type>timestamp with time zone</type>,
<parameter>creation</parameter> <type>timestamp with time zone</type>,
<parameter>isdir</parameter> <type>boolean</type> )
</para>
<para>
Returns a record containing the file's size, last access time stamp,
last modification time stamp, last file status change time stamp (Unix
platforms only), file creation time stamp (Windows only), and a flag
indicating if it is a directory.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
<sect2 id="functions-advisory-locks">
<title>Advisory Lock Functions</title>
<para>
The functions shown in <xref linkend="functions-advisory-locks-table"/>
manage advisory locks. For details about proper use of these functions,
see <xref linkend="advisory-locks"/>.
</para>
<para>
All these functions are intended to be used to lock application-defined
resources, which can be identified either by a single 64-bit key value or
two 32-bit key values (note that these two key spaces do not overlap).
If another session already holds a conflicting lock on the same resource
identifier, the functions will either wait until the resource becomes
available, or return a <literal>false</literal> result, as appropriate for
the function.
Locks can be either shared or exclusive: a shared lock does not conflict
with other shared locks on the same resource, only with exclusive locks.
Locks can be taken at session level (so that they are held until released
or the session ends) or at transaction level (so that they are held until
the current transaction ends; there is no provision for manual release).
Multiple session-level lock requests stack, so that if the same resource
identifier is locked three times there must then be three unlock requests
to release the resource in advance of session end.
</para>
<table id="functions-advisory-locks-table">
<title>Advisory Lock Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_advisory_lock</primary>
</indexterm>
<function>pg_advisory_lock</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>void</returnvalue>
</para>
<para role="func_signature">
<function>pg_advisory_lock</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Obtains an exclusive session-level advisory lock, waiting if necessary.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_advisory_lock_shared</primary>
</indexterm>
<function>pg_advisory_lock_shared</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>void</returnvalue>
</para>
<para role="func_signature">
<function>pg_advisory_lock_shared</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Obtains a shared session-level advisory lock, waiting if necessary.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_advisory_unlock</primary>
</indexterm>
<function>pg_advisory_unlock</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>boolean</returnvalue>
</para>
<para role="func_signature">
<function>pg_advisory_unlock</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Releases a previously-acquired exclusive session-level advisory lock.
Returns <literal>true</literal> if the lock is successfully released.
If the lock was not held, <literal>false</literal> is returned, and in
addition, an SQL warning will be reported by the server.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_advisory_unlock_all</primary>
</indexterm>
<function>pg_advisory_unlock_all</function> ()
<returnvalue>void</returnvalue>
</para>
<para>
Releases all session-level advisory locks held by the current session.
(This function is implicitly invoked at session end, even if the
client disconnects ungracefully.)
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_advisory_unlock_shared</primary>
</indexterm>
<function>pg_advisory_unlock_shared</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>boolean</returnvalue>
</para>
<para role="func_signature">
<function>pg_advisory_unlock_shared</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Releases a previously-acquired shared session-level advisory lock.
Returns <literal>true</literal> if the lock is successfully released.
If the lock was not held, <literal>false</literal> is returned, and in
addition, an SQL warning will be reported by the server.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_advisory_xact_lock</primary>
</indexterm>
<function>pg_advisory_xact_lock</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>void</returnvalue>
</para>
<para role="func_signature">
<function>pg_advisory_xact_lock</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Obtains an exclusive transaction-level advisory lock, waiting if
necessary.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_advisory_xact_lock_shared</primary>
</indexterm>
<function>pg_advisory_xact_lock_shared</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>void</returnvalue>
</para>
<para role="func_signature">
<function>pg_advisory_xact_lock_shared</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Obtains a shared transaction-level advisory lock, waiting if
necessary.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_try_advisory_lock</primary>
</indexterm>
<function>pg_try_advisory_lock</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>boolean</returnvalue>
</para>
<para role="func_signature">
<function>pg_try_advisory_lock</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Obtains an exclusive session-level advisory lock if available.
This will either obtain the lock immediately and
return <literal>true</literal>, or return <literal>false</literal>
without waiting if the lock cannot be acquired immediately.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_try_advisory_lock_shared</primary>
</indexterm>
<function>pg_try_advisory_lock_shared</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>boolean</returnvalue>
</para>
<para role="func_signature">
<function>pg_try_advisory_lock_shared</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Obtains a shared session-level advisory lock if available.
This will either obtain the lock immediately and
return <literal>true</literal>, or return <literal>false</literal>
without waiting if the lock cannot be acquired immediately.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_try_advisory_xact_lock</primary>
</indexterm>
<function>pg_try_advisory_xact_lock</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>boolean</returnvalue>
</para>
<para role="func_signature">
<function>pg_try_advisory_xact_lock</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Obtains an exclusive transaction-level advisory lock if available.
This will either obtain the lock immediately and
return <literal>true</literal>, or return <literal>false</literal>
without waiting if the lock cannot be acquired immediately.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_try_advisory_xact_lock_shared</primary>
</indexterm>
<function>pg_try_advisory_xact_lock_shared</function> ( <parameter>key</parameter> <type>bigint</type> )
<returnvalue>boolean</returnvalue>
</para>
<para role="func_signature">
<function>pg_try_advisory_xact_lock_shared</function> ( <parameter>key1</parameter> <type>integer</type>, <parameter>key2</parameter> <type>integer</type> )
<returnvalue>boolean</returnvalue>
</para>
<para>
Obtains a shared transaction-level advisory lock if available.
This will either obtain the lock immediately and
return <literal>true</literal>, or return <literal>false</literal>
without waiting if the lock cannot be acquired immediately.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
</sect1>
|