1<!-- doc/src/sgml/adminpack.sgml -->
2
3<sect1 id="adminpack" xreflabel="adminpack">
4 <title>adminpack</title>
5
6 <indexterm zone="adminpack">
7  <primary>adminpack</primary>
8 </indexterm>
9
10 <para>
11  <filename>adminpack</filename> provides a number of support functions which
12  <application>pgAdmin</application> and other administration and management tools can
13  use to provide additional functionality, such as remote management
14  of server log files.
15  Use of all these functions is only allowed to the superuser by default but may be
16  allowed to other users by using the <command>GRANT</command> command.
17 </para>
18
19 <para>
20  The functions shown in <xref linkend="functions-adminpack-table"/> provide
21  write access to files on the machine hosting the server.  (See also the
22  functions in <xref linkend="functions-admin-genfile-table"/>, which
23  provide read-only access.)
24  Only files within the database cluster directory can be accessed, unless the
25  user is a superuser or given one of the pg_read_server_files, or pg_write_server_files
26  roles, as appropriate for the function, but either a relative or absolute path is
27  allowable.
28 </para>
29
30 <table id="functions-adminpack-table">
31  <title><filename>adminpack</filename> Functions</title>
32  <tgroup cols="3">
33   <thead>
34    <row><entry>Name</entry> <entry>Return Type</entry> <entry>Description</entry>
35    </row>
36   </thead>
37
38   <tbody>
39    <row>
40     <entry><function>pg_catalog.pg_file_write(filename text, data text, append boolean)</function></entry>
41     <entry><type>bigint</type></entry>
42     <entry>
43      Write, or append to, a text file
44     </entry>
45    </row>
46    <row>
47     <entry><function>pg_catalog.pg_file_rename(oldname text, newname text <optional>, archivename text</optional>)</function></entry>
48     <entry><type>boolean</type></entry>
49     <entry>
50      Rename a file
51     </entry>
52    </row>
53    <row>
54     <entry><function>pg_catalog.pg_file_unlink(filename text)</function></entry>
55     <entry><type>boolean</type></entry>
56     <entry>
57      Remove a file
58     </entry>
59    </row>
60    <row>
61     <entry><function>pg_catalog.pg_logdir_ls()</function></entry>
62     <entry><type>setof record</type></entry>
63     <entry>
64      List the log files in the <varname>log_directory</varname> directory
65     </entry>
66    </row>
67   </tbody>
68  </tgroup>
69 </table>
70
71 <indexterm>
72  <primary>pg_file_write</primary>
73 </indexterm>
74 <para>
75  <function>pg_file_write</function> writes the specified <parameter>data</parameter> into
76  the file named by <parameter>filename</parameter>.  If <parameter>append</parameter> is
77  false, the file must not already exist.  If <parameter>append</parameter> is true,
78  the file can already exist, and will be appended to if so.
79  Returns the number of bytes written.
80 </para>
81
82 <indexterm>
83  <primary>pg_file_rename</primary>
84 </indexterm>
85 <para>
86  <function>pg_file_rename</function> renames a file.  If <parameter>archivename</parameter>
87  is omitted or NULL, it simply renames <parameter>oldname</parameter>
88  to <parameter>newname</parameter> (which must not already exist).
89  If <parameter>archivename</parameter> is provided, it first
90  renames <parameter>newname</parameter> to <parameter>archivename</parameter> (which must
91  not already exist), and then renames <parameter>oldname</parameter>
92  to <parameter>newname</parameter>.  In event of failure of the second rename step,
93  it will try to rename <parameter>archivename</parameter> back
94  to <parameter>newname</parameter> before reporting the error.
95  Returns true on success, false if the source file(s) are not present or
96  not writable; other cases throw errors.
97 </para>
98
99 <indexterm>
100  <primary>pg_file_unlink</primary>
101 </indexterm>
102 <para>
103  <function>pg_file_unlink</function> removes the specified file.
104  Returns true on success, false if the specified file is not present
105  or the <function>unlink()</function> call fails; other cases throw errors.
106 </para>
107
108 <indexterm>
109  <primary>pg_logdir_ls</primary>
110 </indexterm>
111 <para>
112  <function>pg_logdir_ls</function> returns the start timestamps and path
113  names of all the log files in the <xref linkend="guc-log-directory"/>
114  directory.  The <xref linkend="guc-log-filename"/> parameter must have its
115  default setting (<literal>postgresql-%Y-%m-%d_%H%M%S.log</literal>) to use this
116  function.
117 </para>
118
119</sect1>
120