summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/html/functions-admin.html
blob: 2e9828e32f66f21abb5df7234c97b9abb59f18c6 (plain)
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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>9.27. System Administration Functions</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="functions-info.html" title="9.26. System Information Functions and Operators" /><link rel="next" href="functions-trigger.html" title="9.28. Trigger Functions" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">9.27. System Administration Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-info.html" title="9.26. System Information Functions and Operators">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.2 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="functions-trigger.html" title="9.28. Trigger Functions">Next</a></td></tr></table><hr /></div><div class="sect1" id="FUNCTIONS-ADMIN"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.27. System Administration Functions <a href="#FUNCTIONS-ADMIN" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-SET">9.27.1. Configuration Settings Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-SIGNAL">9.27.2. Server Signaling Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-BACKUP">9.27.3. Backup Control Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-RECOVERY-CONTROL">9.27.4. Recovery Control Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION">9.27.5. Snapshot Synchronization Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-REPLICATION">9.27.6. Replication Management Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT">9.27.7. Database Object Management Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-INDEX">9.27.8. Index Maintenance Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-GENFILE">9.27.9. Generic File Access Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADVISORY-LOCKS">9.27.10. Advisory Lock Functions</a></span></dt></dl></div><p>
    The functions described in this section are used to control and
    monitor a <span class="productname">PostgreSQL</span> installation.
   </p><div class="sect2" id="FUNCTIONS-ADMIN-SET"><div class="titlepage"><div><div><h3 class="title">9.27.1. Configuration Settings Functions <a href="#FUNCTIONS-ADMIN-SET" class="id_link">#</a></h3></div></div></div><a id="id-1.5.8.33.3.2" class="indexterm"></a><a id="id-1.5.8.33.3.3" class="indexterm"></a><a id="id-1.5.8.33.3.4" class="indexterm"></a><p>
    <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-SET-TABLE" title="Table 9.89. Configuration Settings Functions">Table 9.89</a> shows the functions
    available to query and alter run-time configuration parameters.
   </p><div class="table" id="FUNCTIONS-ADMIN-SET-TABLE"><p class="title"><strong>Table 9.89. Configuration Settings Functions</strong></p><div class="table-contents"><table class="table" summary="Configuration Settings Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p>
       <p>
        Example(s)
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.3.6.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">current_setting</code> ( <em class="parameter"><code>setting_name</code></em> <code class="type">text</code> [<span class="optional">, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code> </span>] )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        Returns the current value of the
        setting <em class="parameter"><code>setting_name</code></em>.  If there is no such
        setting, <code class="function">current_setting</code> throws an error
        unless <em class="parameter"><code>missing_ok</code></em> is supplied and
        is <code class="literal">true</code> (in which case NULL is returned).
        This function corresponds to
        the <acronym class="acronym">SQL</acronym> command <a class="xref" href="sql-show.html" title="SHOW"><span class="refentrytitle">SHOW</span></a>.
       </p>
       <p>
        <code class="literal">current_setting('datestyle')</code><code class="returnvalue">ISO, MDY</code>
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.3.6.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">set_config</code> (
          <em class="parameter"><code>setting_name</code></em> <code class="type">text</code>,
          <em class="parameter"><code>new_value</code></em> <code class="type">text</code>,
          <em class="parameter"><code>is_local</code></em> <code class="type">boolean</code> )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        Sets the parameter <em class="parameter"><code>setting_name</code></em>
        to <em class="parameter"><code>new_value</code></em>, and returns that value.
        If <em class="parameter"><code>is_local</code></em> is <code class="literal">true</code>, 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 <code class="literal">false</code> instead. This function corresponds to
        the SQL command <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a>.
       </p>
       <p>
        <code class="literal">set_config('log_statement_stats', 'off', false)</code><code class="returnvalue">off</code>
       </p></td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="FUNCTIONS-ADMIN-SIGNAL"><div class="titlepage"><div><div><h3 class="title">9.27.2. Server Signaling Functions <a href="#FUNCTIONS-ADMIN-SIGNAL" class="id_link">#</a></h3></div></div></div><a id="id-1.5.8.33.4.2" class="indexterm"></a><p>
    The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE" title="Table 9.90. Server Signaling Functions">Table 9.90</a> 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
    <code class="command">GRANT</code>, with noted exceptions.
   </p><p>
    Each of these functions returns <code class="literal">true</code> if
    the signal was successfully sent and <code class="literal">false</code>
    if sending the signal failed.
   </p><div class="table" id="FUNCTIONS-ADMIN-SIGNAL-TABLE"><p class="title"><strong>Table 9.90. Server Signaling Functions</strong></p><div class="table-contents"><table class="table" summary="Server Signaling Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.4.5.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_cancel_backend</code> ( <em class="parameter"><code>pid</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        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 <code class="literal">pg_signal_backend</code>,
        however only superusers can cancel superuser backends.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.4.5.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_log_backend_memory_contexts</code> ( <em class="parameter"><code>pid</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        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
        <code class="literal">LOG</code> message level. They will appear in
        the server log based on the log configuration set
        (see <a class="xref" href="runtime-config-logging.html" title="20.8. Error Reporting and Logging">Section 20.8</a> for more information),
        but will not be sent to the client regardless of
        <a class="xref" href="runtime-config-client.html#GUC-CLIENT-MIN-MESSAGES">client_min_messages</a>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.4.5.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_reload_conf</code> ()
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Causes all processes of the <span class="productname">PostgreSQL</span>
        server to reload their configuration files.  (This is initiated by
        sending a <span class="systemitem">SIGHUP</span> signal to the postmaster
        process, which in turn sends <span class="systemitem">SIGHUP</span> to each
        of its children.) You can use the
        <a class="link" href="view-pg-file-settings.html" title="54.7. pg_file_settings"><code class="structname">pg_file_settings</code></a>,
        <a class="link" href="view-pg-hba-file-rules.html" title="54.9. pg_hba_file_rules"><code class="structname">pg_hba_file_rules</code></a> and
        <a class="link" href="view-pg-hba-file-rules.html" title="54.9. pg_hba_file_rules"><code class="structname">pg_ident_file_mappings</code></a> views
        to check the configuration files for possible errors, before reloading.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.4.5.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">pg_rotate_logfile</code> ()
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        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.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.4.5.2.2.5.1.1.1" class="indexterm"></a>
        <code class="function">pg_terminate_backend</code> ( <em class="parameter"><code>pid</code></em> <code class="type">integer</code>, <em class="parameter"><code>timeout</code></em> <code class="type">bigint</code> <code class="literal">DEFAULT</code> <code class="literal">0</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        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 <code class="literal">pg_signal_backend</code>,
        however only superusers can terminate superuser backends.
       </p>
       <p>
        If <em class="parameter"><code>timeout</code></em> is not specified or zero, this
        function returns <code class="literal">true</code> whether the process actually
        terminates or not, indicating only that the sending of the signal was
        successful.  If the <em class="parameter"><code>timeout</code></em> 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 <code class="literal">true</code>.  On timeout, a warning is emitted and
        <code class="literal">false</code> is returned.
       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
    <code class="function">pg_cancel_backend</code> and <code class="function">pg_terminate_backend</code>
    send signals (<span class="systemitem">SIGINT</span> or <span class="systemitem">SIGTERM</span>
    respectively) to backend processes identified by process ID.
    The process ID of an active backend can be found from
    the <code class="structfield">pid</code> column of the
    <code class="structname">pg_stat_activity</code> view, or by listing the
    <code class="command">postgres</code> processes on the server (using
    <span class="application">ps</span> on Unix or the <span class="application">Task
    Manager</span> on <span class="productname">Windows</span>).
    The role of an active backend can be found from the
    <code class="structfield">usename</code> column of the
    <code class="structname">pg_stat_activity</code> view.
   </p><p>
    <code class="function">pg_log_backend_memory_contexts</code> can be used
    to log the memory contexts of a backend process. For example:
</p><pre class="programlisting">
postgres=# SELECT pg_log_backend_memory_contexts(pg_backend_pid());
 pg_log_backend_memory_contexts
--------------------------------
 t
(1 row)
</pre><p>
One message for each memory context will be logged. For example:
</p><pre class="screen">
LOG:  logging memory contexts of PID 10377
STATEMENT:  SELECT pg_log_backend_memory_contexts(pg_backend_pid());
LOG:  level: 0; TopMemoryContext: 80800 total in 6 blocks; 14432 free (5 chunks); 66368 used
LOG:  level: 1; pgstat TabStatusArray lookup hash table: 8192 total in 1 blocks; 1408 free (0 chunks); 6784 used
LOG:  level: 1; TopTransactionContext: 8192 total in 1 blocks; 7720 free (1 chunks); 472 used
LOG:  level: 1; RowDescriptionContext: 8192 total in 1 blocks; 6880 free (0 chunks); 1312 used
LOG:  level: 1; MessageContext: 16384 total in 2 blocks; 5152 free (0 chunks); 11232 used
LOG:  level: 1; Operator class cache: 8192 total in 1 blocks; 512 free (0 chunks); 7680 used
LOG:  level: 1; smgr relation table: 16384 total in 2 blocks; 4544 free (3 chunks); 11840 used
LOG:  level: 1; TransactionAbortContext: 32768 total in 1 blocks; 32504 free (0 chunks); 264 used
...
LOG:  level: 1; 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
</pre><p>
    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.
   </p></div><div class="sect2" id="FUNCTIONS-ADMIN-BACKUP"><div class="titlepage"><div><div><h3 class="title">9.27.3. Backup Control Functions <a href="#FUNCTIONS-ADMIN-BACKUP" class="id_link">#</a></h3></div></div></div><a id="id-1.5.8.33.5.2" class="indexterm"></a><p>
    The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-BACKUP-TABLE" title="Table 9.91. Backup Control Functions">Table 9.91</a> assist in making on-line backups.
    These functions cannot be executed during recovery (except
    <code class="function">pg_backup_start</code>,
    <code class="function">pg_backup_stop</code>,
    and <code class="function">pg_wal_lsn_diff</code>).
   </p><p>
    For details about proper usage of these functions, see
    <a class="xref" href="continuous-archiving.html" title="26.3. Continuous Archiving and Point-in-Time Recovery (PITR)">Section 26.3</a>.
   </p><div class="table" id="FUNCTIONS-ADMIN-BACKUP-TABLE"><p class="title"><strong>Table 9.91. Backup Control Functions</strong></p><div class="table-contents"><table class="table" summary="Backup Control Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_create_restore_point</code> ( <em class="parameter"><code>name</code></em> <code class="type">text</code> )
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        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
        <a class="xref" href="runtime-config-wal.html#GUC-RECOVERY-TARGET-NAME">recovery_target_name</a> 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.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_current_wal_flush_lsn</code> ()
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        Returns the current write-ahead log flush location (see notes below).
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_current_wal_insert_lsn</code> ()
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        Returns the current write-ahead log insert location (see notes below).
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">pg_current_wal_lsn</code> ()
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        Returns the current write-ahead log write location (see notes below).
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.5.1.1.1" class="indexterm"></a>
        <code class="function">pg_backup_start</code> (
          <em class="parameter"><code>label</code></em> <code class="type">text</code>
          [<span class="optional">, <em class="parameter"><code>fast</code></em> <code class="type">boolean</code>
          </span>] )
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        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 <code class="literal">true</code>,
        it specifies executing <code class="function">pg_backup_start</code> as quickly
        as possible.  This forces an immediate checkpoint which will cause a
        spike in I/O operations, slowing any concurrently executing queries.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.6.1.1.1" class="indexterm"></a>
        <code class="function">pg_backup_stop</code> (
          [<span class="optional"><em class="parameter"><code>wait_for_archive</code></em> <code class="type">boolean</code>
          </span>] )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>,
        <em class="parameter"><code>labelfile</code></em> <code class="type">text</code>,
        <em class="parameter"><code>spcmapfile</code></em> <code class="type">text</code> )
       </p>
       <p>
        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).
       </p>
       <p>
        There is an optional parameter of type <code class="type">boolean</code>.
        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, <code class="function">pg_backup_stop</code> will wait for
        WAL to be archived when archiving is enabled.  (On a standby, this
        means that it will wait only when <code class="varname">archive_mode</code> =
        <code class="literal">always</code>.  If write activity on the primary is low,
        it may be useful to run <code class="function">pg_switch_wal</code> on the
        primary in order to trigger an immediate segment switch.)
       </p>
       <p>
        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 <code class="function">pg_backup_start</code>, 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.
       </p>
       <p>
        The result of the function is a single record.
        The <em class="parameter"><code>lsn</code></em> 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.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.7.1.1.1" class="indexterm"></a>
        <code class="function">pg_switch_wal</code> ()
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        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, <code class="function">pg_switch_wal</code> does nothing and
        returns the start location of the write-ahead log file currently in
        use.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.8.1.1.1" class="indexterm"></a>
        <code class="function">pg_walfile_name</code> ( <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code> )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        Converts a write-ahead log location to the name of the WAL file
        holding that location.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.9.1.1.1" class="indexterm"></a>
        <code class="function">pg_walfile_name_offset</code> ( <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code> )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>file_name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>file_offset</code></em> <code class="type">integer</code> )
       </p>
       <p>
        Converts a write-ahead log location to a WAL file name and byte offset
        within that file.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.10.1.1.1" class="indexterm"></a>
        <code class="function">pg_split_walfile_name</code> ( <em class="parameter"><code>file_name</code></em> <code class="type">text</code> )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>segment_number</code></em> <code class="type">numeric</code>,
        <em class="parameter"><code>timeline_id</code></em> <code class="type">bigint</code> )
       </p>
       <p>
        Extracts the sequence number and timeline ID from a WAL file
        name.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.5.5.2.2.11.1.1.1" class="indexterm"></a>
        <code class="function">pg_wal_lsn_diff</code> ( <em class="parameter"><code>lsn1</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>lsn2</code></em> <code class="type">pg_lsn</code> )
        → <code class="returnvalue">numeric</code>
       </p>
       <p>
        Calculates the difference in bytes (<em class="parameter"><code>lsn1</code></em> - <em class="parameter"><code>lsn2</code></em>) between two write-ahead log
        locations.  This can be used
        with <code class="structname">pg_stat_replication</code> or some of the
        functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-BACKUP-TABLE" title="Table 9.91. Backup Control Functions">Table 9.91</a> to
        get the replication lag.
       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
    <code class="function">pg_current_wal_lsn</code> displays the current write-ahead
    log write location in the same format used by the above functions.
    Similarly, <code class="function">pg_current_wal_insert_lsn</code> displays the
    current write-ahead log insertion location
    and <code class="function">pg_current_wal_flush_lsn</code> displays the current
    write-ahead log flush location. The insertion location is
    the <span class="quote"><span class="quote">logical</span></span> 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.
   </p><p>
    You can use <code class="function">pg_walfile_name_offset</code> to extract the
    corresponding write-ahead log file name and byte offset from
    a <code class="type">pg_lsn</code> value.  For example:
