SlideShare a Scribd company logo
Denish Patel
Database Architect, OmniTI
Deploying PostgreSQL on
Amazon EC2
A case study
1
Tuesday, May 7, 13
Story teller?
✤ Denish Patel
✤ denish@omniti.com
✤ Database Architect at OmniTI
✤ Heterogeneous Environment
✤ PostgreSQL, Oracle , MySQL, NoSQL
✤ Scalability, Performance & Simplicity
✤ OmniTI is hiring Database Engineer!
2
Tuesday, May 7, 13
Situation
✤ Startup
✤ Ruby on Rails Shop
✤ Entire IT architecture on Amazon Cloud
✤ 2 Identical Database Environments on EC2
✤ 4 Production Instances
✤ 50GB Each PostgreSQL 9.0 Master - Slave ( 2 Pairs)
✤ 2 QA and 2 Dev environments
3
Tuesday, May 7, 13
Situation
✤ Weekly flake out issues on EC2 instances
✤ Weekly backups using pg_dump
✤ No file system level backup
✤ Master-slave wasn’t working for months!
✤ Schema mismatch between 2 environments
✤ Almost NO monitoring in-place for DBs
4
Tuesday, May 7, 13
Situation
✤ Prod , QA and Dev ...
✤ M1 Extra large instances (m1.xlarge)
✤ 15 GB RAM, 4 Virtual Cores with 2 EC2 compute units each
✤ Configuration Management tool - Puppet
5
Tuesday, May 7, 13
The Amazon Cloud
✤ Business Benefits
✤ Offloading heavy lifting
✤ Lowers cost
✤ Reduces time to market
6
Tuesday, May 7, 13
Amazon Data Centers
7
Tuesday, May 7, 13
Amazon Instances
✤ High CPU
✤ High IO
✤ High Memory
8
Tuesday, May 7, 13
Amazon StorageTypes
9
Tuesday, May 7, 13
Network and Security
✤ Amazon Security Groups
✤ Keep your Amazon EC2 firewall permissions as restrictive as
possible.
✤ Elastic IP Address (EIP)
10
Tuesday, May 7, 13
Deployment Strategies
✤ Sizing Instances and Storage Types
✤ Configuration Management
✤ High Availability
✤ Replication
✤ Failover
✤ Operations
✤ Upgrade, Backups, Maintenance tools
✤ Monitoring
11
Tuesday, May 7, 13
Sizing Instances/Storage
✤ Understand your database , schema and data
✤ Env 1: 50GB , Env 2: 25GB
✤ 2 large archival tables
✤ Working Set about 20-30GB in total
✤ Both environments are inter-related.
✤ Decided to consolidate both environment into single cluster
12
Tuesday, May 7, 13
Sizing Instances/Storage
✤ m2.2xlarge: 34.2GB RAM, 4 Virtual Core
✤ Storage
✤ EBS
✤ RAID 10
✤ Not EBS optimized ( Cost Savings!)
✤ 850 GB
13
Tuesday, May 7, 13
Deployment Phase #1
us-east-1
AV1
AV2
us-west-1
App
Servers
db-master db-slave-
backup
db-slave
Streaming Replication
WAL shipping (OmniPITR)
14
Tuesday, May 7, 13
Configuration Management
✤ Automation
✤ Repeatability
✤ Maintainability
✤ Security
15
Tuesday, May 7, 13
Configuration Management
16
Tuesday, May 7, 13
Puppetizing Postgres
✤ DB server role
✤ PostgreSQL installation
✤ Installing common tools
✤ 3 Roles : prod-master role , prod-slave role, prod-slave-backup role
✤ PostgreSQL Configuration Files: postgresql.conf, pg_hba.conf
✤ Scripts, crontabs
17
Tuesday, May 7, 13
High Availability
✤ Replication
✤ Failover
18
Tuesday, May 7, 13
Replication
✤ Streaming replication
✤ WAL shipping , OmniPITR
✤ Different AV zones
✤ At least 1 slave in different Region
19
Tuesday, May 7, 13
Failover
✤ EIP - about 3 minutes to propagate changes after failover
✤ Failover tools
✤ Semi-automated script
✤ pgbouncer
✤ puppet
20
Tuesday, May 7, 13
Deployment Phase #2
us-east-1
AV1
AV2
us-west-1
App
Servers
db-master
db-slave-
backup
db-slave
Streaming Replication
WAL shipping (OmniPITR)
pgbouncer
21
Tuesday, May 7, 13
pgbouncer
✤ Session Pooling
✤ Supports all Postgres features
✤ Transactions Pooling
✤ Does NOT support PREPARE transactions
22
Tuesday, May 7, 13
Operations
23
Tuesday, May 7, 13
Database Upgrade
✤ Upgraded from PostgreSQL 9.0 to PostgreSQL 9.2
✤ Minimal outage upgrade using Mimeo
✤ http://www.pateldenish.com/2012/10/an-easy-way-to-reduce-
outage-window-for-postgresql-upgrade.html
24
Tuesday, May 7, 13
Beware!!
✤ Sept 24th, 2012
✤ PostgreSQL 9.1.0 to 9.1.5 & 9.2.0
✤ VACUUM all tables in your database & Rebuild Indices
✤ http://wiki.postgresql.org/wiki/20120924updaterelease
✤ April 4th, 2013
✤ PostgreSQL 9.0.* to 9.1.* & 9.2.*
✤ Security release
✤ http://www.postgresql.org/support/security/faq/2013-04-04/
25
Tuesday, May 7, 13
Backups
✤ Online Backups
✤ Daily, db-slave , OmniPITR
✤ Test the backups!!!!
✤ Schema Backups
✤ pg_extractor
✤ Offsite Backup
✤ sending backups to Amazon S3
26
Tuesday, May 7, 13
Tools
✤ tracking schema in git : pg_extractor
✤ pg_bloat_report
✤ Pg log errors reporting : tail_n_mail
✤ Log analysis: pgbadger
✤ log_min_duration_statement = 50 ms
✤ log_line_prefix= '%t [%r] [%p]: [%l-1] user=%u,db=%d,e=%e '
27
Tuesday, May 7, 13
Monitoring
28
Tuesday, May 7, 13
Database Checks
29
Tuesday, May 7, 13
Database Checks
30
Tuesday, May 7, 13
System Checks
31
Tuesday, May 7, 13
Business Metrics
32
Tuesday, May 7, 13
Histograms!
33
Tuesday, May 7, 13
References
✤ http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/
Storage.html
✤ OmniTI labs tools
✤ https://github.com/omniti-labs/pgtreats
✤ OmniPITR
✤ https://github.com/omniti-labs/omnipitr
34
Tuesday, May 7, 13

