blob: 1751a7eec5400976694515ff309392b4f628fa40 [file] [log] [blame]
-- Wait until number of replication sessions drop to 0 or timeout
-- occurs. Returns false if timeout occurred.
create function check_and_wait_for_replication(
timeout int)
returns boolean as
$$
declare
d bigint;
i int;
begin
i := 0;
loop
SELECT count(*) into d FROM pg_stat_replication where application_name = 'walreceiver_test';
if (d = 0) then
return true;
end if;
if i >= $1 then
return false;
end if;
perform pg_sleep(.5);
i := i + 1;
end loop;
end;
$$ language plpgsql;
-- Avoid generating spurious WAL records by hint bit updates. The test below
-- is quite sensitive.
vacuum freeze;
-- Test connection
SELECT test_connect('application_name=walreceiver_test');
test_connect
--------------
t
(1 row)
-- Should report 1 replication
SELECT count(*) FROM pg_stat_replication where application_name = 'walreceiver_test';
count
-------
1
(1 row)
SELECT test_disconnect();
test_disconnect
-----------------
t
(1 row)
SELECT check_and_wait_for_replication(10);
check_and_wait_for_replication
--------------------------------
t
(1 row)
-- Test connection passing hostname
SELECT test_connect('host=localhost application_name=walreceiver_test');
test_connect
--------------
t
(1 row)
SELECT count(*) FROM pg_stat_replication where application_name = 'walreceiver_test';
count
-------
1
(1 row)
SELECT test_disconnect();
test_disconnect
-----------------
t
(1 row)
SELECT check_and_wait_for_replication(10);
check_and_wait_for_replication
--------------------------------
t
(1 row)
-- remember current_wal_lsn.
-- start_ignore
select pg_current_wal_lsn() as lsn;
lsn
-----------
0/D24F4F0
(1 row)
-- end_ignore
\gset
-- lets generate some xlogs
create table testwalreceiver(a int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into testwalreceiver select * from generate_series(0, 9);
-- Connect and receive the xlogs, validate everything was received from start to
-- end
SELECT test_connect('');
test_connect
--------------
t
(1 row)
SELECT test_receive_and_verify(:'lsn', pg_current_wal_lsn());
test_receive_and_verify
-------------------------
t
(1 row)
SELECT test_send();
test_send
-----------
t
(1 row)
SELECT test_disconnect();
test_disconnect
-----------------
t
(1 row)