Create a base backup on the replica
Replicas work by streaming the primary server's WAL log and replaying its transactions in Postgres recovery mode. To do this, the replica needs to be in a state where it can replay the log. You can do this by restoring the replica from a base backup of the primary instance.
Creating a base backup on the replica
- Stop Postgres services.
- If the replica database already contains data, delete it before you run the backup, by removing the Postgres data directory:
If you don't know the location of the data directory, find it with the show data_directory; command.
- Restore from the base backup, using the IP address of the primary database and the replication username:
The -W flag prompts you for a password. If you are using this command in an automated setup, you might need to use a [pgpass file][pgpass-file].
- When the backup is complete, create a [standby.signal][postgres-recovery-docs] file in your data directory. When Postgres finds a
standby.signalfile in its data directory, it starts in recovery mode and streams the WAL through the replication protocol: