From 6532fdc363a5f53a1042aa4609009f1882811da5 Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Fri, 17 Jun 2016 15:19:59 +0800 Subject: [PATCH 1/2] Expose active_pid and confirmed_flush_lsn in pg_replication_slots Create an alias of pg_catalog.pg_replication_slots, bdr.pg_replication_slots, that exposes the two new columns added by the backport in 9.4bdr git HEAD. This makes BDR 0.10.0 require the latest 9.4bdr HEAD (at least c1de99c81), so we'll need to enforce that in packages. But it gives us more useful information when diagnosing issues and monitoring. If you run 0.10.0 on an older 9.4bdr it will be fine unless you query the new view or its backing bdr.pg_get_replication_slots function. Fixes #186 --- Makefile.in | 10 ++++++-- bdr.control | 2 +- expected/init_bdr.out | 14 +++++++++++ expected/upgrade.out | 7 ++++-- extsql/bdr--0.10.0.8--0.10.0.9.sql | 38 ++++++++++++++++++++++++++++++ sql/init_bdr.sql | 4 ++++ sql/upgrade.sql | 5 ++++ 7 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 extsql/bdr--0.10.0.8--0.10.0.9.sql diff --git a/Makefile.in b/Makefile.in index 78ca492ce4..e4284872e8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -41,7 +41,8 @@ DATA = \ extsql/bdr--0.10.0.4--0.10.0.5.sql \ extsql/bdr--0.10.0.5--0.10.0.6.sql \ extsql/bdr--0.10.0.6--0.10.0.7.sql \ - extsql/bdr--0.10.0.7--0.10.0.8.sql + extsql/bdr--0.10.0.7--0.10.0.8.sql \ + extsql/bdr--0.10.0.8--0.10.0.9.sql DATA_built = \ extsql/bdr--0.8.0.1.sql \ @@ -68,7 +69,8 @@ DATA_built = \ extsql/bdr--0.10.0.5.sql \ extsql/bdr--0.10.0.6.sql \ extsql/bdr--0.10.0.7.sql \ - extsql/bdr--0.10.0.8.sql + extsql/bdr--0.10.0.8.sql \ + extsql/bdr--0.10.0.9.sql DOCS = bdr.conf.sample README.bdr SCRIPTS = scripts/bdr_initial_load bdr_init_copy bdr_resetxlog bdr_dump @@ -242,6 +244,10 @@ extsql/bdr--0.10.0.8.sql: extsql/bdr--0.10.0.7.sql extsql/bdr--0.10.0.7--0.10.0. mkdir -p extsql cat $^ > $@ +extsql/bdr--0.10.0.9.sql: extsql/bdr--0.10.0.8.sql extsql/bdr--0.10.0.8--0.10.0.9.sql + mkdir -p extsql + cat $^ > $@ + bdr_resetxlog: pg_resetxlog.o $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(libpq_pgport) $(LIBS) -o $@$(X) diff --git a/bdr.control b/bdr.control index 38a8696fad..beafe563cb 100644 --- a/bdr.control +++ b/bdr.control @@ -1,6 +1,6 @@ # bdr extension comment = 'Bi-directional replication for PostgreSQL' -default_version = '0.10.0.8' +default_version = '0.10.0.9' module_pathname = '$libdir/bdr' relocatable = false requires = btree_gist diff --git a/expected/init_bdr.out b/expected/init_bdr.out index 7cf2b6a492..620ca52f88 100644 --- a/expected/init_bdr.out +++ b/expected/init_bdr.out @@ -66,6 +66,13 @@ SELECT node_status, node_local_dsn, node_init_from_dsn FROM bdr.bdr_nodes ORDER r | dbname=regression | dbname=postgres (2 rows) +SELECT 1 FROM bdr.pg_replication_slots WHERE restart_lsn <= confirmed_flush_lsn; + ?column? +---------- + 1 + 1 +(2 rows) + \c regression SELECT conn_dsn, conn_replication_sets FROM bdr.bdr_connections ORDER BY conn_dsn; conn_dsn | conn_replication_sets @@ -81,6 +88,13 @@ SELECT node_status, node_local_dsn, node_init_from_dsn FROM bdr.bdr_nodes ORDER r | dbname=regression | dbname=postgres (2 rows) +SELECT 1 FROM bdr.pg_replication_slots WHERE restart_lsn <= confirmed_flush_lsn; + ?column? +---------- + 1 + 1 +(2 rows) + SET bdr.permit_ddl_locking = true; SELECT bdr.bdr_replicate_ddl_command($DDL$ CREATE OR REPLACE FUNCTION public.bdr_regress_variables( diff --git a/expected/upgrade.out b/expected/upgrade.out index 09300ad07f..7cc3deb877 100644 --- a/expected/upgrade.out +++ b/expected/upgrade.out @@ -59,6 +59,8 @@ CREATE EXTENSION bdr VERSION '0.10.0.7'; DROP EXTENSION bdr; CREATE EXTENSION bdr VERSION '0.10.0.8'; DROP EXTENSION bdr; +CREATE EXTENSION bdr VERSION '0.10.0.9'; +DROP EXTENSION bdr; -- evolve version one by one from the oldest to the newest one CREATE EXTENSION bdr VERSION '0.8.0'; ALTER EXTENSION bdr UPDATE TO '0.8.0.1'; @@ -119,14 +121,15 @@ ORDER BY t.tgname; (2 rows) ALTER EXTENSION bdr UPDATE TO '0.10.0.8'; +ALTER EXTENSION bdr UPDATE TO '0.10.0.9'; -- Should never have to do anything: You missed adding the new version above. ALTER EXTENSION bdr UPDATE; -NOTICE: version "0.10.0.8" of extension "bdr" is already installed +NOTICE: version "0.10.0.9" of extension "bdr" is already installed \dx bdr List of installed extensions Name | Version | Schema | Description ------+----------+------------+------------------------------------------- - bdr | 0.10.0.8 | pg_catalog | Bi-directional replication for PostgreSQL + bdr | 0.10.0.9 | pg_catalog | Bi-directional replication for PostgreSQL (1 row) \c postgres diff --git a/extsql/bdr--0.10.0.8--0.10.0.9.sql b/extsql/bdr--0.10.0.8--0.10.0.9.sql new file mode 100644 index 0000000000..f979e09105 --- /dev/null +++ b/extsql/bdr--0.10.0.8--0.10.0.9.sql @@ -0,0 +1,38 @@ +SET LOCAL search_path = bdr; +SET bdr.permit_unsafe_ddl_commands = true; +SET bdr.skip_ddl_replication = true; + +-- Define an alias of pg_catalog.pg_get_replication_slots to expose the extra +-- active_pid and confirmed_flush_lsn columns from 9.5 and 9.6 that have been +-- backported to 94bdr. The new columns MUST be last. +-- +CREATE OR REPLACE FUNCTION +bdr.pg_get_replication_slots(OUT slot_name name, OUT plugin name, OUT slot_type text, OUT datoid oid, OUT active boolean, OUT xmin xid, OUT catalog_xmin xid, OUT restart_lsn pg_lsn, OUT active_pid integer, OUT confirmed_flush_lsn pg_lsn) + RETURNS SETOF record + LANGUAGE internal + STABLE ROWS 10 +AS $function$pg_get_replication_slots$function$; + + +-- And a replacement pg_replication_slots view, so if you set your search_path +-- appropriately it'll "just work". The view fixes the column ordering to be +-- the same as 9.6. +CREATE VIEW bdr.pg_replication_slots AS + SELECT + L.slot_name, + L.plugin, + L.slot_type, + L.datoid, + D.datname AS database, + L.active, + L.active_pid, + L.xmin, + L.catalog_xmin, + L.restart_lsn, + L.confirmed_flush_lsn + FROM bdr.pg_get_replication_slots() AS L + LEFT JOIN pg_catalog.pg_database D ON (L.datoid = D.oid); + +RESET bdr.permit_unsafe_ddl_commands; +RESET bdr.skip_ddl_replication; +RESET search_path; diff --git a/sql/init_bdr.sql b/sql/init_bdr.sql index e977a5e8cc..e1d7aaae4b 100644 --- a/sql/init_bdr.sql +++ b/sql/init_bdr.sql @@ -26,10 +26,14 @@ SELECT count(*) FROM pg_stat_replication; SELECT conn_dsn, conn_replication_sets FROM bdr.bdr_connections ORDER BY conn_dsn; SELECT node_status, node_local_dsn, node_init_from_dsn FROM bdr.bdr_nodes ORDER BY node_local_dsn; +SELECT 1 FROM bdr.pg_replication_slots WHERE restart_lsn <= confirmed_flush_lsn; + \c regression SELECT conn_dsn, conn_replication_sets FROM bdr.bdr_connections ORDER BY conn_dsn; SELECT node_status, node_local_dsn, node_init_from_dsn FROM bdr.bdr_nodes ORDER BY node_local_dsn; +SELECT 1 FROM bdr.pg_replication_slots WHERE restart_lsn <= confirmed_flush_lsn; + SET bdr.permit_ddl_locking = true; SELECT bdr.bdr_replicate_ddl_command($DDL$ diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 5784c6d462..babfadecbb 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -87,6 +87,9 @@ DROP EXTENSION bdr; CREATE EXTENSION bdr VERSION '0.10.0.8'; DROP EXTENSION bdr; +CREATE EXTENSION bdr VERSION '0.10.0.9'; +DROP EXTENSION bdr; + -- evolve version one by one from the oldest to the newest one CREATE EXTENSION bdr VERSION '0.8.0'; ALTER EXTENSION bdr UPDATE TO '0.8.0.1'; @@ -142,6 +145,8 @@ ORDER BY t.tgname; ALTER EXTENSION bdr UPDATE TO '0.10.0.8'; +ALTER EXTENSION bdr UPDATE TO '0.10.0.9'; + -- Should never have to do anything: You missed adding the new version above. ALTER EXTENSION bdr UPDATE; From 8feab787394e353d95795fee3da68f182120e79b Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 6 Jul 2016 10:48:28 -0400 Subject: [PATCH 2/2] bdr_quickstart.sh: Use shallow clone, to make it faster --- scripts/bdr_quickstart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bdr_quickstart.sh b/scripts/bdr_quickstart.sh index fc197a2cc6..b207f76cad 100755 --- a/scripts/bdr_quickstart.sh +++ b/scripts/bdr_quickstart.sh @@ -81,7 +81,7 @@ clone_or_update() { echo "Cloning $GITREF sources from git://git.postgresql.org/git/2ndquadrant_bdr.git" echo "This may take some time depending on the speed of your connection." - if ! git clone -b "$GITREF" git://git.postgresql.org/git/2ndquadrant_bdr.git $SRCDIR; then + if ! git clone -b "$GITREF" --depth=1 git://git.postgresql.org/git/2ndquadrant_bdr.git $SRCDIR; then echo "The git clone of the BDR repository failed. Network issues?" echo "Try running the script again. If it fails again, look at the git " echo "output to see what went wrong."