Add pg_ls_summariesdir().
authorNathan Bossart <[email protected]>
Fri, 11 Oct 2024 16:02:09 +0000 (11:02 -0500)
committerNathan Bossart <[email protected]>
Fri, 11 Oct 2024 16:02:09 +0000 (11:02 -0500)
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

doc/src/sgml/func.sgml
src/backend/catalog/system_functions.sql
src/backend/utils/adt/genfile.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/test/regress/expected/misc_functions.out
src/test/regress/sql/misc_functions.sql

index b26db3b04b0919b916740d0e5e6e04188da7fc5a..9656d1891e8c23c46088380e55d0d77d8d261007 100644 (file)
@@ -30530,6 +30530,30 @@ SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size
        </para></entry>
       </row>
 
+      <row>
+       <entry role="func_table_entry"><para role="func_signature">
+        <indexterm>
+         <primary>pg_ls_summariesdir</primary>
+        </indexterm>
+        <function>pg_ls_summariesdir</function> ()
+        <returnvalue>setof record</returnvalue>
+        ( <parameter>name</parameter> <type>text</type>,
+        <parameter>size</parameter> <type>bigint</type>,
+        <parameter>modification</parameter> <type>timestamp with time zone</type> )
+       </para>
+       <para>
+        Returns the name, size, and last modification time (mtime) of each
+        ordinary file in the server's WAL summaries directory
+        (<filename>pg_wal/summaries</filename>).  Filenames beginning
+        with a dot, directories, and other special files are excluded.
+       </para>
+       <para>
+        This function is restricted to superusers and members of
+        the <literal>pg_monitor</literal> role by default, but other users can
+        be granted EXECUTE to run the function.
+       </para></entry>
+      </row>
+
       <row>
        <entry role="func_table_entry"><para role="func_signature">
         <indexterm>
index b0d0de051e7f06b56275d58ae1d6decbedc20b20..fd6b606ae90babf0f21be80f23b609e2afa3a992 100644 (file)
@@ -700,6 +700,8 @@ REVOKE EXECUTE ON FUNCTION pg_ls_waldir() FROM public;
 
 REVOKE EXECUTE ON FUNCTION pg_ls_archive_statusdir() FROM public;
 
+REVOKE EXECUTE ON FUNCTION pg_ls_summariesdir() FROM public;
+
 REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir() FROM public;
 
 REVOKE EXECUTE ON FUNCTION pg_ls_tmpdir(oid) FROM public;
@@ -770,6 +772,8 @@ GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO pg_monitor;
 
 GRANT EXECUTE ON FUNCTION pg_ls_archive_statusdir() TO pg_monitor;
 
+GRANT EXECUTE ON FUNCTION pg_ls_summariesdir() TO pg_monitor;
+
 GRANT EXECUTE ON FUNCTION pg_ls_tmpdir() TO pg_monitor;
 
 GRANT EXECUTE ON FUNCTION pg_ls_tmpdir(oid) TO pg_monitor;
index 24b95c32b787e5608bd6c746e630144f21025701..91d0bb46309c2349d594f106ec38d3f2725b3982 100644 (file)
@@ -689,6 +689,15 @@ pg_ls_archive_statusdir(PG_FUNCTION_ARGS)
    return pg_ls_dir_files(fcinfo, XLOGDIR "/archive_status", true);
 }
 
+/*
+ * Function to return the list of files in the WAL summaries directory.
+ */
+Datum
+pg_ls_summariesdir(PG_FUNCTION_ARGS)
+{
+   return pg_ls_dir_files(fcinfo, XLOGDIR "/summaries", true);
+}
+
 /*
  * Function to return the list of files in the PG_LOGICAL_SNAPSHOTS_DIR
  * directory.
index 8cb918d9116ea3050e46d68e7d37633a4826664d..ca7dc84f48d184bba895103ee6c39665aa155f40 100644 (file)
@@ -57,6 +57,6 @@
  */
 
 /*                         yyyymmddN */
-#define CATALOG_VERSION_NO 202410112
+#define CATALOG_VERSION_NO 202410113
 
 #endif
index 8876bebde07d36f8de0a1f41af01f51501d8ba7d..bcfb92528ee17a46ad33a51265b86d59694a5877 100644 (file)
   provolatile => 'v', prorettype => 'record', proargtypes => '',
   proallargtypes => '{text,int8,timestamptz}', proargmodes => '{o,o,o}',
   proargnames => '{name,size,modification}', prosrc => 'pg_ls_waldir' },
+{ oid => '9220', descr => 'list of files in the pg_wal/summaries directory',
+  proname => 'pg_ls_summariesdir', procost => '10', prorows => '20',
+  proretset => 't', provolatile => 'v', prorettype => 'record',
+  proargtypes => '', proallargtypes => '{text,int8,timestamptz}',
+  proargmodes => '{o,o,o}', proargnames => '{name,size,modification}',
+  prosrc => 'pg_ls_summariesdir' },
 { oid => '5031', descr => 'list of files in the archive_status directory',
   proname => 'pg_ls_archive_statusdir', procost => '10', prorows => '20',
   proretset => 't', provolatile => 'v', prorettype => 'record',
index 5f7bf6b8af67fc211ed4dc439472c1212e4e99b4..36b1201f9f5bb7cb3795220cca9ce1c2d1954f4f 100644 (file)
@@ -412,6 +412,12 @@ select count(*) >= 0 as ok from pg_ls_archive_statusdir();
  t
 (1 row)
 
+select count(*) >= 0 as ok from pg_ls_summariesdir();
+ ok 
+----
+ t
+(1 row)
+
 -- pg_read_file()
 select length(pg_read_file('postmaster.pid')) > 20;
  ?column? 
index 1e90d60af3566877ec509b34c9f4d023bdc0c2c2..b7495d70eb0328b1812dd29c17a6934bfd7af4a9 100644 (file)
@@ -163,6 +163,7 @@ select (w).size = :segsize as ok
 from (select pg_ls_waldir() w) ss where length((w).name) = 24 limit 1;
 
 select count(*) >= 0 as ok from pg_ls_archive_statusdir();
+select count(*) >= 0 as ok from pg_ls_summariesdir();
 
 -- pg_read_file()
 select length(pg_read_file('postmaster.pid')) > 20;