PostgreSQL Replication in 10min - 3rd meetup IDPUG

Click here to load reader

Embed Size (px)

Transcript of PostgreSQL Replication in 10min - 3rd meetup IDPUG

PostgreSQL Replication in 10 Minutes

3rd Meetup IDPUG, Plasa Semanggi 9th Fl. Unit 9.

Backup Mechanism

Cold Backup. (Off-line mode)Stores data into a off-line mode (file dump). There are 2 kind of cold backup: (a) Full Backup, Use SQL dump, or just copy the whole datadir(b) Incremental Backup. Logs the archive and play back later.

Warm BackupThe backup machine is up and running, but the service is not ready yet, usually caused by the disk synchronization (PPRC service or DRBD). So the backup is done by 3rd party other than database itself.

Hot BackupThe backup is on-line, and the service is also ready to serve. It is already hot, as hot as the Master / Main server. There are some kind of Hot backup:(1) Synchronous Replication, (2) Asynchronous Replication, (3) Multi Master Replication Backup Mechanism

High AvailabilityHot Backup which provided by PostgreSQL, combined with Linux-HA and simple promotion (from Replica to Master) enables very nice High Availability.

Fault TolerantUsually implemented on special hardware such as Stratus.

Backup than cannot be restore is not a backupBackup Mechanism

What Is Replication ?Replication also known as backup, mirroring (but actually it is a clone), standby which is used for backup data or service availability in case main server experience failure.

PostgreSQL Replication

PostgreSQL ReplicationSynchronous Streaming ReplicationAsynchronous Streaming ReplicationCascading ReplicationMulti-replica ReplicationTrigger-based ReplicationMulti-master Replication

PostgreSQL Replication

Write-Ahead Log

Synchronous binary streaming replication.

Master Configuration :

1. File: postgresql.conflisten_address = '*'wal_level = hot_standbymax_wal_senders = 5wal_keep_segments = 32hot_standby = on#Sync Replicationsynchronous_commit = onsynchronous_standby_name = 'replica1'

2. File: pg_hba.confhost replication pgsql [slave address/mask] trusthost replication pgsql [master address/mask] trust

3.Restart Master PostgreSQL Service

Streaming Replication

4. Execute pg_start_backupSELECT pg_start_backup ('DC');

5. Create Slave Directoryrsync -argv --exclude 'backup_label' --exclude '' /path/to/datadir/ username@ipslave:/destination/slave/datadir

6. Execute pg_stop_backupSELECT pg_stop_backup();

Streaming Replication

Replica Configuration :1. File: postgresql.conflisten_address = '*'wal_level = hot_standbymax_wal_senders = 5wal_keep_segments = 32hot_standby = on

2. Create File on Replica: recovery.conf:standby_mode = 'on'primary_conninfo = 'host=[master address] port=[master port] user=pgsql application_name=replica1'trigger_file = '/path_to/trigger_file'

3. Start Replica PostgreSQL service

Streaming Replication

Lets Prepare !!

Streaming Replication