On Thu, Nov 18, 2021 at 12:16 AM Bossart, Nathan <bossartn@amazon.com> wrote:
>
> On 10/30/21, 2:36 AM, "Bharath Rupireddy" <bharath.rupireddyforpostgres@gmail.com> wrote:
> > I've added 3 functions pg_ls_logicalsnapdir, pg_ls_logicalmapdir,
> > pg_ls_replslotdir, and attached the patch. The sample output looks
> > like [1]. Please review it further.
>
> I took a look at the patch.
>
> + char path[MAXPGPATH + 11];
>
> Why are you adding 11 to MAXPGPATH here? I would think that MAXPGPATH
> is sufficient.
Yeah, MAXPGPATH is sufficient. Note that the replication slot name be
at max NAMEDATALEN(64 bytes) size
(ReplicationSlotPersistentData->name) and what we pass to the
pg_ls_dir_files is
"pg_replslot/<<user_entered_slot_name_with_max_64_bytes>>", so it can
never cross MAXPGPATH (1024).
> + filename = text_to_cstring(filename_t);
> + snprintf(path, sizeof(path), "%s/%s", "pg_replslot", filename);
> + return pg_ls_dir_files(fcinfo, path, false);
>
> I think we need to do some additional input validation here. It's
> pretty easy to use this to see the contents of other directories.
Done. Checking if the entered slot exists or not, if not throwing an
error, see [1].
Please review the attached v2.
[1]
postgres=# select * from pg_ls_replslotdir('');
ERROR: replication slot "" does not exist
postgres=# select * from pg_ls_replslotdir('../');
ERROR: replication slot "../" does not exist
postgres=# select pg_ls_replslotdir('mysub');
pg_ls_replslotdir
-----------------------------------------------------------------
(xid-722-lsn-0-2000000.spill,36592640,"2021-11-18 07:34:40+00")
(xid-722-lsn-0-5000000.spill,36592640,"2021-11-18 07:34:43+00")
(xid-722-lsn-0-A000000.spill,29910720,"2021-11-18 07:34:48+00")
(xid-722-lsn-0-7000000.spill,36592640,"2021-11-18 07:34:45+00")
(xid-722-lsn-0-9000000.spill,36592640,"2021-11-18 07:34:47+00")
(state,200,"2021-11-18 07:34:36+00")
(xid-722-lsn-0-8000000.spill,36592500,"2021-11-18 07:34:46+00")
(xid-722-lsn-0-6000000.spill,36592640,"2021-11-18 07:34:44+00")
(xid-722-lsn-0-1000000.spill,11171300,"2021-11-18 07:34:39+00")
(xid-722-lsn-0-4000000.spill,36592500,"2021-11-18 07:34:42+00")
(xid-722-lsn-0-3000000.spill,36592640,"2021-11-18 07:34:42+00")
(11 rows)
Regards,
Bharath Rupireddy.