Re: logical decoding/replication: new functions pg_ls_logicaldir and pg_ls_replslotdir

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: "Bossart, Nathan" <bossartn(at)amazon(dot)com>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: logical decoding/replication: new functions pg_ls_logicaldir and pg_ls_replslotdir
Date: 2021-11-18 07:38:44
Message-ID: CALj2ACX4YyjVN_iA4=DPvTuK-GLfSd-e+RcXSF5LQrbqjC30ag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 18, 2021 at 12:16 AM Bossart, Nathan <bossartn(at)amazon(dot)com> wrote:
>
> On 10/30/21, 2:36 AM, "Bharath Rupireddy" <bharath(dot)rupireddyforpostgres(at)gmail(dot)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.

Attachment Content-Type Size
v2-0001-Add-pg_ls_logicalsnapdir-pg_ls_logicalmapdir-pg_l.patch application/octet-stream 8.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2021-11-18 08:02:08 Re: pg_waldump stucks with options --follow or -f and --stats or -z
Previous Message Ken Kato 2021-11-18 07:25:30 Re: CREATE tab completion