aptible db:replicate
This command creates a Database Replica. All new Replicas are created with General Purpose Container Profile, which is the default Container Profile.
Synopsis
📘 The
--version
option is only supported for postgresql logical replicas.
Examples
Create a replica with a custom Disk Size
Create a replica with a custom Container Size
Create a replica with a custom Container and Disk Size
Create an upgraded replica for logical replication
Container Sizes (MB)
General Purpose(M): 512, 1024, 2048, 4096, 7168, 15360, 30720, 61440, 153600, 245760
Profiles
m
: General purpose container
c
: Compute-optimized container
r
: Memory-optimized container
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:
- Update
max_worker_processes
on the replica based on the number of PostgreSQL databases being replicated.pglogical
uses several worker processes per database so it can easily exhaust the defaultmax_worker_processes
if 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
template
:- Create the database on the replica with the
aptible
user as the owner. - Enable the
pglogical
extension on the source and replica database. - Create a
pglogical
subscription 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
information_schema
,pglogical
, andpglogical_origin
schemas and schemas that begin withpg_
(system schemas).
- Create the database on the replica with the
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.
Was this page helpful?