File: functions-admin.html

package info (click to toggle)
pgadmin3 1.4.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 29,796 kB
  • ctags: 10,758
  • sloc: cpp: 55,356; sh: 6,164; ansic: 1,520; makefile: 576; sql: 482; xml: 100; perl: 18
file content (358 lines) | stat: -rw-r--r-- 16,460 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>9.20.System Administration Functions</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="functions.html" title="Chapter9.Functions and Operators">
<link rel="prev" href="functions-info.html" title="9.19.System Information Functions">
<link rel="next" href="typeconv.html" title="Chapter10.Type Conversion">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="functions-admin"></a>9.20.System Administration Functions</h2></div></div></div>
<p>   <a href="functions-admin.html#functions-admin-set-table" title="Table9.44.Configuration Settings Functions">Table9.44, &#8220;Configuration Settings Functions&#8221;</a> shows the functions
   available to query and alter run-time configuration parameters.
  </p>
<div class="table">
<a name="functions-admin-set-table"></a><p class="title"><b>Table9.44.Configuration Settings Functions</b></p>
<div class="table-contents"><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>        <code class="literal"><code class="function">current_setting</code>(<em class="parameter"><code>setting_name</code></em>)</code>
       </td>
<td><code class="type">text</code></td>
<td>current value of setting</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">set_config(<em class="parameter"><code>setting_name</code></em>, ,
                             <em class="parameter"><code>new_value</code></em>, ,
                             <em class="parameter"><code>is_local</code></em>)</code></code>
       </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 name="id624629"></a><a name="id624640"></a><a name="id624650"></a><p>    The function <code class="function">current_setting</code> yields the
    current value of the setting <em class="parameter"><code>setting_name</code></em>.
    It corresponds to the <acronym class="acronym">SQL</acronym> command
    <code class="command">SHOW</code>.  An example:
</p>
<pre class="programlisting">SELECT current_setting('datestyle');

 current_setting
-----------------
 ISO, MDY
(1 row)</pre>
<p>
   </p>
<p>    <code class="function">set_config</code> sets the parameter
    <em class="parameter"><code>setting_name</code></em> to
    <em class="parameter"><code>new_value</code></em>.  If
    <em class="parameter"><code>is_local</code></em> is <code class="literal">true</code>, the
    new value will only apply to the current transaction. If you want
    the new value to apply for the current session, use
    <code class="literal">false</code> instead. The function corresponds to the
    SQL command <code class="command">SET</code>. An example:
</p>
<pre class="programlisting">SELECT set_config('log_statement_stats', 'off', false);

 set_config
------------
 off
(1 row)</pre>
<p>
   </p>
<a name="id624764"></a><a name="id624775"></a><a name="id624785"></a><a name="id624796"></a><p>    The functions shown in <a href="functions-admin.html#functions-admin-signal-table" title="Table9.45.Server Signalling Functions">Table9.45, &#8220;Server Signalling Functions&#8221;</a> send control signals to
    other server processes.  Use of these functions is restricted
    to superusers.
   </p>
<div class="table">
<a name="functions-admin-signal-table"></a><p class="title"><b>Table9.45.Server Signalling Functions</b></p>
<div class="table-contents"><table summary="Server Signalling 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_cancel_backend</code>(<em class="parameter"><code>pid</code></em> <code class="type">int</code>)</code>
        </td>
<td><code class="type">boolean</code></td>
<td>Cancel a backend's current query</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_reload_conf</code>()</code>
        </td>
<td><code class="type">boolean</code></td>
<td>Cause server processes to reload their configuration files</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_rotate_logfile</code>()</code>
        </td>
<td><code class="type">boolean</code></td>
<td>Rotate server's log file</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>    Each of these functions returns <code class="literal">true</code> if
    successful and <code class="literal">false</code> otherwise.
   </p>
<p>    <code class="function">pg_cancel_backend</code> sends a query cancel
    (<span class="systemitem">SIGINT</span>) signal to a backend process identified by
    process ID.  The process ID of an active backend can be found from
    the <code class="structfield">procpid</code> column in the
    <code class="structname">pg_stat_activity</code> view, or by listing the
    <code class="command">postgres</code> processes on the server with
    <span class="application">ps</span>.
   </p>
