]> begriffs open source - ai-pg/blob - full-docs/txt/functions-admin.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / functions-admin.txt
1
2 9.28. System Administration Functions #
3
4    9.28.1. Configuration Settings Functions
5    9.28.2. Server Signaling Functions
6    9.28.3. Backup Control Functions
7    9.28.4. Recovery Control Functions
8    9.28.5. Snapshot Synchronization Functions
9    9.28.6. Replication Management Functions
10    9.28.7. Database Object Management Functions
11    9.28.8. Index Maintenance Functions
12    9.28.9. Generic File Access Functions
13    9.28.10. Advisory Lock Functions
14
15    The functions described in this section are used to control and monitor
16    a PostgreSQL installation.
17
18 9.28.1. Configuration Settings Functions #
19
20    Table 9.95 shows the functions available to query and alter run-time
21    configuration parameters.
22
23    Table 9.95. Configuration Settings Functions
24
25    Function
26
27    Description
28
29    Example(s)
30
31    current_setting ( setting_name text [, missing_ok boolean ] ) → text
32
33    Returns the current value of the setting setting_name. If there is no
34    such setting, current_setting throws an error unless missing_ok is
35    supplied and is true (in which case NULL is returned). This function
36    corresponds to the SQL command SHOW.
37
38    current_setting('datestyle') → ISO, MDY
39
40    set_config ( setting_name text, new_value text, is_local boolean ) →
41    text
42
43    Sets the parameter setting_name to new_value, and returns that value.
44    If is_local is true, the new value will only apply during the current
45    transaction. If you want the new value to apply for the rest of the
46    current session, use false instead. This function corresponds to the
47    SQL command SET.
48
49    set_config accepts the NULL value for new_value, but as settings cannot
50    be null, it is interpreted as a request to reset the setting to its
51    default value.
52
53    set_config('log_statement_stats', 'off', false) → off
54
55 9.28.2. Server Signaling Functions #
56
57    The functions shown in Table 9.96 send control signals to other server
58    processes. Use of these functions is restricted to superusers by
59    default but access may be granted to others using GRANT, with noted
60    exceptions.
61
62    Each of these functions returns true if the signal was successfully
63    sent and false if sending the signal failed.
64
65    Table 9.96. Server Signaling Functions
66
67    Function
68
69    Description
70
71    pg_cancel_backend ( pid integer ) → boolean
72
73    Cancels the current query of the session whose backend process has the
74    specified process ID. This is also allowed if the calling role is a
75    member of the role whose backend is being canceled or the calling role
76    has privileges of pg_signal_backend, however only superusers can cancel
77    superuser backends. As an exception, roles with privileges of
78    pg_signal_autovacuum_worker are permitted to cancel autovacuum worker
79    processes, which are otherwise considered superuser backends.
80
81    pg_log_backend_memory_contexts ( pid integer ) → boolean
82
83    Requests to log the memory contexts of the backend with the specified
84    process ID. This function can send the request to backends and
85    auxiliary processes except logger. These memory contexts will be logged
86    at LOG message level. They will appear in the server log based on the
87    log configuration set (see Section 19.8 for more information), but will
88    not be sent to the client regardless of client_min_messages.
89
90    pg_reload_conf () → boolean
91
92    Causes all processes of the PostgreSQL server to reload their
93    configuration files. (This is initiated by sending a SIGHUP signal to
94    the postmaster process, which in turn sends SIGHUP to each of its
95    children.) You can use the pg_file_settings, pg_hba_file_rules and
96    pg_ident_file_mappings views to check the configuration files for
97    possible errors, before reloading.
98
99    pg_rotate_logfile () → boolean
100
101    Signals the log-file manager to switch to a new output file
102    immediately. This works only when the built-in log collector is
103    running, since otherwise there is no log-file manager subprocess.
104
105    pg_terminate_backend ( pid integer, timeout bigint DEFAULT 0 ) →
106    boolean
107
108    Terminates the session whose backend process has the specified process
109    ID. This is also allowed if the calling role is a member of the role
110    whose backend is being terminated or the calling role has privileges of
111    pg_signal_backend, however only superusers can terminate superuser
112    backends. As an exception, roles with privileges of
113    pg_signal_autovacuum_worker are permitted to terminate autovacuum
114    worker processes, which are otherwise considered superuser backends.
115
116    If timeout is not specified or zero, this function returns true whether
117    the process actually terminates or not, indicating only that the
118    sending of the signal was successful. If the timeout is specified (in
119    milliseconds) and greater than zero, the function waits until the
120    process is actually terminated or until the given time has passed. If
121    the process is terminated, the function returns true. On timeout, a
122    warning is emitted and false is returned.
123
124    pg_cancel_backend and pg_terminate_backend send signals (SIGINT or
125    SIGTERM respectively) to backend processes identified by process ID.
126    The process ID of an active backend can be found from the pid column of
127    the pg_stat_activity view, or by listing the postgres processes on the
128    server (using ps on Unix or the Task Manager on Windows). The role of
129    an active backend can be found from the usename column of the
130    pg_stat_activity view.
131
132    pg_log_backend_memory_contexts can be used to log the memory contexts
133    of a backend process. For example:
134 postgres=# SELECT pg_log_backend_memory_contexts(pg_backend_pid());
135  pg_log_backend_memory_contexts
136 --------------------------------
137  t
138 (1 row)
139
140    One message for each memory context will be logged. For example:
141 LOG:  logging memory contexts of PID 10377
142 STATEMENT:  SELECT pg_log_backend_memory_contexts(pg_backend_pid());
143 LOG:  level: 1; TopMemoryContext: 80800 total in 6 blocks; 14432 free (5 chunks)
144 ; 66368 used
145 LOG:  level: 2; pgstat TabStatusArray lookup hash table: 8192 total in 1 blocks;
146  1408 free (0 chunks); 6784 used
147 LOG:  level: 2; TopTransactionContext: 8192 total in 1 blocks; 7720 free (1 chun
148 ks); 472 used
149 LOG:  level: 2; RowDescriptionContext: 8192 total in 1 blocks; 6880 free (0 chun
150 ks); 1312 used
151 LOG:  level: 2; MessageContext: 16384 total in 2 blocks; 5152 free (0 chunks); 1
152 1232 used
153 LOG:  level: 2; Operator class cache: 8192 total in 1 blocks; 512 free (0 chunks
154 ); 7680 used
155 LOG:  level: 2; smgr relation table: 16384 total in 2 blocks; 4544 free (3 chunk
156 s); 11840 used
157 LOG:  level: 2; TransactionAbortContext: 32768 total in 1 blocks; 32504 free (0
158 chunks); 264 used
159 ...
160 LOG:  level: 2; ErrorContext: 8192 total in 1 blocks; 7928 free (3 chunks); 264
161 used
162 LOG:  Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
163  used
164
165    If there are more than 100 child contexts under the same parent, the
166    first 100 child contexts are logged, along with a summary of the
167    remaining contexts. Note that frequent calls to this function could
168    incur significant overhead, because it may generate a large number of
169    log messages.
170
171 9.28.3. Backup Control Functions #
172
173    The functions shown in Table 9.97 assist in making on-line backups.
174    These functions cannot be executed during recovery (except
175    pg_backup_start, pg_backup_stop, and pg_wal_lsn_diff).
176
177    For details about proper usage of these functions, see Section 25.3.
178
179    Table 9.97. Backup Control Functions
180
181    Function
182
183    Description
184
185    pg_create_restore_point ( name text ) → pg_lsn
186
187    Creates a named marker record in the write-ahead log that can later be
188    used as a recovery target, and returns the corresponding write-ahead
189    log location. The given name can then be used with recovery_target_name
190    to specify the point up to which recovery will proceed. Avoid creating
191    multiple restore points with the same name, since recovery will stop at
192    the first one whose name matches the recovery target.
193
194    This function is restricted to superusers by default, but other users
195    can be granted EXECUTE to run the function.
196
197    pg_current_wal_flush_lsn () → pg_lsn
198
199    Returns the current write-ahead log flush location (see notes below).
200
201    pg_current_wal_insert_lsn () → pg_lsn
202
203    Returns the current write-ahead log insert location (see notes below).
204
205    pg_current_wal_lsn () → pg_lsn
206
207    Returns the current write-ahead log write location (see notes below).
208
209    pg_backup_start ( label text [, fast boolean ] ) → pg_lsn
210
211    Prepares the server to begin an on-line backup. The only required
212    parameter is an arbitrary user-defined label for the backup. (Typically
213    this would be the name under which the backup dump file will be
214    stored.) If the optional second parameter is given as true, it
215    specifies executing pg_backup_start as quickly as possible. This forces
216    an immediate checkpoint which will cause a spike in I/O operations,
217    slowing any concurrently executing queries.
218
219    This function is restricted to superusers by default, but other users
220    can be granted EXECUTE to run the function.
221
222    pg_backup_stop ( [wait_for_archive boolean ] ) → record ( lsn pg_lsn,
223    labelfile text, spcmapfile text )
224
225    Finishes performing an on-line backup. The desired contents of the
226    backup label file and the tablespace map file are returned as part of
227    the result of the function and must be written to files in the backup
228    area. These files must not be written to the live data directory (doing
229    so will cause PostgreSQL to fail to restart in the event of a crash).
230
231    There is an optional parameter of type boolean. If false, the function
232    will return immediately after the backup is completed, without waiting
233    for WAL to be archived. This behavior is only useful with backup
234    software that independently monitors WAL archiving. Otherwise, WAL
235    required to make the backup consistent might be missing and make the
236    backup useless. By default or when this parameter is true,
237    pg_backup_stop will wait for WAL to be archived when archiving is
238    enabled. (On a standby, this means that it will wait only when
239    archive_mode = always. If write activity on the primary is low, it may
240    be useful to run pg_switch_wal on the primary in order to trigger an
241    immediate segment switch.)
242
243    When executed on a primary, this function also creates a backup history
244    file in the write-ahead log archive area. The history file includes the
245    label given to pg_backup_start, the starting and ending write-ahead log
246    locations for the backup, and the starting and ending times of the
247    backup. After recording the ending location, the current write-ahead
248    log insertion point is automatically advanced to the next write-ahead
249    log file, so that the ending write-ahead log file can be archived
250    immediately to complete the backup.
251
252    The result of the function is a single record. The lsn column holds the
253    backup's ending write-ahead log location (which again can be ignored).
254    The second column returns the contents of the backup label file, and
255    the third column returns the contents of the tablespace map file. These
256    must be stored as part of the backup and are required as part of the
257    restore process.
258
259    This function is restricted to superusers by default, but other users
260    can be granted EXECUTE to run the function.
261
262    pg_switch_wal () → pg_lsn
263
264    Forces the server to switch to a new write-ahead log file, which allows
265    the current file to be archived (assuming you are using continuous
266    archiving). The result is the ending write-ahead log location plus 1
267    within the just-completed write-ahead log file. If there has been no
268    write-ahead log activity since the last write-ahead log switch,
269    pg_switch_wal does nothing and returns the start location of the
270    write-ahead log file currently in use.
271
272    This function is restricted to superusers by default, but other users
273    can be granted EXECUTE to run the function.
274
275    pg_walfile_name ( lsn pg_lsn ) → text
276
277    Converts a write-ahead log location to the name of the WAL file holding
278    that location.
279
280    pg_walfile_name_offset ( lsn pg_lsn ) → record ( file_name text,
281    file_offset integer )
282
283    Converts a write-ahead log location to a WAL file name and byte offset
284    within that file.
285
286    pg_split_walfile_name ( file_name text ) → record ( segment_number
287    numeric, timeline_id bigint )
288
289    Extracts the sequence number and timeline ID from a WAL file name.
290
291    pg_wal_lsn_diff ( lsn1 pg_lsn, lsn2 pg_lsn ) → numeric
292
293    Calculates the difference in bytes (lsn1 - lsn2) between two
294    write-ahead log locations. This can be used with pg_stat_replication or
295    some of the functions shown in Table 9.97 to get the replication lag.
296
297    pg_current_wal_lsn displays the current write-ahead log write location
298    in the same format used by the above functions. Similarly,
299    pg_current_wal_insert_lsn displays the current write-ahead log
300    insertion location and pg_current_wal_flush_lsn displays the current
301    write-ahead log flush location. The insertion location is the “logical”
302    end of the write-ahead log at any instant, while the write location is
303    the end of what has actually been written out from the server's
304    internal buffers, and the flush location is the last location known to
305    be written to durable storage. The write location is the end of what
306    can be examined from outside the server, and is usually what you want
307    if you are interested in archiving partially-complete write-ahead log
308    files. The insertion and flush locations are made available primarily
309    for server debugging purposes. These are all read-only operations and
310    do not require superuser permissions.
311
312    You can use pg_walfile_name_offset to extract the corresponding
313    write-ahead log file name and byte offset from a pg_lsn value. For
314    example:
315 postgres=# SELECT * FROM pg_walfile_name_offset((pg_backup_stop()).lsn);
316         file_name         | file_offset
317 --------------------------+-------------
318  00000001000000000000000D |     4039624
319 (1 row)
320
321    Similarly, pg_walfile_name extracts just the write-ahead log file name.
322
323    pg_split_walfile_name is useful to compute a LSN from a file offset and
324    WAL file name, for example:
325 postgres=# \set file_name '000000010000000100C000AB'
326 postgres=# \set offset 256
327 postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
328 AS lsn
329   FROM pg_split_walfile_name(:'file_name') pd,
330        pg_show_all_settings() ps
331   WHERE ps.name = 'wal_segment_size';
332       lsn
333 ---------------
334  C001/AB000100
335 (1 row)
336
337 9.28.4. Recovery Control Functions #
338
339    The functions shown in Table 9.98 provide information about the current
340    status of a standby server. These functions may be executed both during
341    recovery and in normal running.
342
343    Table 9.98. Recovery Information Functions
344
345    Function
346
347    Description
348
349    pg_is_in_recovery () → boolean
350
351    Returns true if recovery is still in progress.
352
353    pg_last_wal_receive_lsn () → pg_lsn
354
355    Returns the last write-ahead log location that has been received and
356    synced to disk by streaming replication. While streaming replication is
357    in progress this will increase monotonically. If recovery has completed
358    then this will remain static at the location of the last WAL record
359    received and synced to disk during recovery. If streaming replication
360    is disabled, or if it has not yet started, the function returns NULL.
361
362    pg_last_wal_replay_lsn () → pg_lsn
363
364    Returns the last write-ahead log location that has been replayed during
365    recovery. If recovery is still in progress this will increase
366    monotonically. If recovery has completed then this will remain static
367    at the location of the last WAL record applied during recovery. When
368    the server has been started normally without recovery, the function
369    returns NULL.
370
371    pg_last_xact_replay_timestamp () → timestamp with time zone
372
373    Returns the time stamp of the last transaction replayed during
374    recovery. This is the time at which the commit or abort WAL record for
375    that transaction was generated on the primary. If no transactions have
376    been replayed during recovery, the function returns NULL. Otherwise, if
377    recovery is still in progress this will increase monotonically. If
378    recovery has completed then this will remain static at the time of the
379    last transaction applied during recovery. When the server has been
380    started normally without recovery, the function returns NULL.
381
382    pg_get_wal_resource_managers () → setof record ( rm_id integer, rm_name
383    text, rm_builtin boolean )
384
385    Returns the currently-loaded WAL resource managers in the system. The
386    column rm_builtin indicates whether it's a built-in resource manager,
387    or a custom resource manager loaded by an extension.
388
389    The functions shown in Table 9.99 control the progress of recovery.
390    These functions may be executed only during recovery.
391
392    Table 9.99. Recovery Control Functions
393
394    Function
395
396    Description
397
398    pg_is_wal_replay_paused () → boolean
399
400    Returns true if recovery pause is requested.
401
402    pg_get_wal_replay_pause_state () → text
403
404    Returns recovery pause state. The return values are not paused if pause
405    is not requested, pause requested if pause is requested but recovery is
406    not yet paused, and paused if the recovery is actually paused.
407
408    pg_promote ( wait boolean DEFAULT true, wait_seconds integer DEFAULT 60
409    ) → boolean
410
411    Promotes a standby server to primary status. With wait set to true (the
412    default), the function waits until promotion is completed or
413    wait_seconds seconds have passed, and returns true if promotion is
414    successful and false otherwise. If wait is set to false, the function
415    returns true immediately after sending a SIGUSR1 signal to the
416    postmaster to trigger promotion.
417
418    This function is restricted to superusers by default, but other users
419    can be granted EXECUTE to run the function.
420
421    pg_wal_replay_pause () → void
422
423    Request to pause recovery. A request doesn't mean that recovery stops
424    right away. If you want a guarantee that recovery is actually paused,
425    you need to check for the recovery pause state returned by
426    pg_get_wal_replay_pause_state(). Note that pg_is_wal_replay_paused()
427    returns whether a request is made. While recovery is paused, no further
428    database changes are applied. If hot standby is active, all new queries
429    will see the same consistent snapshot of the database, and no further
430    query conflicts will be generated until recovery is resumed.
431
432    This function is restricted to superusers by default, but other users
433    can be granted EXECUTE to run the function.
434
435    pg_wal_replay_resume () → void
436
437    Restarts recovery if it was paused.
438
439    This function is restricted to superusers by default, but other users
440    can be granted EXECUTE to run the function.
441
442    pg_wal_replay_pause and pg_wal_replay_resume cannot be executed while a
443    promotion is ongoing. If a promotion is triggered while recovery is
444    paused, the paused state ends and promotion continues.
445
446    If streaming replication is disabled, the paused state may continue
447    indefinitely without a problem. If streaming replication is in progress
448    then WAL records will continue to be received, which will eventually
449    fill available disk space, depending upon the duration of the pause,
450    the rate of WAL generation and available disk space.
451
452 9.28.5. Snapshot Synchronization Functions #
453
454    PostgreSQL allows database sessions to synchronize their snapshots. A
455    snapshot determines which data is visible to the transaction that is
456    using the snapshot. Synchronized snapshots are necessary when two or
457    more sessions need to see identical content in the database. If two
458    sessions just start their transactions independently, there is always a
459    possibility that some third transaction commits between the executions
460    of the two START TRANSACTION commands, so that one session sees the
461    effects of that transaction and the other does not.
462
463    To solve this problem, PostgreSQL allows a transaction to export the
464    snapshot it is using. As long as the exporting transaction remains
465    open, other transactions can import its snapshot, and thereby be
466    guaranteed that they see exactly the same view of the database that the
467    first transaction sees. But note that any database changes made by any
468    one of these transactions remain invisible to the other transactions,
469    as is usual for changes made by uncommitted transactions. So the
470    transactions are synchronized with respect to pre-existing data, but
471    act normally for changes they make themselves.
472
473    Snapshots are exported with the pg_export_snapshot function, shown in
474    Table 9.100, and imported with the SET TRANSACTION command.
475
476    Table 9.100. Snapshot Synchronization Functions
477
478    Function
479
480    Description
481
482    pg_export_snapshot () → text
483
484    Saves the transaction's current snapshot and returns a text string
485    identifying the snapshot. This string must be passed (outside the
486    database) to clients that want to import the snapshot. The snapshot is
487    available for import only until the end of the transaction that
488    exported it.
489
490    A transaction can export more than one snapshot, if needed. Note that
491    doing so is only useful in READ COMMITTED transactions, since in
492    REPEATABLE READ and higher isolation levels, transactions use the same
493    snapshot throughout their lifetime. Once a transaction has exported any
494    snapshots, it cannot be prepared with PREPARE TRANSACTION.
495
496    pg_log_standby_snapshot () → pg_lsn
497
498    Take a snapshot of running transactions and write it to WAL, without
499    having to wait for bgwriter or checkpointer to log one. This is useful
500    for logical decoding on standby, as logical slot creation has to wait
501    until such a record is replayed on the standby.
502
503 9.28.6. Replication Management Functions #
504
505    The functions shown in Table 9.101 are for controlling and interacting
506    with replication features. See Section 26.2.5, Section 26.2.6, and
507    Chapter 48 for information about the underlying features. Use of
508    functions for replication origin is only allowed to the superuser by
509    default, but may be allowed to other users by using the GRANT command.
510    Use of functions for replication slots is restricted to superusers and
511    users having REPLICATION privilege.
512
513    Many of these functions have equivalent commands in the replication
514    protocol; see Section 54.4.
515
516    The functions described in Section 9.28.3, Section 9.28.4, and
517    Section 9.28.5 are also relevant for replication.
518
519    Table 9.101. Replication Management Functions
520
521    Function
522
523    Description
524
525    pg_create_physical_replication_slot ( slot_name name [,
526    immediately_reserve boolean, temporary boolean ] ) → record ( slot_name
527    name, lsn pg_lsn )
528
529    Creates a new physical replication slot named slot_name. The optional
530    second parameter, when true, specifies that the LSN for this
531    replication slot be reserved immediately; otherwise the LSN is reserved
532    on first connection from a streaming replication client. Streaming
533    changes from a physical slot is only possible with the
534    streaming-replication protocol — see Section 54.4. The optional third
535    parameter, temporary, when set to true, specifies that the slot should
536    not be permanently stored to disk and is only meant for use by the
537    current session. Temporary slots are also released upon any error. This
538    function corresponds to the replication protocol command
539    CREATE_REPLICATION_SLOT ... PHYSICAL.
540
541    pg_drop_replication_slot ( slot_name name ) → void
542
543    Drops the physical or logical replication slot named slot_name. Same as
544    replication protocol command DROP_REPLICATION_SLOT.
545
546    pg_create_logical_replication_slot ( slot_name name, plugin name [,
547    temporary boolean, twophase boolean, failover boolean ] ) → record (
548    slot_name name, lsn pg_lsn )
549
550    Creates a new logical (decoding) replication slot named slot_name using
551    the output plugin plugin. The optional third parameter, temporary, when
552    set to true, specifies that the slot should not be permanently stored
553    to disk and is only meant for use by the current session. Temporary
554    slots are also released upon any error. The optional fourth parameter,
555    twophase, when set to true, specifies that the decoding of prepared
556    transactions is enabled for this slot. The optional fifth parameter,
557    failover, when set to true, specifies that this slot is enabled to be
558    synced to the standbys so that logical replication can be resumed after
559    failover. A call to this function has the same effect as the
560    replication protocol command CREATE_REPLICATION_SLOT ... LOGICAL.
561
562    pg_copy_physical_replication_slot ( src_slot_name name, dst_slot_name
563    name [, temporary boolean ] ) → record ( slot_name name, lsn pg_lsn )
564
565    Copies an existing physical replication slot named src_slot_name to a
566    physical replication slot named dst_slot_name. The copied physical slot
567    starts to reserve WAL from the same LSN as the source slot. temporary
568    is optional. If temporary is omitted, the same value as the source slot
569    is used. Copy of an invalidated slot is not allowed.
570
571    pg_copy_logical_replication_slot ( src_slot_name name, dst_slot_name
572    name [, temporary boolean [, plugin name ]] ) → record ( slot_name
573    name, lsn pg_lsn )
574
575    Copies an existing logical replication slot named src_slot_name to a
576    logical replication slot named dst_slot_name, optionally changing the
577    output plugin and persistence. The copied logical slot starts from the
578    same LSN as the source logical slot. Both temporary and plugin are
579    optional; if they are omitted, the values of the source slot are used.
580    The failover option of the source logical slot is not copied and is set
581    to false by default. This is to avoid the risk of being unable to
582    continue logical replication after failover to standby where the slot
583    is being synchronized. Copy of an invalidated slot is not allowed.
584
585    pg_logical_slot_get_changes ( slot_name name, upto_lsn pg_lsn,
586    upto_nchanges integer, VARIADIC options text[] ) → setof record ( lsn
587    pg_lsn, xid xid, data text )
588
589    Returns changes in the slot slot_name, starting from the point from
590    which changes have been consumed last. If upto_lsn and upto_nchanges
591    are NULL, logical decoding will continue until end of WAL. If upto_lsn
592    is non-NULL, decoding will include only those transactions which commit
593    prior to the specified LSN. If upto_nchanges is non-NULL, decoding will
594    stop when the number of rows produced by decoding exceeds the specified
595    value. Note, however, that the actual number of rows returned may be
596    larger, since this limit is only checked after adding the rows produced
597    when decoding each new transaction commit. If the specified slot is a
598    logical failover slot then the function will not return until all
599    physical slots specified in synchronized_standby_slots have confirmed
600    WAL receipt.
601
602    pg_logical_slot_peek_changes ( slot_name name, upto_lsn pg_lsn,
603    upto_nchanges integer, VARIADIC options text[] ) → setof record ( lsn
604    pg_lsn, xid xid, data text )
605
606    Behaves just like the pg_logical_slot_get_changes() function, except
607    that changes are not consumed; that is, they will be returned again on
608    future calls.
609
610    pg_logical_slot_get_binary_changes ( slot_name name, upto_lsn pg_lsn,
611    upto_nchanges integer, VARIADIC options text[] ) → setof record ( lsn
612    pg_lsn, xid xid, data bytea )
613
614    Behaves just like the pg_logical_slot_get_changes() function, except
615    that changes are returned as bytea.
616
617    pg_logical_slot_peek_binary_changes ( slot_name name, upto_lsn pg_lsn,
618    upto_nchanges integer, VARIADIC options text[] ) → setof record ( lsn
619    pg_lsn, xid xid, data bytea )
620
621    Behaves just like the pg_logical_slot_peek_changes() function, except
622    that changes are returned as bytea.
623
624    pg_replication_slot_advance ( slot_name name, upto_lsn pg_lsn ) →
625    record ( slot_name name, end_lsn pg_lsn )
626
627    Advances the current confirmed position of a replication slot named
628    slot_name. The slot will not be moved backwards, and it will not be
629    moved beyond the current insert location. Returns the name of the slot
630    and the actual position that it was advanced to. The updated slot
631    position information is written out at the next checkpoint if any
632    advancing is done. So in the event of a crash, the slot may return to
633    an earlier position. If the specified slot is a logical failover slot
634    then the function will not return until all physical slots specified in
635    synchronized_standby_slots have confirmed WAL receipt.
636
637    pg_replication_origin_create ( node_name text ) → oid
638
639    Creates a replication origin with the given external name, and returns
640    the internal ID assigned to it. The name must be no longer than 512
641    bytes.
642
643    pg_replication_origin_drop ( node_name text ) → void
644
645    Deletes a previously-created replication origin, including any
646    associated replay progress.
647
648    pg_replication_origin_oid ( node_name text ) → oid
649
650    Looks up a replication origin by name and returns the internal ID. If
651    no such replication origin is found, NULL is returned.
652
653    pg_replication_origin_session_setup ( node_name text ) → void
654
655    Marks the current session as replaying from the given origin, allowing
656    replay progress to be tracked. Can only be used if no origin is
657    currently selected. Use pg_replication_origin_session_reset to undo.
658
659    pg_replication_origin_session_reset () → void
660
661    Cancels the effects of pg_replication_origin_session_setup().
662
663    pg_replication_origin_session_is_setup () → boolean
664
665    Returns true if a replication origin has been selected in the current
666    session.
667
668    pg_replication_origin_session_progress ( flush boolean ) → pg_lsn
669
670    Returns the replay location for the replication origin selected in the
671    current session. The parameter flush determines whether the
672    corresponding local transaction will be guaranteed to have been flushed
673    to disk or not.
674
675    pg_replication_origin_xact_setup ( origin_lsn pg_lsn, origin_timestamp
676    timestamp with time zone ) → void
677
678    Marks the current transaction as replaying a transaction that has
679    committed at the given LSN and timestamp. Can only be called when a
680    replication origin has been selected using
681    pg_replication_origin_session_setup.
682
683    pg_replication_origin_xact_reset () → void
684
685    Cancels the effects of pg_replication_origin_xact_setup().
686
687    pg_replication_origin_advance ( node_name text, lsn pg_lsn ) → void
688
689    Sets replication progress for the given node to the given location.
690    This is primarily useful for setting up the initial location, or
691    setting a new location after configuration changes and similar. Be
692    aware that careless use of this function can lead to inconsistently
693    replicated data.
694
695    pg_replication_origin_progress ( node_name text, flush boolean ) →
696    pg_lsn
697
698    Returns the replay location for the given replication origin. The
699    parameter flush determines whether the corresponding local transaction
700    will be guaranteed to have been flushed to disk or not.
701
702    pg_logical_emit_message ( transactional boolean, prefix text, content
703    text [, flush boolean DEFAULT false] ) → pg_lsn
704
705    pg_logical_emit_message ( transactional boolean, prefix text, content
706    bytea [, flush boolean DEFAULT false] ) → pg_lsn
707
708    Emits a logical decoding message. This can be used to pass generic
709    messages to logical decoding plugins through WAL. The transactional
710    parameter specifies if the message should be part of the current
711    transaction, or if it should be written immediately and decoded as soon
712    as the logical decoder reads the record. The prefix parameter is a
713    textual prefix that can be used by logical decoding plugins to easily
714    recognize messages that are interesting for them. The content parameter
715    is the content of the message, given either in text or binary form. The
716    flush parameter (default set to false) controls if the message is
717    immediately flushed to WAL or not. flush has no effect with
718    transactional, as the message's WAL record is flushed along with its
719    transaction.
720
721    pg_sync_replication_slots () → void
722
723    Synchronize the logical failover replication slots from the primary
724    server to the standby server. This function can only be executed on the
725    standby server. Temporary synced slots, if any, cannot be used for
726    logical decoding and must be dropped after promotion. See
727    Section 47.2.3 for details. Note that this function is primarily
728    intended for testing and debugging purposes and should be used with
729    caution. Additionally, this function cannot be executed if
730    sync_replication_slots is enabled and the slotsync worker is already
731    running to perform the synchronization of slots.
732
733 Caution
734
735    If, after executing the function, hot_standby_feedback is disabled on
736    the standby or the physical slot configured in primary_slot_name is
737    removed, then it is possible that the necessary rows of the
738    synchronized slot will be removed by the VACUUM process on the primary
739    server, resulting in the synchronized slot becoming invalidated.
740
741 9.28.7. Database Object Management Functions #
742
743    The functions shown in Table 9.102 calculate the disk space usage of
744    database objects, or assist in presentation or understanding of usage
745    results. bigint results are measured in bytes. If an OID that does not
746    represent an existing object is passed to one of these functions, NULL
747    is returned.
748
749    Table 9.102. Database Object Size Functions
750
751    Function
752
753    Description
754
755    pg_column_size ( "any" ) → integer
756
757    Shows the number of bytes used to store any individual data value. If
758    applied directly to a table column value, this reflects any compression
759    that was done.
760
761    pg_column_compression ( "any" ) → text
762
763    Shows the compression algorithm that was used to compress an individual
764    variable-length value. Returns NULL if the value is not compressed.
765
766    pg_column_toast_chunk_id ( "any" ) → oid
767
768    Shows the chunk_id of an on-disk TOASTed value. Returns NULL if the
769    value is un-TOASTed or not on-disk. See Section 66.2 for more
770    information about TOAST.
771
772    pg_database_size ( name ) → bigint
773
774    pg_database_size ( oid ) → bigint
775
776    Computes the total disk space used by the database with the specified
777    name or OID. To use this function, you must have CONNECT privilege on
778    the specified database (which is granted by default) or have privileges
779    of the pg_read_all_stats role.
780
781    pg_indexes_size ( regclass ) → bigint
782
783    Computes the total disk space used by indexes attached to the specified
784    table.
785
786    pg_relation_size ( relation regclass [, fork text ] ) → bigint
787
788    Computes the disk space used by one “fork” of the specified relation.
789    (Note that for most purposes it is more convenient to use the
790    higher-level functions pg_total_relation_size or pg_table_size, which
791    sum the sizes of all forks.) With one argument, this returns the size
792    of the main data fork of the relation. The second argument can be
793    provided to specify which fork to examine:
794      * main returns the size of the main data fork of the relation.
795      * fsm returns the size of the Free Space Map (see Section 66.3)
796        associated with the relation.
797      * vm returns the size of the Visibility Map (see Section 66.4)
798        associated with the relation.
799      * init returns the size of the initialization fork, if any,
800        associated with the relation.
801
802    pg_size_bytes ( text ) → bigint
803
804    Converts a size in human-readable format (as returned by
805    pg_size_pretty) into bytes. Valid units are bytes, B, kB, MB, GB, TB,
806    and PB.
807
808    pg_size_pretty ( bigint ) → text
809
810    pg_size_pretty ( numeric ) → text
811
812    Converts a size in bytes into a more easily human-readable format with
813    size units (bytes, kB, MB, GB, TB, or PB as appropriate). Note that the
814    units are powers of 2 rather than powers of 10, so 1kB is 1024 bytes,
815    1MB is 1024^2 = 1048576 bytes, and so on.
816
817    pg_table_size ( regclass ) → bigint
818
819    Computes the disk space used by the specified table, excluding indexes
820    (but including its TOAST table if any, free space map, and visibility
821    map).
822
823    pg_tablespace_size ( name ) → bigint
824
825    pg_tablespace_size ( oid ) → bigint
826
827    Computes the total disk space used in the tablespace with the specified
828    name or OID. To use this function, you must have CREATE privilege on
829    the specified tablespace or have privileges of the pg_read_all_stats
830    role, unless it is the default tablespace for the current database.
831
832    pg_total_relation_size ( regclass ) → bigint
833
834    Computes the total disk space used by the specified table, including
835    all indexes and TOAST data. The result is equivalent to pg_table_size +
836    pg_indexes_size.
837
838    The functions above that operate on tables or indexes accept a regclass
839    argument, which is simply the OID of the table or index in the pg_class
840    system catalog. You do not have to look up the OID by hand, however,
841    since the regclass data type's input converter will do the work for
842    you. See Section 8.19 for details.
843
844    The functions shown in Table 9.103 assist in identifying the specific
845    disk files associated with database objects.
846
847    Table 9.103. Database Object Location Functions
848
849    Function
850
851    Description
852
853    pg_relation_filenode ( relation regclass ) → oid
854
855    Returns the “filenode” number currently assigned to the specified
856    relation. The filenode is the base component of the file name(s) used
857    for the relation (see Section 66.1 for more information). For most
858    relations the result is the same as pg_class.relfilenode, but for
859    certain system catalogs relfilenode is zero and this function must be
860    used to get the correct value. The function returns NULL if passed a
861    relation that does not have storage, such as a view.
862
863    pg_relation_filepath ( relation regclass ) → text
864
865    Returns the entire file path name (relative to the database cluster's
866    data directory, PGDATA) of the relation.
867
868    pg_filenode_relation ( tablespace oid, filenode oid ) → regclass
869
870    Returns a relation's OID given the tablespace OID and filenode it is
871    stored under. This is essentially the inverse mapping of
872    pg_relation_filepath. For a relation in the database's default
873    tablespace, the tablespace can be specified as zero. Returns NULL if no
874    relation in the current database is associated with the given values,
875    or if dealing with a temporary relation.
876
877    Table 9.104 lists functions used to manage collations.
878
879    Table 9.104. Collation Management Functions
880
881    Function
882
883    Description
884
885    pg_collation_actual_version ( oid ) → text
886
887    Returns the actual version of the collation object as it is currently
888    installed in the operating system. If this is different from the value
889    in pg_collation.collversion, then objects depending on the collation
890    might need to be rebuilt. See also ALTER COLLATION.
891
892    pg_database_collation_actual_version ( oid ) → text
893
894    Returns the actual version of the database's collation as it is
895    currently installed in the operating system. If this is different from
896    the value in pg_database.datcollversion, then objects depending on the
897    collation might need to be rebuilt. See also ALTER DATABASE.
898
899    pg_import_system_collations ( schema regnamespace ) → integer
900
901    Adds collations to the system catalog pg_collation based on all the
902    locales it finds in the operating system. This is what initdb uses; see
903    Section 23.2.2 for more details. If additional locales are installed
904    into the operating system later on, this function can be run again to
905    add collations for the new locales. Locales that match existing entries
906    in pg_collation will be skipped. (But collation objects based on
907    locales that are no longer present in the operating system are not
908    removed by this function.) The schema parameter would typically be
909    pg_catalog, but that is not a requirement; the collations could be
910    installed into some other schema as well. The function returns the
911    number of new collation objects it created. Use of this function is
912    restricted to superusers.
913
914    Table 9.105 lists functions used to manipulate statistics. These
915    functions cannot be executed during recovery.
916
917 Warning
918
919    Changes made by these statistics manipulation functions are likely to
920    be overwritten by autovacuum (or manual VACUUM or ANALYZE) and should
921    be considered temporary.
922
923    Table 9.105. Database Object Statistics Manipulation Functions
924
925    Function
926
927    Description
928
929    pg_restore_relation_stats ( VARIADIC kwargs "any" ) → boolean
930
931    Updates table-level statistics. Ordinarily, these statistics are
932    collected automatically or updated as a part of VACUUM or ANALYZE, so
933    it's not necessary to call this function. However, it is useful after a
934    restore to enable the optimizer to choose better plans if ANALYZE has
935    not been run yet.
936
937    The tracked statistics may change from version to version, so arguments
938    are passed as pairs of argname and argvalue in the form:
939 SELECT pg_restore_relation_stats(
940     'arg1name', 'arg1value'::arg1type,
941     'arg2name', 'arg2value'::arg2type,
942     'arg3name', 'arg3value'::arg3type);
943
944    For example, to set the relpages and reltuples values for the table
945    mytable:
946 SELECT pg_restore_relation_stats(
947     'schemaname', 'myschema',
948     'relname',    'mytable',
949     'relpages',   173::integer,
950     'reltuples',  10000::real);
951
952    The arguments schemaname and relname are required, and specify the
953    table. Other arguments are the names and values of statistics
954    corresponding to certain columns in pg_class. The currently-supported
955    relation statistics are relpages with a value of type integer,
956    reltuples with a value of type real, relallvisible with a value of type
957    integer, and relallfrozen with a value of type integer.
958
959    Additionally, this function accepts argument name version of type
960    integer, which specifies the server version from which the statistics
961    originated. This is anticipated to be helpful in porting statistics
962    from older versions of PostgreSQL.
963
964    Minor errors are reported as a WARNING and ignored, and remaining
965    statistics will still be restored. If all specified statistics are
966    successfully restored, returns true, otherwise false.
967
968    The caller must have the MAINTAIN privilege on the table or be the
969    owner of the database.
970
971    pg_clear_relation_stats ( schemaname text, relname text ) → void
972
973    Clears table-level statistics for the given relation, as though the
974    table was newly created.
975
976    The caller must have the MAINTAIN privilege on the table or be the
977    owner of the database.
978
979    pg_restore_attribute_stats ( VARIADIC kwargs "any" ) → boolean
980
981    Creates or updates column-level statistics. Ordinarily, these
982    statistics are collected automatically or updated as a part of VACUUM
983    or ANALYZE, so it's not necessary to call this function. However, it is
984    useful after a restore to enable the optimizer to choose better plans
985    if ANALYZE has not been run yet.
986
987    The tracked statistics may change from version to version, so arguments
988    are passed as pairs of argname and argvalue in the form:
989 SELECT pg_restore_attribute_stats(
990     'arg1name', 'arg1value'::arg1type,
991     'arg2name', 'arg2value'::arg2type,
992     'arg3name', 'arg3value'::arg3type);
993
994    For example, to set the avg_width and null_frac values for the
995    attribute col1 of the table mytable:
996 SELECT pg_restore_attribute_stats(
997     'schemaname', 'myschema',
998     'relname',    'mytable',
999     'attname',    'col1',
1000     'inherited',  false,
1001     'avg_width',  125::integer,
1002     'null_frac',  0.5::real);
1003
1004    The required arguments are schemaname and relname with a value of type
1005    text which specify the table; either attname with a value of type text
1006    or attnum with a value of type smallint, which specifies the column;
1007    and inherited, which specifies whether the statistics include values
1008    from child tables. Other arguments are the names and values of
1009    statistics corresponding to columns in pg_stats.
1010
1011    Additionally, this function accepts argument name version of type
1012    integer, which specifies the server version from which the statistics
1013    originated. This is anticipated to be helpful in porting statistics
1014    from older versions of PostgreSQL.
1015
1016    Minor errors are reported as a WARNING and ignored, and remaining
1017    statistics will still be restored. If all specified statistics are
1018    successfully restored, returns true, otherwise false.
1019
1020    The caller must have the MAINTAIN privilege on the table or be the
1021    owner of the database.
1022
1023    pg_clear_attribute_stats ( schemaname text, relname text, attname text,
1024    inherited boolean ) → void
1025
1026    Clears column-level statistics for the given relation and attribute, as
1027    though the table was newly created.
1028
1029    The caller must have the MAINTAIN privilege on the table or be the
1030    owner of the database.
1031
1032    Table 9.106 lists functions that provide information about the
1033    structure of partitioned tables.
1034
1035    Table 9.106. Partitioning Information Functions
1036
1037    Function
1038
1039    Description
1040
1041    pg_partition_tree ( regclass ) → setof record ( relid regclass,
1042    parentrelid regclass, isleaf boolean, level integer )
1043
1044    Lists the tables or indexes in the partition tree of the given
1045    partitioned table or partitioned index, with one row for each
1046    partition. Information provided includes the OID of the partition, the
1047    OID of its immediate parent, a boolean value telling if the partition
1048    is a leaf, and an integer telling its level in the hierarchy. The level
1049    value is 0 for the input table or index, 1 for its immediate child
1050    partitions, 2 for their partitions, and so on. Returns no rows if the
1051    relation does not exist or is not a partition or partitioned table.
1052
1053    pg_partition_ancestors ( regclass ) → setof regclass
1054
1055    Lists the ancestor relations of the given partition, including the
1056    relation itself. Returns no rows if the relation does not exist or is
1057    not a partition or partitioned table.
1058
1059    pg_partition_root ( regclass ) → regclass
1060
1061    Returns the top-most parent of the partition tree to which the given
1062    relation belongs. Returns NULL if the relation does not exist or is not
1063    a partition or partitioned table.
1064
1065    For example, to check the total size of the data contained in a
1066    partitioned table measurement, one could use the following query:
1067 SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size
1068   FROM pg_partition_tree('measurement');
1069
1070 9.28.8. Index Maintenance Functions #
1071
1072    Table 9.107 shows the functions available for index maintenance tasks.
1073    (Note that these maintenance tasks are normally done automatically by
1074    autovacuum; use of these functions is only required in special cases.)
1075    These functions cannot be executed during recovery. Use of these
1076    functions is restricted to superusers and the owner of the given index.
1077
1078    Table 9.107. Index Maintenance Functions
1079
1080    Function
1081
1082    Description
1083
1084    brin_summarize_new_values ( index regclass ) → integer
1085
1086    Scans the specified BRIN index to find page ranges in the base table
1087    that are not currently summarized by the index; for any such range it
1088    creates a new summary index tuple by scanning those table pages.
1089    Returns the number of new page range summaries that were inserted into
1090    the index.
1091
1092    brin_summarize_range ( index regclass, blockNumber bigint ) → integer
1093
1094    Summarizes the page range covering the given block, if not already
1095    summarized. This is like brin_summarize_new_values except that it only
1096    processes the page range that covers the given table block number.
1097
1098    brin_desummarize_range ( index regclass, blockNumber bigint ) → void
1099
1100    Removes the BRIN index tuple that summarizes the page range covering
1101    the given table block, if there is one.
1102
1103    gin_clean_pending_list ( index regclass ) → bigint
1104
1105    Cleans up the “pending” list of the specified GIN index by moving
1106    entries in it, in bulk, to the main GIN data structure. Returns the
1107    number of pages removed from the pending list. If the argument is a GIN
1108    index built with the fastupdate option disabled, no cleanup happens and
1109    the result is zero, because the index doesn't have a pending list. See
1110    Section 65.4.4.1 and Section 65.4.5 for details about the pending list
1111    and fastupdate option.
1112
1113 9.28.9. Generic File Access Functions #
1114
1115    The functions shown in Table 9.108 provide native access to files on
1116    the machine hosting the server. Only files within the database cluster
1117    directory and the log_directory can be accessed, unless the user is a
1118    superuser or is granted the role pg_read_server_files. Use a relative
1119    path for files in the cluster directory, and a path matching the
1120    log_directory configuration setting for log files.
1121
1122    Note that granting users the EXECUTE privilege on pg_read_file(), or
1123    related functions, allows them the ability to read any file on the
1124    server that the database server process can read; these functions
1125    bypass all in-database privilege checks. This means that, for example,
1126    a user with such access is able to read the contents of the pg_authid
1127    table where authentication information is stored, as well as read any
1128    table data in the database. Therefore, granting access to these
1129    functions should be carefully considered.
1130
1131    When granting privilege on these functions, note that the table entries
1132    showing optional parameters are mostly implemented as several physical
1133    functions with different parameter lists. Privilege must be granted
1134    separately on each such function, if it is to be used. psql's \df
1135    command can be useful to check what the actual function signatures are.
1136
1137    Some of these functions take an optional missing_ok parameter, which
1138    specifies the behavior when the file or directory does not exist. If
1139    true, the function returns NULL or an empty result set, as appropriate.
1140    If false, an error is raised. (Failure conditions other than “file not
1141    found” are reported as errors in any case.) The default is false.
1142
1143    Table 9.108. Generic File Access Functions
1144
1145    Function
1146
1147    Description
1148
1149    pg_ls_dir ( dirname text [, missing_ok boolean, include_dot_dirs
1150    boolean ] ) → setof text
1151
1152    Returns the names of all files (and directories and other special
1153    files) in the specified directory. The include_dot_dirs parameter
1154    indicates whether “.” and “..” are to be included in the result set;
1155    the default is to exclude them. Including them can be useful when
1156    missing_ok is true, to distinguish an empty directory from a
1157    non-existent directory.
1158
1159    This function is restricted to superusers by default, but other users
1160    can be granted EXECUTE to run the function.
1161
1162    pg_ls_logdir () → setof record ( name text, size bigint, modification
1163    timestamp with time zone )
1164
1165    Returns the name, size, and last modification time (mtime) of each
1166    ordinary file in the server's log directory. Filenames beginning with a
1167    dot, directories, and other special files are excluded.
1168
1169    This function is restricted to superusers and roles with privileges of
1170    the pg_monitor role by default, but other users can be granted EXECUTE
1171    to run the function.
1172
1173    pg_ls_waldir () → setof record ( name text, size bigint, modification
1174    timestamp with time zone )
1175
1176    Returns the name, size, and last modification time (mtime) of each
1177    ordinary file in the server's write-ahead log (WAL) directory.
1178    Filenames beginning with a dot, directories, and other special files
1179    are excluded.
1180
1181    This function is restricted to superusers and roles with privileges of
1182    the pg_monitor role by default, but other users can be granted EXECUTE
1183    to run the function.
1184
1185    pg_ls_logicalmapdir () → setof record ( name text, size bigint,
1186    modification timestamp with time zone )
1187
1188    Returns the name, size, and last modification time (mtime) of each
1189    ordinary file in the server's pg_logical/mappings directory. Filenames
1190    beginning with a dot, directories, and other special files are
1191    excluded.
1192
1193    This function is restricted to superusers and members of the pg_monitor
1194    role by default, but other users can be granted EXECUTE to run the
1195    function.
1196
1197    pg_ls_logicalsnapdir () → setof record ( name text, size bigint,
1198    modification timestamp with time zone )
1199
1200    Returns the name, size, and last modification time (mtime) of each
1201    ordinary file in the server's pg_logical/snapshots directory. Filenames
1202    beginning with a dot, directories, and other special files are
1203    excluded.
1204
1205    This function is restricted to superusers and members of the pg_monitor
1206    role by default, but other users can be granted EXECUTE to run the
1207    function.
1208
1209    pg_ls_replslotdir ( slot_name text ) → setof record ( name text, size
1210    bigint, modification timestamp with time zone )
1211
1212    Returns the name, size, and last modification time (mtime) of each
1213    ordinary file in the server's pg_replslot/slot_name directory, where
1214    slot_name is the name of the replication slot provided as input of the
1215    function. Filenames beginning with a dot, directories, and other
1216    special files are excluded.
1217
1218    This function is restricted to superusers and members of the pg_monitor
1219    role by default, but other users can be granted EXECUTE to run the
1220    function.
1221
1222    pg_ls_summariesdir () → setof record ( name text, size bigint,
1223    modification timestamp with time zone )
1224
1225    Returns the name, size, and last modification time (mtime) of each
1226    ordinary file in the server's WAL summaries directory
1227    (pg_wal/summaries). Filenames beginning with a dot, directories, and
1228    other special files are excluded.
1229
1230    This function is restricted to superusers and members of the pg_monitor
1231    role by default, but other users can be granted EXECUTE to run the
1232    function.
1233
1234    pg_ls_archive_statusdir () → setof record ( name text, size bigint,
1235    modification timestamp with time zone )
1236
1237    Returns the name, size, and last modification time (mtime) of each
1238    ordinary file in the server's WAL archive status directory
1239    (pg_wal/archive_status). Filenames beginning with a dot, directories,
1240    and other special files are excluded.
1241
1242    This function is restricted to superusers and members of the pg_monitor
1243    role by default, but other users can be granted EXECUTE to run the
1244    function.
1245
1246    pg_ls_tmpdir ( [ tablespace oid ] ) → setof record ( name text, size
1247    bigint, modification timestamp with time zone )
1248
1249    Returns the name, size, and last modification time (mtime) of each
1250    ordinary file in the temporary file directory for the specified
1251    tablespace. If tablespace is not provided, the pg_default tablespace is
1252    examined. Filenames beginning with a dot, directories, and other
1253    special files are excluded.
1254
1255    This function is restricted to superusers and members of the pg_monitor
1256    role by default, but other users can be granted EXECUTE to run the
1257    function.
1258
1259    pg_read_file ( filename text [, offset bigint, length bigint ] [,
1260    missing_ok boolean ] ) → text
1261
1262    Returns all or part of a text file, starting at the given byte offset,
1263    returning at most length bytes (less if the end of file is reached
1264    first). If offset is negative, it is relative to the end of the file.
1265    If offset and length are omitted, the entire file is returned. The
1266    bytes read from the file are interpreted as a string in the database's
1267    encoding; an error is thrown if they are not valid in that encoding.
1268
1269    This function is restricted to superusers by default, but other users
1270    can be granted EXECUTE to run the function.
1271
1272    pg_read_binary_file ( filename text [, offset bigint, length bigint ]
1273    [, missing_ok boolean ] ) → bytea
1274
1275    Returns all or part of a file. This function is identical to
1276    pg_read_file except that it can read arbitrary binary data, returning
1277    the result as bytea not text; accordingly, no encoding checks are
1278    performed.
1279
1280    This function is restricted to superusers by default, but other users
1281    can be granted EXECUTE to run the function.
1282
1283    In combination with the convert_from function, this function can be
1284    used to read a text file in a specified encoding and convert to the
1285    database's encoding:
1286 SELECT convert_from(pg_read_binary_file('file_in_utf8.txt'), 'UTF8');
1287
1288    pg_stat_file ( filename text [, missing_ok boolean ] ) → record ( size
1289    bigint, access timestamp with time zone, modification timestamp with
1290    time zone, change timestamp with time zone, creation timestamp with
1291    time zone, isdir boolean )
1292
1293    Returns a record containing the file's size, last access time stamp,
1294    last modification time stamp, last file status change time stamp (Unix
1295    platforms only), file creation time stamp (Windows only), and a flag
1296    indicating if it is a directory.
1297
1298    This function is restricted to superusers by default, but other users
1299    can be granted EXECUTE to run the function.
1300
1301 9.28.10. Advisory Lock Functions #
1302
1303    The functions shown in Table 9.109 manage advisory locks. For details
1304    about proper use of these functions, see Section 13.3.5.
1305
1306    All these functions are intended to be used to lock application-defined
1307    resources, which can be identified either by a single 64-bit key value
1308    or two 32-bit key values (note that these two key spaces do not
1309    overlap). If another session already holds a conflicting lock on the
1310    same resource identifier, the functions will either wait until the
1311    resource becomes available, or return a false result, as appropriate
1312    for the function. Locks can be either shared or exclusive: a shared
1313    lock does not conflict with other shared locks on the same resource,
1314    only with exclusive locks. Locks can be taken at session level (so that
1315    they are held until released or the session ends) or at transaction
1316    level (so that they are held until the current transaction ends; there
1317    is no provision for manual release). Multiple session-level lock
1318    requests stack, so that if the same resource identifier is locked three
1319    times there must then be three unlock requests to release the resource
1320    in advance of session end.
1321
1322    Table 9.109. Advisory Lock Functions
1323
1324    Function
1325
1326    Description
1327
1328    pg_advisory_lock ( key bigint ) → void
1329
1330    pg_advisory_lock ( key1 integer, key2 integer ) → void
1331
1332    Obtains an exclusive session-level advisory lock, waiting if necessary.
1333
1334    pg_advisory_lock_shared ( key bigint ) → void
1335
1336    pg_advisory_lock_shared ( key1 integer, key2 integer ) → void
1337
1338    Obtains a shared session-level advisory lock, waiting if necessary.
1339
1340    pg_advisory_unlock ( key bigint ) → boolean
1341
1342    pg_advisory_unlock ( key1 integer, key2 integer ) → boolean
1343
1344    Releases a previously-acquired exclusive session-level advisory lock.
1345    Returns true if the lock is successfully released. If the lock was not
1346    held, false is returned, and in addition, an SQL warning will be
1347    reported by the server.
1348
1349    pg_advisory_unlock_all () → void
1350
1351    Releases all session-level advisory locks held by the current session.
1352    (This function is implicitly invoked at session end, even if the client
1353    disconnects ungracefully.)
1354
1355    pg_advisory_unlock_shared ( key bigint ) → boolean
1356
1357    pg_advisory_unlock_shared ( key1 integer, key2 integer ) → boolean
1358
1359    Releases a previously-acquired shared session-level advisory lock.
1360    Returns true if the lock is successfully released. If the lock was not
1361    held, false is returned, and in addition, an SQL warning will be
1362    reported by the server.
1363
1364    pg_advisory_xact_lock ( key bigint ) → void
1365
1366    pg_advisory_xact_lock ( key1 integer, key2 integer ) → void
1367
1368    Obtains an exclusive transaction-level advisory lock, waiting if
1369    necessary.
1370
1371    pg_advisory_xact_lock_shared ( key bigint ) → void
1372
1373    pg_advisory_xact_lock_shared ( key1 integer, key2 integer ) → void
1374
1375    Obtains a shared transaction-level advisory lock, waiting if necessary.
1376
1377    pg_try_advisory_lock ( key bigint ) → boolean
1378
1379    pg_try_advisory_lock ( key1 integer, key2 integer ) → boolean
1380
1381    Obtains an exclusive session-level advisory lock if available. This
1382    will either obtain the lock immediately and return true, or return
1383    false without waiting if the lock cannot be acquired immediately.
1384
1385    pg_try_advisory_lock_shared ( key bigint ) → boolean
1386
1387    pg_try_advisory_lock_shared ( key1 integer, key2 integer ) → boolean
1388
1389    Obtains a shared session-level advisory lock if available. This will
1390    either obtain the lock immediately and return true, or return false
1391    without waiting if the lock cannot be acquired immediately.
1392
1393    pg_try_advisory_xact_lock ( key bigint ) → boolean
1394
1395    pg_try_advisory_xact_lock ( key1 integer, key2 integer ) → boolean
1396
1397    Obtains an exclusive transaction-level advisory lock if available. This
1398    will either obtain the lock immediately and return true, or return
1399    false without waiting if the lock cannot be acquired immediately.
1400
1401    pg_try_advisory_xact_lock_shared ( key bigint ) → boolean
1402
1403    pg_try_advisory_xact_lock_shared ( key1 integer, key2 integer ) →
1404    boolean
1405
1406    Obtains a shared transaction-level advisory lock if available. This
1407    will either obtain the lock immediately and return true, or return
1408    false without waiting if the lock cannot be acquired immediately.