Skip to content

Commit 4e1fad3

Browse files
Add pg_ls_summariesdir().
This function returns the name, size, and last modification time of each regular file in pg_wal/summaries. This allows administrators to grant privileges to view the contents of this directory without granting privileges on pg_ls_dir(), which allows listing the contents of many other directories. This commit also gives the pg_monitor predefined role EXECUTE privileges on the new pg_ls_summariesdir() function. Bumps catversion. Author: Yushi Ogiwara Reviewed-by: Michael Paquier, Fujii Masao Discussion: https://postgr.es/m/a0a3af15a9b9daa107739eb45aa9a9bc%40oss.nttdata.com
1 parent add7775 commit 4e1fad3

File tree

7 files changed

+51
-1
lines changed

7 files changed

+51
-1
lines changed

doc/src/sgml/func.sgml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30530,6 +30530,30 @@ SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size
3053030530
</para></entry>
3053130531
</row>
3053230532

30533+
<row>
30534+
<entry role="func_table_entry"><para role="func_signature">
30535+
<indexterm>
30536+
<primary>pg_ls_summariesdir</primary>
30537+
</indexterm>
30538+
<function>pg_ls_summariesdir</function> ()
30539+
<returnvalue>setof record</returnvalue>
30540+
( <parameter>name</parameter> <type>text</type>,
30541+
<parameter>size</parameter> <type>bigint</type>,
30542+
<parameter>modification</parameter> <type>timestamp with time zone</type> )
30543+
</para>
30544+
<para>
30545+
Returns the name, size, and last modification time (mtime) of each
30546+
ordinary file in the server's WAL summaries directory
30547+
(<filename>pg_wal/summaries</filename>). Filenames beginning
30548+
with a dot, directories, and other special files are excluded.
30549+
</para>
30550+
<para>
30551+
This function is restricted to superusers and members of
30552+
the <literal>pg_monitor</literal> role by default, but other users can
30553+
be granted EXECUTE to run the function.
30554+
</para></entry>
30555+
</row>
30556+
3053330557
<row>
3053430558
<entry role="func_table_entry"><para role="func_signature">
3053530559
<indexterm>

src/backend/catalog/system_functions.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ REVOKE EXECUTE ON FUNCTION pg_ls_waldir() FROM public;
700700

701701
REVOKE EXECUTE ON FUNCTION pg_ls_archive_statusdir() FROM public;
702702

703+
REVOKE EXECUTE ON FUNCTION pg_ls_summariesdir() FROM public;
704+
703705
REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir() FROM public;
704706

705707
REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir(oid) FROM public;
@@ -770,6 +772,8 @@ GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO pg_monitor;
770772

771773
GRANT EXECUTE ON FUNCTION pg_ls_archive_statusdir() TO pg_monitor;
772774

775+
GRANT EXECUTE ON FUNCTION pg_ls_summariesdir() TO pg_monitor;
776+
773777
GRANT EXECUTE ON FUNCTION pg_ls_tmpdir() TO pg_monitor;
774778

775779
GRANT EXECUTE ON FUNCTION pg_ls_tmpdir(oid) TO pg_monitor;

src/backend/utils/adt/genfile.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,15 @@ pg_ls_archive_statusdir(PG_FUNCTION_ARGS)
689689
return pg_ls_dir_files(fcinfo, XLOGDIR "/archive_status", true);
690690
}
691691

692+
/*
693+
* Function to return the list of files in the WAL summaries directory.
694+
*/
695+
Datum
696+
pg_ls_summariesdir(PG_FUNCTION_ARGS)
697+
{
698+
return pg_ls_dir_files(fcinfo, XLOGDIR "/summaries", true);
699+
}
700+
692701
/*
693702
* Function to return the list of files in the PG_LOGICAL_SNAPSHOTS_DIR
694703
* directory.

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202410112
60+
#define CATALOG_VERSION_NO 202410113
6161

6262
#endif

src/include/catalog/pg_proc.dat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12186,6 +12186,12 @@
1218612186
provolatile => 'v', prorettype => 'record', proargtypes => '',
1218712187
proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
1218812188
proargnames => '{name,size,modification}', prosrc => 'pg_ls_waldir' },
12189+
{ oid => '9220', descr => 'list of files in the pg_wal/summaries directory',
12190+
proname => 'pg_ls_summariesdir', procost => '10', prorows => '20',
12191+
proretset => 't', provolatile => 'v', prorettype => 'record',
12192+
proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
12193+
proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
12194+
prosrc => 'pg_ls_summariesdir' },
1218912195
{ oid => '5031', descr => 'list of files in the archive_status directory',
1219012196
proname => 'pg_ls_archive_statusdir', procost => '10', prorows => '20',
1219112197
proretset => 't', provolatile => 'v', prorettype => 'record',

src/test/regress/expected/misc_functions.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ select count(*) >= 0 as ok from pg_ls_archive_statusdir();
412412
t
413413
(1 row)
414414

415+
select count(*) >= 0 as ok from pg_ls_summariesdir();
416+
ok
417+
----
418+
t
419+
(1 row)
420+
415421
-- pg_read_file()
416422
select length(pg_read_file('postmaster.pid')) > 20;
417423
?column?

src/test/regress/sql/misc_functions.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ select (w).size = :segsize as ok
163163
from (select pg_ls_waldir() w) ss where length((w).name) = 24 limit 1;
164164

165165
select count(*) >= 0 as ok from pg_ls_archive_statusdir();
166+
select count(*) >= 0 as ok from pg_ls_summariesdir();
166167

167168
-- pg_read_file()
168169
select length(pg_read_file('postmaster.pid')) > 20;

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