Skip to content

Commit b89e151

Browse files
committed
Introduce logical decoding.
This feature, building on previous commits, allows the write-ahead log stream to be decoded into a series of logical changes; that is, inserts, updates, and deletes and the transactions which contain them. It is capable of handling decoding even across changes to the schema of the effected tables. The output format is controlled by a so-called "output plugin"; an example is included. To make use of this in a real replication system, the output plugin will need to be modified to produce output in the format appropriate to that system, and to perform filtering. Currently, information can be extracted from the logical decoding system only via SQL; future commits will add the ability to stream changes via walsender. Andres Freund, with review and other contributions from many other people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan, Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve Singer.
1 parent de94b47 commit b89e151

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+12997
-193
lines changed

contrib/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ SUBDIRS = \
5050
spi \
5151
tablefunc \
5252
tcn \
53+
test_decoding \
5354
test_parser \
5455
test_shm_mq \
5556
tsearch2 \

contrib/test_decoding/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Generated subdirectories
2+
/log/
3+
/results/
4+
/tmp_check/

contrib/test_decoding/Makefile

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# contrib/test_decoding/Makefile
2+
3+
MODULES = test_decoding
4+
OBJS = test_decoding.o
5+
6+
# Note: because we don't tell the Makefile there are any regression tests,
7+
# we have to clean those result files explicitly
8+
EXTRA_CLEAN = -r $(pg_regress_clean_files)
9+
10+
ifdef USE_PGXS
11+
PG_CONFIG = pg_config
12+
PGXS := $(shell $(PG_CONFIG) --pgxs)
13+
include $(PGXS)
14+
else
15+
subdir = contrib/test_decoding
16+
top_builddir = ../..
17+
include $(top_builddir)/src/Makefile.global
18+
include $(top_srcdir)/contrib/contrib-global.mk
19+
endif
20+
21+
# Disabled because these tests require "wal_level=logical", which
22+
# typical installcheck users do not have (e.g. buildfarm clients).
23+
installcheck:;
24+
25+
# But it can nonetheless be very helpful to run tests on preexisting
26+
# installation, allow to do so, but only if requested explicitly.
27+
installcheck-force: regresscheck-install-force isolationcheck-install-force
28+
29+
check: regresscheck isolationcheck
30+
31+
submake-regress:
32+
$(MAKE) -C $(top_builddir)/src/test/regress all
33+
34+
submake-isolation:
35+
$(MAKE) -C $(top_builddir)/src/test/isolation all
36+
37+
submake-test_decoding:
38+
$(MAKE) -C $(top_builddir)/contrib/test_decoding
39+
40+
REGRESSCHECKS=ddl rewrite toast permissions decoding_in_xact binary
41+
42+
regresscheck: all | submake-regress submake-test_decoding
43+
$(pg_regress_check) \
44+
--temp-config $(top_srcdir)/contrib/test_decoding/logical.conf \
45+
--temp-install=./tmp_check \
46+
--extra-install=contrib/test_decoding \
47+
$(REGRESSCHECKS)
48+
49+
regresscheck-install-force: | submake-regress submake-test_decoding
50+
$(pg_regress_installcheck) \
51+
--extra-install=contrib/test_decoding \
52+
$(REGRESSCHECKS)
53+
54+
ISOLATIONCHECKS=mxact delayed_startup concurrent_ddl_dml
55+
56+
isolationcheck: all | submake-isolation submake-test_decoding
57+
$(pg_isolation_regress_check) \
58+
--temp-config $(top_srcdir)/contrib/test_decoding/logical.conf \
59+
--extra-install=contrib/test_decoding \
60+
$(ISOLATIONCHECKS)
61+
62+
isolationcheck-install-force: all | submake-isolation submake-test_decoding
63+
$(pg_isolation_regress_installcheck) \
64+
--extra-install=contrib/test_decoding \
65+
$(ISOLATIONCHECKS)
66+
67+
PHONY: submake-test_decoding submake-regress check \
68+
regresscheck regresscheck-install-force \
69+
isolationcheck isolationcheck-install-force
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- predictability
2+
SET synchronous_commit = on;
3+
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
4+
?column?
5+
----------
6+
init
7+
(1 row)
8+
9+
-- succeeds, textual plugin, textual consumer
10+
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'force-binary', '0');
11+
data
12+
------
13+
(0 rows)
14+
15+
-- fails, binary plugin, textual consumer
16+
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'force-binary', '1');
17+
ERROR: output plugin cannot produce text output
18+
-- succeeds, textual plugin, binary consumer
19+
SELECT data FROM pg_logical_slot_get_binary_changes('regression_slot', NULL, NULL, 'force-binary', '0');
20+
data
21+
------
22+
(0 rows)
23+
24+
-- succeeds, binary plugin, binary consumer
25+
SELECT data FROM pg_logical_slot_get_binary_changes('regression_slot', NULL, NULL, 'force-binary', '1');
26+
data
27+
------
28+
(0 rows)
29+
30+
SELECT 'init' FROM pg_drop_replication_slot('regression_slot');
31+
?column?
32+
----------
33+
init
34+
(1 row)
35+

0 commit comments

Comments
 (0)