</p><pre class="programlisting">
postgres=# SELECT * FROM pg_walfile_name_offset((pg_backup_stop()).lsn);
        file_name         | file_offset
--------------------------+-------------
 00000001000000000000000D |     4039624
(1 row)
</pre><p>
    Similarly, <code class="function">pg_walfile_name</code> extracts just the write-ahead log file name.
    When the given write-ahead log location is exactly at a write-ahead log file boundary, both
    these functions return the name of the preceding write-ahead log file.
    This is usually the desired behavior for managing write-ahead log archiving
    behavior, since the preceding file is the last one that currently
    needs to be archived.
   </p><p>
    <code class="function">pg_split_walfile_name</code> is useful to compute a
    <acronym class="acronym">LSN</acronym> from a file offset and WAL file name, for example:
</p><pre class="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)
</pre><p>
   </p></div><div class="sect2" id="FUNCTIONS-RECOVERY-CONTROL"><div class="titlepage"><div><div><h3 class="title">9.27.4. Recovery Control Functions <a href="#FUNCTIONS-RECOVERY-CONTROL" class="id_link">#</a></h3></div></div></div><p>
    The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-RECOVERY-INFO-TABLE" title="Table 9.92. Recovery Information Functions">Table 9.92</a> provide information
    about the current status of a standby server.
    These functions may be executed both during recovery and in normal running.
   </p><div class="table" id="FUNCTIONS-RECOVERY-INFO-TABLE"><p class="title"><strong>Table 9.92. Recovery Information Functions</strong></p><div class="table-contents"><table class="table" summary="Recovery Information Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.3.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_is_in_recovery</code> ()
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Returns true if recovery is still in progress.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.3.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_last_wal_receive_lsn</code> ()
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        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 <code class="literal">NULL</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.3.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_last_wal_replay_lsn</code> ()
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        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 <code class="literal">NULL</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.3.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">pg_last_xact_replay_timestamp</code> ()
        → <code class="returnvalue">timestamp with time zone</code>
       </p>
       <p>
        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 <code class="literal">NULL</code>.  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 <code class="literal">NULL</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.3.2.2.5.1.1.1" class="indexterm"></a>
        <code class="function">pg_get_wal_resource_managers</code> ()
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>rm_id</code></em> <code class="type">integer</code>,
        <em class="parameter"><code>rm_name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>rm_builtin</code></em> <code class="type">boolean</code> )
       </p>
       <p>
        Returns the currently-loaded WAL resource managers in the system. The
        column <em class="parameter"><code>rm_builtin</code></em> indicates whether it's a
        built-in resource manager, or a custom resource manager loaded by an
        extension.
       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
    The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-RECOVERY-CONTROL-TABLE" title="Table 9.93. Recovery Control Functions">Table 9.93</a> control the progress of recovery.
    These functions may be executed only during recovery.
   </p><div class="table" id="FUNCTIONS-RECOVERY-CONTROL-TABLE"><p class="title"><strong>Table 9.93. Recovery Control Functions</strong></p><div class="table-contents"><table class="table" summary="Recovery Control Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.5.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_is_wal_replay_paused</code> ()
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Returns true if recovery pause is requested.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.5.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_get_wal_replay_pause_state</code> ()
        → <code class="returnvalue">text</code>
       </p>
       <p>
        Returns recovery pause state.  The return values are <code class="literal">
        not paused</code> if pause is not requested, <code class="literal">
        pause requested</code> if pause is requested but recovery is
        not yet paused, and <code class="literal">paused</code> if the recovery is
        actually paused.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.5.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_promote</code> ( <em class="parameter"><code>wait</code></em> <code class="type">boolean</code> <code class="literal">DEFAULT</code> <code class="literal">true</code>, <em class="parameter"><code>wait_seconds</code></em> <code class="type">integer</code> <code class="literal">DEFAULT</code> <code class="literal">60</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Promotes a standby server to primary status.
        With <em class="parameter"><code>wait</code></em> set to <code class="literal">true</code> (the
        default), the function waits until promotion is completed
        or <em class="parameter"><code>wait_seconds</code></em> seconds have passed, and
        returns <code class="literal">true</code> if promotion is successful
        and <code class="literal">false</code> otherwise.
        If <em class="parameter"><code>wait</code></em> is set to <code class="literal">false</code>, the
        function returns <code class="literal">true</code> immediately after sending a
        <code class="literal">SIGUSR1</code> signal to the postmaster to trigger
        promotion.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.5.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">pg_wal_replay_pause</code> ()
        → <code class="returnvalue">void</code>
       </p>
       <p>
        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
        <code class="function">pg_get_wal_replay_pause_state()</code>.  Note that
        <code class="function">pg_is_wal_replay_paused()</code> 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.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.6.5.2.2.5.1.1.1" class="indexterm"></a>
        <code class="function">pg_wal_replay_resume</code> ()
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Restarts recovery if it was paused.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
    <code class="function">pg_wal_replay_pause</code> and
    <code class="function">pg_wal_replay_resume</code> cannot be executed while
    a promotion is ongoing. If a promotion is triggered while recovery
    is paused, the paused state ends and promotion continues.
   </p><p>
    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.
   </p></div><div class="sect2" id="FUNCTIONS-SNAPSHOT-SYNCHRONIZATION"><div class="titlepage"><div><div><h3 class="title">9.27.5. Snapshot Synchronization Functions <a href="#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION" class="id_link">#</a></h3></div></div></div><p>
    <span class="productname">PostgreSQL</span> allows database sessions to synchronize their
    snapshots. A <em class="firstterm">snapshot</em> 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 <code class="command">START TRANSACTION</code> commands,
    so that one session sees the effects of that transaction and the other
    does not.
   </p><p>
    To solve this problem, <span class="productname">PostgreSQL</span> allows a transaction to
    <em class="firstterm">export</em> the snapshot it is using.  As long as the exporting
    transaction remains open, other transactions can <em class="firstterm">import</em> 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.
   </p><p>
    Snapshots are exported with the <code class="function">pg_export_snapshot</code> function,
    shown in <a class="xref" href="functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION-TABLE" title="Table 9.94. Snapshot Synchronization Functions">Table 9.94</a>, and
    imported with the <a class="xref" href="sql-set-transaction.html" title="SET TRANSACTION"><span class="refentrytitle">SET TRANSACTION</span></a> command.
   </p><div class="table" id="FUNCTIONS-SNAPSHOT-SYNCHRONIZATION-TABLE"><p class="title"><strong>Table 9.94. Snapshot Synchronization Functions</strong></p><div class="table-contents"><table class="table" summary="Snapshot Synchronization Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.7.5.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_export_snapshot</code> ()
        → <code class="returnvalue">text</code>
       </p>
       <p>
        Saves the transaction's current snapshot and returns
        a <code class="type">text</code> 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.
       </p>
       <p>
        A transaction can export more than one snapshot, if needed.  Note that
        doing so is only useful in <code class="literal">READ COMMITTED</code>
        transactions, since in <code class="literal">REPEATABLE READ</code> and higher
        isolation levels, transactions use the same snapshot throughout their
        lifetime.  Once a transaction has exported any snapshots, it cannot be
        prepared with <a class="xref" href="sql-prepare-transaction.html" title="PREPARE TRANSACTION"><span class="refentrytitle">PREPARE TRANSACTION</span></a>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.7.5.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_log_standby_snapshot</code> ()
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        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.
       </p></td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="FUNCTIONS-REPLICATION"><div class="titlepage"><div><div><h3 class="title">9.27.6. Replication Management Functions <a href="#FUNCTIONS-REPLICATION" class="id_link">#</a></h3></div></div></div><p>
    The functions shown
    in <a class="xref" href="functions-admin.html#FUNCTIONS-REPLICATION-TABLE" title="Table 9.95. Replication Management Functions">Table 9.95</a> are for
    controlling and interacting with replication features.
    See <a class="xref" href="warm-standby.html#STREAMING-REPLICATION" title="27.2.5. Streaming Replication">Section 27.2.5</a>,
    <a class="xref" href="warm-standby.html#STREAMING-REPLICATION-SLOTS" title="27.2.6. Replication Slots">Section 27.2.6</a>, and
    <a class="xref" href="replication-origins.html" title="Chapter 50. Replication Progress Tracking">Chapter 50</a>
    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
    <code class="literal">GRANT</code> command.
    Use of functions for replication slots is restricted to superusers
    and users having <code class="literal">REPLICATION</code> privilege.
   </p><p>
    Many of these functions have equivalent commands in the replication
    protocol; see <a class="xref" href="protocol-replication.html" title="55.4. Streaming Replication Protocol">Section 55.4</a>.
   </p><p>
    The functions described in
    <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-BACKUP" title="9.27.3. Backup Control Functions">Section 9.27.3</a>,
    <a class="xref" href="functions-admin.html#FUNCTIONS-RECOVERY-CONTROL" title="9.27.4. Recovery Control Functions">Section 9.27.4</a>, and
    <a class="xref" href="functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION" title="9.27.5. Snapshot Synchronization Functions">Section 9.27.5</a>
    are also relevant for replication.
   </p><div class="table" id="FUNCTIONS-REPLICATION-TABLE"><p class="title"><strong>Table 9.95. Replication Management Functions</strong></p><div class="table-contents"><table class="table" summary="Replication Management Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_create_physical_replication_slot</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code> [<span class="optional">, <em class="parameter"><code>immediately_reserve</code></em> <code class="type">boolean</code>, <em class="parameter"><code>temporary</code></em> <code class="type">boolean</code> </span>] )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>,
        <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code> )
       </p>
       <p>
        Creates a new physical replication slot named
        <em class="parameter"><code>slot_name</code></em>. The optional second parameter,
        when <code class="literal">true</code>, specifies that the <acronym class="acronym">LSN</acronym> for this
        replication slot be reserved immediately; otherwise
        the <acronym class="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 <a class="xref" href="protocol-replication.html" title="55.4. Streaming Replication Protocol">Section 55.4</a>. The optional third
        parameter, <em class="parameter"><code>temporary</code></em>, 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 <code class="literal">CREATE_REPLICATION_SLOT
        ... PHYSICAL</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_drop_replication_slot</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Drops the physical or logical replication slot
        named <em class="parameter"><code>slot_name</code></em>. Same as replication protocol
        command <code class="literal">DROP_REPLICATION_SLOT</code>. For logical slots, this must
        be called while connected to the same database the slot was created on.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_create_logical_replication_slot</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>plugin</code></em> <code class="type">name</code> [<span class="optional">, <em class="parameter"><code>temporary</code></em> <code class="type">boolean</code>, <em class="parameter"><code>twophase</code></em> <code class="type">boolean</code> </span>] )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>,
        <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code> )
       </p>
       <p>
        Creates a new logical (decoding) replication slot named
        <em class="parameter"><code>slot_name</code></em> using the output plugin
        <em class="parameter"><code>plugin</code></em>. The optional third
        parameter, <em class="parameter"><code>temporary</code></em>, 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,
        <em class="parameter"><code>twophase</code></em>, when set to true, specifies
        that the decoding of prepared transactions is enabled for this
        slot. A call to this function has the same effect as the replication
        protocol command <code class="literal">CREATE_REPLICATION_SLOT ... LOGICAL</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">pg_copy_physical_replication_slot</code> ( <em class="parameter"><code>src_slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>dst_slot_name</code></em> <code class="type">name</code> [<span class="optional">, <em class="parameter"><code>temporary</code></em> <code class="type">boolean</code> </span>] )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>,
        <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code> )
       </p>
       <p>
        Copies an existing physical replication slot named <em class="parameter"><code>src_slot_name</code></em>
        to a physical replication slot named <em class="parameter"><code>dst_slot_name</code></em>.
        The copied physical slot starts to reserve WAL from the same <acronym class="acronym">LSN</acronym> as the
        source slot.
        <em class="parameter"><code>temporary</code></em> is optional. If <em class="parameter"><code>temporary</code></em>
        is omitted, the same value as the source slot is used.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.5.1.1.1" class="indexterm"></a>
        <code class="function">pg_copy_logical_replication_slot</code> ( <em class="parameter"><code>src_slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>dst_slot_name</code></em> <code class="type">name</code> [<span class="optional">, <em class="parameter"><code>temporary</code></em> <code class="type">boolean</code> [<span class="optional">, <em class="parameter"><code>plugin</code></em> <code class="type">name</code> </span>]</span>] )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>,
        <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code> )
       </p>
       <p>
        Copies an existing logical replication slot
        named <em class="parameter"><code>src_slot_name</code></em> to a logical replication
        slot named <em class="parameter"><code>dst_slot_name</code></em>, optionally changing
        the output plugin and persistence.  The copied logical slot starts
        from the same <acronym class="acronym">LSN</acronym> as the source logical slot.  Both
        <em class="parameter"><code>temporary</code></em> and <em class="parameter"><code>plugin</code></em> are
        optional; if they are omitted, the values of the source slot are used.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.6.1.1.1" class="indexterm"></a>
        <code class="function">pg_logical_slot_get_changes</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>upto_nchanges</code></em> <code class="type">integer</code>, <code class="literal">VARIADIC</code> <em class="parameter"><code>options</code></em> <code class="type">text[]</code> )
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>,
        <em class="parameter"><code>xid</code></em> <code class="type">xid</code>,
        <em class="parameter"><code>data</code></em> <code class="type">text</code> )
       </p>
       <p>
        Returns changes in the slot <em class="parameter"><code>slot_name</code></em>, starting
        from the point from which changes have been consumed last.  If
        <em class="parameter"><code>upto_lsn</code></em>
        and <em class="parameter"><code>upto_nchanges</code></em> are NULL,
        logical decoding will continue until end of WAL.  If
        <em class="parameter"><code>upto_lsn</code></em> is non-NULL, decoding will include only
        those transactions which commit prior to the specified LSN.  If
        <em class="parameter"><code>upto_nchanges</code></em> 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.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.7.1.1.1" class="indexterm"></a>
        <code class="function">pg_logical_slot_peek_changes</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>upto_nchanges</code></em> <code class="type">integer</code>, <code class="literal">VARIADIC</code> <em class="parameter"><code>options</code></em> <code class="type">text[]</code> )
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>,
        <em class="parameter"><code>xid</code></em> <code class="type">xid</code>,
         <em class="parameter"><code>data</code></em> <code class="type">text</code> )
       </p>
       <p>
        Behaves just like
        the <code class="function">pg_logical_slot_get_changes()</code> function,
        except that changes are not consumed; that is, they will be returned
        again on future calls.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.8.1.1.1" class="indexterm"></a>
        <code class="function">pg_logical_slot_get_binary_changes</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>upto_nchanges</code></em> <code class="type">integer</code>, <code class="literal">VARIADIC</code> <em class="parameter"><code>options</code></em> <code class="type">text[]</code> )
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>,
        <em class="parameter"><code>xid</code></em> <code class="type">xid</code>,
        <em class="parameter"><code>data</code></em> <code class="type">bytea</code> )
       </p>
       <p>
        Behaves just like
        the <code class="function">pg_logical_slot_get_changes()</code> function,
        except that changes are returned as <code class="type">bytea</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.9.1.1.1" class="indexterm"></a>
        <code class="function">pg_logical_slot_peek_binary_changes</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>upto_nchanges</code></em> <code class="type">integer</code>, <code class="literal">VARIADIC</code> <em class="parameter"><code>options</code></em> <code class="type">text[]</code> )
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>,
        <em class="parameter"><code>xid</code></em> <code class="type">xid</code>,
        <em class="parameter"><code>data</code></em> <code class="type">bytea</code> )
       </p>
       <p>
        Behaves just like
        the <code class="function">pg_logical_slot_peek_changes()</code> function,
        except that changes are returned as <code class="type">bytea</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.10.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_slot_advance</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code> )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>slot_name</code></em> <code class="type">name</code>,
        <em class="parameter"><code>end_lsn</code></em> <code class="type">pg_lsn</code> )
       </p>
       <p>
        Advances the current confirmed position of a replication slot named
        <em class="parameter"><code>slot_name</code></em>. 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.
       </p></td></tr><tr><td id="PG-REPLICATION-ORIGIN-CREATE" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.11.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_create</code> ( <em class="parameter"><code>node_name</code></em> <code class="type">text</code> )
        → <code class="returnvalue">oid</code>
       </p>
       <p>
        Creates a replication origin with the given external
        name, and returns the internal ID assigned to it.
       </p></td></tr><tr><td id="PG-REPLICATION-ORIGIN-DROP" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.12.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_drop</code> ( <em class="parameter"><code>node_name</code></em> <code class="type">text</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Deletes a previously-created replication origin, including any
        associated replay progress.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.13.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_oid</code> ( <em class="parameter"><code>node_name</code></em> <code class="type">text</code> )
        → <code class="returnvalue">oid</code>
       </p>
       <p>
        Looks up a replication origin by name and returns the internal ID. If
        no such replication origin is found, <code class="literal">NULL</code> is
        returned.
       </p></td></tr><tr><td id="PG-REPLICATION-ORIGIN-SESSION-SETUP" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.14.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_session_setup</code> ( <em class="parameter"><code>node_name</code></em> <code class="type">text</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        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 <code class="function">pg_replication_origin_session_reset</code> to undo.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.15.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_session_reset</code> ()
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Cancels the effects
        of <code class="function">pg_replication_origin_session_setup()</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.16.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_session_is_setup</code> ()
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Returns true if a replication origin has been selected in the
        current session.
       </p></td></tr><tr><td id="PG-REPLICATION-ORIGIN-SESSION-PROGRESS" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.17.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_session_progress</code> ( <em class="parameter"><code>flush</code></em> <code class="type">boolean</code> )
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        Returns the replay location for the replication origin selected in
        the current session. The parameter <em class="parameter"><code>flush</code></em>
        determines whether the corresponding local transaction will be
        guaranteed to have been flushed to disk or not.
       </p></td></tr><tr><td id="PG-REPLICATION-ORIGIN-XACT-SETUP" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.18.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_xact_setup</code> ( <em class="parameter"><code>origin_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>origin_timestamp</code></em> <code class="type">timestamp with time zone</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Marks the current transaction as replaying a transaction that has
        committed at the given <acronym class="acronym">LSN</acronym> and timestamp. Can
        only be called when a replication origin has been selected
        using <code class="function">pg_replication_origin_session_setup</code>.
       </p></td></tr><tr><td id="PG-REPLICATION-ORIGIN-XACT-RESET" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.19.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_xact_reset</code> ()
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Cancels the effects of
        <code class="function">pg_replication_origin_xact_setup()</code>.
       </p></td></tr><tr><td id="PG-REPLICATION-ORIGIN-ADVANCE" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.20.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_advance</code> ( <em class="parameter"><code>node_name</code></em> <code class="type">text</code>, <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        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.
       </p></td></tr><tr><td id="PG-REPLICATION-ORIGIN-PROGRESS" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.21.1.1.1" class="indexterm"></a>
        <code class="function">pg_replication_origin_progress</code> ( <em class="parameter"><code>node_name</code></em> <code class="type">text</code>, <em class="parameter"><code>flush</code></em> <code class="type">boolean</code> )
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        Returns the replay location for the given replication origin. The
        parameter <em class="parameter"><code>flush</code></em> determines whether the
        corresponding local transaction will be guaranteed to have been
        flushed to disk or not.
       </p></td></tr><tr><td id="PG-LOGICAL-EMIT-MESSAGE" class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.8.5.2.2.22.1.1.1" class="indexterm"></a>
        <code class="function">pg_logical_emit_message</code> ( <em class="parameter"><code>transactional</code></em> <code class="type">boolean</code>, <em class="parameter"><code>prefix</code></em> <code class="type">text</code>, <em class="parameter"><code>content</code></em> <code class="type">text</code> )
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_logical_emit_message</code> ( <em class="parameter"><code>transactional</code></em> <code class="type">boolean</code>, <em class="parameter"><code>prefix</code></em> <code class="type">text</code>, <em class="parameter"><code>content</code></em> <code class="type">bytea</code> )
        → <code class="returnvalue">pg_lsn</code>
       </p>
       <p>
        Emits a logical decoding message. This can be used to pass generic
        messages to logical decoding plugins through
        WAL. The <em class="parameter"><code>transactional</code></em> 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 <em class="parameter"><code>prefix</code></em> parameter is a
        textual prefix that can be used by logical decoding plugins to easily
        recognize messages that are interesting for them.
        The <em class="parameter"><code>content</code></em> parameter is the content of the
        message, given either in text or binary form.
       </p></td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="FUNCTIONS-ADMIN-DBOBJECT"><div class="titlepage"><div><div><h3 class="title">9.27.7. Database Object Management Functions <a href="#FUNCTIONS-ADMIN-DBOBJECT" class="id_link">#</a></h3></div></div></div><p>
    The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-DBSIZE" title="Table 9.96. Database Object Size Functions">Table 9.96</a> calculate
    the disk space usage of database objects, or assist in presentation
    or understanding of usage results.  <code class="literal">bigint</code> results
    are measured in bytes.  If an OID that does
    not represent an existing object is passed to one of these
    functions, <code class="literal">NULL</code> is returned.
   </p><div class="table" id="FUNCTIONS-ADMIN-DBSIZE"><p class="title"><strong>Table 9.96. Database Object Size Functions</strong></p><div class="table-contents"><table class="table" summary="Database Object Size Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_column_size</code> ( <code class="type">"any"</code> )
        → <code class="returnvalue">integer</code>
       </p>
       <p>
        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.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_column_compression</code> ( <code class="type">"any"</code> )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        Shows the compression algorithm that was used to compress
        an individual variable-length value. Returns <code class="literal">NULL</code>
        if the value is not compressed.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_database_size</code> ( <code class="type">name</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_database_size</code> ( <code class="type">oid</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p>
        Computes the total disk space used by the database with the specified
        name or OID.  To use this function, you must
        have <code class="literal">CONNECT</code> privilege on the specified database
        (which is granted by default) or have privileges of
        the <code class="literal">pg_read_all_stats</code> role.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">pg_indexes_size</code> ( <code class="type">regclass</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p>
        Computes the total disk space used by indexes attached to the
        specified table.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.5.1.1.1" class="indexterm"></a>
        <code class="function">pg_relation_size</code> ( <em class="parameter"><code>relation</code></em> <code class="type">regclass</code> [<span class="optional">, <em class="parameter"><code>fork</code></em> <code class="type">text</code> </span>] )
        → <code class="returnvalue">bigint</code>
       </p>
       <p>
        Computes the disk space used by one <span class="quote"><span class="quote">fork</span></span> of the
        specified relation.  (Note that for most purposes it is more
        convenient to use the higher-level
        functions <code class="function">pg_total_relation_size</code>
        or <code class="function">pg_table_size</code>, 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:
        </p><div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; "><li class="listitem"><p>
           <code class="literal">main</code> returns the size of the main
           data fork of the relation.
          </p></li><li class="listitem"><p>
           <code class="literal">fsm</code> returns the size of the Free Space Map
           (see <a class="xref" href="storage-fsm.html" title="73.3. Free Space Map">Section 73.3</a>) associated with the relation.
          </p></li><li class="listitem"><p>
           <code class="literal">vm</code> returns the size of the Visibility Map
           (see <a class="xref" href="storage-vm.html" title="73.4. Visibility Map">Section 73.4</a>) associated with the relation.
          </p></li><li class="listitem"><p>
           <code class="literal">init</code> returns the size of the initialization
           fork, if any, associated with the relation.
          </p></li></ul></div><p>
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.6.1.1.1" class="indexterm"></a>
        <code class="function">pg_size_bytes</code> ( <code class="type">text</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p>
        Converts a size in human-readable format (as returned
        by <code class="function">pg_size_pretty</code>) into bytes.  Valid units are
        <code class="literal">bytes</code>, <code class="literal">B</code>, <code class="literal">kB</code>,
        <code class="literal">MB</code>, <code class="literal">GB</code>, <code class="literal">TB</code>,
        and <code class="literal">PB</code>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.7.1.1.1" class="indexterm"></a>
        <code class="function">pg_size_pretty</code> ( <code class="type">bigint</code> )
        → <code class="returnvalue">text</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_size_pretty</code> ( <code class="type">numeric</code> )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        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<sup>2</sup> = 1048576 bytes, and so on.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.8.1.1.1" class="indexterm"></a>
        <code class="function">pg_table_size</code> ( <code class="type">regclass</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p>
        Computes the disk space used by the specified table, excluding indexes
        (but including its TOAST table if any, free space map, and visibility
        map).
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.9.1.1.1" class="indexterm"></a>
        <code class="function">pg_tablespace_size</code> ( <code class="type">name</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_tablespace_size</code> ( <code class="type">oid</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p>
        Computes the total disk space used in the tablespace with the
        specified name or OID. To use this function, you must
        have <code class="literal">CREATE</code> privilege on the specified tablespace
        or have privileges of the <code class="literal">pg_read_all_stats</code> role,
        unless it is the default tablespace for the current database.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.3.2.2.10.1.1.1" class="indexterm"></a>
        <code class="function">pg_total_relation_size</code> ( <code class="type">regclass</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p>
        Computes the total disk space used by the specified table, including
        all indexes and <acronym class="acronym">TOAST</acronym> data.  The result is
        equivalent to <code class="function">pg_table_size</code>
        <code class="literal">+</code> <code class="function">pg_indexes_size</code>.
       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
    The functions above that operate on tables or indexes accept a
    <code class="type">regclass</code> argument, which is simply the OID of the table or index
    in the <code class="structname">pg_class</code> system catalog.  You do not have to look up
    the OID by hand, however, since the <code class="type">regclass</code> data type's input
    converter will do the work for you.  See <a class="xref" href="datatype-oid.html" title="8.19. Object Identifier Types">Section 8.19</a>
    for details.
   </p><p>
    The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-DBLOCATION" title="Table 9.97. Database Object Location Functions">Table 9.97</a> assist
    in identifying the specific disk files associated with database objects.
   </p><div class="table" id="FUNCTIONS-ADMIN-DBLOCATION"><p class="title"><strong>Table 9.97. Database Object Location Functions</strong></p><div class="table-contents"><table class="table" summary="Database Object Location Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.6.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_relation_filenode</code> ( <em class="parameter"><code>relation</code></em> <code class="type">regclass</code> )
        → <code class="returnvalue">oid</code>
       </p>
       <p>
        Returns the <span class="quote"><span class="quote">filenode</span></span> number currently assigned to the
        specified relation.  The filenode is the base component of the file
        name(s) used for the relation (see
        <a class="xref" href="storage-file-layout.html" title="73.1. Database File Layout">Section 73.1</a> for more information).
        For most relations the result is the same as
        <code class="structname">pg_class</code>.<code class="structfield">relfilenode</code>,
        but for certain system catalogs <code class="structfield">relfilenode</code>
        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.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.6.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_relation_filepath</code> ( <em class="parameter"><code>relation</code></em> <code class="type">regclass</code> )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        Returns the entire file path name (relative to the database cluster's
        data directory, <code class="varname">PGDATA</code>) of the relation.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.6.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_filenode_relation</code> ( <em class="parameter"><code>tablespace</code></em> <code class="type">oid</code>, <em class="parameter"><code>filenode</code></em> <code class="type">oid</code> )
        → <code class="returnvalue">regclass</code>
       </p>
       <p>
        Returns a relation's OID given the tablespace OID and filenode it is
        stored under.  This is essentially the inverse mapping of
        <code class="function">pg_relation_filepath</code>.  For a relation in the
        database's default tablespace, the tablespace can be specified as zero.
        Returns <code class="literal">NULL</code> if no relation in the current database
        is associated with the given values.
       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
    <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-COLLATION" title="Table 9.98. Collation Management Functions">Table 9.98</a> lists functions used to manage
    collations.
   </p><div class="table" id="FUNCTIONS-ADMIN-COLLATION"><p class="title"><strong>Table 9.98. Collation Management Functions</strong></p><div class="table-contents"><table class="table" summary="Collation Management Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.8.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_collation_actual_version</code> ( <code class="type">oid</code> )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        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
        <code class="structname">pg_collation</code>.<code class="structfield">collversion</code>,
        then objects depending on the collation might need to be rebuilt.  See
        also <a class="xref" href="sql-altercollation.html" title="ALTER COLLATION"><span class="refentrytitle">ALTER COLLATION</span></a>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.8.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_database_collation_actual_version</code> ( <code class="type">oid</code> )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        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
        <code class="structname">pg_database</code>.<code class="structfield">datcollversion</code>,
        then objects depending on the collation might need to be rebuilt.  See
        also <a class="xref" href="sql-alterdatabase.html" title="ALTER DATABASE"><span class="refentrytitle">ALTER DATABASE</span></a>.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.8.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_import_system_collations</code> ( <em class="parameter"><code>schema</code></em> <code class="type">regnamespace</code> )
        → <code class="returnvalue">integer</code>
       </p>
       <p>
        Adds collations to the system
        catalog <code class="structname">pg_collation</code> based on all the locales
        it finds in the operating system.  This is
        what <code class="command">initdb</code> uses; see
        <a class="xref" href="collation.html#COLLATION-MANAGING" title="24.2.2. Managing Collations">Section 24.2.2</a> 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 <code class="structname">pg_collation</code> 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 <em class="parameter"><code>schema</code></em> parameter would typically
        be <code class="literal">pg_catalog</code>, 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.
       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
    <a class="xref" href="functions-admin.html#FUNCTIONS-INFO-PARTITION" title="Table 9.99. Partitioning Information Functions">Table 9.99</a> lists functions that provide
    information about the structure of partitioned tables.
   </p><div class="table" id="FUNCTIONS-INFO-PARTITION"><p class="title"><strong>Table 9.99. Partitioning Information Functions</strong></p><div class="table-contents"><table class="table" summary="Partitioning Information Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.10.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_partition_tree</code> ( <code class="type">regclass</code> )
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>relid</code></em> <code class="type">regclass</code>,
        <em class="parameter"><code>parentrelid</code></em> <code class="type">regclass</code>,
        <em class="parameter"><code>isleaf</code></em> <code class="type">boolean</code>,
        <em class="parameter"><code>level</code></em> <code class="type">integer</code> )
       </p>
       <p>
        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.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.10.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_partition_ancestors</code> ( <code class="type">regclass</code> )
        → <code class="returnvalue">setof regclass</code>
       </p>
       <p>
        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.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.9.10.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_partition_root</code> ( <code class="type">regclass</code> )
        → <code class="returnvalue">regclass</code>
       </p>
       <p>
        Returns the top-most parent of the partition tree to which the given
        relation belongs.  Returns <code class="literal">NULL</code> if the relation
        does not exist or is not a partition or partitioned table.
       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
    For example, to check the total size of the data contained in a
    partitioned table <code class="structname">measurement</code>, one could use the
    following query:
</p><pre class="programlisting">
SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size
  FROM pg_partition_tree('measurement');
</pre><p>
   </p></div><div class="sect2" id="FUNCTIONS-ADMIN-INDEX"><div class="titlepage"><div><div><h3 class="title">9.27.8. Index Maintenance Functions <a href="#FUNCTIONS-ADMIN-INDEX" class="id_link">#</a></h3></div></div></div><p>
    <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-INDEX-TABLE" title="Table 9.100. Index Maintenance Functions">Table 9.100</a> 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.
   </p><div class="table" id="FUNCTIONS-ADMIN-INDEX-TABLE"><p class="title"><strong>Table 9.100. Index Maintenance Functions</strong></p><div class="table-contents"><table class="table" summary="Index Maintenance Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.10.3.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">brin_summarize_new_values</code> ( <em class="parameter"><code>index</code></em> <code class="type">regclass</code> )
        → <code class="returnvalue">integer</code>
       </p>
       <p>
        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.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.10.3.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">brin_summarize_range</code> ( <em class="parameter"><code>index</code></em> <code class="type">regclass</code>, <em class="parameter"><code>blockNumber</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">integer</code>
       </p>
       <p>
        Summarizes the page range covering the given block, if not already
        summarized.  This is
        like <code class="function">brin_summarize_new_values</code> except that it
        only processes the page range that covers the given table block number.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.10.3.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">brin_desummarize_range</code> ( <em class="parameter"><code>index</code></em> <code class="type">regclass</code>, <em class="parameter"><code>blockNumber</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Removes the BRIN index tuple that summarizes the page range covering
        the given table block, if there is one.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.10.3.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">gin_clean_pending_list</code> ( <em class="parameter"><code>index</code></em> <code class="type">regclass</code> )
        → <code class="returnvalue">bigint</code>
       </p>
       <p>
        Cleans up the <span class="quote"><span class="quote">pending</span></span> 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 <code class="literal">fastupdate</code> option disabled, no cleanup happens
        and the result is zero, because the index doesn't have a pending list.
        See <a class="xref" href="gin-implementation.html#GIN-FAST-UPDATE" title="70.4.1. GIN Fast Update Technique">Section 70.4.1</a> and <a class="xref" href="gin-tips.html" title="70.5. GIN Tips and Tricks">Section 70.5</a>
        for details about the pending list and <code class="literal">fastupdate</code>
        option.
       </p></td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="FUNCTIONS-ADMIN-GENFILE"><div class="titlepage"><div><div><h3 class="title">9.27.9. Generic File Access Functions <a href="#FUNCTIONS-ADMIN-GENFILE" class="id_link">#</a></h3></div></div></div><p>
    The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-GENFILE-TABLE" title="Table 9.101. Generic File Access Functions">Table 9.101</a> provide native access to
    files on the machine hosting the server. Only files within the
    database cluster directory and the <code class="varname">log_directory</code> can be
    accessed, unless the user is a superuser or is granted the role
    <code class="literal">pg_read_server_files</code>.  Use a relative path for files in
    the cluster directory, and a path matching the <code class="varname">log_directory</code>
    configuration setting for log files.
   </p><p>
    Note that granting users the EXECUTE privilege on
    <code class="function">pg_read_file()</code>, 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 <code class="structname">pg_authid</code> 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.
   </p><p>
    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.  <span class="application">psql</span>'s <code class="command">\df</code> command
    can be useful to check what the actual function signatures are.
   </p><p>
    Some of these functions take an optional <em class="parameter"><code>missing_ok</code></em>
    parameter, which specifies the behavior when the file or directory does
    not exist.  If <code class="literal">true</code>, the function
    returns <code class="literal">NULL</code> or an empty result set, as appropriate.
    If <code class="literal">false</code>, an error is raised.  (Failure conditions
    other than <span class="quote"><span class="quote">file not found</span></span> are reported as errors in any
    case.)  The default is <code class="literal">false</code>.
   </p><div class="table" id="FUNCTIONS-ADMIN-GENFILE-TABLE"><p class="title"><strong>Table 9.101. Generic File Access Functions</strong></p><div class="table-contents"><table class="table" summary="Generic File Access Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_ls_dir</code> ( <em class="parameter"><code>dirname</code></em> <code class="type">text</code> [<span class="optional">, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code>, <em class="parameter"><code>include_dot_dirs</code></em> <code class="type">boolean</code> </span>] )
        → <code class="returnvalue">setof text</code>
       </p>
       <p>
        Returns the names of all files (and directories and other special
        files) in the specified
        directory. The <em class="parameter"><code>include_dot_dirs</code></em> parameter
        indicates whether <span class="quote"><span class="quote">.</span></span> and <span class="quote"><span class="quote">..</span></span> are to be
        included in the result set; the default is to exclude them.  Including
        them can be useful when <em class="parameter"><code>missing_ok</code></em>
        is <code class="literal">true</code>, to distinguish an empty directory from a
        non-existent directory.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_ls_logdir</code> ()
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>size</code></em> <code class="type">bigint</code>,
        <em class="parameter"><code>modification</code></em> <code class="type">timestamp with time zone</code> )
       </p>
       <p>
        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.
       </p>
       <p>
        This function is restricted to superusers and roles with privileges of
        the <code class="literal">pg_monitor</code> role by default, but other users can
        be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_ls_waldir</code> ()
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>size</code></em> <code class="type">bigint</code>,
        <em class="parameter"><code>modification</code></em> <code class="type">timestamp with time zone</code> )
       </p>
       <p>
        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.
       </p>
       <p>
        This function is restricted to superusers and roles with privileges of
        the <code class="literal">pg_monitor</code> role by default, but other users can
        be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">pg_ls_logicalmapdir</code> ()
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>size</code></em> <code class="type">bigint</code>,
        <em class="parameter"><code>modification</code></em> <code class="type">timestamp with time zone</code> )
       </p>
       <p>
        Returns the name, size, and last modification time (mtime) of each
        ordinary file in the server's <code class="filename">pg_logical/mappings</code>
        directory. Filenames beginning with a dot, directories, and other
        special files are excluded.
       </p>
       <p>
        This function is restricted to superusers and members of
        the <code class="literal">pg_monitor</code> role by default, but other users can
        be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.5.1.1.1" class="indexterm"></a>
        <code class="function">pg_ls_logicalsnapdir</code> ()
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>size</code></em> <code class="type">bigint</code>,
        <em class="parameter"><code>modification</code></em> <code class="type">timestamp with time zone</code> )
       </p>
       <p>
        Returns the name, size, and last modification time (mtime) of each
        ordinary file in the server's <code class="filename">pg_logical/snapshots</code>
        directory. Filenames beginning with a dot, directories, and other
        special files are excluded.
       </p>
       <p>
        This function is restricted to superusers and members of
        the <code class="literal">pg_monitor</code> role by default, but other users can
        be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.6.1.1.1" class="indexterm"></a>
        <code class="function">pg_ls_replslotdir</code> ( <em class="parameter"><code>slot_name</code></em> <code class="type">text</code> )
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>size</code></em> <code class="type">bigint</code>,
        <em class="parameter"><code>modification</code></em> <code class="type">timestamp with time zone</code> )
       </p>
       <p>
        Returns the name, size, and last modification time (mtime) of each
        ordinary file in the server's <code class="filename">pg_replslot/slot_name</code>
        directory, where <em class="parameter"><code>slot_name</code></em> 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.
       </p>
       <p>
        This function is restricted to superusers and members of
        the <code class="literal">pg_monitor</code> role by default, but other users can
        be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.7.1.1.1" class="indexterm"></a>
        <code class="function">pg_ls_archive_statusdir</code> ()
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>size</code></em> <code class="type">bigint</code>,
        <em class="parameter"><code>modification</code></em> <code class="type">timestamp with time zone</code> )
       </p>
       <p>
        Returns the name, size, and last modification time (mtime) of each
        ordinary file in the server's WAL archive status directory
        (<code class="filename">pg_wal/archive_status</code>).  Filenames beginning
        with a dot, directories, and other special files are excluded.
       </p>
       <p>
        This function is restricted to superusers and members of
        the <code class="literal">pg_monitor</code> role by default, but other users can
        be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">

        <a id="id-1.5.8.33.11.6.2.2.8.1.1.1" class="indexterm"></a>
        <code class="function">pg_ls_tmpdir</code> ( [<span class="optional"> <em class="parameter"><code>tablespace</code></em> <code class="type">oid</code> </span>] )
        → <code class="returnvalue">setof record</code>
        ( <em class="parameter"><code>name</code></em> <code class="type">text</code>,
        <em class="parameter"><code>size</code></em> <code class="type">bigint</code>,
        <em class="parameter"><code>modification</code></em> <code class="type">timestamp with time zone</code> )
       </p>
       <p>
        Returns the name, size, and last modification time (mtime) of each
        ordinary file in the temporary file directory for the
        specified <em class="parameter"><code>tablespace</code></em>.
        If <em class="parameter"><code>tablespace</code></em> is not provided,
        the <code class="literal">pg_default</code> tablespace is examined.  Filenames
        beginning with a dot, directories, and other special files are
        excluded.
       </p>
       <p>
        This function is restricted to superusers and members of
        the <code class="literal">pg_monitor</code> role by default, but other users can
        be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.9.1.1.1" class="indexterm"></a>
        <code class="function">pg_read_file</code> ( <em class="parameter"><code>filename</code></em> <code class="type">text</code> [<span class="optional">, <em class="parameter"><code>offset</code></em> <code class="type">bigint</code>, <em class="parameter"><code>length</code></em> <code class="type">bigint</code> </span>] [<span class="optional">, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code> </span>] )
        → <code class="returnvalue">text</code>
       </p>
       <p>
        Returns all or part of a text file, starting at the
        given byte <em class="parameter"><code>offset</code></em>, returning at
        most <em class="parameter"><code>length</code></em> bytes (less if the end of file is
        reached first).  If <em class="parameter"><code>offset</code></em> is negative, it is
        relative to the end of the file.  If <em class="parameter"><code>offset</code></em>
        and <em class="parameter"><code>length</code></em> 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.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.10.1.1.1" class="indexterm"></a>
        <code class="function">pg_read_binary_file</code> ( <em class="parameter"><code>filename</code></em> <code class="type">text</code> [<span class="optional">, <em class="parameter"><code>offset</code></em> <code class="type">bigint</code>, <em class="parameter"><code>length</code></em> <code class="type">bigint</code> </span>] [<span class="optional">, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code> </span>] )
        → <code class="returnvalue">bytea</code>
       </p>
       <p>
        Returns all or part of a file.  This function is identical to
        <code class="function">pg_read_file</code> except that it can read arbitrary
        binary data, returning the result as <code class="type">bytea</code>
        not <code class="type">text</code>; accordingly, no encoding checks are performed.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p>
       <p>
        In combination with the <code class="function">convert_from</code> function,
        this function can be used to read a text file in a specified encoding
        and convert to the database's encoding:
</p><pre class="programlisting">
SELECT convert_from(pg_read_binary_file('file_in_utf8.txt'), 'UTF8');
</pre><p>
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.11.6.2.2.11.1.1.1" class="indexterm"></a>
        <code class="function">pg_stat_file</code> ( <em class="parameter"><code>filename</code></em> <code class="type">text</code> [<span class="optional">, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code> </span>] )
        → <code class="returnvalue">record</code>
        ( <em class="parameter"><code>size</code></em> <code class="type">bigint</code>,
        <em class="parameter"><code>access</code></em> <code class="type">timestamp with time zone</code>,
        <em class="parameter"><code>modification</code></em> <code class="type">timestamp with time zone</code>,
        <em class="parameter"><code>change</code></em> <code class="type">timestamp with time zone</code>,
        <em class="parameter"><code>creation</code></em> <code class="type">timestamp with time zone</code>,
        <em class="parameter"><code>isdir</code></em> <code class="type">boolean</code> )
       </p>
       <p>
        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.
       </p>
       <p>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </p></td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="FUNCTIONS-ADVISORY-LOCKS"><div class="titlepage"><div><div><h3 class="title">9.27.10. Advisory Lock Functions <a href="#FUNCTIONS-ADVISORY-LOCKS" class="id_link">#</a></h3></div></div></div><p>
    The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADVISORY-LOCKS-TABLE" title="Table 9.102. Advisory Lock Functions">Table 9.102</a>
    manage advisory locks.  For details about proper use of these functions,
    see <a class="xref" href="explicit-locking.html#ADVISORY-LOCKS" title="13.3.5. Advisory Locks">Section 13.3.5</a>.
   </p><p>
    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 <code class="literal">false</code> 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.
   </p><div class="table" id="FUNCTIONS-ADVISORY-LOCKS-TABLE"><p class="title"><strong>Table 9.102. Advisory Lock Functions</strong></p><div class="table-contents"><table class="table" summary="Advisory Lock Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">pg_advisory_lock</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_advisory_lock</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Obtains an exclusive session-level advisory lock, waiting if necessary.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">pg_advisory_lock_shared</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_advisory_lock_shared</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Obtains a shared session-level advisory lock, waiting if necessary.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">pg_advisory_unlock</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_advisory_unlock</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Releases a previously-acquired exclusive session-level advisory lock.
        Returns <code class="literal">true</code> if the lock is successfully released.
        If the lock was not held, <code class="literal">false</code> is returned, and in
        addition, an SQL warning will be reported by the server.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.4.1.1.1" class="indexterm"></a>
        <code class="function">pg_advisory_unlock_all</code> ()
        → <code class="returnvalue">void</code>
       </p>
       <p>
        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.)
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.5.1.1.1" class="indexterm"></a>
        <code class="function">pg_advisory_unlock_shared</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_advisory_unlock_shared</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Releases a previously-acquired shared session-level advisory lock.
        Returns <code class="literal">true</code> if the lock is successfully released.
        If the lock was not held, <code class="literal">false</code> is returned, and in
        addition, an SQL warning will be reported by the server.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.6.1.1.1" class="indexterm"></a>
        <code class="function">pg_advisory_xact_lock</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_advisory_xact_lock</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Obtains an exclusive transaction-level advisory lock, waiting if
        necessary.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.7.1.1.1" class="indexterm"></a>
        <code class="function">pg_advisory_xact_lock_shared</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_advisory_xact_lock_shared</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">void</code>
       </p>
       <p>
        Obtains a shared transaction-level advisory lock, waiting if
        necessary.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.8.1.1.1" class="indexterm"></a>
        <code class="function">pg_try_advisory_lock</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_try_advisory_lock</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Obtains an exclusive session-level advisory lock if available.
        This will either obtain the lock immediately and
        return <code class="literal">true</code>, or return <code class="literal">false</code>
        without waiting if the lock cannot be acquired immediately.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.9.1.1.1" class="indexterm"></a>
        <code class="function">pg_try_advisory_lock_shared</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_try_advisory_lock_shared</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Obtains a shared session-level advisory lock if available.
        This will either obtain the lock immediately and
        return <code class="literal">true</code>, or return <code class="literal">false</code>
        without waiting if the lock cannot be acquired immediately.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.10.1.1.1" class="indexterm"></a>
        <code class="function">pg_try_advisory_xact_lock</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_try_advisory_xact_lock</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Obtains an exclusive transaction-level advisory lock if available.
        This will either obtain the lock immediately and
        return <code class="literal">true</code>, or return <code class="literal">false</code>
        without waiting if the lock cannot be acquired immediately.
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.33.12.4.2.2.11.1.1.1" class="indexterm"></a>
        <code class="function">pg_try_advisory_xact_lock_shared</code> ( <em class="parameter"><code>key</code></em> <code class="type">bigint</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p class="func_signature">
        <code class="function">pg_try_advisory_xact_lock_shared</code> ( <em class="parameter"><code>key1</code></em> <code class="type">integer</code>, <em class="parameter"><code>key2</code></em> <code class="type">integer</code> )
        → <code class="returnvalue">boolean</code>
       </p>
       <p>
        Obtains a shared transaction-level advisory lock if available.
        This will either obtain the lock immediately and
        return <code class="literal">true</code>, or return <code class="literal">false</code>
        without waiting if the lock cannot be acquired immediately.
       </p></td></tr></tbody></table></div></div><br class="table-break" /></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-info.html" title="9.26. System Information Functions and Operators">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-trigger.html" title="9.28. Trigger Functions">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.26. System Information Functions and Operators </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.2 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 9.28. Trigger Functions</td></tr></table></div></body></html>