gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1122 linhas
102KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>9.26. System Administration Functions</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="functions-info.html" title="9.25. System Information Functions and Operators" /><link rel="next" href="functions-trigger.html" title="9.27. Trigger Functions" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">9.26. System Administration Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-info.html" title="9.25. System Information Functions and Operators">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="functions-trigger.html" title="9.27. Trigger Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUNCTIONS-ADMIN"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.26. System Administration Functions</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-SET">9.26.1. Configuration Settings Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-SIGNAL">9.26.2. Server Signaling Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-BACKUP">9.26.3. Backup Control Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-RECOVERY-CONTROL">9.26.4. Recovery Control Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION">9.26.5. Snapshot Synchronization Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-REPLICATION">9.26.6. Replication Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT">9.26.7. Database Object Management Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-INDEX">9.26.8. Index Maintenance Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADMIN-GENFILE">9.26.9. Generic File Access Functions</a></span></dt><dt><span class="sect2"><a href="functions-admin.html#FUNCTIONS-ADVISORY-LOCKS">9.26.10. Advisory Lock Functions</a></span></dt></dl></div><p>
  3. The functions described in this section are used to control and
  4. monitor a <span class="productname">PostgreSQL</span> installation.
  5. </p><div class="sect2" id="FUNCTIONS-ADMIN-SET"><div class="titlepage"><div><div><h3 class="title">9.26.1. Configuration Settings Functions</h3></div></div></div><p>
  6. <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-SET-TABLE" title="Table 9.82. Configuration Settings Functions">Table 9.82</a> shows the functions
  7. available to query and alter run-time configuration parameters.
  8. </p><div class="table" id="FUNCTIONS-ADMIN-SET-TABLE"><p class="title"><strong>Table 9.82. Configuration Settings Functions</strong></p><div class="table-contents"><table class="table" summary="Configuration Settings Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  9. <a id="id-1.5.8.31.3.3.2.2.1.1.1" class="indexterm"></a>
  10. <code class="literal"><code class="function">current_setting(<em class="parameter"><code>setting_name</code></em> [, <em class="parameter"><code>missing_ok</code></em> ])</code></code>
  11. </td><td><code class="type">text</code></td><td>get current value of setting</td></tr><tr><td>
  12. <a id="id-1.5.8.31.3.3.2.2.2.1.1" class="indexterm"></a>
  13. <code class="literal"><code class="function">set_config(<em class="parameter"><code>setting_name</code></em>,
  14. <em class="parameter"><code>new_value</code></em>,
  15. <em class="parameter"><code>is_local</code></em>)</code></code>
  16. </td><td><code class="type">text</code></td><td>set parameter and return new value</td></tr></tbody></table></div></div><br class="table-break" /><a id="id-1.5.8.31.3.4" class="indexterm"></a><a id="id-1.5.8.31.3.5" class="indexterm"></a><a id="id-1.5.8.31.3.6" class="indexterm"></a><p>
  17. The function <code class="function">current_setting</code> yields the
  18. current value of the setting <em class="parameter"><code>setting_name</code></em>.
  19. It corresponds to the <acronym class="acronym">SQL</acronym> command
  20. <code class="command">SHOW</code>. An example:
  21. </p><pre class="programlisting">
  22. SELECT current_setting('datestyle');
  23. current_setting
  24. -----------------
  25. ISO, MDY
  26. (1 row)
  27. </pre><p>
  28. If there is no setting named <em class="parameter"><code>setting_name</code></em>,
  29. <code class="function">current_setting</code> throws an error
  30. unless <em class="parameter"><code>missing_ok</code></em> is supplied and is
  31. <code class="literal">true</code>.
  32. </p><p>
  33. <code class="function">set_config</code> sets the parameter
  34. <em class="parameter"><code>setting_name</code></em> to
  35. <em class="parameter"><code>new_value</code></em>. If
  36. <em class="parameter"><code>is_local</code></em> is <code class="literal">true</code>, the
  37. new value will only apply to the current transaction. If you want
  38. the new value to apply for the current session, use
  39. <code class="literal">false</code> instead. The function corresponds to the
  40. SQL command <code class="command">SET</code>. An example:
  41. </p><pre class="programlisting">
  42. SELECT set_config('log_statement_stats', 'off', false);
  43. set_config
  44. ------------
  45. off
  46. (1 row)
  47. </pre><p>
  48. </p></div><div class="sect2" id="FUNCTIONS-ADMIN-SIGNAL"><div class="titlepage"><div><div><h3 class="title">9.26.2. Server Signaling Functions</h3></div></div></div><a id="id-1.5.8.31.4.2" class="indexterm"></a><a id="id-1.5.8.31.4.3" class="indexterm"></a><a id="id-1.5.8.31.4.4" class="indexterm"></a><a id="id-1.5.8.31.4.5" class="indexterm"></a><a id="id-1.5.8.31.4.6" class="indexterm"></a><p>
  49. The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE" title="Table 9.83. Server Signaling Functions">Table 9.83</a> send control signals to
  50. other server processes. Use of these functions is restricted to
  51. superusers by default but access may be granted to others using
  52. <code class="command">GRANT</code>, with noted exceptions.
  53. </p><div class="table" id="FUNCTIONS-ADMIN-SIGNAL-TABLE"><p class="title"><strong>Table 9.83. Server Signaling Functions</strong></p><div class="table-contents"><table class="table" summary="Server Signaling Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  54. <code class="literal"><code class="function">pg_cancel_backend(<em class="parameter"><code>pid</code></em> <code class="type">int</code>)</code></code>
  55. </td><td><code class="type">boolean</code></td><td>Cancel a backend's current query. This is also allowed if the
  56. calling role is a member of the role whose backend is being canceled or
  57. the calling role has been granted <code class="literal">pg_signal_backend</code>,
  58. however only superusers can cancel superuser backends.
  59. </td></tr><tr><td>
  60. <code class="literal"><code class="function">pg_reload_conf()</code></code>
  61. </td><td><code class="type">boolean</code></td><td>Cause server processes to reload their configuration files</td></tr><tr><td>
  62. <code class="literal"><code class="function">pg_rotate_logfile()</code></code>
  63. </td><td><code class="type">boolean</code></td><td>Rotate server's log file</td></tr><tr><td>
  64. <code class="literal"><code class="function">pg_terminate_backend(<em class="parameter"><code>pid</code></em> <code class="type">int</code>)</code></code>
  65. </td><td><code class="type">boolean</code></td><td>Terminate a backend. This is also allowed if the calling role
  66. is a member of the role whose backend is being terminated or the
  67. calling role has been granted <code class="literal">pg_signal_backend</code>,
  68. however only superusers can terminate superuser backends.
  69. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  70. Each of these functions returns <code class="literal">true</code> if
  71. successful and <code class="literal">false</code> otherwise.
  72. </p><p>
  73. <code class="function">pg_cancel_backend</code> and <code class="function">pg_terminate_backend</code>
  74. send signals (<span class="systemitem">SIGINT</span> or <span class="systemitem">SIGTERM</span>
  75. respectively) to backend processes identified by process ID.
  76. The process ID of an active backend can be found from
  77. the <code class="structfield">pid</code> column of the
  78. <code class="structname">pg_stat_activity</code> view, or by listing the
  79. <code class="command">postgres</code> processes on the server (using
  80. <span class="application">ps</span> on Unix or the <span class="application">Task
  81. Manager</span> on <span class="productname">Windows</span>).
  82. The role of an active backend can be found from the
  83. <code class="structfield">usename</code> column of the
  84. <code class="structname">pg_stat_activity</code> view.
  85. </p><p>
  86. <code class="function">pg_reload_conf</code> sends a <span class="systemitem">SIGHUP</span> signal
  87. to the server, causing configuration files
  88. to be reloaded by all server processes.
  89. </p><p>
  90. <code class="function">pg_rotate_logfile</code> signals the log-file manager to switch
  91. to a new output file immediately. This works only when the built-in
  92. log collector is running, since otherwise there is no log-file manager
  93. subprocess.
  94. </p></div><div class="sect2" id="FUNCTIONS-ADMIN-BACKUP"><div class="titlepage"><div><div><h3 class="title">9.26.3. Backup Control Functions</h3></div></div></div><a id="id-1.5.8.31.5.2" class="indexterm"></a><a id="id-1.5.8.31.5.3" class="indexterm"></a><a id="id-1.5.8.31.5.4" class="indexterm"></a><a id="id-1.5.8.31.5.5" class="indexterm"></a><a id="id-1.5.8.31.5.6" class="indexterm"></a><a id="id-1.5.8.31.5.7" class="indexterm"></a><a id="id-1.5.8.31.5.8" class="indexterm"></a><a id="id-1.5.8.31.5.9" class="indexterm"></a><a id="id-1.5.8.31.5.10" class="indexterm"></a><a id="id-1.5.8.31.5.11" class="indexterm"></a><a id="id-1.5.8.31.5.12" class="indexterm"></a><a id="id-1.5.8.31.5.13" class="indexterm"></a><a id="id-1.5.8.31.5.14" class="indexterm"></a><p>
  95. The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-BACKUP-TABLE" title="Table 9.84. Backup Control Functions">Table 9.84</a> assist in making on-line backups.
  96. These functions cannot be executed during recovery (except
  97. non-exclusive <code class="function">pg_start_backup</code>,
  98. non-exclusive <code class="function">pg_stop_backup</code>,
  99. <code class="function">pg_is_in_backup</code>, <code class="function">pg_backup_start_time</code>
  100. and <code class="function">pg_wal_lsn_diff</code>).
  101. </p><div class="table" id="FUNCTIONS-ADMIN-BACKUP-TABLE"><p class="title"><strong>Table 9.84. Backup Control Functions</strong></p><div class="table-contents"><table class="table" summary="Backup Control Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  102. <code class="literal"><code class="function">pg_create_restore_point(<em class="parameter"><code>name</code></em> <code class="type">text</code>)</code></code>
  103. </td><td><code class="type">pg_lsn</code></td><td>Create a named point for performing restore (restricted to superusers by default, but other users can be granted EXECUTE to run the function)</td></tr><tr><td>
  104. <code class="literal"><code class="function">pg_current_wal_flush_lsn()</code></code>
  105. </td><td><code class="type">pg_lsn</code></td><td>Get current write-ahead log flush location</td></tr><tr><td>
  106. <code class="literal"><code class="function">pg_current_wal_insert_lsn()</code></code>
  107. </td><td><code class="type">pg_lsn</code></td><td>Get current write-ahead log insert location</td></tr><tr><td>
  108. <code class="literal"><code class="function">pg_current_wal_lsn()</code></code>
  109. </td><td><code class="type">pg_lsn</code></td><td>Get current write-ahead log write location</td></tr><tr><td>
  110. <code class="literal"><code class="function">pg_start_backup(<em class="parameter"><code>label</code></em> <code class="type">text</code> [<span class="optional">, <em class="parameter"><code>fast</code></em> <code class="type">boolean</code> [<span class="optional">, <em class="parameter"><code>exclusive</code></em> <code class="type">boolean</code> </span>]</span>])</code></code>
  111. </td><td><code class="type">pg_lsn</code></td><td>Prepare for performing on-line backup (restricted to superusers by default, but other users can be granted EXECUTE to run the function)</td></tr><tr><td>
  112. <code class="literal"><code class="function">pg_stop_backup()</code></code>
  113. </td><td><code class="type">pg_lsn</code></td><td>Finish performing exclusive on-line backup (restricted to superusers by default, but other users can be granted EXECUTE to run the function)</td></tr><tr><td>
  114. <code class="literal"><code class="function">pg_stop_backup(<em class="parameter"><code>exclusive</code></em> <code class="type">boolean</code> [<span class="optional">, <em class="parameter"><code>wait_for_archive</code></em> <code class="type">boolean</code> </span>])</code></code>
  115. </td><td><code class="type">setof record</code></td><td>Finish performing exclusive or non-exclusive on-line backup (restricted to superusers by default, but other users can be granted EXECUTE to run the function)</td></tr><tr><td>
  116. <code class="literal"><code class="function">pg_is_in_backup()</code></code>
  117. </td><td><code class="type">bool</code></td><td>True if an on-line exclusive backup is still in progress.</td></tr><tr><td>
  118. <code class="literal"><code class="function">pg_backup_start_time()</code></code>
  119. </td><td><code class="type">timestamp with time zone</code></td><td>Get start time of an on-line exclusive backup in progress.</td></tr><tr><td>
  120. <code class="literal"><code class="function">pg_switch_wal()</code></code>
  121. </td><td><code class="type">pg_lsn</code></td><td>Force switch to a new write-ahead log file (restricted to superusers by default, but other users can be granted EXECUTE to run the function)</td></tr><tr><td>
  122. <code class="literal"><code class="function">pg_walfile_name(<em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>)</code></code>
  123. </td><td><code class="type">text</code></td><td>Convert write-ahead log location to file name</td></tr><tr><td>
  124. <code class="literal"><code class="function">pg_walfile_name_offset(<em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>)</code></code>
  125. </td><td><code class="type">text</code>, <code class="type">integer</code></td><td>Convert write-ahead log location to file name and decimal byte offset within file</td></tr><tr><td>
  126. <code class="literal"><code class="function">pg_wal_lsn_diff(<em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>)</code></code>
  127. </td><td><code class="type">numeric</code></td><td>Calculate the difference between two write-ahead log locations</td></tr></tbody></table></div></div><br class="table-break" /><p>
  128. <code class="function">pg_start_backup</code> accepts an arbitrary user-defined label for
  129. the backup. (Typically this would be the name under which the backup dump
  130. file will be stored.) When used in exclusive mode, the function writes a
  131. backup label file (<code class="filename">backup_label</code>) and, if there are any links
  132. in the <code class="filename">pg_tblspc/</code> directory, a tablespace map file
  133. (<code class="filename">tablespace_map</code>) into the database cluster's data directory,
  134. performs a checkpoint, and then returns the backup's starting write-ahead
  135. log location as text. The user can ignore this result value, but it is
  136. provided in case it is useful. When used in non-exclusive mode, the
  137. contents of these files are instead returned by the
  138. <code class="function">pg_stop_backup</code> function, and should be written to the backup
  139. by the caller.
  140. </p><pre class="programlisting">
  141. postgres=# select pg_start_backup('label_goes_here');
  142. pg_start_backup
  143. -----------------
  144. 0/D4445B8
  145. (1 row)
  146. </pre><p>
  147. There is an optional second parameter of type <code class="type">boolean</code>. If <code class="literal">true</code>,
  148. it specifies executing <code class="function">pg_start_backup</code> as quickly as
  149. possible. This forces an immediate checkpoint which will cause a
  150. spike in I/O operations, slowing any concurrently executing queries.
  151. </p><p>
  152. In an exclusive backup, <code class="function">pg_stop_backup</code> removes the label file
  153. and, if it exists, the <code class="filename">tablespace_map</code> file created by
  154. <code class="function">pg_start_backup</code>. In a non-exclusive backup, the contents of
  155. the <code class="filename">backup_label</code> and <code class="filename">tablespace_map</code> are returned
  156. in the result of the function, and should be written to files in the
  157. backup (and not in the data directory). There is an optional second
  158. parameter of type <code class="type">boolean</code>. If false, the <code class="function">pg_stop_backup</code>
  159. will return immediately after the backup is completed without waiting for
  160. WAL to be archived. This behavior is only useful for backup
  161. software which independently monitors WAL archiving. Otherwise, WAL
  162. required to make the backup consistent might be missing and make the backup
  163. useless. When this parameter is set to true, <code class="function">pg_stop_backup</code>
  164. will wait for WAL to be archived when archiving is enabled; on the standby,
  165. this means that it will wait only when <code class="varname">archive_mode = always</code>.
  166. If write activity on the primary is low, it may be useful to run
  167. <code class="function">pg_switch_wal</code> on the primary in order to trigger
  168. an immediate segment switch.
  169. </p><p>
  170. When executed on a primary, the function also creates a backup history file
  171. in the write-ahead log
  172. archive area. The history file includes the label given to
  173. <code class="function">pg_start_backup</code>, the starting and ending write-ahead log locations for
  174. the backup, and the starting and ending times of the backup. The return
  175. value is the backup's ending write-ahead log location (which again
  176. can be ignored). After recording the ending location, the current
  177. write-ahead log insertion
  178. point is automatically advanced to the next write-ahead log file, so that the
  179. ending write-ahead log file can be archived immediately to complete the backup.
  180. </p><p>
  181. <code class="function">pg_switch_wal</code> moves to the next write-ahead log file, allowing the
  182. current file to be archived (assuming you are using continuous archiving).
  183. The return value is the ending write-ahead log location + 1 within the just-completed write-ahead log file.
  184. If there has been no write-ahead log activity since the last write-ahead log switch,
  185. <code class="function">pg_switch_wal</code> does nothing and returns the start location
  186. of the write-ahead log file currently in use.
  187. </p><p>
  188. <code class="function">pg_create_restore_point</code> creates a named write-ahead log
  189. record that can be used as recovery target, and returns the corresponding
  190. write-ahead log location. The given name can then be used with
  191. <a class="xref" href="runtime-config-wal.html#GUC-RECOVERY-TARGET-NAME">recovery_target_name</a> to specify the point up to which
  192. recovery will proceed. Avoid creating multiple restore points with the
  193. same name, since recovery will stop at the first one whose name matches
  194. the recovery target.
  195. </p><p>
  196. <code class="function">pg_current_wal_lsn</code> displays the current write-ahead log write
  197. location in the same format used by the above functions. Similarly,
  198. <code class="function">pg_current_wal_insert_lsn</code> displays the current write-ahead log
  199. insertion location and <code class="function">pg_current_wal_flush_lsn</code> displays the
  200. current write-ahead log flush location. The insertion location is the <span class="quote">“<span class="quote">logical</span>”</span>
  201. end of the write-ahead log at any instant, while the write location is the end of
  202. what has actually been written out from the server's internal buffers and flush
  203. location is the location guaranteed to be written to durable storage. The write
  204. location is the end of what can be examined from outside the server, and is usually
  205. what you want if you are interested in archiving partially-complete write-ahead log
  206. files. The insertion and flush locations are made available primarily for server
  207. debugging purposes. These are both read-only operations and do not
  208. require superuser permissions.
  209. </p><p>
  210. You can use <code class="function">pg_walfile_name_offset</code> to extract the
  211. corresponding write-ahead log file name and byte offset from the results of any of the
  212. above functions. For example:
  213. </p><pre class="programlisting">
  214. postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup());
  215. file_name | file_offset
  216. --------------------------+-------------
  217. 00000001000000000000000D | 4039624
  218. (1 row)
  219. </pre><p>
  220. Similarly, <code class="function">pg_walfile_name</code> extracts just the write-ahead log file name.
  221. When the given write-ahead log location is exactly at a write-ahead log file boundary, both
  222. these functions return the name of the preceding write-ahead log file.
  223. This is usually the desired behavior for managing write-ahead log archiving
  224. behavior, since the preceding file is the last one that currently
  225. needs to be archived.
  226. </p><p>
  227. <code class="function">pg_wal_lsn_diff</code> calculates the difference in bytes
  228. between two write-ahead log locations. It can be used with
  229. <code class="structname">pg_stat_replication</code> or some functions shown in
  230. <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-BACKUP-TABLE" title="Table 9.84. Backup Control Functions">Table 9.84</a> to get the replication lag.
  231. </p><p>
  232. For details about proper usage of these functions, see
  233. <a class="xref" href="continuous-archiving.html" title="25.3. Continuous Archiving and Point-in-Time Recovery (PITR)">Section 25.3</a>.
  234. </p></div><div class="sect2" id="FUNCTIONS-RECOVERY-CONTROL"><div class="titlepage"><div><div><h3 class="title">9.26.4. Recovery Control Functions</h3></div></div></div><a id="id-1.5.8.31.6.2" class="indexterm"></a><a id="id-1.5.8.31.6.3" class="indexterm"></a><a id="id-1.5.8.31.6.4" class="indexterm"></a><a id="id-1.5.8.31.6.5" class="indexterm"></a><p>
  235. The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-RECOVERY-INFO-TABLE" title="Table 9.85. Recovery Information Functions">Table 9.85</a> provide information
  236. about the current status of the standby.
  237. These functions may be executed both during recovery and in normal running.
  238. </p><div class="table" id="FUNCTIONS-RECOVERY-INFO-TABLE"><p class="title"><strong>Table 9.85. Recovery Information Functions</strong></p><div class="table-contents"><table class="table" summary="Recovery Information Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  239. <code class="literal"><code class="function">pg_is_in_recovery()</code></code>
  240. </td><td><code class="type">bool</code></td><td>True if recovery is still in progress.
  241. </td></tr><tr><td>
  242. <code class="literal"><code class="function">pg_last_wal_receive_lsn()</code></code>
  243. </td><td><code class="type">pg_lsn</code></td><td>Get last write-ahead log location received and synced to disk by
  244. streaming replication. While streaming replication is in progress
  245. this will increase monotonically. If recovery has completed this will
  246. remain static at
  247. the value of the last WAL record received and synced to disk during
  248. recovery. If streaming replication is disabled, or if it has not yet
  249. started, the function returns NULL.
  250. </td></tr><tr><td>
  251. <code class="literal"><code class="function">pg_last_wal_replay_lsn()</code></code>
  252. </td><td><code class="type">pg_lsn</code></td><td>Get last write-ahead log location replayed during recovery.
  253. If recovery is still in progress this will increase monotonically.
  254. If recovery has completed then this value will remain static at
  255. the value of the last WAL record applied during that recovery.
  256. When the server has been started normally without recovery
  257. the function returns NULL.
  258. </td></tr><tr><td>
  259. <code class="literal"><code class="function">pg_last_xact_replay_timestamp()</code></code>
  260. </td><td><code class="type">timestamp with time zone</code></td><td>Get time stamp of last transaction replayed during recovery.
  261. This is the time at which the commit or abort WAL record for that
  262. transaction was generated on the primary.
  263. If no transactions have been replayed during recovery, this function
  264. returns NULL. Otherwise, if recovery is still in progress this will
  265. increase monotonically. If recovery has completed then this value will
  266. remain static at the value of the last transaction applied during that
  267. recovery. When the server has been started normally without recovery
  268. the function returns NULL.
  269. </td></tr></tbody></table></div></div><br class="table-break" /><a id="id-1.5.8.31.6.8" class="indexterm"></a><a id="id-1.5.8.31.6.9" class="indexterm"></a><a id="id-1.5.8.31.6.10" class="indexterm"></a><a id="id-1.5.8.31.6.11" class="indexterm"></a><p>
  270. The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-RECOVERY-CONTROL-TABLE" title="Table 9.86. Recovery Control Functions">Table 9.86</a> control the progress of recovery.
  271. These functions may be executed only during recovery.
  272. </p><div class="table" id="FUNCTIONS-RECOVERY-CONTROL-TABLE"><p class="title"><strong>Table 9.86. Recovery Control Functions</strong></p><div class="table-contents"><table class="table" summary="Recovery Control Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  273. <code class="literal"><code class="function">pg_is_wal_replay_paused()</code></code>
  274. </td><td><code class="type">bool</code></td><td>True if recovery is paused.
  275. </td></tr><tr><td>
  276. <code class="literal"><code class="function">pg_promote(<em class="parameter"><code>wait</code></em> <code class="type">boolean</code> DEFAULT true, <em class="parameter"><code>wait_seconds</code></em> <code class="type">integer</code> DEFAULT 60)</code></code>
  277. </td><td><code class="type">boolean</code></td><td>
  278. Promotes a physical standby server. With <em class="parameter"><code>wait</code></em>
  279. set to <code class="literal">true</code> (the default), the function waits until
  280. promotion is completed or <em class="parameter"><code>wait_seconds</code></em> seconds
  281. have passed, and returns <code class="literal">true</code> if promotion is
  282. successful and <code class="literal">false</code> otherwise.
  283. If <em class="parameter"><code>wait</code></em> is set to <code class="literal">false</code>, the
  284. function returns <code class="literal">true</code> immediately after sending
  285. <code class="literal">SIGUSR1</code> to the postmaster to trigger the promotion.
  286. This function is restricted to superusers by default, but other users
  287. can be granted EXECUTE to run the function.
  288. </td></tr><tr><td>
  289. <code class="literal"><code class="function">pg_wal_replay_pause()</code></code>
  290. </td><td><code class="type">void</code></td><td>Pauses recovery immediately (restricted to superusers by default, but other users can be granted EXECUTE to run the function).
  291. </td></tr><tr><td>
  292. <code class="literal"><code class="function">pg_wal_replay_resume()</code></code>
  293. </td><td><code class="type">void</code></td><td>Restarts recovery if it was paused (restricted to superusers by default, but other users can be granted EXECUTE to run the function).
  294. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  295. While recovery is paused no further database changes are applied.
  296. If in hot standby, all new queries will see the same consistent snapshot
  297. of the database, and no further query conflicts will be generated until
  298. recovery is resumed.
  299. </p><p>
  300. If streaming replication is disabled, the paused state may continue
  301. indefinitely without problem. While streaming replication is in
  302. progress WAL records will continue to be received, which will
  303. eventually fill available disk space, depending upon the duration of
  304. the pause, the rate of WAL generation and available disk space.
  305. </p></div><div class="sect2" id="FUNCTIONS-SNAPSHOT-SYNCHRONIZATION"><div class="titlepage"><div><div><h3 class="title">9.26.5. Snapshot Synchronization Functions</h3></div></div></div><a id="id-1.5.8.31.7.2" class="indexterm"></a><p>
  306. <span class="productname">PostgreSQL</span> allows database sessions to synchronize their
  307. snapshots. A <em class="firstterm">snapshot</em> determines which data is visible to the
  308. transaction that is using the snapshot. Synchronized snapshots are
  309. necessary when two or more sessions need to see identical content in the
  310. database. If two sessions just start their transactions independently,
  311. there is always a possibility that some third transaction commits
  312. between the executions of the two <code class="command">START TRANSACTION</code> commands,
  313. so that one session sees the effects of that transaction and the other
  314. does not.
  315. </p><p>
  316. To solve this problem, <span class="productname">PostgreSQL</span> allows a transaction to
  317. <em class="firstterm">export</em> the snapshot it is using. As long as the exporting
  318. transaction remains open, other transactions can <em class="firstterm">import</em> its
  319. snapshot, and thereby be guaranteed that they see exactly the same view
  320. of the database that the first transaction sees. But note that any
  321. database changes made by any one of these transactions remain invisible
  322. to the other transactions, as is usual for changes made by uncommitted
  323. transactions. So the transactions are synchronized with respect to
  324. pre-existing data, but act normally for changes they make themselves.
  325. </p><p>
  326. Snapshots are exported with the <code class="function">pg_export_snapshot</code> function,
  327. shown in <a class="xref" href="functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION-TABLE" title="Table 9.87. Snapshot Synchronization Functions">Table 9.87</a>, and
  328. imported with the <a class="xref" href="sql-set-transaction.html" title="SET TRANSACTION"><span class="refentrytitle">SET TRANSACTION</span></a> command.
  329. </p><div class="table" id="FUNCTIONS-SNAPSHOT-SYNCHRONIZATION-TABLE"><p class="title"><strong>Table 9.87. Snapshot Synchronization Functions</strong></p><div class="table-contents"><table class="table" summary="Snapshot Synchronization Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  330. <code class="literal"><code class="function">pg_export_snapshot()</code></code>
  331. </td><td><code class="type">text</code></td><td>Save the current snapshot and return its identifier</td></tr></tbody></table></div></div><br class="table-break" /><p>
  332. The function <code class="function">pg_export_snapshot</code> saves the current snapshot
  333. and returns a <code class="type">text</code> string identifying the snapshot. This string
  334. must be passed (outside the database) to clients that want to import the
  335. snapshot. The snapshot is available for import only until the end of the
  336. transaction that exported it. A transaction can export more than one
  337. snapshot, if needed. Note that doing so is only useful in <code class="literal">READ
  338. COMMITTED</code> transactions, since in <code class="literal">REPEATABLE READ</code> and
  339. higher isolation levels, transactions use the same snapshot throughout
  340. their lifetime. Once a transaction has exported any snapshots, it cannot
  341. be prepared with <a class="xref" href="sql-prepare-transaction.html" title="PREPARE TRANSACTION"><span class="refentrytitle">PREPARE TRANSACTION</span></a>.
  342. </p><p>
  343. See <a class="xref" href="sql-set-transaction.html" title="SET TRANSACTION"><span class="refentrytitle">SET TRANSACTION</span></a> for details of how to use an
  344. exported snapshot.
  345. </p></div><div class="sect2" id="FUNCTIONS-REPLICATION"><div class="titlepage"><div><div><h3 class="title">9.26.6. Replication Functions</h3></div></div></div><p>
  346. The functions shown
  347. in <a class="xref" href="functions-admin.html#FUNCTIONS-REPLICATION-TABLE" title="Table 9.88. Replication SQL Functions">Table 9.88</a> are for
  348. controlling and interacting with replication features.
  349. See <a class="xref" href="warm-standby.html#STREAMING-REPLICATION" title="26.2.5. Streaming Replication">Section 26.2.5</a>,
  350. <a class="xref" href="warm-standby.html#STREAMING-REPLICATION-SLOTS" title="26.2.6. Replication Slots">Section 26.2.6</a>, and
  351. <a class="xref" href="replication-origins.html" title="Chapter 49. Replication Progress Tracking">Chapter 49</a>
  352. for information about the underlying features.
  353. Use of functions for replication origin is restricted to superusers.
  354. Use of functions for replication slot is restricted to superusers
  355. and users having <code class="literal">REPLICATION</code> privilege.
  356. </p><p>
  357. Many of these functions have equivalent commands in the replication
  358. protocol; see <a class="xref" href="protocol-replication.html" title="52.4. Streaming Replication Protocol">Section 52.4</a>.
  359. </p><p>
  360. The functions described in
  361. <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-BACKUP" title="9.26.3. Backup Control Functions">Section 9.26.3</a>,
  362. <a class="xref" href="functions-admin.html#FUNCTIONS-RECOVERY-CONTROL" title="9.26.4. Recovery Control Functions">Section 9.26.4</a>, and
  363. <a class="xref" href="functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION" title="9.26.5. Snapshot Synchronization Functions">Section 9.26.5</a>
  364. are also relevant for replication.
  365. </p><div class="table" id="FUNCTIONS-REPLICATION-TABLE"><p class="title"><strong>Table 9.88. Replication <acronym class="acronym">SQL</acronym> Functions</strong></p><div class="table-contents"><table class="table" summary="Replication SQL Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Function</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  366. <a id="id-1.5.8.31.8.5.2.2.1.1.1" class="indexterm"></a>
  367. <code class="literal"><code class="function">pg_create_physical_replication_slot(<em class="parameter"><code>slot_name</code></em> <code class="type">name</code> [<span class="optional">, <em class="parameter"><code>immediately_reserve</code></em> <code class="type">boolean</code>, <em class="parameter"><code>temporary</code></em> <code class="type">boolean</code></span>])</code></code>
  368. </td><td>
  369. (<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>)
  370. </td><td>
  371. Creates a new physical replication slot named
  372. <em class="parameter"><code>slot_name</code></em>. The optional second parameter,
  373. when <code class="literal">true</code>, specifies that the <acronym class="acronym">LSN</acronym> for this
  374. replication slot be reserved immediately; otherwise
  375. the <acronym class="acronym">LSN</acronym> is reserved on first connection from a streaming
  376. replication client. Streaming changes from a physical slot is only
  377. possible with the streaming-replication protocol —
  378. see <a class="xref" href="protocol-replication.html" title="52.4. Streaming Replication Protocol">Section 52.4</a>. The optional third
  379. parameter, <em class="parameter"><code>temporary</code></em>, when set to true, specifies that
  380. the slot should not be permanently stored to disk and is only meant
  381. for use by current session. Temporary slots are also
  382. released upon any error. This function corresponds
  383. to the replication protocol command <code class="literal">CREATE_REPLICATION_SLOT
  384. ... PHYSICAL</code>.
  385. </td></tr><tr><td>
  386. <a id="id-1.5.8.31.8.5.2.2.2.1.1" class="indexterm"></a>
  387. <code class="literal"><code class="function">pg_drop_replication_slot(<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>)</code></code>
  388. </td><td>
  389. <code class="type">void</code>
  390. </td><td>
  391. Drops the physical or logical replication slot
  392. named <em class="parameter"><code>slot_name</code></em>. Same as replication protocol
  393. command <code class="literal">DROP_REPLICATION_SLOT</code>. For logical slots, this must
  394. be called when connected to the same database the slot was created on.
  395. </td></tr><tr><td>
  396. <a id="id-1.5.8.31.8.5.2.2.3.1.1" class="indexterm"></a>
  397. <code class="literal"><code class="function">pg_create_logical_replication_slot(<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>plugin</code></em> <code class="type">name</code> [<span class="optional">, <em class="parameter"><code>temporary</code></em> <code class="type">boolean</code></span>])</code></code>
  398. </td><td>
  399. (<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>)
  400. </td><td>
  401. Creates a new logical (decoding) replication slot named
  402. <em class="parameter"><code>slot_name</code></em> using the output plugin
  403. <em class="parameter"><code>plugin</code></em>. The optional third
  404. parameter, <em class="parameter"><code>temporary</code></em>, when set to true, specifies that
  405. the slot should not be permanently stored to disk and is only meant
  406. for use by current session. Temporary slots are also
  407. released upon any error. A call to this function has the same
  408. effect as the replication protocol command
  409. <code class="literal">CREATE_REPLICATION_SLOT ... LOGICAL</code>.
  410. </td></tr><tr><td>
  411. <a id="id-1.5.8.31.8.5.2.2.4.1.1" class="indexterm"></a>
  412. <code class="literal"><code class="function">pg_copy_physical_replication_slot(<em class="parameter"><code>src_slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>dst_slot_name</code></em> <code class="type">name</code> [<span class="optional">, <em class="parameter"><code>temporary</code></em> <code class="type">boolean</code></span>])</code></code>
  413. </td><td>
  414. (<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>)
  415. </td><td>
  416. Copies an existing physical replication slot named <em class="parameter"><code>src_slot_name</code></em>
  417. to a physical replication slot named <em class="parameter"><code>dst_slot_name</code></em>.
  418. The copied physical slot starts to reserve WAL from the same <acronym class="acronym">LSN</acronym> as the
  419. source slot.
  420. <em class="parameter"><code>temporary</code></em> is optional. If <em class="parameter"><code>temporary</code></em>
  421. is omitted, the same value as the source slot is used.
  422. </td></tr><tr><td>
  423. <a id="id-1.5.8.31.8.5.2.2.5.1.1" class="indexterm"></a>
  424. <code class="literal"><code class="function">pg_copy_logical_replication_slot(<em class="parameter"><code>src_slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>dst_slot_name</code></em> <code class="type">name</code> [<span class="optional">, <em class="parameter"><code>temporary</code></em> <code class="type">boolean</code> [<span class="optional">, <em class="parameter"><code>plugin</code></em> <code class="type">name</code></span>]</span>])</code></code>
  425. </td><td>
  426. (<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>)
  427. </td><td>
  428. Copies an existing logical replication slot named <em class="parameter"><code>src_slot_name</code></em>
  429. to a logical replication slot named <em class="parameter"><code>dst_slot_name</code></em>
  430. while changing the output plugin and persistence. The copied logical slot starts
  431. from the same <acronym class="acronym">LSN</acronym> as the source logical slot. Both
  432. <em class="parameter"><code>temporary</code></em> and <em class="parameter"><code>plugin</code></em> are optional.
  433. If <em class="parameter"><code>temporary</code></em> or <em class="parameter"><code>plugin</code></em> are omitted,
  434. the same values as the source logical slot are used.
  435. </td></tr><tr><td>
  436. <a id="id-1.5.8.31.8.5.2.2.6.1.1" class="indexterm"></a>
  437. <code class="literal"><code class="function">pg_logical_slot_get_changes(<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>upto_nchanges</code></em> <code class="type">int</code>, VARIADIC <em class="parameter"><code>options</code></em> <code class="type">text[]</code>)</code></code>
  438. </td><td>
  439. (<em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>xid</code></em> <code class="type">xid</code>, <em class="parameter"><code>data</code></em> <code class="type">text</code>)
  440. </td><td>
  441. Returns changes in the slot <em class="parameter"><code>slot_name</code></em>, starting
  442. from the point at which since changes have been consumed last. If
  443. <em class="parameter"><code>upto_lsn</code></em> and <em class="parameter"><code>upto_nchanges</code></em> are NULL,
  444. logical decoding will continue until end of WAL. If
  445. <em class="parameter"><code>upto_lsn</code></em> is non-NULL, decoding will include only
  446. those transactions which commit prior to the specified LSN. If
  447. <em class="parameter"><code>upto_nchanges</code></em> is non-NULL, decoding will
  448. stop when the number of rows produced by decoding exceeds
  449. the specified value. Note, however, that the actual number of
  450. rows returned may be larger, since this limit is only checked after
  451. adding the rows produced when decoding each new transaction commit.
  452. </td></tr><tr><td>
  453. <a id="id-1.5.8.31.8.5.2.2.7.1.1" class="indexterm"></a>
  454. <code class="literal"><code class="function">pg_logical_slot_peek_changes(<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>upto_nchanges</code></em> <code class="type">int</code>, VARIADIC <em class="parameter"><code>options</code></em> <code class="type">text[]</code>)</code></code>
  455. </td><td>
  456. (<em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>xid</code></em> <code class="type">xid</code>, <em class="parameter"><code>data</code></em> <code class="type">text</code>)
  457. </td><td>
  458. Behaves just like
  459. the <code class="function">pg_logical_slot_get_changes()</code> function,
  460. except that changes are not consumed; that is, they will be returned
  461. again on future calls.
  462. </td></tr><tr><td>
  463. <a id="id-1.5.8.31.8.5.2.2.8.1.1" class="indexterm"></a>
  464. <code class="literal"><code class="function">pg_logical_slot_get_binary_changes(<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>upto_nchanges</code></em> <code class="type">int</code>, VARIADIC <em class="parameter"><code>options</code></em> <code class="type">text[]</code>)</code></code>
  465. </td><td>
  466. (<em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>xid</code></em> <code class="type">xid</code>, <em class="parameter"><code>data</code></em> <code class="type">bytea</code>)
  467. </td><td>
  468. Behaves just like
  469. the <code class="function">pg_logical_slot_get_changes()</code> function,
  470. except that changes are returned as <code class="type">bytea</code>.
  471. </td></tr><tr><td>
  472. <a id="id-1.5.8.31.8.5.2.2.9.1.1" class="indexterm"></a>
  473. <code class="literal"><code class="function">pg_logical_slot_peek_binary_changes(<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>upto_nchanges</code></em> <code class="type">int</code>, VARIADIC <em class="parameter"><code>options</code></em> <code class="type">text[]</code>)</code></code>
  474. </td><td>
  475. (<em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>xid</code></em> <code class="type">xid</code>, <em class="parameter"><code>data</code></em> <code class="type">bytea</code>)
  476. </td><td>
  477. Behaves just like
  478. the <code class="function">pg_logical_slot_get_changes()</code> function,
  479. except that changes are returned as <code class="type">bytea</code> and that
  480. changes are not consumed; that is, they will be returned again
  481. on future calls.
  482. </td></tr><tr><td>
  483. <a id="id-1.5.8.31.8.5.2.2.10.1.1" class="indexterm"></a>
  484. <code class="literal"><code class="function">pg_replication_slot_advance(<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>upto_lsn</code></em> <code class="type">pg_lsn</code>)</code></code>
  485. </td><td>
  486. (<em class="parameter"><code>slot_name</code></em> <code class="type">name</code>, <em class="parameter"><code>end_lsn</code></em> <code class="type">pg_lsn</code>)
  487. <code class="type">bool</code>
  488. </td><td>
  489. Advances the current confirmed position of a replication slot named
  490. <em class="parameter"><code>slot_name</code></em>. The slot will not be moved backwards,
  491. and it will not be moved beyond the current insert location. Returns
  492. the name of the slot and the real position to which it was advanced to.
  493. The information of the updated slot is written out at the follow-up
  494. checkpoint if any advancing is done. In the event of a crash, the
  495. slot may return to an earlier position.
  496. </td></tr><tr><td id="PG-REPLICATION-ORIGIN-CREATE">
  497. <a id="id-1.5.8.31.8.5.2.2.11.1.1" class="indexterm"></a>
  498. <code class="literal"><code class="function">pg_replication_origin_create(<em class="parameter"><code>node_name</code></em> <code class="type">text</code>)</code></code>
  499. </td><td>
  500. <code class="type">oid</code>
  501. </td><td>
  502. Create a replication origin with the given external
  503. name, and return the internal id assigned to it.
  504. </td></tr><tr><td id="PG-REPLICATION-ORIGIN-DROP">
  505. <a id="id-1.5.8.31.8.5.2.2.12.1.1" class="indexterm"></a>
  506. <code class="literal"><code class="function">pg_replication_origin_drop(<em class="parameter"><code>node_name</code></em> <code class="type">text</code>)</code></code>
  507. </td><td>
  508. <code class="type">void</code>
  509. </td><td>
  510. Delete a previously created replication origin, including any
  511. associated replay progress.
  512. </td></tr><tr><td>
  513. <a id="id-1.5.8.31.8.5.2.2.13.1.1" class="indexterm"></a>
  514. <code class="literal"><code class="function">pg_replication_origin_oid(<em class="parameter"><code>node_name</code></em> <code class="type">text</code>)</code></code>
  515. </td><td>
  516. <code class="type">oid</code>
  517. </td><td>
  518. Lookup a replication origin by name and return the internal id. If no
  519. corresponding replication origin is found an error is thrown.
  520. </td></tr><tr><td id="PG-REPLICATION-ORIGIN-SESSION-SETUP">
  521. <a id="id-1.5.8.31.8.5.2.2.14.1.1" class="indexterm"></a>
  522. <code class="literal"><code class="function">pg_replication_origin_session_setup(<em class="parameter"><code>node_name</code></em> <code class="type">text</code>)</code></code>
  523. </td><td>
  524. <code class="type">void</code>
  525. </td><td>
  526. Mark the current session as replaying from the given
  527. origin, allowing replay progress to be tracked. Use
  528. <code class="function">pg_replication_origin_session_reset</code> to revert.
  529. Can only be used if no previous origin is configured.
  530. </td></tr><tr><td>
  531. <a id="id-1.5.8.31.8.5.2.2.15.1.1" class="indexterm"></a>
  532. <code class="literal"><code class="function">pg_replication_origin_session_reset()</code></code>
  533. </td><td>
  534. <code class="type">void</code>
  535. </td><td>
  536. Cancel the effects
  537. of <code class="function">pg_replication_origin_session_setup()</code>.
  538. </td></tr><tr><td>
  539. <a id="id-1.5.8.31.8.5.2.2.16.1.1" class="indexterm"></a>
  540. <code class="literal"><code class="function">pg_replication_origin_session_is_setup()</code></code>
  541. </td><td>
  542. <code class="type">bool</code>
  543. </td><td>
  544. Has a replication origin been configured in the current session?
  545. </td></tr><tr><td id="PG-REPLICATION-ORIGIN-SESSION-PROGRESS">
  546. <a id="id-1.5.8.31.8.5.2.2.17.1.1" class="indexterm"></a>
  547. <code class="literal"><code class="function">pg_replication_origin_session_progress(<em class="parameter"><code>flush</code></em> <code class="type">bool</code>)</code></code>
  548. </td><td>
  549. <code class="type">pg_lsn</code>
  550. </td><td>
  551. Return the replay location for the replication origin configured in
  552. the current session. The parameter <em class="parameter"><code>flush</code></em>
  553. determines whether the corresponding local transaction will be
  554. guaranteed to have been flushed to disk or not.
  555. </td></tr><tr><td id="PG-REPLICATION-ORIGIN-XACT-SETUP">
  556. <a id="id-1.5.8.31.8.5.2.2.18.1.1" class="indexterm"></a>
  557. <code class="literal"><code class="function">pg_replication_origin_xact_setup(<em class="parameter"><code>origin_lsn</code></em> <code class="type">pg_lsn</code>, <em class="parameter"><code>origin_timestamp</code></em> <code class="type">timestamptz</code>)</code></code>
  558. </td><td>
  559. <code class="type">void</code>
  560. </td><td>
  561. Mark the current transaction as replaying a transaction that has
  562. committed at the given <acronym class="acronym">LSN</acronym> and timestamp. Can
  563. only be called when a replication origin has previously been
  564. configured using
  565. <code class="function">pg_replication_origin_session_setup()</code>.
  566. </td></tr><tr><td id="PG-REPLICATION-ORIGIN-XACT-RESET">
  567. <a id="id-1.5.8.31.8.5.2.2.19.1.1" class="indexterm"></a>
  568. <code class="literal"><code class="function">pg_replication_origin_xact_reset()</code></code>
  569. </td><td>
  570. <code class="type">void</code>
  571. </td><td>
  572. Cancel the effects of
  573. <code class="function">pg_replication_origin_xact_setup()</code>.
  574. </td></tr><tr><td id="PG-REPLICATION-ORIGIN-ADVANCE">
  575. <a id="id-1.5.8.31.8.5.2.2.20.1.1" class="indexterm"></a>
  576. <code class="literal">pg_replication_origin_advance<code class="function">(<em class="parameter"><code>node_name</code></em> <code class="type">text</code>, <em class="parameter"><code>lsn</code></em> <code class="type">pg_lsn</code>)</code></code>
  577. </td><td>
  578. <code class="type">void</code>
  579. </td><td>
  580. Set replication progress for the given node to the given
  581. location. This primarily is useful for setting up the initial location
  582. or a new location after configuration changes and similar. Be aware
  583. that careless use of this function can lead to inconsistently
  584. replicated data.
  585. </td></tr><tr><td id="PG-REPLICATION-ORIGIN-PROGRESS">
  586. <a id="id-1.5.8.31.8.5.2.2.21.1.1" class="indexterm"></a>
  587. <code class="literal"><code class="function">pg_replication_origin_progress(<em class="parameter"><code>node_name</code></em> <code class="type">text</code>, <em class="parameter"><code>flush</code></em> <code class="type">bool</code>)</code></code>
  588. </td><td>
  589. <code class="type">pg_lsn</code>
  590. </td><td>
  591. Return the replay location for the given replication origin. The
  592. parameter <em class="parameter"><code>flush</code></em> determines whether the
  593. corresponding local transaction will be guaranteed to have been
  594. flushed to disk or not.
  595. </td></tr><tr><td id="PG-LOGICAL-EMIT-MESSAGE-TEXT">
  596. <a id="id-1.5.8.31.8.5.2.2.22.1.1" class="indexterm"></a>
  597. <code class="literal"><code class="function">pg_logical_emit_message(<em class="parameter"><code>transactional</code></em> <code class="type">bool</code>, <em class="parameter"><code>prefix</code></em> <code class="type">text</code>, <em class="parameter"><code>content</code></em> <code class="type">text</code>)</code></code>
  598. </td><td>
  599. <code class="type">pg_lsn</code>
  600. </td><td>
  601. Emit text logical decoding message. This can be used to pass generic
  602. messages to logical decoding plugins through WAL. The parameter
  603. <em class="parameter"><code>transactional</code></em> specifies if the message should
  604. be part of current transaction or if it should be written immediately
  605. and decoded as soon as the logical decoding reads the record. The
  606. <em class="parameter"><code>prefix</code></em> is textual prefix used by the logical
  607. decoding plugins to easily recognize interesting messages for them.
  608. The <em class="parameter"><code>content</code></em> is the text of the message.
  609. </td></tr><tr><td id="PG-LOGICAL-EMIT-MESSAGE-BYTEA">
  610. <code class="literal"><code class="function">pg_logical_emit_message(<em class="parameter"><code>transactional</code></em> <code class="type">bool</code>, <em class="parameter"><code>prefix</code></em> <code class="type">text</code>, <em class="parameter"><code>content</code></em> <code class="type">bytea</code>)</code></code>
  611. </td><td>
  612. <code class="type">pg_lsn</code>
  613. </td><td>
  614. Emit binary logical decoding message. This can be used to pass generic
  615. messages to logical decoding plugins through WAL. The parameter
  616. <em class="parameter"><code>transactional</code></em> specifies if the message should
  617. be part of current transaction or if it should be written immediately
  618. and decoded as soon as the logical decoding reads the record. The
  619. <em class="parameter"><code>prefix</code></em> is textual prefix used by the logical
  620. decoding plugins to easily recognize interesting messages for them.
  621. The <em class="parameter"><code>content</code></em> is the binary content of the
  622. message.
  623. </td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="FUNCTIONS-ADMIN-DBOBJECT"><div class="titlepage"><div><div><h3 class="title">9.26.7. Database Object Management Functions</h3></div></div></div><p>
  624. The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-DBSIZE" title="Table 9.89. Database Object Size Functions">Table 9.89</a> calculate
  625. the disk space usage of database objects.
  626. </p><a id="id-1.5.8.31.9.3" class="indexterm"></a><a id="id-1.5.8.31.9.4" class="indexterm"></a><a id="id-1.5.8.31.9.5" class="indexterm"></a><a id="id-1.5.8.31.9.6" class="indexterm"></a><a id="id-1.5.8.31.9.7" class="indexterm"></a><a id="id-1.5.8.31.9.8" class="indexterm"></a><a id="id-1.5.8.31.9.9" class="indexterm"></a><a id="id-1.5.8.31.9.10" class="indexterm"></a><a id="id-1.5.8.31.9.11" class="indexterm"></a><div class="table" id="FUNCTIONS-ADMIN-DBSIZE"><p class="title"><strong>Table 9.89. Database Object Size Functions</strong></p><div class="table-contents"><table class="table" summary="Database Object Size Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="literal"><code class="function">pg_column_size(<code class="type">any</code>)</code></code></td><td><code class="type">int</code></td><td>Number of bytes used to store a particular value (possibly compressed)</td></tr><tr><td>
  627. <code class="literal"><code class="function">pg_database_size(<code class="type">oid</code>)</code></code>
  628. </td><td><code class="type">bigint</code></td><td>Disk space used by the database with the specified OID</td></tr><tr><td>
  629. <code class="literal"><code class="function">pg_database_size(<code class="type">name</code>)</code></code>
  630. </td><td><code class="type">bigint</code></td><td>Disk space used by the database with the specified name</td></tr><tr><td>
  631. <code class="literal"><code class="function">pg_indexes_size(<code class="type">regclass</code>)</code></code>
  632. </td><td><code class="type">bigint</code></td><td>
  633. Total disk space used by indexes attached to the specified table
  634. </td></tr><tr><td>
  635. <code class="literal"><code class="function">pg_relation_size(<em class="parameter"><code>relation</code></em> <code class="type">regclass</code>, <em class="parameter"><code>fork</code></em> <code class="type">text</code>)</code></code>
  636. </td><td><code class="type">bigint</code></td><td>
  637. Disk space used by the specified fork (<code class="literal">'main'</code>,
  638. <code class="literal">'fsm'</code>, <code class="literal">'vm'</code>, or <code class="literal">'init'</code>)
  639. of the specified table or index
  640. </td></tr><tr><td>
  641. <code class="literal"><code class="function">pg_relation_size(<em class="parameter"><code>relation</code></em> <code class="type">regclass</code>)</code></code>
  642. </td><td><code class="type">bigint</code></td><td>
  643. Shorthand for <code class="literal">pg_relation_size(..., 'main')</code>
  644. </td></tr><tr><td>
  645. <code class="literal"><code class="function">pg_size_bytes(<code class="type">text</code>)</code></code>
  646. </td><td><code class="type">bigint</code></td><td>
  647. Converts a size in human-readable format with size units into bytes
  648. </td></tr><tr><td>
  649. <code class="literal"><code class="function">pg_size_pretty(<code class="type">bigint</code>)</code></code>
  650. </td><td><code class="type">text</code></td><td>
  651. Converts a size in bytes expressed as a 64-bit integer into a
  652. human-readable format with size units
  653. </td></tr><tr><td>
  654. <code class="literal"><code class="function">pg_size_pretty(<code class="type">numeric</code>)</code></code>
  655. </td><td><code class="type">text</code></td><td>
  656. Converts a size in bytes expressed as a numeric value into a
  657. human-readable format with size units
  658. </td></tr><tr><td>
  659. <code class="literal"><code class="function">pg_table_size(<code class="type">regclass</code>)</code></code>
  660. </td><td><code class="type">bigint</code></td><td>
  661. Disk space used by the specified table, excluding indexes
  662. (but including TOAST, free space map, and visibility map)
  663. </td></tr><tr><td>
  664. <code class="literal"><code class="function">pg_tablespace_size(<code class="type">oid</code>)</code></code>
  665. </td><td><code class="type">bigint</code></td><td>Disk space used by the tablespace with the specified OID</td></tr><tr><td>
  666. <code class="literal"><code class="function">pg_tablespace_size(<code class="type">name</code>)</code></code>
  667. </td><td><code class="type">bigint</code></td><td>Disk space used by the tablespace with the specified name</td></tr><tr><td>
  668. <code class="literal"><code class="function">pg_total_relation_size(<code class="type">regclass</code>)</code></code>
  669. </td><td><code class="type">bigint</code></td><td>
  670. Total disk space used by the specified table,
  671. including all indexes and <acronym class="acronym">TOAST</acronym> data
  672. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  673. <code class="function">pg_column_size</code> shows the space used to store any individual
  674. data value.
  675. </p><p>
  676. <code class="function">pg_total_relation_size</code> accepts the OID or name of a
  677. table or toast table, and returns the total on-disk space used for
  678. that table, including all associated indexes. This function is
  679. equivalent to <code class="function">pg_table_size</code>
  680. <code class="literal">+</code> <code class="function">pg_indexes_size</code>.
  681. </p><p>
  682. <code class="function">pg_table_size</code> accepts the OID or name of a table and
  683. returns the disk space needed for that table, exclusive of indexes.
  684. (TOAST space, free space map, and visibility map are included.)
  685. </p><p>
  686. <code class="function">pg_indexes_size</code> accepts the OID or name of a table and
  687. returns the total disk space used by all the indexes attached to that
  688. table.
  689. </p><p>
  690. <code class="function">pg_database_size</code> and <code class="function">pg_tablespace_size</code>
  691. accept the OID or name of a database or tablespace, and return the total
  692. disk space used therein. To use <code class="function">pg_database_size</code>,
  693. you must have <code class="literal">CONNECT</code> permission on the specified database
  694. (which is granted by default), or be a member of the <code class="literal">pg_read_all_stats</code>
  695. role. To use <code class="function">pg_tablespace_size</code>, you must have
  696. <code class="literal">CREATE</code> permission on the specified tablespace, or be a member
  697. of the <code class="literal">pg_read_all_stats</code> role unless it is the default tablespace for
  698. the current database.
  699. </p><p>
  700. <code class="function">pg_relation_size</code> accepts the OID or name of a table, index
  701. or toast table, and returns the on-disk size in bytes of one fork of
  702. that relation. (Note that for most purposes it is more convenient to
  703. use the higher-level functions <code class="function">pg_total_relation_size</code>
  704. or <code class="function">pg_table_size</code>, which sum the sizes of all forks.)
  705. With one argument, it returns the size of the main data fork of the
  706. relation. The second argument can be provided to specify which fork
  707. to examine:
  708. </p><div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; "><li class="listitem"><p>
  709. <code class="literal">'main'</code> returns the size of the main
  710. data fork of the relation.
  711. </p></li><li class="listitem"><p>
  712. <code class="literal">'fsm'</code> returns the size of the Free Space Map
  713. (see <a class="xref" href="storage-fsm.html" title="68.3. Free Space Map">Section 68.3</a>) associated with the relation.
  714. </p></li><li class="listitem"><p>
  715. <code class="literal">'vm'</code> returns the size of the Visibility Map
  716. (see <a class="xref" href="storage-vm.html" title="68.4. Visibility Map">Section 68.4</a>) associated with the relation.
  717. </p></li><li class="listitem"><p>
  718. <code class="literal">'init'</code> returns the size of the initialization
  719. fork, if any, associated with the relation.
  720. </p></li></ul></div><p>
  721. </p><p>
  722. <code class="function">pg_size_pretty</code> can be used to format the result of one of
  723. the other functions in a human-readable way, using bytes, kB, MB, GB or TB
  724. as appropriate.
  725. </p><p>
  726. <code class="function">pg_size_bytes</code> can be used to get the size in bytes from a
  727. string in human-readable format. The input may have units of bytes, kB,
  728. MB, GB or TB, and is parsed case-insensitively. If no units are specified,
  729. bytes are assumed.
  730. </p><div class="note"><h3 class="title">Note</h3><p>
  731. The units kB, MB, GB and TB used by the functions
  732. <code class="function">pg_size_pretty</code> and <code class="function">pg_size_bytes</code> are defined
  733. using powers of 2 rather than powers of 10, so 1kB is 1024 bytes, 1MB is
  734. 1024<sup>2</sup> = 1048576 bytes, and so on.
  735. </p></div><p>
  736. The functions above that operate on tables or indexes accept a
  737. <code class="type">regclass</code> argument, which is simply the OID of the table or index
  738. in the <code class="structname">pg_class</code> system catalog. You do not have to look up
  739. the OID by hand, however, since the <code class="type">regclass</code> data type's input
  740. converter will do the work for you. Just write the table name enclosed in
  741. single quotes so that it looks like a literal constant. For compatibility
  742. with the handling of ordinary <acronym class="acronym">SQL</acronym> names, the string
  743. will be converted to lower case unless it contains double quotes around
  744. the table name.
  745. </p><p>
  746. If an OID that does not represent an existing object is passed as
  747. argument to one of the above functions, NULL is returned.
  748. </p><p>
  749. The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-DBLOCATION" title="Table 9.90. Database Object Location Functions">Table 9.90</a> assist
  750. in identifying the specific disk files associated with database objects.
  751. </p><a id="id-1.5.8.31.9.25" class="indexterm"></a><a id="id-1.5.8.31.9.26" class="indexterm"></a><a id="id-1.5.8.31.9.27" class="indexterm"></a><div class="table" id="FUNCTIONS-ADMIN-DBLOCATION"><p class="title"><strong>Table 9.90. Database Object Location Functions</strong></p><div class="table-contents"><table class="table" summary="Database Object Location Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  752. <code class="literal"><code class="function">pg_relation_filenode(<em class="parameter"><code>relation</code></em> <code class="type">regclass</code>)</code></code>
  753. </td><td><code class="type">oid</code></td><td>
  754. Filenode number of the specified relation
  755. </td></tr><tr><td>
  756. <code class="literal"><code class="function">pg_relation_filepath(<em class="parameter"><code>relation</code></em> <code class="type">regclass</code>)</code></code>
  757. </td><td><code class="type">text</code></td><td>
  758. File path name of the specified relation
  759. </td></tr><tr><td>
  760. <code class="literal"><code class="function">pg_filenode_relation(<em class="parameter"><code>tablespace</code></em> <code class="type">oid</code>, <em class="parameter"><code>filenode</code></em> <code class="type">oid</code>)</code></code>
  761. </td><td><code class="type">regclass</code></td><td>
  762. Find the relation associated with a given tablespace and filenode
  763. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  764. <code class="function">pg_relation_filenode</code> accepts the OID or name of a table,
  765. index, sequence, or toast table, and returns the <span class="quote">“<span class="quote">filenode</span>”</span> number
  766. currently assigned to it. The filenode is the base component of the file
  767. name(s) used for the relation (see <a class="xref" href="storage-file-layout.html" title="68.1. Database File Layout">Section 68.1</a>
  768. for more information). For most tables the result is the same as
  769. <code class="structname">pg_class</code>.<code class="structfield">relfilenode</code>, but for certain
  770. system catalogs <code class="structfield">relfilenode</code> is zero and this function must
  771. be used to get the correct value. The function returns NULL if passed
  772. a relation that does not have storage, such as a view.
  773. </p><p>
  774. <code class="function">pg_relation_filepath</code> is similar to
  775. <code class="function">pg_relation_filenode</code>, but it returns the entire file path name
  776. (relative to the database cluster's data directory <code class="varname">PGDATA</code>) of
  777. the relation.
  778. </p><p>
  779. <code class="function">pg_filenode_relation</code> is the reverse of
  780. <code class="function">pg_relation_filenode</code>. Given a <span class="quote">“<span class="quote">tablespace</span>”</span> OID and
  781. a <span class="quote">“<span class="quote">filenode</span>”</span>, it returns the associated relation's OID. For a table
  782. in the database's default tablespace, the tablespace can be specified as 0.
  783. </p><p>
  784. <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-COLLATION" title="Table 9.91. Collation Management Functions">Table 9.91</a> lists functions used to manage
  785. collations.
  786. </p><div class="table" id="FUNCTIONS-ADMIN-COLLATION"><p class="title"><strong>Table 9.91. Collation Management Functions</strong></p><div class="table-contents"><table class="table" summary="Collation Management Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  787. <a id="id-1.5.8.31.9.33.2.2.1.1.1" class="indexterm"></a>
  788. <code class="literal"><code class="function">pg_collation_actual_version(<code class="type">oid</code>)</code></code>
  789. </td><td><code class="type">text</code></td><td>Return actual version of collation from operating system</td></tr><tr><td>
  790. <a id="id-1.5.8.31.9.33.2.2.2.1.1" class="indexterm"></a>
  791. <code class="literal"><code class="function">pg_import_system_collations(<em class="parameter"><code>schema</code></em> <code class="type">regnamespace</code>)</code></code>
  792. </td><td><code class="type">integer</code></td><td>Import operating system collations</td></tr></tbody></table></div></div><br class="table-break" /><p>
  793. <code class="function">pg_collation_actual_version</code> returns the actual
  794. version of the collation object as it is currently installed in the
  795. operating system. If this is different from the value
  796. in <code class="literal">pg_collation.collversion</code>, then objects depending on
  797. the collation might need to be rebuilt. See also
  798. <a class="xref" href="sql-altercollation.html" title="ALTER COLLATION"><span class="refentrytitle">ALTER COLLATION</span></a>.
  799. </p><p>
  800. <code class="function">pg_import_system_collations</code> adds collations to the system
  801. catalog <code class="literal">pg_collation</code> based on all the
  802. locales it finds in the operating system. This is
  803. what <code class="command">initdb</code> uses;
  804. see <a class="xref" href="collation.html#COLLATION-MANAGING" title="23.2.2. Managing Collations">Section 23.2.2</a> for more details. If additional
  805. locales are installed into the operating system later on, this function
  806. can be run again to add collations for the new locales. Locales that
  807. match existing entries in <code class="literal">pg_collation</code> will be skipped.
  808. (But collation objects based on locales that are no longer
  809. present in the operating system are not removed by this function.)
  810. The <em class="parameter"><code>schema</code></em> parameter would typically
  811. be <code class="literal">pg_catalog</code>, but that is not a requirement;
  812. the collations could be installed into some other schema as well.
  813. The function returns the number of new collation objects it created.
  814. </p><div class="table" id="FUNCTIONS-INFO-PARTITION"><p class="title"><strong>Table 9.92. Partitioning Information Functions</strong></p><div class="table-contents"><table class="table" summary="Partitioning Information Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  815. <a id="id-1.5.8.31.9.36.2.2.1.1.1" class="indexterm"></a>
  816. <code class="literal"><code class="function">pg_partition_tree(<code class="type">regclass</code>)</code></code>
  817. </td><td><code class="type">setof record</code></td><td>
  818. List information about tables or indexes in a partition tree for a
  819. given partitioned table or partitioned index, with one row for each
  820. partition. Information provided includes the name of the partition,
  821. the name of its immediate parent, a boolean value telling if the
  822. partition is a leaf, and an integer telling its level in the hierarchy.
  823. The value of level begins at <code class="literal">0</code> for the input table
  824. or index in its role as the root of the partition tree,
  825. <code class="literal">1</code> for its partitions, <code class="literal">2</code> for
  826. their partitions, and so on.
  827. </td></tr><tr><td>
  828. <a id="id-1.5.8.31.9.36.2.2.2.1.1" class="indexterm"></a>
  829. <code class="literal"><code class="function">pg_partition_ancestors(<code class="type">regclass</code>)</code></code>
  830. </td><td><code class="type">setof regclass</code></td><td>
  831. List the ancestor relations of the given partition,
  832. including the partition itself.
  833. </td></tr><tr><td>
  834. <a id="id-1.5.8.31.9.36.2.2.3.1.1" class="indexterm"></a>
  835. <code class="literal"><code class="function">pg_partition_root(<code class="type">regclass</code>)</code></code>
  836. </td><td><code class="type">regclass</code></td><td>
  837. Return the top-most parent of a partition tree to which the given
  838. relation belongs.
  839. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  840. To check the total size of the data contained in
  841. <code class="structname">measurement</code> table described in
  842. <a class="xref" href="ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE-EXAMPLE" title="5.11.2.1. Example">Section 5.11.2.1</a>, one could use the
  843. following query:
  844. </p><pre class="programlisting">
  845. =# SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size
  846. FROM pg_partition_tree('measurement');
  847. total_size
  848. ------------
  849. 24 kB
  850. (1 row)
  851. </pre></div><div class="sect2" id="FUNCTIONS-ADMIN-INDEX"><div class="titlepage"><div><div><h3 class="title">9.26.8. Index Maintenance Functions</h3></div></div></div><a id="id-1.5.8.31.10.2" class="indexterm"></a><a id="id-1.5.8.31.10.3" class="indexterm"></a><a id="id-1.5.8.31.10.4" class="indexterm"></a><a id="id-1.5.8.31.10.5" class="indexterm"></a><p>
  852. <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-INDEX-TABLE" title="Table 9.93. Index Maintenance Functions">Table 9.93</a> shows the functions
  853. available for index maintenance tasks.
  854. These functions cannot be executed during recovery.
  855. Use of these functions is restricted to superusers and the owner
  856. of the given index.
  857. </p><div class="table" id="FUNCTIONS-ADMIN-INDEX-TABLE"><p class="title"><strong>Table 9.93. Index Maintenance Functions</strong></p><div class="table-contents"><table class="table" summary="Index Maintenance Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  858. <code class="literal"><code class="function">brin_summarize_new_values(<em class="parameter"><code>index</code></em> <code class="type">regclass</code>)</code></code>
  859. </td><td><code class="type">integer</code></td><td>summarize page ranges not already summarized</td></tr><tr><td>
  860. <code class="literal"><code class="function">brin_summarize_range(<em class="parameter"><code>index</code></em> <code class="type">regclass</code>, <em class="parameter"><code>blockNumber</code></em> <code class="type">bigint</code>)</code></code>
  861. </td><td><code class="type">integer</code></td><td>summarize the page range covering the given block, if not already summarized</td></tr><tr><td>
  862. <code class="literal"><code class="function">brin_desummarize_range(<em class="parameter"><code>index</code></em> <code class="type">regclass</code>, <em class="parameter"><code>blockNumber</code></em> <code class="type">bigint</code>)</code></code>
  863. </td><td><code class="type">integer</code></td><td>de-summarize the page range covering the given block, if summarized</td></tr><tr><td>
  864. <code class="literal"><code class="function">gin_clean_pending_list(<em class="parameter"><code>index</code></em> <code class="type">regclass</code>)</code></code>
  865. </td><td><code class="type">bigint</code></td><td>move GIN pending list entries into main index structure</td></tr></tbody></table></div></div><br class="table-break" /><p>
  866. <code class="function">brin_summarize_new_values</code> accepts the OID or name of a
  867. BRIN index and inspects the index to find page ranges in the base table
  868. that are not currently summarized by the index; for any such range
  869. it creates a new summary index tuple by scanning the table pages.
  870. It returns the number of new page range summaries that were inserted
  871. into the index. <code class="function">brin_summarize_range</code> does the same, except
  872. it only summarizes the range that covers the given block number.
  873. </p><p>
  874. <code class="function">gin_clean_pending_list</code> accepts the OID or name of
  875. a GIN index and cleans up the pending list of the specified index
  876. by moving entries in it to the main GIN data structure in bulk.
  877. It returns the number of pages removed from the pending list.
  878. Note that if the argument is a GIN index built with
  879. the <code class="literal">fastupdate</code> option disabled, no cleanup happens and the
  880. return value is 0, because the index doesn't have a pending list.
  881. Please see <a class="xref" href="gin-implementation.html#GIN-FAST-UPDATE" title="66.4.1. GIN Fast Update Technique">Section 66.4.1</a> and <a class="xref" href="gin-tips.html" title="66.5. GIN Tips and Tricks">Section 66.5</a>
  882. for details of the pending list and <code class="literal">fastupdate</code> option.
  883. </p></div><div class="sect2" id="FUNCTIONS-ADMIN-GENFILE"><div class="titlepage"><div><div><h3 class="title">9.26.9. Generic File Access Functions</h3></div></div></div><p>
  884. The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-GENFILE-TABLE" title="Table 9.94. Generic File Access Functions">Table 9.94</a> provide native access to
  885. files on the machine hosting the server. Only files within the
  886. database cluster directory and the <code class="varname">log_directory</code> can be
  887. accessed unless the user is granted the role
  888. <code class="literal">pg_read_server_files</code>. Use a relative path for files in
  889. the cluster directory, and a path matching the <code class="varname">log_directory</code>
  890. configuration setting for log files.
  891. </p><p>
  892. Note that granting users the EXECUTE privilege on
  893. <code class="function">pg_read_file()</code>, or related functions, allows them the
  894. ability to read any file on the server which the database can read and
  895. that those reads bypass all in-database privilege checks. This means that,
  896. among other things, a user with this access is able to read the contents of the
  897. <code class="literal">pg_authid</code> table where authentication information is contained,
  898. as well as read any file in the database. Therefore, granting access to these
  899. functions should be carefully considered.
  900. </p><div class="table" id="FUNCTIONS-ADMIN-GENFILE-TABLE"><p class="title"><strong>Table 9.94. Generic File Access Functions</strong></p><div class="table-contents"><table class="table" summary="Generic File Access Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  901. <code class="literal"><code class="function">pg_ls_dir(<em class="parameter"><code>dirname</code></em> <code class="type">text</code> [, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code>, <em class="parameter"><code>include_dot_dirs</code></em> <code class="type">boolean</code>])</code></code>
  902. </td><td><code class="type">setof text</code></td><td>
  903. List the contents of a directory. Restricted to superusers by default, but other users can be granted EXECUTE to run the function.
  904. </td></tr><tr><td>
  905. <code class="literal"><code class="function">pg_ls_logdir()</code></code>
  906. </td><td><code class="type">setof record</code></td><td>
  907. List the name, size, and last modification time of files in the log
  908. directory. Access is granted to members of the <code class="literal">pg_monitor</code>
  909. role and may be granted to other non-superuser roles.
  910. </td></tr><tr><td>
  911. <code class="literal"><code class="function">pg_ls_waldir()</code></code>
  912. </td><td><code class="type">setof record</code></td><td>
  913. List the name, size, and last modification time of files in the WAL
  914. directory. Access is granted to members of the <code class="literal">pg_monitor</code>
  915. role and may be granted to other non-superuser roles.
  916. </td></tr><tr><td>
  917. <code class="literal"><code class="function">pg_ls_archive_statusdir()</code></code>
  918. </td><td><code class="type">setof record</code></td><td>
  919. List the name, size, and last modification time of files in the WAL
  920. archive status directory. Access is granted to members of the
  921. <code class="literal">pg_monitor</code> role and may be granted to other
  922. non-superuser roles.
  923. </td></tr><tr><td>
  924. <code class="literal"><code class="function">pg_ls_tmpdir([<span class="optional"><em class="parameter"><code>tablespace</code></em> <code class="type">oid</code></span>])</code></code>
  925. </td><td><code class="type">setof record</code></td><td>
  926. List the name, size, and last modification time of files in the
  927. temporary directory for <em class="parameter"><code>tablespace</code></em>. If
  928. <em class="parameter"><code>tablespace</code></em> is not provided, the
  929. <code class="literal">pg_default</code> tablespace is used. Access is granted
  930. to members of the <code class="literal">pg_monitor</code> role and may be
  931. granted to other non-superuser roles.
  932. </td></tr><tr><td>
  933. <code class="literal"><code class="function">pg_read_file(<em class="parameter"><code>filename</code></em> <code class="type">text</code> [, <em class="parameter"><code>offset</code></em> <code class="type">bigint</code>, <em class="parameter"><code>length</code></em> <code class="type">bigint</code> [, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code>] ])</code></code>
  934. </td><td><code class="type">text</code></td><td>
  935. Return the contents of a text file. Restricted to superusers by default, but other users can be granted EXECUTE to run the function.
  936. </td></tr><tr><td>
  937. <code class="literal"><code class="function">pg_read_binary_file(<em class="parameter"><code>filename</code></em> <code class="type">text</code> [, <em class="parameter"><code>offset</code></em> <code class="type">bigint</code>, <em class="parameter"><code>length</code></em> <code class="type">bigint</code> [, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code>] ])</code></code>
  938. </td><td><code class="type">bytea</code></td><td>
  939. Return the contents of a file. Restricted to superusers by default, but other users can be granted EXECUTE to run the function.
  940. </td></tr><tr><td>
  941. <code class="literal"><code class="function">pg_stat_file(<em class="parameter"><code>filename</code></em> <code class="type">text</code>[, <em class="parameter"><code>missing_ok</code></em> <code class="type">boolean</code>])</code></code>
  942. </td><td><code class="type">record</code></td><td>
  943. Return information about a file. Restricted to superusers by default, but other users can be granted EXECUTE to run the function.
  944. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  945. Some of these functions take an optional <em class="parameter"><code>missing_ok</code></em> parameter,
  946. which specifies the behavior when the file or directory does not exist.
  947. If <code class="literal">true</code>, the function returns NULL (except
  948. <code class="function">pg_ls_dir</code>, which returns an empty result set). If
  949. <code class="literal">false</code>, an error is raised. The default is <code class="literal">false</code>.
  950. </p><a id="id-1.5.8.31.11.6" class="indexterm"></a><p>
  951. <code class="function">pg_ls_dir</code> returns the names of all files (and directories
  952. and other special files) in the specified directory. The <em class="parameter"><code>
  953. include_dot_dirs</code></em> indicates whether <span class="quote">“<span class="quote">.</span>”</span> and <span class="quote">“<span class="quote">..</span>”</span> are
  954. included in the result set. The default is to exclude them
  955. (<code class="literal">false</code>), but including them can be useful when
  956. <em class="parameter"><code>missing_ok</code></em> is <code class="literal">true</code>, to distinguish an
  957. empty directory from an non-existent directory.
  958. </p><a id="id-1.5.8.31.11.8" class="indexterm"></a><p>
  959. <code class="function">pg_ls_logdir</code> returns the name, size, and last modified time
  960. (mtime) of each file in the log directory. By default, only superusers
  961. and members of the <code class="literal">pg_monitor</code> role can use this function.
  962. Access may be granted to others using <code class="command">GRANT</code>.
  963. Filenames beginning with a dot, directories, and other special files are not shown.
  964. </p><a id="id-1.5.8.31.11.10" class="indexterm"></a><p>
  965. <code class="function">pg_ls_waldir</code> returns the name, size, and last modified time
  966. (mtime) of each file in the write ahead log (WAL) directory. By
  967. default only superusers and members of the <code class="literal">pg_monitor</code> role
  968. can use this function. Access may be granted to others using
  969. <code class="command">GRANT</code>.
  970. Filenames beginning with a dot, directories, and other special files are not shown.
  971. </p><a id="id-1.5.8.31.11.12" class="indexterm"></a><p>
  972. <code class="function">pg_ls_archive_statusdir</code> returns the name, size, and
  973. last modified time (mtime) of each file in the WAL archive status
  974. directory <code class="filename">pg_wal/archive_status</code>. By default only
  975. superusers and members of the <code class="literal">pg_monitor</code> role can
  976. use this function. Access may be granted to others using
  977. <code class="command">GRANT</code>.
  978. Filenames beginning with a dot, directories, and other special files are not shown.
  979. </p><a id="id-1.5.8.31.11.14" class="indexterm"></a><p>
  980. <code class="function">pg_ls_tmpdir</code> returns the name, size, and last modified
  981. time (mtime) of each file in the temporary file directory for the specified
  982. <em class="parameter"><code>tablespace</code></em>. If <em class="parameter"><code>tablespace</code></em> is
  983. not provided, the <code class="literal">pg_default</code> tablespace is used. By
  984. default only superusers and members of the <code class="literal">pg_monitor</code>
  985. role can use this function. Access may be granted to others using
  986. <code class="command">GRANT</code>.
  987. Filenames beginning with a dot, directories, and other special files are not shown.
  988. </p><a id="id-1.5.8.31.11.16" class="indexterm"></a><p>
  989. <code class="function">pg_read_file</code> returns part of a text file, starting
  990. at the given <em class="parameter"><code>offset</code></em>, returning at most <em class="parameter"><code>length</code></em>
  991. bytes (less if the end of file is reached first). If <em class="parameter"><code>offset</code></em>
  992. is negative, it is relative to the end of the file.
  993. If <em class="parameter"><code>offset</code></em> and <em class="parameter"><code>length</code></em> are omitted, the entire
  994. file is returned. The bytes read from the file are interpreted as a string
  995. in the server encoding; an error is thrown if they are not valid in that
  996. encoding.
  997. </p><a id="id-1.5.8.31.11.18" class="indexterm"></a><p>
  998. <code class="function">pg_read_binary_file</code> is similar to
  999. <code class="function">pg_read_file</code>, except that the result is a <code class="type">bytea</code> value;
  1000. accordingly, no encoding checks are performed.
  1001. In combination with the <code class="function">convert_from</code> function, this function
  1002. can be used to read a file in a specified encoding:
  1003. </p><pre class="programlisting">
  1004. SELECT convert_from(pg_read_binary_file('file_in_utf8.txt'), 'UTF8');
  1005. </pre><p>
  1006. </p><a id="id-1.5.8.31.11.20" class="indexterm"></a><p>
  1007. <code class="function">pg_stat_file</code> returns a record containing the file
  1008. size, last accessed time stamp, last modified time stamp,
  1009. last file status change time stamp (Unix platforms only),
  1010. file creation time stamp (Windows only), and a <code class="type">boolean</code>
  1011. indicating if it is a directory. Typical usages include:
  1012. </p><pre class="programlisting">
  1013. SELECT * FROM pg_stat_file('filename');
  1014. SELECT (pg_stat_file('filename')).modification;
  1015. </pre><p>
  1016. </p></div><div class="sect2" id="FUNCTIONS-ADVISORY-LOCKS"><div class="titlepage"><div><div><h3 class="title">9.26.10. Advisory Lock Functions</h3></div></div></div><p>
  1017. The functions shown in <a class="xref" href="functions-admin.html#FUNCTIONS-ADVISORY-LOCKS-TABLE" title="Table 9.95. Advisory Lock Functions">Table 9.95</a>
  1018. manage advisory locks. For details about proper use of these functions,
  1019. see <a class="xref" href="explicit-locking.html#ADVISORY-LOCKS" title="13.3.5. Advisory Locks">Section 13.3.5</a>.
  1020. </p><div class="table" id="FUNCTIONS-ADVISORY-LOCKS-TABLE"><p class="title"><strong>Table 9.95. Advisory Lock Functions</strong></p><div class="table-contents"><table class="table" summary="Advisory Lock Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  1021. <code class="literal"><code class="function">pg_advisory_lock(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1022. </td><td><code class="type">void</code></td><td>Obtain exclusive session level advisory lock</td></tr><tr><td>
  1023. <code class="literal"><code class="function">pg_advisory_lock(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1024. </td><td><code class="type">void</code></td><td>Obtain exclusive session level advisory lock</td></tr><tr><td>
  1025. <code class="literal"><code class="function">pg_advisory_lock_shared(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1026. </td><td><code class="type">void</code></td><td>Obtain shared session level advisory lock</td></tr><tr><td>
  1027. <code class="literal"><code class="function">pg_advisory_lock_shared(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1028. </td><td><code class="type">void</code></td><td>Obtain shared session level advisory lock</td></tr><tr><td>
  1029. <code class="literal"><code class="function">pg_advisory_unlock(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1030. </td><td><code class="type">boolean</code></td><td>Release an exclusive session level advisory lock</td></tr><tr><td>
  1031. <code class="literal"><code class="function">pg_advisory_unlock(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1032. </td><td><code class="type">boolean</code></td><td>Release an exclusive session level advisory lock</td></tr><tr><td>
  1033. <code class="literal"><code class="function">pg_advisory_unlock_all()</code></code>
  1034. </td><td><code class="type">void</code></td><td>Release all session level advisory locks held by the current session</td></tr><tr><td>
  1035. <code class="literal"><code class="function">pg_advisory_unlock_shared(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1036. </td><td><code class="type">boolean</code></td><td>Release a shared session level advisory lock</td></tr><tr><td>
  1037. <code class="literal"><code class="function">pg_advisory_unlock_shared(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1038. </td><td><code class="type">boolean</code></td><td>Release a shared session level advisory lock</td></tr><tr><td>
  1039. <code class="literal"><code class="function">pg_advisory_xact_lock(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1040. </td><td><code class="type">void</code></td><td>Obtain exclusive transaction level advisory lock</td></tr><tr><td>
  1041. <code class="literal"><code class="function">pg_advisory_xact_lock(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1042. </td><td><code class="type">void</code></td><td>Obtain exclusive transaction level advisory lock</td></tr><tr><td>
  1043. <code class="literal"><code class="function">pg_advisory_xact_lock_shared(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1044. </td><td><code class="type">void</code></td><td>Obtain shared transaction level advisory lock</td></tr><tr><td>
  1045. <code class="literal"><code class="function">pg_advisory_xact_lock_shared(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1046. </td><td><code class="type">void</code></td><td>Obtain shared transaction level advisory lock</td></tr><tr><td>
  1047. <code class="literal"><code class="function">pg_try_advisory_lock(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1048. </td><td><code class="type">boolean</code></td><td>Obtain exclusive session level advisory lock if available</td></tr><tr><td>
  1049. <code class="literal"><code class="function">pg_try_advisory_lock(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1050. </td><td><code class="type">boolean</code></td><td>Obtain exclusive session level advisory lock if available</td></tr><tr><td>
  1051. <code class="literal"><code class="function">pg_try_advisory_lock_shared(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1052. </td><td><code class="type">boolean</code></td><td>Obtain shared session level advisory lock if available</td></tr><tr><td>
  1053. <code class="literal"><code class="function">pg_try_advisory_lock_shared(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1054. </td><td><code class="type">boolean</code></td><td>Obtain shared session level advisory lock if available</td></tr><tr><td>
  1055. <code class="literal"><code class="function">pg_try_advisory_xact_lock(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1056. </td><td><code class="type">boolean</code></td><td>Obtain exclusive transaction level advisory lock if available</td></tr><tr><td>
  1057. <code class="literal"><code class="function">pg_try_advisory_xact_lock(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1058. </td><td><code class="type">boolean</code></td><td>Obtain exclusive transaction level advisory lock if available</td></tr><tr><td>
  1059. <code class="literal"><code class="function">pg_try_advisory_xact_lock_shared(<em class="parameter"><code>key</code></em> <code class="type">bigint</code>)</code></code>
  1060. </td><td><code class="type">boolean</code></td><td>Obtain shared transaction level advisory lock if available</td></tr><tr><td>
  1061. <code class="literal"><code class="function">pg_try_advisory_xact_lock_shared(<em class="parameter"><code>key1</code></em> <code class="type">int</code>, <em class="parameter"><code>key2</code></em> <code class="type">int</code>)</code></code>
  1062. </td><td><code class="type">boolean</code></td><td>Obtain shared transaction level advisory lock if available</td></tr></tbody></table></div></div><br class="table-break" /><a id="id-1.5.8.31.12.4" class="indexterm"></a><p>
  1063. <code class="function">pg_advisory_lock</code> locks an application-defined resource,
  1064. which can be identified either by a single 64-bit key value or two
  1065. 32-bit key values (note that these two key spaces do not overlap).
  1066. If another session already holds a lock on the same resource identifier,
  1067. this function will wait until the resource becomes available. The lock
  1068. is exclusive. Multiple lock requests stack, so that if the same resource
  1069. is locked three times it must then be unlocked three times to be
  1070. released for other sessions' use.
  1071. </p><a id="id-1.5.8.31.12.6" class="indexterm"></a><p>
  1072. <code class="function">pg_advisory_lock_shared</code> works the same as
  1073. <code class="function">pg_advisory_lock</code>,
  1074. except the lock can be shared with other sessions requesting shared locks.
  1075. Only would-be exclusive lockers are locked out.
  1076. </p><a id="id-1.5.8.31.12.8" class="indexterm"></a><p>
  1077. <code class="function">pg_try_advisory_lock</code> is similar to
  1078. <code class="function">pg_advisory_lock</code>, except the function will not wait for the
  1079. lock to become available. It will either obtain the lock immediately and
  1080. return <code class="literal">true</code>, or return <code class="literal">false</code> if the lock cannot be
  1081. acquired immediately.
  1082. </p><a id="id-1.5.8.31.12.10" class="indexterm"></a><p>
  1083. <code class="function">pg_try_advisory_lock_shared</code> works the same as
  1084. <code class="function">pg_try_advisory_lock</code>, except it attempts to acquire
  1085. a shared rather than an exclusive lock.
  1086. </p><a id="id-1.5.8.31.12.12" class="indexterm"></a><p>
  1087. <code class="function">pg_advisory_unlock</code> will release a previously-acquired
  1088. exclusive session level advisory lock. It
  1089. returns <code class="literal">true</code> if the lock is successfully released.
  1090. If the lock was not held, it will return <code class="literal">false</code>,
  1091. and in addition, an SQL warning will be reported by the server.
  1092. </p><a id="id-1.5.8.31.12.14" class="indexterm"></a><p>
  1093. <code class="function">pg_advisory_unlock_shared</code> works the same as
  1094. <code class="function">pg_advisory_unlock</code>,
  1095. except it releases a shared session level advisory lock.
  1096. </p><a id="id-1.5.8.31.12.16" class="indexterm"></a><p>
  1097. <code class="function">pg_advisory_unlock_all</code> will release all session level advisory
  1098. locks held by the current session. (This function is implicitly invoked
  1099. at session end, even if the client disconnects ungracefully.)
  1100. </p><a id="id-1.5.8.31.12.18" class="indexterm"></a><p>
  1101. <code class="function">pg_advisory_xact_lock</code> works the same as
  1102. <code class="function">pg_advisory_lock</code>, except the lock is automatically released
  1103. at the end of the current transaction and cannot be released explicitly.
  1104. </p><a id="id-1.5.8.31.12.20" class="indexterm"></a><p>
  1105. <code class="function">pg_advisory_xact_lock_shared</code> works the same as
  1106. <code class="function">pg_advisory_lock_shared</code>, except the lock is automatically released
  1107. at the end of the current transaction and cannot be released explicitly.
  1108. </p><a id="id-1.5.8.31.12.22" class="indexterm"></a><p>
  1109. <code class="function">pg_try_advisory_xact_lock</code> works the same as
  1110. <code class="function">pg_try_advisory_lock</code>, except the lock, if acquired,
  1111. is automatically released at the end of the current transaction and
  1112. cannot be released explicitly.
  1113. </p><a id="id-1.5.8.31.12.24" class="indexterm"></a><p>
  1114. <code class="function">pg_try_advisory_xact_lock_shared</code> works the same as
  1115. <code class="function">pg_try_advisory_lock_shared</code>, except the lock, if acquired,
  1116. is automatically released at the end of the current transaction and
  1117. cannot be released explicitly.
  1118. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-info.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-trigger.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.25. System Information Functions and Operators </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 9.27. Trigger Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1