File: time.sql

package info (click to toggle)
postgresql-11 11.16-0%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 143,648 kB
  • sloc: ansic: 819,646; sql: 85,616; yacc: 33,032; xml: 31,044; perl: 25,261; lex: 8,166; makefile: 5,038; sh: 4,631; cpp: 712; python: 121; asm: 65; sed: 15
file content (22 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SET synchronous_commit = on;

CREATE TABLE test_time(data text);

-- remember the current time
SELECT set_config('test.time_before', NOW()::text, false) IS NOT NULL;

SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');

-- a single transaction, to get the commit time
INSERT INTO test_time(data) VALUES ('');

-- parse the commit time from the changeset
SELECT set_config('test.time_after', regexp_replace(data, '^COMMIT \(at (.*)\)$', '\1'), false) IS NOT NULL
FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'include-timestamp', '1')
WHERE data ~ 'COMMIT' LIMIT 1;

-- ensure commit time is sane in relation to the previous time
SELECT (time_after - time_before) <= '10 minutes'::interval, time_after >= time_before
FROM (SELECT current_setting('test.time_after')::timestamptz AS time_after, (SELECT current_setting('test.time_before')::timestamptz) AS time_before) AS d;

SELECT pg_drop_replication_slot('regression_slot');