<p>    <code class="function">pg_reload_conf</code> sends a <span class="systemitem">SIGHUP</span> signal
    to the <span class="application">postmaster</span>, causing the configuration files
    to be reloaded by all server processes.
   </p>
<p>    <code class="function">pg_rotate_logfile</code> signals the log-file manager to switch
    to a new output file immediately.  This works only when
    <code class="varname">redirect_stderr</code> is used for logging, since otherwise there
    is no log-file manager subprocess.
   </p>
<a name="id625022"></a><a name="id625032"></a><a name="id625043"></a><p>    The functions shown in <a href="functions-admin.html#functions-admin-backup-table" title="Table9.46.Backup Control Functions">Table9.46, &#8220;Backup Control Functions&#8221;</a> assist in making on-line backups.
    Use of these functions is restricted to superusers.
   </p>
<div class="table">
<a name="functions-admin-backup-table"></a><p class="title"><b>Table9.46.Backup Control Functions</b></p>
<div class="table-contents"><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>        <code class="literal"><code class="function">pg_start_backup</code>(<em class="parameter"><code>label</code></em> <code class="type">text</code>)</code>
        </td>
<td><code class="type">text</code></td>
<td>Set up for performing on-line backup</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_stop_backup</code>()</code>
        </td>
<td><code class="type">text</code></td>
<td>Finish performing on-line backup</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>    <code class="function">pg_start_backup</code> accepts a single parameter which is an
    arbitrary user-defined label for the backup.  (Typically this would be
    the name under which the backup dump file will be stored.)  The function
    writes a backup label file into the database cluster's data directory,
    and then returns the backup's starting WAL offset as text.  (The user
    need not pay any attention to this result value, but it is provided in
    case it is of use.)
   </p>
<p>    <code class="function">pg_stop_backup</code> removes the label file created by
    <code class="function">pg_start_backup</code>, and instead creates a backup history file in
    the WAL archive area.  The history file includes the label given to
    <code class="function">pg_start_backup</code>, the starting and ending WAL offsets for
    the backup, and the starting and ending times of the backup.  The return
    value is the backup's ending WAL offset (which again may be of little
    interest).
   </p>
<p>    For details about proper usage of these functions, see
    <a href="backup-online.html" title="23.3.On-line backup and point-in-time recovery (PITR)">Section23.3, &#8220;On-line backup and point-in-time recovery (PITR)&#8221;</a>.
   </p>
<p>    The functions shown in <a href="functions-admin.html#functions-admin-dbsize" title="Table9.47.Database Object Size Functions">Table9.47, &#8220;Database Object Size Functions&#8221;</a> calculate
    the actual disk space usage of database objects.
   </p>
