-
-
Save delano/737d32515de6ab9b4232095a970695f1 to your computer and use it in GitHub Desktop.
Postgres logical replication breakage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
master: | |
image: postgres:11 | |
environment: | |
POSTGRES_PASSWORD: abc123 | |
command: -c config_file=/etc/postgresql/postgresql.conf | |
volumes: | |
- ./postgresql.conf:/etc/postgresql/postgresql.conf | |
ports: | |
- 5432:5432 | |
replica: | |
image: postgres:11 | |
environment: | |
POSTGRES_PASSWORD: abc123 | |
command: -c config_file=/etc/postgresql/postgresql.conf | |
volumes: | |
- ./postgresql.conf:/etc/postgresql/postgresql.conf | |
ports: | |
- 15432:5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT pg_create_logical_replication_slot('my_slot', 'pgoutput'); | |
CREATE ROLE repuser WITH LOGIN REPLICATION PASSWORD 'abc123'; | |
CREATE TABLE widgets ( | |
id SERIAL, | |
name TEXT, | |
price DECIMAL, | |
CONSTRAINT widgets_pkey PRIMARY KEY (id) | |
); | |
GRANT ALL PRIVILEGES ON TABLE widgets TO repuser; | |
INSERT INTO widgets (name, price) VALUES ('Hammer', 4.50), ('Coffee Mug', 6.20), ('Cupholder', 3.80); | |
CREATE PUBLICATION widgets_pub; | |
ALTER PUBLICATION widgets_pub ADD TABLE ONLY widgets; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE ROLE repuser WITH LOGIN REPLICATION PASSWORD 'abc123'; | |
CREATE TABLE widgets ( | |
id SERIAL, | |
name TEXT, | |
price DECIMAL, | |
CONSTRAINT widgets_pkey PRIMARY KEY (id) | |
); | |
GRANT ALL PRIVILEGES ON TABLE widgets TO repuser; | |
INSERT INTO widgets (name, price) VALUES ('Hammer', 4.50), ('Coffee Mug', 6.20), ('Cupholder', 3.80); | |
CREATE PUBLICATION widgets_pub; | |
ALTER PUBLICATION widgets_pub ADD TABLE ONLY widgets; | |
SELECT pg_create_logical_replication_slot('my_slot', 'pgoutput'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wal_level = logical | |
listen_addresses = '*' | |
log_min_messages = debug1 | |
log_min_error_statement = debug1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE widgets ( | |
id SERIAL, | |
name TEXT, | |
price DECIMAL, | |
CONSTRAINT widgets_pkey PRIMARY KEY (id) | |
); | |
CREATE SUBSCRIPTION widgets_sub | |
CONNECTION 'dbname=testdb host=master port=5432 user=repuser password=abc123' | |
PUBLICATION widgets_pub | |
WITH (slot_name='my_slot', create_slot=false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
docker-compose up -d | |
export PGHOST=127.0.0.1 | |
export PGPORT=5432 | |
export PGUSER=postgres | |
export PGPASSWORD=abc123 | |
echo -n "Waiting for database to be available" | |
until psql postgres -c 'SELECT 1;' &>/dev/null; do | |
echo -n "." | |
sleep 1 | |
done; echo | |
echo "Load sql on master" | |
createdb testdb | |
psql testdb < $1 | |
sleep 2 | |
export PGPORT=15432 | |
echo "Creating database on replica" | |
createdb testdb | |
echo "Load sql on replica" | |
psql testdb < replica.sql | |
docker-compose logs -f replica | |
docker-compose down |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment