Provisioning and Automating High Availability Postgres on AWS EC2 Payal Singh DBA@OmniTI 1
Who am I? DBA@OmniTI Github: payals Blog: http://penningpence.blogspot.com Twitter: @pallureshu Email: payal@omniti.com 2
Agenda vs Design Automation 3
Why EC2 over RDS? Control Debugging Third party tools Resources Flexibility Migration - globals Compatibility with non-AWS resources Monitoring 4
If you’re going from RDS to EC2... More administration Less handholding Security Basic monitoring 5
Automation Tools 6
Popular Automation Tools http://www.infoworld.com/article/2609482/data-center/data-center-review-puppet-vs-chef-vs-ansible-vs-salt.html 7
Types of Tools 8
What is Terraform? Tool for building, changing and versioning infrastructure Specializes in cloud infrastructure management 9
10
Why I chose Ansible Simple Learning curve Galaxy and modules Push - more convenient Clarity - YAML 11
Design 12
What to Design? EC2 Setup Installs and reinstalls, dependencies Tuning and customization Replication Backups Monitoring Failover 13
Is there any such thing as a In Postgres automation? 14
YES 15
16
17
18
19
20
21
Setup and Initialization 22
EC2 Setup - variables 23
EC2 Setup - main.tf 24
EC2 Setup - main.tf optionals 25
Terraform apply
Terraform applied!
Installs Get the repository: Installing postgres and supporting packages: postgresql_version: "9.6" 28
Re-installs 29
Customization $PGDATA Extensions 30
Tuning - postgresql.conf Template files: Attributes: 31
Tuning - pg_hba.conf Template: 32
Tuning pg_hba.conf Values: File: 33
Ansible-playbook main.yml
Replication 37
Replication – recovery.conf
Ansible and replication Groups: 39
Backups and restores - Setup PITR: S3: 42
Backups 43
Restores 44
Configure PITR 45
WAL-e dependencies 46
Custom Monitoring http://docs.ansible.com/ansible/list_of_monitoring_modules.html
CloudWatch Monitoring
Failover Boolean parameter: promote_slave: False 49
Completely Automated Failover 51
Pgpool
PgPool
Watchdog
Watchdog
PgPool + Watchdog
Virtual IPs Elastic IP in AWS: 57
Pgpass file 58
Slave Rebuild Switch Base backup 59
pg_rewind Synchronize a PostgreSQL cluster with another copy of the same cluster, after the clusters' timelines have diverged 9.5 and above Superuser access wal_log_hints = 'on' or enable data checksums 60
Cronjobs 61
Useful Links https://github.com/payals/postgresql_automation https://galaxy.ansible.com/ http://docs.ansible.com/ https://www.terraform.io/docs/ 62
Questions? 63