<a name="id625213"></a><a name="id625223"></a><a name="id625234"></a><a name="id625244"></a><a name="id625255"></a><a name="id625265"></a><div class="table">
<a name="functions-admin-dbsize"></a><p class="title"><b>Table9.47.Database Object Size Functions</b></p>
<div class="table-contents"><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="function">pg_column_size</code>(<code class="type">any</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>        <code class="literal"><code class="function">pg_tablespace_size</code>(<code class="type">oid</code>)</code>
        </td>
<td><code class="type">bigint</code></td>
<td>Disk space used by the tablespace with the specified OID</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_tablespace_size</code>(<code class="type">name</code>)</code>
        </td>
<td><code class="type">bigint</code></td>
<td>Disk space used by the tablespace with the specified name</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_database_size</code>(<code class="type">oid</code>)</code>
        </td>
<td><code class="type">bigint</code></td>
<td>Disk space used by the database with the specified OID</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_database_size</code>(<code class="type">name</code>)</code>
        </td>
<td><code class="type">bigint</code></td>
<td>Disk space used by the database with the specified name</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_relation_size</code>(<code class="type">oid</code>)</code>
        </td>
<td><code class="type">bigint</code></td>
<td>Disk space used by the table or index with the specified OID</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_relation_size</code>(<code class="type">text</code>)</code>
        </td>
<td><code class="type">bigint</code></td>
<td>        Disk space used by the table or index with the specified name.
        The table name may be qualified with a schema name
       </td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_total_relation_size</code>(<code class="type">oid</code>)</code>
        </td>
<td><code class="type">bigint</code></td>
<td>        Total disk space used by the table with the specified OID,
        including indexes and toasted data
       </td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_total_relation_size</code>(<code class="type">text</code>)</code>
        </td>
<td><code class="type">bigint</code></td>
<td>        Total disk space used by the table with the specified name,
        including indexes and toasted data.  The table name may be
        qualified with a schema name
       </td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_size_pretty</code>(<code class="type">bigint</code>)</code>
        </td>
<td><code class="type">text</code></td>
<td>Converts a size in bytes into a human-readable format with size units</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>    <code class="function">pg_column_size</code> shows the space used to store any individual
    data value.
   </p>
<p>    <code class="function">pg_tablespace_size</code> and <code class="function">pg_database_size</code> accept
    the OID or name of a tablespace or database, and return the total disk
    space used therein.
   </p>
<p>    <code class="function">pg_relation_size</code> accepts the OID or name of a table, index or
    toast table, and returns the size in bytes.
   </p>
<p>    <code class="function">pg_total_relation_size</code> accepts the OID or name of a
    table or toast table, and returns the size in bytes of the data
    and all associated indexes and toast tables.
   </p>
<p>    <code class="function">pg_size_pretty</code> can be used to format the result of one of
    the other functions in a human-readable way, using kB, MB, GB or TB as
    appropriate.
   </p>
<p>    The functions shown in <a href="functions-admin.html#functions-admin-genfile" title="Table9.48.Generic File Access Functions">Table9.48, &#8220;Generic File Access Functions&#8221;</a> provide native file access to
    files on the machine hosting the server. Only files within the
    database cluster directory and the <code class="varname">log_directory</code> may be
    accessed.  Use a relative path for files within the cluster directory,
    and a path matching the <code class="varname">log_directory</code> configuration setting
    for log files.  Use of these functions is restricted to superusers.
   </p>
<div class="table">
<a name="functions-admin-genfile"></a><p class="title"><b>Table9.48.Generic File Access Functions</b></p>
<div class="table-contents"><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>        <code class="literal"><code class="function">pg_ls_dir</code>(<em class="parameter"><code>dirname</code></em> <code class="type">text</code>)</code>
       </td>
<td><code class="type">setof text</code></td>
<td>List the contents of a directory</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_read_file</code>(<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>)</code>
       </td>
<td><code class="type">text</code></td>
<td>Return the contents of a text file</td>
</tr>
<tr>
<td>        <code class="literal"><code class="function">pg_stat_file</code>(<em class="parameter"><code>filename</code></em> <code class="type">text</code>)</code>
       </td>
<td><code class="type">record</code></td>
<td>Return information about a file</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><a name="id625785"></a><p>    <code class="function">pg_ls_dir</code> returns all the names in the specified
    directory, except the special entries &#8220;<span class="quote"><code class="literal">.</code></span>&#8221; and
    &#8220;<span class="quote"><code class="literal">..</code></span>&#8221;.
   </p>
<a name="id625820"></a><p>    <code class="function">pg_read_file</code> returns part of a text file, starting
    at the given <em class="parameter"><code>offset</code></em>, returning at most <em class="parameter"><code>length</code></em>
    bytes (less if the end of file is reached first).  If <em class="parameter"><code>offset</code></em>
    is negative, it is relative to the end of the file.
   </p>
<a name="id625862"></a><p>    <code class="function">pg_stat_file</code> returns a record containing the file
    size, last accessed time stamp, last modified time stamp, 
    last file status change time stamp (Unix platforms only), 
    file creation timestamp (Windows only), and a <code class="type">boolean</code> indicating 
    if it is a directory.  Typical usages include:
</p>
<pre class="programlisting">SELECT * FROM pg_stat_file('filename');
SELECT (pg_stat_file('filename')).modification;</pre>
<p>
   </p>
</div></body>
</html>