SlideShare a Scribd company logo
1 of 39
Download to read offline
PostgreSQL on AWS
PGBR 2013
by Emanuel Calvo
Saturday, August 17, 13
Palomino - Service Offerings
• Monthly Support:
o Being renamed to Palomino DBA as a service.
o Eliminating 10 hour monthly clients.
o Discounts are based on spend per month (0-80, 81-160, 161+
o We will be penalizing excessive paging financially.
o Quarterly onsite day from Palomino executive, DBA and PM for clients
using 80 hours or more per month.
o Clients using 80-160 hours get 2 New Relic licenses. 160 hours plus
get 4.
• Adding annual support contracts:
o Consultation as needed.
o Emergency pages allowed.
o Small bucket of DBA hours (8, 16 or 24)
For more information, please go to: Spreadsheet
Saturday, August 17, 13
About me:
• Operational DBA at PalominoDB.
o PostgreSQL teach leader, MySQL, MariaDB, Cassandra databases.
• Check out my LinkedIn Profile at: http://es.linkedin.com/in/ecbcbcb/
• Co-author of “RDBMS in the Cloud: PostgreSQL on AWS” (Amazon
Library)
• Mercenary.
Saturday, August 17, 13
About me:
• Operational DBA at PalominoDB.
o PostgreSQL teach leader, MySQL, MariaDB, Cassandra databases.
• Check out my LinkedIn Profile at: http://es.linkedin.com/in/ecbcbcb/
• Co-author of “RDBMS in the Cloud: PostgreSQL on AWS” (Amazon
Library)
• Mercenary.
Aviso: Não jogue objetos contundentes para o
apresentador. Em qualquer caso, apontam para o
tradutor.
Saturday, August 17, 13
This talk is about:
• Main services available for Postgres implementation on AWS.
• Some advises you’ll appreciate.
• Do you want a hands on? Copy the following URL on your browser and
copy the key on a text file !
http://bit.ly/16Wkfm6
Saturday, August 17, 13
Amazon Web Services
• Services provider.
• Services will depend on the regions (not all the features are available
across the regions).
Saturday, August 17, 13
Amazon Web Services (2)
• Regions
Saturday, August 17, 13
Where is Slonik(*) in AWS?
• Redshift
• PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC)
3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.516
• Paraccel - http://www.paraccel.com/ http://en.wikipedia.org/wiki/
ParAccel
• Expensive (aprox 20u$s per day, one host).
• Scale horizontally
• EC2
• Yes, you can run an elephant here.
• Call it “Cloud hosting”
• Multi-region replication and WAN tunnel
• Vertical scaling
• You can use CC (Cluster Compute) instances.
• CloudWatch
• Customizable monitoring
• No RDS for Postgres
• Haters gonna hate here.
(*) Slonik is the Elephant logo name
Saturday, August 17, 13
EC2
Running Postgres over the cloud, customized.
Saturday, August 17, 13
Before go to EC2, you may know:
• SLA (Service License Agreement): 99,95% (“Annual Uptime Percentage”)
• Real? 99,2%
• Prepare for easy failover and switchover
• Never stay with only 1 host. Even Chuck Norris has a replica.
• If you can go with a Master with Multi-AZ and PIOPS for durability,
you’ll rock!
• Prepare to scale up and down.
• Reduce costs scaling down.
• Add more gas to your servers scaling up.
• Go VLC from the beginning. ELBs for internal Load balancing.
Saturday, August 17, 13
Before go to EC2, you may know:
• SLA: 99,95% (“Annual Uptime Percentage”)
• Real? 99,2%
• Prepare for easy failover and switchover
• Never stay with only 1 host. Even Chuck Norris has a replica.
• If you can go with a Master with Multi-AZ and PIOPS for durability,
you’ll rock!
• Prepare to scale up and down.
• Reduce costs scaling down.
• Add more gas to your servers scaling up.
• Go VLC from the beginning. ELBs for internal Load balancing.
• Don’t be the Joker:
Saturday, August 17, 13
Before go to EC2, you may know:
• SLA: 99,95% (“Annual Uptime Percentage”)
• Real? 99,2%
• Prepare for easy failover and switchover
• Never stay with only 1 host. Even Chuck Norris has a replica.
• If you can go with a Master with Multi-AZ and PIOPS for durability,
you’ll rock!
• Prepare to scale up and down.
• Reduce costs scaling down.
• Add more gas to your servers scaling up.
• Go VLC from the beginning. ELBs for internal Load balancing.
• Don’t be the Joker:
Saturday, August 17, 13
EC2 Instances Sizes
• Instances are classified by “sizes”
Saturday, August 17, 13
Sizes for CC
• Instances are classified by “sizes”
Saturday, August 17, 13
Prepare for the disaster
• EBS hang
• Database crash
• (Don’t remember last time I saw this for Postgres, even in AWS)
• Common Human Errors:
• DROP DATABASE production;
• DELETE FROM really_important_table;
• DROP TABLE fire_me_if_you_can;
• Don’t overcloud. And do not enter the rage or panic states.
How?
• Multi AZ master with PIOPs
• Rebuild replicas after failover
• Oh, wait! 9.3 doesn’t need this for cascade slaves!
• Document step by step the PANIC MODEs in the corresponding runbook
on your Confluence/Wiki.
• Obviously, there are non-conventional ways...
Saturday, August 17, 13
Other non-conventional procedures
Rage
Saturday, August 17, 13
Storages
• S3
• Store cheap and slow. Perfect for backup pieces.
• Very durable (99.999999999% )
• Glacier
• Even more slower, even more cheaper.
• EBS 100, 200, 400 IOPS
• Lower cost and persistent.
• Use always EBS optimized option (available from m1.large and on)
• I/O unpredictable sometimes.
• (NUM_IOPS * BLOCK_SIZE) / 1024 = Megabytes/Sec
• That is 400 IOPS is 3MB at 8K block size
• PIOPS 1000,2000,4000
• Want better performance? Guaranteed throughput.
• Lower failure rate.
• SSD (ephemeral)
• You don’t want to have you main servers with this setup, unless you’re
very sure what you want.
• 150.000 IOPS (YMMV)
• Temporal tablespaces or unlogged tables
Saturday, August 17, 13
Storages (2)
Internally, EBS manages 16K blocks. If you run a wild write with 16k against
a 8k writes, you’ll see that 16k size block is faster. Although, PostgreSQL
compiled in the default block size (8k) showed the best performance in a
wide workload.
More information at:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/
EBSPerformance.html
[root@ip-10-248-82-137 ~]# mkdir -p /data
[root@ip-10-248-82-137 ~]# mkfs.xfs /dev/sdb
meta-data=/dev/sdb isize=256 agcount=4, agsize=1966080
blks
= sectsz=512 attr=2
data = bsize=4096 blocks=7864320, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=3840, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@ip-10-248-82-137 ~]# mount -t xfs /dev/sdb /data
[root@ip-10-248-82-137 ~]# useradd postgres
Saturday, August 17, 13
Storages (2)
Saturday, August 17, 13
Storages (3)
Saturday, August 17, 13
Scale up
• Horizontally
• Replicas
• More replicas
• More cascade slaves, specially if you are planning to run 9.3
• Try to use CC (Cluster Compute technology)
• Sharding
• What did you say? What? Excuse me, don’t speak english.
• Vertically
• Increase the instance type
• Try to fit your RSS in memory
• Move to PIOPs (you can move back and forth from EBS)
• http://aws.amazon.com/contact-us/ebs_volume_limit_request/
Saturday, August 17, 13
PostgreSQL Replication
Saturday, August 17, 13
PostgreSQL Replication (2)
• 2 ways to setup a slave:
• pg_basebackup
• Snapshot the EBS devices
• I don’t recommend this. Snapshots don’t warranty consistency in a
100%.
• Don’t underestimate the bandwidth across the zones. For 200GB a
snapshot took almost the same time as a pg_basebackup. Yeah.
• Really?
• Yeah. Told ya’.
Saturday, August 17, 13
Don’t overallocate! Scale down!
• Turn off PIOPS
• Kill non used slaves
• downgrade the instance type
• Maintain S3 clean.
• Archive your data.
Saturday, August 17, 13
... unless you’re this kid:
Saturday, August 17, 13
Backups
• Use S3 to store pieces (you’ll need to encrypt)
• Generate a pair-key
• openssl req -x509 -nodes -days 100000 -newkey rsa:2048 -keyout
private.pem -out public.pem -subj '/'
• Encrypt a piece/full_plain_backup:
• $PGBINHOME/pg_dumpall -U $DBUSER | gzip -c | openssl smime -
encrypt -aes256 -binary -outform DEM -out backups.zip.enc
$PUB_KEY_PATH  || { BACKUP_STATUS=5 ; echo"failed to dump
database" ; mail "failed to dump database" $BACKUP_STATUS ;   }
• Decrypt:
• openssl smime -decrypt -in $TEMP_ENC_BACKUP -binary -inform DEM
-inkey $PRIVATE_KEY -out $TEMP_DEC_BACKUP || { echo Decryption
failed ; exit 1500; }
• Tools:
• https://github.com/wal-e/wal-e
Saturday, August 17, 13
Snaphots
• Shoot the snapshot
• SELECT pg_start_backup(‘label’,true);
• ec2-create-snapshot -d "postgres clon" vol-24592c0e
• SELECT pg_stop_backup();
Output:
SNAPSHOT snap-219c1308 vol-24592c0e pending 2012-12-03T01:34:12+0000
052088341151 10 postgres clon
Saturday, August 17, 13
Snaphots/Restore
$ ec2-describe-snapshots
SNAPSHOT snap-219c1308 vol-24592c0e completed 2012-12-03T01:34:12+0000 100%
052088341151 10 postgres clon
$ ec2-create-volume --snapshot snap-219c1308 --availability-zone eu-west-1c
VOLUME vol-eb1561c1 10 snap-219c1308 eu-west-1c creating
2012-12-03T10:13:44+0000
$ ec2-attach-volume -i i-96ec5edd -d /dev/sdc vol-eb1561c1
ATTACHMENT vol-eb1561c1 i-96ec5edd /dev/sdc attaching
2012-12-03T10:23:37+0000
$ dmesg | tail
[3889500.959401] blkfront: xvdc: barrier or flush: disabled
[3889500.961193] xvdd: unknown partition table
[root@ip-10-208-8-123 ~]# mkdir -p /data
[root@ip-10-208-8-123 ~]# chown -R postgres: /data
# echo “/dev/xvdd /data auto noatime,noexec,nodiratime 0 0” >> /etc/fstab
# mount -a
* Start postgres!
Saturday, August 17, 13
CloudWatch
$ ec2-monitor-instances i-08fe4e43
i-08fe4e43 monitoring-pending
# while true ; do CloudWatch-1.0.13.4/bin/mon-put-data --metric-name backends --
namespace Postgres --dimensions "InstanceId=i-08fe4e43" --value `psql -Upostgres -Atc
'SELECT sum(numbackends) FROM
pg_stat_database'` --timestamp `date +%Y-%m-%dT%H:%M:%S.000Z` ; sleep 60 ; done
# CloudWatch-1.0.13.4/bin/mon-list-metrics | grep -i backends
backends Postgres {InstanceId=i-08fe4e43}
# CloudWatch-1.0.13.4/bin/mon-get-stats backends --namespace Postgres --statistics
"Average,Maximum" --dimensions "InstanceId=i-08fe4e43" --start-time
2013-03-04T23:00:00.000Z
2013-03-05 13:15:00 1.0 1.0 None
2013-03-05 13:16:00 1.0 1.0 None
2013-03-05 13:17:00 1.0 1.0 None
2013-03-05 13:22:00 1.0 1.0 None
2013-03-05 13:23:00 1.0 1.0 None
2013-03-05 13:24:00 1.0 1.0 None
…
• CloudWatch does not graph.
• Customizable monitor.
• The following example shows how we can graph using a normal query.
Saturday, August 17, 13
Configuration
Specific Amazon-configuration at the postgresql.conf:
random_page_cost = 1
And know is when you ask. Don’t. I’ll explain.
Saturday, August 17, 13
Tools
• Web client
• Nice
• Rage clicking
• Yeah, next - next - click - click. Super-click for check snaphots process
status or instances creation (sometimes hangs)
• API cli
• Command line API
• External tools
• https://github.com/timkay/aws (Perl)
• https://github.com/aws/aws-cli (Python)
Saturday, August 17, 13
Featured documents
You may want to read the following links:
• RDBMS on the Cloud, Amazon Library: http://
media.amazonwebservices.com/AWS_RDBMS_PostgreSQL.pdf
• Benchmarking PG on AWS 4000 PIOPs EBS instances: http://
www.palominodb.com/blog/2013/05/08/benchmarking-postgres-aws-4000-
piops-ebs-instances
• MySQL patters on AWS by Jay Edwards and Ben Black: http://
www.slideshare.net/palominodb/mysql-patterns-in-aws#btnNext
• Laine Campbell at Velocity http://cdn.oreillystatic.com/en/assets/1/event/94/
Using%20Amazon%20Web%20Services%20for%20MySQL%20at%20Scale
%20Presentation.pdf
Saturday, August 17, 13
Redshift
An old elephant for massive processing.
Saturday, August 17, 13
Soup of features and links
• http://aws.amazon.com/documentation/redshift/
• Query parallelizing
• Distribution
• Data importation only available from
• S3
• DynamoDB
• Expensive
• Manages lower amount of data than Hadoop (i.e.) but is good for query with
more frequently.
• Scaling is horizontal
• Add nodes for increase performance
• http://docs.aws.amazon.com/redshift/latest/gsg/getting-started-create-
sample-db.html
• http://www.slideshare.net/Hapyrus/amazon-redshift-is-10x-faster-and-
cheaper-than-hadoop-hive
Saturday, August 17, 13
Different feelings
http://www.wired.com/wiredenterprise/2013/08/memsql-and-amazon/ -- Why
Some Startups Say the Cloud Is a Waste of Money
http://programming.oreilly.com/2013/06/ins-and-outs-of-running-mysql-on-
aws.html#! by Laine Campbell
Saturday, August 17, 13
Prices and Free tier*
Is not a topic of this talk, but you can find the prices here:
http://aws.amazon.com/ec2/pricing/
Free Tier*
As part of AWS’s Free Usage Tier, new AWS customers can get started with Amazon EC2 for free. Upon sign-up, new AWS
customers receive the following EC2 services each month for one year:
• 750 hours of EC2 running Linux/UNIX or RHEL Micro instance usage
• 750 hours of EC2 running Microsoft Windows Server Micro instance usage
• 750 hours of Elastic Load Balancing plus 15 GB data processing
• 30 GB of Amazon EBS Standard volume storage plus 2 million IOs and 1 GB snapshot storage
• 15 GB of bandwidth out aggregated across all AWS services
• 1 GB of Regional Data Transfer
Saturday, August 17, 13
Reality
Colleagues reaction when AWS isn’t available/region outage and they are
running with their own iron:
Saturday, August 17, 13
Saturday, August 17, 13
Thanks!
Obrigado!
Contact us!
We are hiring!
emanuel@palominodb.com
Saturday, August 17, 13

More Related Content

What's hot

What's hot (18)

GitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedGitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons Learned
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
 
Really Big Elephants: PostgreSQL DW
Really Big Elephants: PostgreSQL DWReally Big Elephants: PostgreSQL DW
Really Big Elephants: PostgreSQL DW
 
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
 
Logical replication with pglogical
Logical replication with pglogicalLogical replication with pglogical
Logical replication with pglogical
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaAutovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
 
Streaming replication in PostgreSQL
Streaming replication in PostgreSQLStreaming replication in PostgreSQL
Streaming replication in PostgreSQL
 
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4
 
Shootout at the PAAS Corral
Shootout at the PAAS CorralShootout at the PAAS Corral
Shootout at the PAAS Corral
 
Tuning Linux for Databases.
Tuning Linux for Databases.Tuning Linux for Databases.
Tuning Linux for Databases.
 
Shootout at the AWS Corral
Shootout at the AWS CorralShootout at the AWS Corral
Shootout at the AWS Corral
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 

Viewers also liked

Amazon Elastic Beanstalk
Amazon Elastic BeanstalkAmazon Elastic Beanstalk
Amazon Elastic Beanstalk
Eberhard Wolff
 

Viewers also liked (7)

Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
 
Amazon RDS for Performance-Intensive Production Applications (DAT301) | AWS r...
Amazon RDS for Performance-Intensive Production Applications (DAT301) | AWS r...Amazon RDS for Performance-Intensive Production Applications (DAT301) | AWS r...
Amazon RDS for Performance-Intensive Production Applications (DAT301) | AWS r...
 
How Sumo Logic And Anki Build Highly Resilient Services On AWS To Manage Mass...
How Sumo Logic And Anki Build Highly Resilient Services On AWS To Manage Mass...How Sumo Logic And Anki Build Highly Resilient Services On AWS To Manage Mass...
How Sumo Logic And Anki Build Highly Resilient Services On AWS To Manage Mass...
 
Amazon Elastic Beanstalk
Amazon Elastic BeanstalkAmazon Elastic Beanstalk
Amazon Elastic Beanstalk
 
AWS RDS Benchmark - Instance comparison
AWS RDS Benchmark - Instance comparisonAWS RDS Benchmark - Instance comparison
AWS RDS Benchmark - Instance comparison
 
AWS Summit Auckland - Application Delivery Patterns for Developers
AWS Summit Auckland - Application Delivery Patterns for DevelopersAWS Summit Auckland - Application Delivery Patterns for Developers
AWS Summit Auckland - Application Delivery Patterns for Developers
 
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201
 

Similar to Pgbr 2013 postgres on aws

Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 
MongoDB and AWS Best Practices
MongoDB and AWS Best PracticesMongoDB and AWS Best Practices
MongoDB and AWS Best Practices
MongoDB
 
Ceph Day Chicago - Ceph Deployment at Target: Best Practices and Lessons Learned
Ceph Day Chicago - Ceph Deployment at Target: Best Practices and Lessons LearnedCeph Day Chicago - Ceph Deployment at Target: Best Practices and Lessons Learned
Ceph Day Chicago - Ceph Deployment at Target: Best Practices and Lessons Learned
Ceph Community
 

Similar to Pgbr 2013 postgres on aws (20)

AWS Webcast - Achieving consistent high performance with Postgres on Amazon W...
AWS Webcast - Achieving consistent high performance with Postgres on Amazon W...AWS Webcast - Achieving consistent high performance with Postgres on Amazon W...
AWS Webcast - Achieving consistent high performance with Postgres on Amazon W...
 
Running Oracle EBS in the cloud (OAUG Collaborate 18 edition)
Running Oracle EBS in the cloud (OAUG Collaborate 18 edition)Running Oracle EBS in the cloud (OAUG Collaborate 18 edition)
Running Oracle EBS in the cloud (OAUG Collaborate 18 edition)
 
The Proto-Burst Buffer: Experience with the flash-based file system on SDSC's...
The Proto-Burst Buffer: Experience with the flash-based file system on SDSC's...The Proto-Burst Buffer: Experience with the flash-based file system on SDSC's...
The Proto-Burst Buffer: Experience with the flash-based file system on SDSC's...
 
How Parse Built a Mobile Backend as a Service on AWS (MBL307) | AWS re:Invent...
How Parse Built a Mobile Backend as a Service on AWS (MBL307) | AWS re:Invent...How Parse Built a Mobile Backend as a Service on AWS (MBL307) | AWS re:Invent...
How Parse Built a Mobile Backend as a Service on AWS (MBL307) | AWS re:Invent...
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMP
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 
Sanger OpenStack presentation March 2017
Sanger OpenStack presentation March 2017Sanger OpenStack presentation March 2017
Sanger OpenStack presentation March 2017
 
What Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database ScalabilityWhat Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database Scalability
 
Top 10 Perl Performance Tips
Top 10 Perl Performance TipsTop 10 Perl Performance Tips
Top 10 Perl Performance Tips
 
MongoDB and AWS Best Practices
MongoDB and AWS Best PracticesMongoDB and AWS Best Practices
MongoDB and AWS Best Practices
 
Architecture at Scale
Architecture at ScaleArchitecture at Scale
Architecture at Scale
 
Running Oracle EBS in the cloud (DOAG TECH17 edition)
Running Oracle EBS in the cloud (DOAG TECH17 edition)Running Oracle EBS in the cloud (DOAG TECH17 edition)
Running Oracle EBS in the cloud (DOAG TECH17 edition)
 
Logstash
LogstashLogstash
Logstash
 
AWS Activate webinar - Scalable databases for fast growing startups
AWS Activate webinar - Scalable databases for fast growing startupsAWS Activate webinar - Scalable databases for fast growing startups
AWS Activate webinar - Scalable databases for fast growing startups
 
Design, Deploy, and Optimize SQL Server on AWS - June 2017 AWS Online Tech Talks
Design, Deploy, and Optimize SQL Server on AWS - June 2017 AWS Online Tech TalksDesign, Deploy, and Optimize SQL Server on AWS - June 2017 AWS Online Tech Talks
Design, Deploy, and Optimize SQL Server on AWS - June 2017 AWS Online Tech Talks
 
Understanding Elastic Block Store Availability and Performance
Understanding Elastic Block Store Availability and PerformanceUnderstanding Elastic Block Store Availability and Performance
Understanding Elastic Block Store Availability and Performance
 
AWS Cloud experience concepts tips and tricks
AWS Cloud experience concepts tips and tricksAWS Cloud experience concepts tips and tricks
AWS Cloud experience concepts tips and tricks
 
Design, Deploy, and Optimize SQL Server on AWS - AWS Online Tech Talks
Design, Deploy, and Optimize SQL Server on AWS - AWS Online Tech TalksDesign, Deploy, and Optimize SQL Server on AWS - AWS Online Tech Talks
Design, Deploy, and Optimize SQL Server on AWS - AWS Online Tech Talks
 
SRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon AuroraSRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon Aurora
 
Ceph Day Chicago - Ceph Deployment at Target: Best Practices and Lessons Learned
Ceph Day Chicago - Ceph Deployment at Target: Best Practices and Lessons LearnedCeph Day Chicago - Ceph Deployment at Target: Best Practices and Lessons Learned
Ceph Day Chicago - Ceph Deployment at Target: Best Practices and Lessons Learned
 

More from Emanuel Calvo (8)

Open Source SQL Databases
Open Source SQL DatabasesOpen Source SQL Databases
Open Source SQL Databases
 
Demystifying postgres logical replication percona live sc
Demystifying postgres logical replication percona live scDemystifying postgres logical replication percona live sc
Demystifying postgres logical replication percona live sc
 
PostgreSQL and Sphinx pgcon 2013
PostgreSQL and Sphinx   pgcon 2013PostgreSQL and Sphinx   pgcon 2013
PostgreSQL and Sphinx pgcon 2013
 
PostgreSQL FTS Solutions FOSDEM 2013 - PGDAY
PostgreSQL FTS Solutions FOSDEM 2013 - PGDAYPostgreSQL FTS Solutions FOSDEM 2013 - PGDAY
PostgreSQL FTS Solutions FOSDEM 2013 - PGDAY
 
LSWC PostgreSQL 9.1 (2011)
LSWC PostgreSQL 9.1 (2011)LSWC PostgreSQL 9.1 (2011)
LSWC PostgreSQL 9.1 (2011)
 
Admon PG 1
Admon PG 1Admon PG 1
Admon PG 1
 
Monitoreo de MySQL y PostgreSQL con SQL
Monitoreo de MySQL y PostgreSQL con SQLMonitoreo de MySQL y PostgreSQL con SQL
Monitoreo de MySQL y PostgreSQL con SQL
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Pgbr 2013 postgres on aws

  • 1. PostgreSQL on AWS PGBR 2013 by Emanuel Calvo Saturday, August 17, 13
  • 2. Palomino - Service Offerings • Monthly Support: o Being renamed to Palomino DBA as a service. o Eliminating 10 hour monthly clients. o Discounts are based on spend per month (0-80, 81-160, 161+ o We will be penalizing excessive paging financially. o Quarterly onsite day from Palomino executive, DBA and PM for clients using 80 hours or more per month. o Clients using 80-160 hours get 2 New Relic licenses. 160 hours plus get 4. • Adding annual support contracts: o Consultation as needed. o Emergency pages allowed. o Small bucket of DBA hours (8, 16 or 24) For more information, please go to: Spreadsheet Saturday, August 17, 13
  • 3. About me: • Operational DBA at PalominoDB. o PostgreSQL teach leader, MySQL, MariaDB, Cassandra databases. • Check out my LinkedIn Profile at: http://es.linkedin.com/in/ecbcbcb/ • Co-author of “RDBMS in the Cloud: PostgreSQL on AWS” (Amazon Library) • Mercenary. Saturday, August 17, 13
  • 4. About me: • Operational DBA at PalominoDB. o PostgreSQL teach leader, MySQL, MariaDB, Cassandra databases. • Check out my LinkedIn Profile at: http://es.linkedin.com/in/ecbcbcb/ • Co-author of “RDBMS in the Cloud: PostgreSQL on AWS” (Amazon Library) • Mercenary. Aviso: Não jogue objetos contundentes para o apresentador. Em qualquer caso, apontam para o tradutor. Saturday, August 17, 13
  • 5. This talk is about: • Main services available for Postgres implementation on AWS. • Some advises you’ll appreciate. • Do you want a hands on? Copy the following URL on your browser and copy the key on a text file ! http://bit.ly/16Wkfm6 Saturday, August 17, 13
  • 6. Amazon Web Services • Services provider. • Services will depend on the regions (not all the features are available across the regions). Saturday, August 17, 13
  • 7. Amazon Web Services (2) • Regions Saturday, August 17, 13
  • 8. Where is Slonik(*) in AWS? • Redshift • PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.516 • Paraccel - http://www.paraccel.com/ http://en.wikipedia.org/wiki/ ParAccel • Expensive (aprox 20u$s per day, one host). • Scale horizontally • EC2 • Yes, you can run an elephant here. • Call it “Cloud hosting” • Multi-region replication and WAN tunnel • Vertical scaling • You can use CC (Cluster Compute) instances. • CloudWatch • Customizable monitoring • No RDS for Postgres • Haters gonna hate here. (*) Slonik is the Elephant logo name Saturday, August 17, 13
  • 9. EC2 Running Postgres over the cloud, customized. Saturday, August 17, 13
  • 10. Before go to EC2, you may know: • SLA (Service License Agreement): 99,95% (“Annual Uptime Percentage”) • Real? 99,2% • Prepare for easy failover and switchover • Never stay with only 1 host. Even Chuck Norris has a replica. • If you can go with a Master with Multi-AZ and PIOPS for durability, you’ll rock! • Prepare to scale up and down. • Reduce costs scaling down. • Add more gas to your servers scaling up. • Go VLC from the beginning. ELBs for internal Load balancing. Saturday, August 17, 13
  • 11. Before go to EC2, you may know: • SLA: 99,95% (“Annual Uptime Percentage”) • Real? 99,2% • Prepare for easy failover and switchover • Never stay with only 1 host. Even Chuck Norris has a replica. • If you can go with a Master with Multi-AZ and PIOPS for durability, you’ll rock! • Prepare to scale up and down. • Reduce costs scaling down. • Add more gas to your servers scaling up. • Go VLC from the beginning. ELBs for internal Load balancing. • Don’t be the Joker: Saturday, August 17, 13
  • 12. Before go to EC2, you may know: • SLA: 99,95% (“Annual Uptime Percentage”) • Real? 99,2% • Prepare for easy failover and switchover • Never stay with only 1 host. Even Chuck Norris has a replica. • If you can go with a Master with Multi-AZ and PIOPS for durability, you’ll rock! • Prepare to scale up and down. • Reduce costs scaling down. • Add more gas to your servers scaling up. • Go VLC from the beginning. ELBs for internal Load balancing. • Don’t be the Joker: Saturday, August 17, 13
  • 13. EC2 Instances Sizes • Instances are classified by “sizes” Saturday, August 17, 13
  • 14. Sizes for CC • Instances are classified by “sizes” Saturday, August 17, 13
  • 15. Prepare for the disaster • EBS hang • Database crash • (Don’t remember last time I saw this for Postgres, even in AWS) • Common Human Errors: • DROP DATABASE production; • DELETE FROM really_important_table; • DROP TABLE fire_me_if_you_can; • Don’t overcloud. And do not enter the rage or panic states. How? • Multi AZ master with PIOPs • Rebuild replicas after failover • Oh, wait! 9.3 doesn’t need this for cascade slaves! • Document step by step the PANIC MODEs in the corresponding runbook on your Confluence/Wiki. • Obviously, there are non-conventional ways... Saturday, August 17, 13
  • 17. Storages • S3 • Store cheap and slow. Perfect for backup pieces. • Very durable (99.999999999% ) • Glacier • Even more slower, even more cheaper. • EBS 100, 200, 400 IOPS • Lower cost and persistent. • Use always EBS optimized option (available from m1.large and on) • I/O unpredictable sometimes. • (NUM_IOPS * BLOCK_SIZE) / 1024 = Megabytes/Sec • That is 400 IOPS is 3MB at 8K block size • PIOPS 1000,2000,4000 • Want better performance? Guaranteed throughput. • Lower failure rate. • SSD (ephemeral) • You don’t want to have you main servers with this setup, unless you’re very sure what you want. • 150.000 IOPS (YMMV) • Temporal tablespaces or unlogged tables Saturday, August 17, 13
  • 18. Storages (2) Internally, EBS manages 16K blocks. If you run a wild write with 16k against a 8k writes, you’ll see that 16k size block is faster. Although, PostgreSQL compiled in the default block size (8k) showed the best performance in a wide workload. More information at: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ EBSPerformance.html [root@ip-10-248-82-137 ~]# mkdir -p /data [root@ip-10-248-82-137 ~]# mkfs.xfs /dev/sdb meta-data=/dev/sdb isize=256 agcount=4, agsize=1966080 blks = sectsz=512 attr=2 data = bsize=4096 blocks=7864320, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=3840, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@ip-10-248-82-137 ~]# mount -t xfs /dev/sdb /data [root@ip-10-248-82-137 ~]# useradd postgres Saturday, August 17, 13
  • 21. Scale up • Horizontally • Replicas • More replicas • More cascade slaves, specially if you are planning to run 9.3 • Try to use CC (Cluster Compute technology) • Sharding • What did you say? What? Excuse me, don’t speak english. • Vertically • Increase the instance type • Try to fit your RSS in memory • Move to PIOPs (you can move back and forth from EBS) • http://aws.amazon.com/contact-us/ebs_volume_limit_request/ Saturday, August 17, 13
  • 23. PostgreSQL Replication (2) • 2 ways to setup a slave: • pg_basebackup • Snapshot the EBS devices • I don’t recommend this. Snapshots don’t warranty consistency in a 100%. • Don’t underestimate the bandwidth across the zones. For 200GB a snapshot took almost the same time as a pg_basebackup. Yeah. • Really? • Yeah. Told ya’. Saturday, August 17, 13
  • 24. Don’t overallocate! Scale down! • Turn off PIOPS • Kill non used slaves • downgrade the instance type • Maintain S3 clean. • Archive your data. Saturday, August 17, 13
  • 25. ... unless you’re this kid: Saturday, August 17, 13
  • 26. Backups • Use S3 to store pieces (you’ll need to encrypt) • Generate a pair-key • openssl req -x509 -nodes -days 100000 -newkey rsa:2048 -keyout private.pem -out public.pem -subj '/' • Encrypt a piece/full_plain_backup: • $PGBINHOME/pg_dumpall -U $DBUSER | gzip -c | openssl smime - encrypt -aes256 -binary -outform DEM -out backups.zip.enc $PUB_KEY_PATH  || { BACKUP_STATUS=5 ; echo"failed to dump database" ; mail "failed to dump database" $BACKUP_STATUS ;   } • Decrypt: • openssl smime -decrypt -in $TEMP_ENC_BACKUP -binary -inform DEM -inkey $PRIVATE_KEY -out $TEMP_DEC_BACKUP || { echo Decryption failed ; exit 1500; } • Tools: • https://github.com/wal-e/wal-e Saturday, August 17, 13
  • 27. Snaphots • Shoot the snapshot • SELECT pg_start_backup(‘label’,true); • ec2-create-snapshot -d "postgres clon" vol-24592c0e • SELECT pg_stop_backup(); Output: SNAPSHOT snap-219c1308 vol-24592c0e pending 2012-12-03T01:34:12+0000 052088341151 10 postgres clon Saturday, August 17, 13
  • 28. Snaphots/Restore $ ec2-describe-snapshots SNAPSHOT snap-219c1308 vol-24592c0e completed 2012-12-03T01:34:12+0000 100% 052088341151 10 postgres clon $ ec2-create-volume --snapshot snap-219c1308 --availability-zone eu-west-1c VOLUME vol-eb1561c1 10 snap-219c1308 eu-west-1c creating 2012-12-03T10:13:44+0000 $ ec2-attach-volume -i i-96ec5edd -d /dev/sdc vol-eb1561c1 ATTACHMENT vol-eb1561c1 i-96ec5edd /dev/sdc attaching 2012-12-03T10:23:37+0000 $ dmesg | tail [3889500.959401] blkfront: xvdc: barrier or flush: disabled [3889500.961193] xvdd: unknown partition table [root@ip-10-208-8-123 ~]# mkdir -p /data [root@ip-10-208-8-123 ~]# chown -R postgres: /data # echo “/dev/xvdd /data auto noatime,noexec,nodiratime 0 0” >> /etc/fstab # mount -a * Start postgres! Saturday, August 17, 13
  • 29. CloudWatch $ ec2-monitor-instances i-08fe4e43 i-08fe4e43 monitoring-pending # while true ; do CloudWatch-1.0.13.4/bin/mon-put-data --metric-name backends -- namespace Postgres --dimensions "InstanceId=i-08fe4e43" --value `psql -Upostgres -Atc 'SELECT sum(numbackends) FROM pg_stat_database'` --timestamp `date +%Y-%m-%dT%H:%M:%S.000Z` ; sleep 60 ; done # CloudWatch-1.0.13.4/bin/mon-list-metrics | grep -i backends backends Postgres {InstanceId=i-08fe4e43} # CloudWatch-1.0.13.4/bin/mon-get-stats backends --namespace Postgres --statistics "Average,Maximum" --dimensions "InstanceId=i-08fe4e43" --start-time 2013-03-04T23:00:00.000Z 2013-03-05 13:15:00 1.0 1.0 None 2013-03-05 13:16:00 1.0 1.0 None 2013-03-05 13:17:00 1.0 1.0 None 2013-03-05 13:22:00 1.0 1.0 None 2013-03-05 13:23:00 1.0 1.0 None 2013-03-05 13:24:00 1.0 1.0 None … • CloudWatch does not graph. • Customizable monitor. • The following example shows how we can graph using a normal query. Saturday, August 17, 13
  • 30. Configuration Specific Amazon-configuration at the postgresql.conf: random_page_cost = 1 And know is when you ask. Don’t. I’ll explain. Saturday, August 17, 13
  • 31. Tools • Web client • Nice • Rage clicking • Yeah, next - next - click - click. Super-click for check snaphots process status or instances creation (sometimes hangs) • API cli • Command line API • External tools • https://github.com/timkay/aws (Perl) • https://github.com/aws/aws-cli (Python) Saturday, August 17, 13
  • 32. Featured documents You may want to read the following links: • RDBMS on the Cloud, Amazon Library: http:// media.amazonwebservices.com/AWS_RDBMS_PostgreSQL.pdf • Benchmarking PG on AWS 4000 PIOPs EBS instances: http:// www.palominodb.com/blog/2013/05/08/benchmarking-postgres-aws-4000- piops-ebs-instances • MySQL patters on AWS by Jay Edwards and Ben Black: http:// www.slideshare.net/palominodb/mysql-patterns-in-aws#btnNext • Laine Campbell at Velocity http://cdn.oreillystatic.com/en/assets/1/event/94/ Using%20Amazon%20Web%20Services%20for%20MySQL%20at%20Scale %20Presentation.pdf Saturday, August 17, 13
  • 33. Redshift An old elephant for massive processing. Saturday, August 17, 13
  • 34. Soup of features and links • http://aws.amazon.com/documentation/redshift/ • Query parallelizing • Distribution • Data importation only available from • S3 • DynamoDB • Expensive • Manages lower amount of data than Hadoop (i.e.) but is good for query with more frequently. • Scaling is horizontal • Add nodes for increase performance • http://docs.aws.amazon.com/redshift/latest/gsg/getting-started-create- sample-db.html • http://www.slideshare.net/Hapyrus/amazon-redshift-is-10x-faster-and- cheaper-than-hadoop-hive Saturday, August 17, 13
  • 35. Different feelings http://www.wired.com/wiredenterprise/2013/08/memsql-and-amazon/ -- Why Some Startups Say the Cloud Is a Waste of Money http://programming.oreilly.com/2013/06/ins-and-outs-of-running-mysql-on- aws.html#! by Laine Campbell Saturday, August 17, 13
  • 36. Prices and Free tier* Is not a topic of this talk, but you can find the prices here: http://aws.amazon.com/ec2/pricing/ Free Tier* As part of AWS’s Free Usage Tier, new AWS customers can get started with Amazon EC2 for free. Upon sign-up, new AWS customers receive the following EC2 services each month for one year: • 750 hours of EC2 running Linux/UNIX or RHEL Micro instance usage • 750 hours of EC2 running Microsoft Windows Server Micro instance usage • 750 hours of Elastic Load Balancing plus 15 GB data processing • 30 GB of Amazon EBS Standard volume storage plus 2 million IOs and 1 GB snapshot storage • 15 GB of bandwidth out aggregated across all AWS services • 1 GB of Regional Data Transfer Saturday, August 17, 13
  • 37. Reality Colleagues reaction when AWS isn’t available/region outage and they are running with their own iron: Saturday, August 17, 13
  • 39. Thanks! Obrigado! Contact us! We are hiring! emanuel@palominodb.com Saturday, August 17, 13