Stay organized with collections Save and categorize content based on your preferences.
This page describes how to configure a Cloud SQL instance that replicates to a replica external to Cloud SQL using the
pglogical extensionwith
logical decoding
.
For more information about replication, see About replication in Cloud SQL.
Set up the external replica configuration Before you beginBefore you start this task, you must have a Cloud SQL instance and an external PostgreSQL instance that meets the requirements for external replicas.
Configure the primary instanceFor information about enabling IP access, see Configuring access for IP connections.
gcloud sql connect PRIMARY_INSTANCE_NAME \ --user=postgres
REPLICATION
attribute.
CREATE USER REPLICATION_USER WITH REPLICATION IN ROLE cloudsqlsuperuser LOGIN PASSWORD 'REPLICATION_USER_PASSWORD';
Edit the Cloud SQL instance to add and set the following flags:
cloudsql.enable_pglogical
cloudsql.logical_decoding
max_replication_slots
max_worker_processes
max_wal_senders
For more information about these flags, see the PostgreSQL resources page.
Restart the database, then login, change to the replication_user, create the pglogical
extension:
CREATE EXTENSION pglogical;
A pglogical _node_ represents a physical PostgreSQL instance, and stores connection details for that instance.
SELECT pglogical.create_node( node_name := 'provider', dsn := 'host=PRIMARY_PUBLIC_IP_ADDRESS port=5432 dbname=DATABASE_NAME user=REPLICATION_USER password=REPLICATION_USER_PASSWORD' );
CREATE DATABASE test; \connect test; CREATE TABLE replica_test (id SERIAL PRIMARY KEY, data text); INSERT INTO replica_test (data) VALUES ('apple'), ('banana'), ('cherry'); CREATE EXTENSION pglogical;
SELECT pglogical.replication_set_add_table('default', 'replica_test', true);
CREATE USER REPLICATION_USER WITH REPLICATION SUPERUSER LOGIN PASSWORD 'REPLICATION_USER_PASSWORD';
CREATE DATABASE test; \connect test; CREATE TABLE replica_test (id SERIAL PRIMARY KEY, data text); INSERT INTO replica_test (data) VALUES ('apple'), ('banana'), ('cherry');
gcloud storage
command:
gcloud storage cp gs://BUCKET_NAME/DUMP_FILE_NAME .
psql --user=postgres --password < DUMP_FILE_NAME.
pglogical
according to your OS. For example, on Debian systems running PostgreSQL version 13, sudo apt-get install postgresql-13-pglogical
.ALTER SYSTEM SET shared_preload_libraries = 'pglogical'; ALTER SYSTEM SET max_replication_slots = #; (where # is the same as you set on the primary). ALTER SYSTEM SET max_worker_processes = #; (where # is the same as you set on the primary). # Logout of the database and restart it. For example, #sudo /etc/init.d/postgresql restart
# Log back in the database as the replication_user. # Since the pglogical extension is created local to each database, you need to # executeCREATE EXTENSION pglogical
in each database you create, so if you # haven't already done that: CREATE EXTENSION pglogical;For more information about these flags, see the PostgreSQL resources page.
SELECT pglogical.create_node( node_name := 'subscriber', dsn := 'host=REPLICA_PUBLIC_IP_ADDRESS port=5432 dbname=DATABASE_NAME user=REPLICATION_USER password=REPLICATION_USER_PASSWORD' );
SELECT pglogical.create_subscription( subscription_name := 'SUBSCRIPTION_NAME', provider_dsn := 'host=PRIMARY_PUBLIC_IP_ADDRESS port=5432 dbname=DATABASE_NAME user=REPLICATION_USER password=REPLICATION_USER_PASSWORD' );
SELECT * FROM pglogical.show_subscription_status('SUBSCRIPTION_NAME');
replicating
, then the setup is successful.See
Troubleshooting pglogical What's nextExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-02 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4