More Related Content

PDF
Postgres in Amazon RDS
PDF
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
ODP
PostgreSQL Replication in 10 Minutes - SCALE
PDF
Out of the box replication in postgres 9.4(pg confus)
PDF
Out of the box replication in postgres 9.4
ODP
Shootout at the AWS Corral
ODP
Shootout at the PAAS Corral
PPT
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Postgres in Amazon RDS
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL Replication in 10 Minutes - SCALE
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4
Shootout at the AWS Corral
Shootout at the PAAS Corral
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...

What's hot (18)

ODP
Logical replication with pglogical
PDF
Linux tuning to improve PostgreSQL performance
PDF
PostgreSQL WAL for DBAs
PDF
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
PDF
Streaming replication in practice
PDF
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
ODP
GUC Tutorial Package (9.0)
PPTX
Streaming replication in PostgreSQL
PDF
Architecture for building scalable and highly available Postgres Cluster
PDF
Logical Replication in PostgreSQL - FLOSSUK 2016
PDF
Replication Solutions for PostgreSQL
PDF
Linux internals for Database administrators at Linux Piter 2016
PDF
PostgreSQL High Availability in a Containerized World
PDF
Elephant Roads: a tour of Postgres forks
PPT
PostgreSQL9.3 Switchover/Switchback
PDF
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
ODP
Fail over fail_back
PPTX
PostgreSQL Hangout Parameter Tuning
Logical replication with pglogical
Linux tuning to improve PostgreSQL performance
PostgreSQL WAL for DBAs
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
Streaming replication in practice
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
GUC Tutorial Package (9.0)
Streaming replication in PostgreSQL
Architecture for building scalable and highly available Postgres Cluster
Logical Replication in PostgreSQL - FLOSSUK 2016
Replication Solutions for PostgreSQL
Linux internals for Database administrators at Linux Piter 2016
PostgreSQL High Availability in a Containerized World
Elephant Roads: a tour of Postgres forks
PostgreSQL9.3 Switchover/Switchback
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
Fail over fail_back
PostgreSQL Hangout Parameter Tuning
Ad

