2 9.28. System Administration Functions #
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
15 The functions described in this section are used to control and monitor
16 a PostgreSQL installation.
18 9.28.1. Configuration Settings Functions #
20 Table 9.95 shows the functions available to query and alter run-time
21 configuration parameters.
23 Table 9.95. Configuration Settings Functions
31 current_setting ( setting_name text [, missing_ok boolean ] ) → text
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.
38 current_setting('datestyle') → ISO, MDY
40 set_config ( setting_name text, new_value text, is_local boolean ) →
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
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
53 set_config('log_statement_stats', 'off', false) → off
55 9.28.2. Server Signaling Functions #
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
62 Each of these functions returns true if the signal was successfully
63 sent and false if sending the signal failed.
65 Table 9.96. Server Signaling Functions
71 pg_cancel_backend ( pid integer ) → boolean
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.
81 pg_log_backend_memory_contexts ( pid integer ) → boolean
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.
90 pg_reload_conf () → boolean
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.
99 pg_rotate_logfile () → boolean
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.
105 pg_terminate_backend ( pid integer, timeout bigint DEFAULT 0 ) →
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.
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.
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.
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 --------------------------------
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)
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
149 LOG: level: 2; RowDescriptionContext: 8192 total in 1 blocks; 6880 free (0 chun
151 LOG: level: 2; MessageContext: 16384 total in 2 blocks; 5152 free (0 chunks); 1
153 LOG: level: 2; Operator class cache: 8192 total in 1 blocks; 512 free (0 chunks
155 LOG: level: 2; smgr relation table: 16384 total in 2 blocks; 4544 free (3 chunk
157 LOG: level: 2; TransactionAbortContext: 32768 total in 1 blocks; 32504 free (0
160 LOG: level: 2; ErrorContext: 8192 total in 1 blocks; 7928 free (3 chunks); 264
162 LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
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
171 9.28.3. Backup Control Functions #
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).
177 For details about proper usage of these functions, see Section 25.3.
179 Table 9.97. Backup Control Functions
185 pg_create_restore_point ( name text ) → pg_lsn
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.
194 This function is restricted to superusers by default, but other users
195 can be granted EXECUTE to run the function.
197 pg_current_wal_flush_lsn () → pg_lsn
199 Returns the current write-ahead log flush location (see notes below).
201 pg_current_wal_insert_lsn () → pg_lsn
203 Returns the current write-ahead log insert location (see notes below).
205 pg_current_wal_lsn () → pg_lsn
207 Returns the current write-ahead log write location (see notes below).
209 pg_backup_start ( label text [, fast boolean ] ) → pg_lsn
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.
219 This function is restricted to superusers by default, but other users
220 can be granted EXECUTE to run the function.
222 pg_backup_stop ( [wait_for_archive boolean ] ) → record ( lsn pg_lsn,
223 labelfile text, spcmapfile text )
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).
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.)
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.
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
259 This function is restricted to superusers by default, but other users
260 can be granted EXECUTE to run the function.
262 pg_switch_wal () → pg_lsn
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.
272 This function is restricted to superusers by default, but other users
273 can be granted EXECUTE to run the function.
275 pg_walfile_name ( lsn pg_lsn ) → text
277 Converts a write-ahead log location to the name of the WAL file holding
280 pg_walfile_name_offset ( lsn pg_lsn ) → record ( file_name text,
281 file_offset integer )
283 Converts a write-ahead log location to a WAL file name and byte offset
286 pg_split_walfile_name ( file_name text ) → record ( segment_number
287 numeric, timeline_id bigint )
289 Extracts the sequence number and timeline ID from a WAL file name.
291 pg_wal_lsn_diff ( lsn1 pg_lsn, lsn2 pg_lsn ) → numeric
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.
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.
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
315 postgres=# SELECT * FROM pg_walfile_name_offset((pg_backup_stop()).lsn);
316 file_name | file_offset
317 --------------------------+-------------
318 00000001000000000000000D | 4039624
321 Similarly, pg_walfile_name extracts just the write-ahead log file name.
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
329 FROM pg_split_walfile_name(:'file_name') pd,
330 pg_show_all_settings() ps
331 WHERE ps.name = 'wal_segment_size';
337 9.28.4. Recovery Control Functions #
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.
343 Table 9.98. Recovery Information Functions
349 pg_is_in_recovery () → boolean
351 Returns true if recovery is still in progress.
353 pg_last_wal_receive_lsn () → pg_lsn
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.
362 pg_last_wal_replay_lsn () → pg_lsn
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
371 pg_last_xact_replay_timestamp () → timestamp with time zone
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.
382 pg_get_wal_resource_managers () → setof record ( rm_id integer, rm_name
383 text, rm_builtin boolean )
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.
389 The functions shown in Table 9.99 control the progress of recovery.
390 These functions may be executed only during recovery.
392 Table 9.99. Recovery Control Functions
398 pg_is_wal_replay_paused () → boolean
400 Returns true if recovery pause is requested.
402 pg_get_wal_replay_pause_state () → text
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.
408 pg_promote ( wait boolean DEFAULT true, wait_seconds integer DEFAULT 60
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.
418 This function is restricted to superusers by default, but other users
419 can be granted EXECUTE to run the function.
421 pg_wal_replay_pause () → void
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.
432 This function is restricted to superusers by default, but other users
433 can be granted EXECUTE to run the function.
435 pg_wal_replay_resume () → void
437 Restarts recovery if it was paused.
439 This function is restricted to superusers by default, but other users
440 can be granted EXECUTE to run the function.
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.
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.
452 9.28.5. Snapshot Synchronization Functions #
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.
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.
473 Snapshots are exported with the pg_export_snapshot function, shown in
474 Table 9.100, and imported with the SET TRANSACTION command.
476 Table 9.100. Snapshot Synchronization Functions
482 pg_export_snapshot () → text
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
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.
496 pg_log_standby_snapshot () → pg_lsn
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.
503 9.28.6. Replication Management Functions #
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.
513 Many of these functions have equivalent commands in the replication
514 protocol; see Section 54.4.
516 The functions described in Section 9.28.3, Section 9.28.4, and
517 Section 9.28.5 are also relevant for replication.
519 Table 9.101. Replication Management Functions
525 pg_create_physical_replication_slot ( slot_name name [,
526 immediately_reserve boolean, temporary boolean ] ) → record ( slot_name
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.
541 pg_drop_replication_slot ( slot_name name ) → void
543 Drops the physical or logical replication slot named slot_name. Same as
544 replication protocol command DROP_REPLICATION_SLOT.
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 )
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.
562 pg_copy_physical_replication_slot ( src_slot_name name, dst_slot_name
563 name [, temporary boolean ] ) → record ( slot_name name, lsn pg_lsn )
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.
571 pg_copy_logical_replication_slot ( src_slot_name name, dst_slot_name
572 name [, temporary boolean [, plugin name ]] ) → record ( slot_name
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.
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 )
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
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 )
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
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 )
614 Behaves just like the pg_logical_slot_get_changes() function, except
615 that changes are returned as bytea.
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 )
621 Behaves just like the pg_logical_slot_peek_changes() function, except
622 that changes are returned as bytea.
624 pg_replication_slot_advance ( slot_name name, upto_lsn pg_lsn ) →
625 record ( slot_name name, end_lsn pg_lsn )
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.
637 pg_replication_origin_create ( node_name text ) → oid
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
643 pg_replication_origin_drop ( node_name text ) → void
645 Deletes a previously-created replication origin, including any
646 associated replay progress.
648 pg_replication_origin_oid ( node_name text ) → oid
650 Looks up a replication origin by name and returns the internal ID. If
651 no such replication origin is found, NULL is returned.
653 pg_replication_origin_session_setup ( node_name text ) → void
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.
659 pg_replication_origin_session_reset () → void
661 Cancels the effects of pg_replication_origin_session_setup().
663 pg_replication_origin_session_is_setup () → boolean
665 Returns true if a replication origin has been selected in the current
668 pg_replication_origin_session_progress ( flush boolean ) → pg_lsn
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
675 pg_replication_origin_xact_setup ( origin_lsn pg_lsn, origin_timestamp
676 timestamp with time zone ) → void
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.
683 pg_replication_origin_xact_reset () → void
685 Cancels the effects of pg_replication_origin_xact_setup().
687 pg_replication_origin_advance ( node_name text, lsn pg_lsn ) → void
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
695 pg_replication_origin_progress ( node_name text, flush boolean ) →
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.
702 pg_logical_emit_message ( transactional boolean, prefix text, content
703 text [, flush boolean DEFAULT false] ) → pg_lsn
705 pg_logical_emit_message ( transactional boolean, prefix text, content
706 bytea [, flush boolean DEFAULT false] ) → pg_lsn
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
721 pg_sync_replication_slots () → void
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.
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.
741 9.28.7. Database Object Management Functions #
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
749 Table 9.102. Database Object Size Functions
755 pg_column_size ( "any" ) → integer
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
761 pg_column_compression ( "any" ) → text
763 Shows the compression algorithm that was used to compress an individual
764 variable-length value. Returns NULL if the value is not compressed.
766 pg_column_toast_chunk_id ( "any" ) → oid
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.
772 pg_database_size ( name ) → bigint
774 pg_database_size ( oid ) → bigint
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.
781 pg_indexes_size ( regclass ) → bigint
783 Computes the total disk space used by indexes attached to the specified
786 pg_relation_size ( relation regclass [, fork text ] ) → bigint
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.
802 pg_size_bytes ( text ) → bigint
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,
808 pg_size_pretty ( bigint ) → text
810 pg_size_pretty ( numeric ) → text
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.
817 pg_table_size ( regclass ) → bigint
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
823 pg_tablespace_size ( name ) → bigint
825 pg_tablespace_size ( oid ) → bigint
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.
832 pg_total_relation_size ( regclass ) → bigint
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 +
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.
844 The functions shown in Table 9.103 assist in identifying the specific
845 disk files associated with database objects.
847 Table 9.103. Database Object Location Functions
853 pg_relation_filenode ( relation regclass ) → oid
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.
863 pg_relation_filepath ( relation regclass ) → text
865 Returns the entire file path name (relative to the database cluster's
866 data directory, PGDATA) of the relation.
868 pg_filenode_relation ( tablespace oid, filenode oid ) → regclass
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.
877 Table 9.104 lists functions used to manage collations.
879 Table 9.104. Collation Management Functions
885 pg_collation_actual_version ( oid ) → text
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.
892 pg_database_collation_actual_version ( oid ) → text
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.
899 pg_import_system_collations ( schema regnamespace ) → integer
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.
914 Table 9.105 lists functions used to manipulate statistics. These
915 functions cannot be executed during recovery.
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.
923 Table 9.105. Database Object Statistics Manipulation Functions
929 pg_restore_relation_stats ( VARIADIC kwargs "any" ) → boolean
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
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);
944 For example, to set the relpages and reltuples values for the table
946 SELECT pg_restore_relation_stats(
947 'schemaname', 'myschema',
948 'relname', 'mytable',
949 'relpages', 173::integer,
950 'reltuples', 10000::real);
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.
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.
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.
968 The caller must have the MAINTAIN privilege on the table or be the
969 owner of the database.
971 pg_clear_relation_stats ( schemaname text, relname text ) → void
973 Clears table-level statistics for the given relation, as though the
974 table was newly created.
976 The caller must have the MAINTAIN privilege on the table or be the
977 owner of the database.
979 pg_restore_attribute_stats ( VARIADIC kwargs "any" ) → boolean
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.
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);
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',
1001 'avg_width', 125::integer,
1002 'null_frac', 0.5::real);
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.
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.
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.
1020 The caller must have the MAINTAIN privilege on the table or be the
1021 owner of the database.
1023 pg_clear_attribute_stats ( schemaname text, relname text, attname text,
1024 inherited boolean ) → void
1026 Clears column-level statistics for the given relation and attribute, as
1027 though the table was newly created.
1029 The caller must have the MAINTAIN privilege on the table or be the
1030 owner of the database.
1032 Table 9.106 lists functions that provide information about the
1033 structure of partitioned tables.
1035 Table 9.106. Partitioning Information Functions
1041 pg_partition_tree ( regclass ) → setof record ( relid regclass,
1042 parentrelid regclass, isleaf boolean, level integer )
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.
1053 pg_partition_ancestors ( regclass ) → setof regclass
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.
1059 pg_partition_root ( regclass ) → regclass
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.
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');
1070 9.28.8. Index Maintenance Functions #
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.
1078 Table 9.107. Index Maintenance Functions
1084 brin_summarize_new_values ( index regclass ) → integer
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
1092 brin_summarize_range ( index regclass, blockNumber bigint ) → integer
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.
1098 brin_desummarize_range ( index regclass, blockNumber bigint ) → void
1100 Removes the BRIN index tuple that summarizes the page range covering
1101 the given table block, if there is one.
1103 gin_clean_pending_list ( index regclass ) → bigint
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.
1113 9.28.9. Generic File Access Functions #
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.
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.
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.
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.
1143 Table 9.108. Generic File Access Functions
1149 pg_ls_dir ( dirname text [, missing_ok boolean, include_dot_dirs
1150 boolean ] ) → setof text
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.
1159 This function is restricted to superusers by default, but other users
1160 can be granted EXECUTE to run the function.
1162 pg_ls_logdir () → setof record ( name text, size bigint, modification
1163 timestamp with time zone )
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.
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.
1173 pg_ls_waldir () → setof record ( name text, size bigint, modification
1174 timestamp with time zone )
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
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.
1185 pg_ls_logicalmapdir () → setof record ( name text, size bigint,
1186 modification timestamp with time zone )
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
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
1197 pg_ls_logicalsnapdir () → setof record ( name text, size bigint,
1198 modification timestamp with time zone )
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
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
1209 pg_ls_replslotdir ( slot_name text ) → setof record ( name text, size
1210 bigint, modification timestamp with time zone )
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.
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
1222 pg_ls_summariesdir () → setof record ( name text, size bigint,
1223 modification timestamp with time zone )
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.
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
1234 pg_ls_archive_statusdir () → setof record ( name text, size bigint,
1235 modification timestamp with time zone )
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.
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
1246 pg_ls_tmpdir ( [ tablespace oid ] ) → setof record ( name text, size
1247 bigint, modification timestamp with time zone )
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.
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
1259 pg_read_file ( filename text [, offset bigint, length bigint ] [,
1260 missing_ok boolean ] ) → text
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.
1269 This function is restricted to superusers by default, but other users
1270 can be granted EXECUTE to run the function.
1272 pg_read_binary_file ( filename text [, offset bigint, length bigint ]
1273 [, missing_ok boolean ] ) → bytea
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
1280 This function is restricted to superusers by default, but other users
1281 can be granted EXECUTE to run the function.
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');
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 )
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.
1298 This function is restricted to superusers by default, but other users
1299 can be granted EXECUTE to run the function.
1301 9.28.10. Advisory Lock Functions #
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.
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.
1322 Table 9.109. Advisory Lock Functions
1328 pg_advisory_lock ( key bigint ) → void
1330 pg_advisory_lock ( key1 integer, key2 integer ) → void
1332 Obtains an exclusive session-level advisory lock, waiting if necessary.
1334 pg_advisory_lock_shared ( key bigint ) → void
1336 pg_advisory_lock_shared ( key1 integer, key2 integer ) → void
1338 Obtains a shared session-level advisory lock, waiting if necessary.
1340 pg_advisory_unlock ( key bigint ) → boolean
1342 pg_advisory_unlock ( key1 integer, key2 integer ) → boolean
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.
1349 pg_advisory_unlock_all () → void
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.)
1355 pg_advisory_unlock_shared ( key bigint ) → boolean
1357 pg_advisory_unlock_shared ( key1 integer, key2 integer ) → boolean
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.
1364 pg_advisory_xact_lock ( key bigint ) → void
1366 pg_advisory_xact_lock ( key1 integer, key2 integer ) → void
1368 Obtains an exclusive transaction-level advisory lock, waiting if
1371 pg_advisory_xact_lock_shared ( key bigint ) → void
1373 pg_advisory_xact_lock_shared ( key1 integer, key2 integer ) → void
1375 Obtains a shared transaction-level advisory lock, waiting if necessary.
1377 pg_try_advisory_lock ( key bigint ) → boolean
1379 pg_try_advisory_lock ( key1 integer, key2 integer ) → boolean
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.
1385 pg_try_advisory_lock_shared ( key bigint ) → boolean
1387 pg_try_advisory_lock_shared ( key1 integer, key2 integer ) → boolean
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.
1393 pg_try_advisory_xact_lock ( key bigint ) → boolean
1395 pg_try_advisory_xact_lock ( key1 integer, key2 integer ) → boolean
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.
1401 pg_try_advisory_xact_lock_shared ( key bigint ) → boolean
1403 pg_try_advisory_xact_lock_shared ( key1 integer, key2 integer ) →
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.