Re:Re: pg_recvlogical: Prevent flushed data from being re-sent after restarting replication

Dewei Dai <daidewei1970@163.com>

From: "Dewei Dai" <daidewei1970@163.com>
To: "Fujii Masao" <masao.fujii@gmail.com>
Cc: "Mircea Cadariu" <cadariu.mircea@gmail.com>, "PostgreSQL Hackers" <pgsql-hackers@lists.postgresql.org>
Date: 2026-01-11T09:48:50Z
Lists: pgsql-hackers
Hi Fujii,
At 2026-01-11 17:21:19, "Fujii Masao" <masao.fujii@gmail.com> wrote:
>That's possible. But TBH I'm not sure how much effort is justified here.
>The test uses pg_recvlogical to activate the slot and doesn't really test
>pg_recvlogical itself. It's unclear how valuable it is to additionally run
>this test on Windows...

>
I applied the V4 patch and tested it on a CentOS 7 x86_64 platform. The test steps are as follows:


1. Create a table:

`create table test_id(id integer);`

2. Create a function to close the connection:

`create or replace function test_f(id integer) returns integer as $$

declare

 var1 integer;

begin

  SELECT active_pid into var1 FROM pg_replication_slots WHERE slot_name = 'reconnect_test';

  perform pg_terminate_backend(var1);

  return 1;

end; $$ language plpgsql;`

3. Execute the command to receive logs:

`./pg_recvlogical --create-slot --slot reconnect_test --dbname postgres --start --file decoding.out --fsync-interval 200 --status-interval 100 --verbose`

4. Execute the following shell script:

`while true

do

 ./psql -d postgres<<EOF

select test_f(1);

\q

EOF

done`

5. Execute data insertion using psql:

`insert into test_id values(1);

insert into test_id values(2);`

6. `tail -f decoding.out`

I found duplicate insert statements in the file.

I don't know if this is a problem.
Additionally, I tried moving the two lines involving `Stream LogicalLog` outside the loop
 in the `main` function, and then it worked correctly.
`output_written_lsn = InvalidXLogRecPtr;`
`output_fsync_lsn = InvalidXLogRecPtr;`

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. pg_recvlogical: remove unnecessary OutputFsync() return value checks.

  2. Add test for pg_recvlogical reconnection behavior.

  3. Add a new helper function wait_for_file() to Utils.pm.

  4. pg_recvlogical: Prevent flushed data from being re-sent.