Similar to Deploying postgre sql on amazon ec2 (20)

PDF
Pgbr 2013 postgres on aws
PDF
Elephants in the Cloud
PDF
Best Practices & Lessons Learned from Deployment of PostgreSQL
 
ODP
Pro PostgreSQL, OSCon 2008
PPTX
Automating Disaster Recovery PostgreSQL
PPTX
Automating the Entire PostgreSQL Lifecycle
PDF
Top 10 Tips for an Effective Postgres Deployment
 
PDF
How to Upgrade Major Version of Your Production PostgreSQL
PDF
9.6_Course Material-Postgresql_002.pdf
PDF
Postgres in Production - Best Practices 2014
 
PPTX
Migrate to platform of your choice
PPTX
Amazon RDS for PostgreSQL - PGConf 2016
PDF
Building the Enterprise infrastructure with PostgreSQL as the basis for stori...
PDF
Patroni - HA PostgreSQL made easy
PDF
Yandex.Mail success story
PPTX
Pg conf 2017 HIPAA Compliant and HA DB architecture on AWS
PDF
10/ EnterpriseDB @ OPEN'16
PPTX
Amazon RDS for PostgreSQL - Postgres Open 2016 - New Features and Lessons Lea...
PDF
Think_your_Postgres_backups_and_recovery_are_safe_lets_talk.pptx
PDF
Postgres Open
Pgbr 2013 postgres on aws
Elephants in the Cloud
Best Practices & Lessons Learned from Deployment of PostgreSQL
 
Pro PostgreSQL, OSCon 2008
Automating Disaster Recovery PostgreSQL
Automating the Entire PostgreSQL Lifecycle
Top 10 Tips for an Effective Postgres Deployment
 
How to Upgrade Major Version of Your Production PostgreSQL
9.6_Course Material-Postgresql_002.pdf
Postgres in Production - Best Practices 2014
 
Migrate to platform of your choice
Amazon RDS for PostgreSQL - PGConf 2016
Building the Enterprise infrastructure with PostgreSQL as the basis for stori...
Patroni - HA PostgreSQL made easy
Yandex.Mail success story
Pg conf 2017 HIPAA Compliant and HA DB architecture on AWS
10/ EnterpriseDB @ OPEN'16
Amazon RDS for PostgreSQL - Postgres Open 2016 - New Features and Lessons Lea...
Think_your_Postgres_backups_and_recovery_are_safe_lets_talk.pptx
Postgres Open
Ad

More from Denish Patel (15)

PDF
Advanced Postgres Monitoring
PDF
Out of the Box Replication in Postgres 9.4(PgConfUS)
PDF
Out of the Box Replication in Postgres 9.4(pgconfsf)
PDF
Out of the Box Replication in Postgres 9.4(PgCon)
PDF
Out of the Box Replication in Postgres 9.4(PgCon)
PDF
Choosing the "D" , Lightning talk
PDF
Scaling postgres
PDF
Two Elephants Inthe Room
PPTX
Deploying Maximum HA Architecture With PostgreSQL
PPT
Deploying Maximum HA Architecture With PostgreSQL
PDF
P90 X Your Database!!
PDF
Achieving Pci Compliace
PDF
Using SQL Standards? Database SQL comparition
PDF
Oracle10g New Features I
PDF
Yet Another Replication Tool: RubyRep
Advanced Postgres Monitoring
Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
Choosing the "D" , Lightning talk
Scaling postgres
Two Elephants Inthe Room
Deploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQL
P90 X Your Database!!
Achieving Pci Compliace
Using SQL Standards? Database SQL comparition
Oracle10g New Features I
Yet Another Replication Tool: RubyRep

Deploying postgre sql on amazon ec2