Usage: aptible db:replicate HANDLE REPLICA_HANDLE [--container-size SIZE_MB] [--disk-size SIZE_GB] [--logical --version VERSION] [--key-arn KEY_ARN] Options: [--environment=ENVIRONMENT] [--container-size=N] [--size=N] [--disk-size=N] [--logical], [--no-logical] [--version=VERSION] [--key-arn=KEY_ARN] Create a replica/follower of a Database
Create a replica with a custom Disk Size
aptible db:replicate "$DB_HANDLE" "$REPLICA_HANDLE" \ --disk-size 20
Create a replica with a custom Container Size
aptible db:replicate "$DB_HANDLE" "$REPLICA_HANDLE" \ --container-size 2048
Create a replica with a custom Container and Disk Size
aptible db:replicate "$DB_HANDLE" "$REPLICA_HANDLE" \ --container-size 2048 \ --disk-size 20
Create an upgraded replica for logical replication
aptible db:replicate "$DB_HANDLE" "$REPLICA_HANDLE" \ --logical --version 12
How Logical Replication Works
aptible db:replicate --logical should work in most cases. This section provides additional details details on how the CLI command works for debugging or if you'd like to know more about what the command does for you.
The CLI command uses the
pglogical extension to set up logical replication between the existing Database and the new replica Database. At a high level, these are the steps the CLI command takes to setup logical replication for you:
max_worker_processeson the replica based on the number of PostgreSQL databases being replicated.
pglogicaluses several worker processes per database so it can easily exhaust the default
max_worker_processesif replicating more than a couple of databases.
- Recreate all roles (users) on the replica.
pglogical's copy of the source database structure includes assigning the same owner to each table and granting the same permissions. The roles must exist on the replica in order for this to work.
- For each PostgreSQL database on the source Database, excluding those that beginning with
- Create the database on the replica with the
aptibleuser as the owner.
- Enable the
pglogicalextension on the source and replica database.
- Create a
pglogicalsubscription between the source and replica database. This will copy the source database's structure (e.g. schemas, tables, permissions, extensions, etc.).
- Start the initial data sync. This will truncate and sync data for all tables in all schemas except for the
pglogical_originschemas and schemas that begin with
The replica does not wait for the initial data sync to complete before coming online. The time it takes to sync all of the data from the source Database depends on the size of the Database.
When run on the replica, the following query will list all tables that are not in the
replicating state and, therefore, have not finished syncing the initial data from the source Database.
SELECT * FROM pglogical.local_sync_status WHERE NOT sync_status = 'r';