Skip to content

Commit c481016

Browse files
committed
Add pg_ls_archive_statusdir function
This function lists the contents of the WAL archive status directory, and is intended to be used by monitoring tools. Unlike pg_ls_dir(), access to it can be granted to non-superusers so that those monitoring tools can observe the principle of least privilege. Access is also given by default to members of pg_monitor. Author: Christoph Moench-Tegeder Reviewed-by: Aya Iwata Discussion: https://postgr.es/m/20180930205920.GA64534@elch.exwg.net
1 parent bfa6c5a commit c481016

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

doc/src/sgml/func.sgml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20355,6 +20355,18 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup());
2035520355
role and may be granted to other non-superuser roles.
2035620356
</entry>
2035720357
</row>
20358+
<row>
20359+
<entry>
20360+
<literal><function>pg_ls_archive_statusdir()</function></literal>
20361+
</entry>
20362+
<entry><type>setof record</type></entry>
20363+
<entry>
20364+
List the name, size, and last modification time of files in the WAL
20365+
archive status directory. Access is granted to members of the
20366+
<literal>pg_monitor</literal> role and may be granted to other
20367+
non-superuser roles.
20368+
</entry>
20369+
</row>
2035820370
<row>
2035920371
<entry>
2036020372
<literal><function>pg_ls_tmpdir(<optional><parameter>tablespace</parameter> <type>oid</type></optional>)</function></literal>
@@ -20442,6 +20454,18 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup());
2044220454
<command>GRANT</command>.
2044320455
</para>
2044420456

20457+
<indexterm>
20458+
<primary>pg_ls_archive_statusdir</primary>
20459+
</indexterm>
20460+
<para>
20461+
<function>pg_ls_archive_statusdir</function> returns the name, size, and
20462+
last modified time (mtime) of each file in the WAL archive status
20463+
directory <literal>pg_wal/archive_status</literal>. By default only
20464+
superusers and members of the <literal>pg_monitor</literal> role can
20465+
use this function. Access may be granted to others using
20466+
<command>GRANT</command>.
20467+
</para>
20468+
2044520469
<indexterm>
2044620470
<primary>pg_ls_tmpdir</primary>
2044720471
</indexterm>

src/backend/catalog/system_views.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,7 @@ REVOKE EXECUTE ON FUNCTION lo_export(oid, text) FROM public;
11501150

11511151
REVOKE EXECUTE ON FUNCTION pg_ls_logdir() FROM public;
11521152
REVOKE EXECUTE ON FUNCTION pg_ls_waldir() FROM public;
1153+
REVOKE EXECUTE ON FUNCTION pg_ls_archive_statusdir() FROM public;
11531154
REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir() FROM public;
11541155
REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir(oid) FROM public;
11551156

@@ -1172,6 +1173,7 @@ REVOKE EXECUTE ON FUNCTION pg_ls_dir(text,boolean,boolean) FROM public;
11721173
--
11731174
GRANT EXECUTE ON FUNCTION pg_ls_logdir() TO pg_monitor;
11741175
GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO pg_monitor;
1176+
GRANT EXECUTE ON FUNCTION pg_ls_archive_statusdir() TO pg_monitor;
11751177
GRANT EXECUTE ON FUNCTION pg_ls_tmpdir() TO pg_monitor;
11761178
GRANT EXECUTE ON FUNCTION pg_ls_tmpdir(oid) TO pg_monitor;
11771179

src/backend/utils/adt/genfile.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,3 +658,12 @@ pg_ls_tmpdir_1arg(PG_FUNCTION_ARGS)
658658
{
659659
return pg_ls_tmpdir(fcinfo, PG_GETARG_OID(0));
660660
}
661+
662+
/*
663+
* Function to return the list of files in the WAL archive status directory.
664+
*/
665+
Datum
666+
pg_ls_archive_statusdir(PG_FUNCTION_ARGS)
667+
{
668+
return pg_ls_dir_files(fcinfo, XLOGDIR "/archive_status", true);
669+
}

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201810061
56+
#define CATALOG_VERSION_NO 201810091
5757

5858
#endif

src/include/catalog/pg_proc.dat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10200,6 +10200,11 @@
1020010200
provolatile => 'v', prorettype => 'record', proargtypes => '',
1020110201
proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
1020210202
proargnames => '{name,size,modification}', prosrc => 'pg_ls_waldir' },
10203+
{ oid => '5031', descr => 'list of files in the archive_status directory',
10204+
proname => 'pg_ls_archive_statusdir', procost => '10', prorows => '20', proretset => 't',
10205+
provolatile => 'v', prorettype => 'record', proargtypes => '',
10206+
proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
10207+
proargnames => '{name,size,modification}', prosrc => 'pg_ls_archive_statusdir' },
1020310208
{ oid => '5029', descr => 'list files in the pgsql_tmp directory',
1020410209
proname => 'pg_ls_tmpdir', procost => '10', prorows => '20', proretset => 't',
1020510210
provolatile => 'v', prorettype => 'record', proargtypes => '',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy