Download - PostgreSQL Replication in 10min - 3rd meetup IDPUG

Transcript
Page 1: PostgreSQL Replication in 10min - 3rd meetup IDPUG

PostgreSQL Replication in 10 Minutes

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

Page 2: PostgreSQL Replication in 10min - 3rd meetup IDPUG
Page 3: PostgreSQL Replication in 10min - 3rd meetup IDPUG
Page 4: PostgreSQL Replication in 10min - 3rd meetup IDPUG

Backup Mechanism

Page 5: PostgreSQL Replication in 10min - 3rd meetup IDPUG

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

Page 6: PostgreSQL Replication in 10min - 3rd meetup IDPUG

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 backup”

Backup Mechanism

Page 7: PostgreSQL Replication in 10min - 3rd meetup IDPUG

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

Page 8: PostgreSQL Replication in 10min - 3rd meetup IDPUG

PostgreSQL Replication

1.Synchronous Streaming Replication2.Asynchronous Streaming Replication3.Cascading Replication4.Multi-replica Replication5.Trigger-based Replication6.Multi-master Replication

Page 9: PostgreSQL Replication in 10min - 3rd meetup IDPUG

PostgreSQL Replication

Write-Ahead Log

Page 10: PostgreSQL Replication in 10min - 3rd meetup IDPUG

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

Page 11: PostgreSQL Replication in 10min - 3rd meetup IDPUG

4. Execute pg_start_backupSELECT pg_start_backup ('DC');

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

6. Execute pg_stop_backupSELECT pg_stop_backup();

Streaming Replication

Page 12: PostgreSQL Replication in 10min - 3rd meetup IDPUG

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

Page 13: PostgreSQL Replication in 10min - 3rd meetup IDPUG

Let’s Prepare !!

Page 14: PostgreSQL Replication in 10min - 3rd meetup IDPUG

Streaming Replication

Page 15: PostgreSQL Replication in 10min - 3rd meetup IDPUG

Discussion?