Debian Codegraph @

contrib/test_decoding/sql/time.sql

raw
1 SET synchronous_commit = on;
2
3 CREATE TABLE test_time(data text);
4
5 -- remember the current time
6 SELECT set_config('test.time_before', NOW()::text, false) IS NOT NULL;
7
8 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
9
10 -- a single transaction, to get the commit time
11 INSERT INTO test_time(data) VALUES ('');
12
13 -- parse the commit time from the changeset
14 SELECT set_config('test.time_after', regexp_replace(data, '^COMMIT \(at (.*)\)$', '\1'), false) IS NOT NULL
15 FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'include-timestamp', '1')
16 WHERE data ~ 'COMMIT' LIMIT 1;
17
18 -- ensure commit time is sane in relation to the previous time
19 SELECT (time_after - time_before) <= '10 minutes'::interval, time_after >= time_before
20 FROM (SELECT current_setting('test.time_after')::timestamptz AS time_after, (SELECT current_setting('test.time_before')::timestamptz) AS time_before) AS d;
21
22 SELECT pg_drop_replication_slot('regression_slot');