SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
PGConf RU 2019
Tips and Tricks with Amazon
RDS for PostgreSQL
Jignesh Shah
Amazon RDS for PostgreSQL
Amazon Relational Database Service
Managed relational database service with a choice of popular database
engines
No need to provision
infrastructure, install,
and maintain DB
software
Scale DB compute
and storage with a
few clicks; minimal
downtime for your
application
Automatic Multi-AZ
data replication;
automated backup,
snapshots, and failover
SSD storage
and guaranteed
provisioned I/O;
data encryption at
rest and in transit
Amazon RDS for PostgreSQL
Supports
• Multiple major versions of PostgreSQL
• 10, 9.6, 9.5 and 9.4
• Up to 96 vCPU, 768 GiB RAM,
• Up to 32TiB Storage, 40K IOPS
• Multi-AZ for High Availability
• Encryption at rest
• Start and Stop of PostgreSQL Instances
• In-region and Cross region Read Replicas
Amazon RDS for PostgreSQL
Supports:
• 60+ PostgreSQL Extensions and decoder plugins
• In-built Native Logical replication
• Replication to Amazon Aurora PostgreSQL
• RDS Performance Insights for PostgreSQL
Amazon RDS Database Preview environment
• PostgreSQL 11 available
New PostgreSQL Extensions Supported
Extensions Description
pglogical Support logical replication –for PostgreSQL 9.6 and PostgreSQL 10
pg_similarity Extension for supporting similar text queries
pageinspect Allows to inspect the contents of database pages at a low level
protobuf Enable Map Box Vector Tiles support in PostGIS
amcheck Allows verify the logical consistency of the structure of indexes
orafce Implements commonly used functions to ease migration from Oracle
prefix Makes it easy to match prefix using @> operator
Tips for Amazon RDS
Tip #1: Secure network access with Amazon VPC
Security groups provide a network firewall for your database server
Protocol Port range Source
TCP 5432 172.31.0.0/16
TCP 5432
“Application
security group”
Corporate address admins
Application tier
Tip #2: Scale your compute and storage
Right Scale your instance size and storage before your peaks
Scale compute up to handle increased
load or down to save costs
• As little as 1vCPU / 1 GiB of RAM
• Up to 96 vCPU and 768 GiB of RAM
• Minimal disruption for
compute scaling
Scale storage for larger data sets
• Scalable Amazon EBS storage up to 32 TiB
• General Purpose SSD or Provisioned IOPS
SSD storage
• No downtime for storage scaling
• Amazon Aurora automatically scales to 64
TiB
• Scheduled daily volume
backup of entire instance
• Archive database change
logs
• 35–day maximum retention
• Negligible impact on
database performance
• Taken from standby when
running Multi-AZ
Tip #3: Turn on automated backups
Point-in-time recovery for your DB instance
Every day during your backup
window, RDS creates a storage
volume snapshot of your instance
Every five minutes, RDS backs up the
transaction logs of your database
Fault tolerance across
multiple data centers
• Automatic failover
• Synchronous replication
• Enabled with a few clicks
Redirection to the new
primary instance is
provided through DNS
Tip #4: Enable Multi-AZ configuration
Enterprise-grade high availability
• Relieve pressure on your master node
with additional read capacity
• Bring data close to your applications
in different regions
• Promote a read replica to a master for
faster recovery in the event of disaster
• Low latency replicas for Amazon Aurora
can be used for both read scaling and
failover targets
Tip #5: Create read replicas
Read scaling and disaster recovery
• Outbound access (FDW access) from
read replica also available
• Faster DR with Multi-AZ Read Replicas
Tip #5: Read Replicas (Contd)
Read scaling and disaster recovery
• Prevent accidental deletes from CLI,
Console, CloudFormation, etc.
Tip #6: Delete Protection for Production
Prevent accidental deletes
• Minor versions are upgraded in
maintenance window when the option
is selected
Tip #7: Automated Minor Version Upgrade
Keep up with new minor releases
Tip #8: Upgrade from PostgreSQL 9.3 databases
First released by community in
09/2013
End of support in Amazon RDS in
11/2018
Preferred to be upgraded to
PostgreSQL 10 or 9.6
PostgreSQL 9.3
• Provide best practice guidance for
customers by analyzing configuration
and usage metrics
• Initial launch includes 7 configuration-
based recommendations
• Results are presented in the AWS
Console so they can be applied
immediately (if relevant)
Tip #8: RDS Recommendations
Most common things to do
Tip #9: Aurora Read Replica or Snapshot Import
Planning to upgrade to Amazon
Aurora PostgreSQL?
Supports Snapshot import (encrypted
snapshot is also available)
Create Aurora Read Replica for RDS
PostgreSQL Promote Aurora Read
Replica to Aurora PostgreSQL Cluster
Tricks with Amazon RDS for
PostgreSQL
Increase wal_keep_segments to allow replicas to catch
up after interruption
Use wal_compression = on
Use higher checkpoint_timeout
Use hot_standby_feedback = on on read replicas
Use similar sized Instance size
Lag for replicas vs long running queries on replicas
• max_standby_archive_delay
• max_standby_streaming_delay
Trick #1: Optimizing Replica Lag
Read Replicas use asynchronous replication
• Automated minor version upgrade
already takes care of your minor
versions
• Recommended to do major version
upgrade to the current major version
once 2-3 years
• Highly recommended to test
applications with new versions
Trick #2: Major Version Upgrade
A single version is not life long
Backup Backup
Prod
9.6
Prod
10
pg_upgrade
No PITR
• Create with a read replica of your
production without Multi-AZ
• Stop workload on production server
• Promote Read replica with 0 days
backup
• Use major version upgrade multiple
times to get to latest preferred major
version
• Enable Automated Backup (and Multi-
AZ protection)
• Spin up more read replicas (Use aws
CLI to spin multiple at the same time
Trick #2: Major Version Upgrade (Contd)
Multiple versions helps to save another downtime next year
Prod
9.4
Prod
9.5
Prod
10
Prod
9.6
Multiple Upgrades back to back
• PostgreSQL 10 supports inbuilt logical
replication using
publication/subscription
• Pglogical Extension available in
Amazon RDS for PostgreSQL 9.6 and
10
For source in Amazon RDS
• Requires setting rds.logical_replication
to “on” on source
• Set role rds_replication to the user
Trick #3: On-Premise to Amazon RDS replication
Introducing inbuilt logical replication and pglogical extension
9.6
Amazon
RDS
10
pglogical
10
10
10
Native
Logical
• Use IAM to control who can
perform actions on Amazon
RDS resources
• Do not use AWS root
credentials to manage
Amazon RDS resources—you
should create an IAM user for
everyone, including yourself
• Can use AWS multi-factor
authentication (MFA) to
provide extra level of
protection
• Can use IAM to control access
to the database
Trick #4: IAM Authentication Support for PostgreSQL
Access and Password Management
DBA and Ops
Amazon RDS
{
"Version": "2012-10-17",
"Statement": [
{ "Effect": "Allow", "Action": [
"rds-db:connect"
],
"Resource": [
"arn:aws:rds-db:us-east-
2:1234567890:dbuser:db-
12ABC34DEFG5HIJ6KLMNOP78QR/jane_doe"
]
}
]
}
Trick #5: Restrict Password changes on PostgreSQL
Simplifies integration of home grown or 3rd party
password management tools
New database parameter to restrict password
changes
• rds.restrict_password_commands = on/off
Flexibility to assign a role to allow certain users to
• GRANT rds_password TO tom;
Password
Manager
Amazon RDS
Enable Amazon RDS Performance Insights
and Enhanced Monitoring
• DB load: average active sessions
• Adjustable timeframe
• Hour, day, week, and longer
Enable auto_explain,
pg_stat_statements extensions.
Need libraries to shared_preload_libraries.
(Requires restart)
Trick #6: Performance Tuning
Tuning results in lower resources and helps to save costs
Set following values in db parameters
• auto_explain.log_min_duration = 5000
• auto_explain.log_nested_statements = on
Trick #6: Performance Tuning (Contd)
Tuning results in lower resources and helps to save costs
CREATE EXTENSION pg_stat_statements
SELECT * from pg_stat_statements order by total_time
DESC;
-[ RECORD 2 ]-------+--------
userid | 16388
dbid | 16464
queryid | 4286627671
query | UPDATE pgbench_accounts SET abalance = abalance + ? WHERE aid
= ?;
calls | 165125
total_time | 5251.54200000001
min_time | 0.015
max_time | 5.558
mean_time | 0.0318034337623008
stddev_time | 0.0369181019548524
rows | 165125
Trick #6: Performance Tuning (Contd)
Tuning results in lower resources and helps to save costs
Connection Pools can be
• Centralized (pgpool, pgbouncer)
• Decentralized (C3P0, inbuilt application ones)
Use intelligent minimums and maximums
Use max_age or equivalent
• Helps reclaim work_mem bloat
Use max_idle or equivalent
• Helps reduce idle processes and free up resources
For large connections, verify hugepages = on
• Better memory management and lower CPU utilization
Trick #7: Connection Poolers
Warm pool is good but can increase memory usage
MVCC in PostgreSQL
• DELETE operations mark a row as dead
• UPDATE operations are essentially
• Marking current row version as dead
• Row with new version is added
• Eventually, all dead rows need to be garbage collected
VACUUM utility
• Cleans up dead rows but does not release space to OS
• FULL option also reorganizes the table to release space to OS
Trick #8: Bloat Management
Lean and Fit results in better performance also
Reorganizes Table with a very short lock
• Must have PRIMARY key or UNIQUE NOT-NULL key
Quick Setup
• CREATE EXTENSION pg_repack
• Use pg_repack client utility using rds_superuser privileges with –k option
pg_repack -h myproductiondb.XXXXXXXX.us-west-
2.rds.amazonaws.com -U pgadmin -k postgres
Trick #8: Bloat Management (Contd)
Lean and Fit results in better performance also
For 24/7 constant load on Database server
• AUTOVACUUM may not get a chance to finish its job
For high number of tables
• Increase autovacuum_max_workers from default 3 to higher number
• Increase autovacuum_vacuum_cost_limit
• Note: With this change, there may be performance impact
For large tables use
• Decrease autovacuum_vacuum_scale_factor from 0.2 (20%) to 0.05
(5%)
• ALTER TABLE myablename SET autovacuum_scale_factor =
0.02
Trick #9: Preempt Transaction Wrap around
This is not a drill
Amazon RDS PostgreSQL Customers
Thank you!

Mais conteúdo relacionado

Mais de Jignesh Shah

PostgreSQL and Linux Containers
PostgreSQL and Linux ContainersPostgreSQL and Linux Containers
PostgreSQL and Linux ContainersJignesh Shah
 
My experience with embedding PostgreSQL
 My experience with embedding PostgreSQL My experience with embedding PostgreSQL
My experience with embedding PostgreSQLJignesh Shah
 
SFPUG - DVDStore Performance Benchmark and PostgreSQL
SFPUG - DVDStore Performance Benchmark and PostgreSQLSFPUG - DVDStore Performance Benchmark and PostgreSQL
SFPUG - DVDStore Performance Benchmark and PostgreSQLJignesh Shah
 
Best Practices of running PostgreSQL in Virtual Environments
Best Practices of running PostgreSQL in Virtual EnvironmentsBest Practices of running PostgreSQL in Virtual Environments
Best Practices of running PostgreSQL in Virtual EnvironmentsJignesh Shah
 
Understanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksUnderstanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksJignesh Shah
 
OLTP Performance Benchmark Review
OLTP Performance Benchmark ReviewOLTP Performance Benchmark Review
OLTP Performance Benchmark ReviewJignesh Shah
 
Introduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsIntroduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsJignesh Shah
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsJignesh Shah
 

Mais de Jignesh Shah (8)

PostgreSQL and Linux Containers
PostgreSQL and Linux ContainersPostgreSQL and Linux Containers
PostgreSQL and Linux Containers
 
My experience with embedding PostgreSQL
 My experience with embedding PostgreSQL My experience with embedding PostgreSQL
My experience with embedding PostgreSQL
 
SFPUG - DVDStore Performance Benchmark and PostgreSQL
SFPUG - DVDStore Performance Benchmark and PostgreSQLSFPUG - DVDStore Performance Benchmark and PostgreSQL
SFPUG - DVDStore Performance Benchmark and PostgreSQL
 
Best Practices of running PostgreSQL in Virtual Environments
Best Practices of running PostgreSQL in Virtual EnvironmentsBest Practices of running PostgreSQL in Virtual Environments
Best Practices of running PostgreSQL in Virtual Environments
 
Understanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksUnderstanding PostgreSQL LW Locks
Understanding PostgreSQL LW Locks
 
OLTP Performance Benchmark Review
OLTP Performance Benchmark ReviewOLTP Performance Benchmark Review
OLTP Performance Benchmark Review
 
Introduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsIntroduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System Administrators
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
 

Último

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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 DevelopmentsTrustArc
 
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 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Último (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Tips and Tricks with Amazon RDS for PostgreSQL

  • 1. PGConf RU 2019 Tips and Tricks with Amazon RDS for PostgreSQL Jignesh Shah Amazon RDS for PostgreSQL
  • 2. Amazon Relational Database Service Managed relational database service with a choice of popular database engines No need to provision infrastructure, install, and maintain DB software Scale DB compute and storage with a few clicks; minimal downtime for your application Automatic Multi-AZ data replication; automated backup, snapshots, and failover SSD storage and guaranteed provisioned I/O; data encryption at rest and in transit
  • 3. Amazon RDS for PostgreSQL Supports • Multiple major versions of PostgreSQL • 10, 9.6, 9.5 and 9.4 • Up to 96 vCPU, 768 GiB RAM, • Up to 32TiB Storage, 40K IOPS • Multi-AZ for High Availability • Encryption at rest • Start and Stop of PostgreSQL Instances • In-region and Cross region Read Replicas
  • 4. Amazon RDS for PostgreSQL Supports: • 60+ PostgreSQL Extensions and decoder plugins • In-built Native Logical replication • Replication to Amazon Aurora PostgreSQL • RDS Performance Insights for PostgreSQL Amazon RDS Database Preview environment • PostgreSQL 11 available
  • 5. New PostgreSQL Extensions Supported Extensions Description pglogical Support logical replication –for PostgreSQL 9.6 and PostgreSQL 10 pg_similarity Extension for supporting similar text queries pageinspect Allows to inspect the contents of database pages at a low level protobuf Enable Map Box Vector Tiles support in PostGIS amcheck Allows verify the logical consistency of the structure of indexes orafce Implements commonly used functions to ease migration from Oracle prefix Makes it easy to match prefix using @> operator
  • 7. Tip #1: Secure network access with Amazon VPC Security groups provide a network firewall for your database server Protocol Port range Source TCP 5432 172.31.0.0/16 TCP 5432 “Application security group” Corporate address admins Application tier
  • 8. Tip #2: Scale your compute and storage Right Scale your instance size and storage before your peaks Scale compute up to handle increased load or down to save costs • As little as 1vCPU / 1 GiB of RAM • Up to 96 vCPU and 768 GiB of RAM • Minimal disruption for compute scaling Scale storage for larger data sets • Scalable Amazon EBS storage up to 32 TiB • General Purpose SSD or Provisioned IOPS SSD storage • No downtime for storage scaling • Amazon Aurora automatically scales to 64 TiB
  • 9. • Scheduled daily volume backup of entire instance • Archive database change logs • 35–day maximum retention • Negligible impact on database performance • Taken from standby when running Multi-AZ Tip #3: Turn on automated backups Point-in-time recovery for your DB instance Every day during your backup window, RDS creates a storage volume snapshot of your instance Every five minutes, RDS backs up the transaction logs of your database
  • 10. Fault tolerance across multiple data centers • Automatic failover • Synchronous replication • Enabled with a few clicks Redirection to the new primary instance is provided through DNS Tip #4: Enable Multi-AZ configuration Enterprise-grade high availability
  • 11. • Relieve pressure on your master node with additional read capacity • Bring data close to your applications in different regions • Promote a read replica to a master for faster recovery in the event of disaster • Low latency replicas for Amazon Aurora can be used for both read scaling and failover targets Tip #5: Create read replicas Read scaling and disaster recovery
  • 12. • Outbound access (FDW access) from read replica also available • Faster DR with Multi-AZ Read Replicas Tip #5: Read Replicas (Contd) Read scaling and disaster recovery
  • 13. • Prevent accidental deletes from CLI, Console, CloudFormation, etc. Tip #6: Delete Protection for Production Prevent accidental deletes
  • 14. • Minor versions are upgraded in maintenance window when the option is selected Tip #7: Automated Minor Version Upgrade Keep up with new minor releases
  • 15. Tip #8: Upgrade from PostgreSQL 9.3 databases First released by community in 09/2013 End of support in Amazon RDS in 11/2018 Preferred to be upgraded to PostgreSQL 10 or 9.6 PostgreSQL 9.3
  • 16. • Provide best practice guidance for customers by analyzing configuration and usage metrics • Initial launch includes 7 configuration- based recommendations • Results are presented in the AWS Console so they can be applied immediately (if relevant) Tip #8: RDS Recommendations Most common things to do
  • 17. Tip #9: Aurora Read Replica or Snapshot Import Planning to upgrade to Amazon Aurora PostgreSQL? Supports Snapshot import (encrypted snapshot is also available) Create Aurora Read Replica for RDS PostgreSQL Promote Aurora Read Replica to Aurora PostgreSQL Cluster
  • 18. Tricks with Amazon RDS for PostgreSQL
  • 19. Increase wal_keep_segments to allow replicas to catch up after interruption Use wal_compression = on Use higher checkpoint_timeout Use hot_standby_feedback = on on read replicas Use similar sized Instance size Lag for replicas vs long running queries on replicas • max_standby_archive_delay • max_standby_streaming_delay Trick #1: Optimizing Replica Lag Read Replicas use asynchronous replication
  • 20. • Automated minor version upgrade already takes care of your minor versions • Recommended to do major version upgrade to the current major version once 2-3 years • Highly recommended to test applications with new versions Trick #2: Major Version Upgrade A single version is not life long Backup Backup Prod 9.6 Prod 10 pg_upgrade No PITR
  • 21. • Create with a read replica of your production without Multi-AZ • Stop workload on production server • Promote Read replica with 0 days backup • Use major version upgrade multiple times to get to latest preferred major version • Enable Automated Backup (and Multi- AZ protection) • Spin up more read replicas (Use aws CLI to spin multiple at the same time Trick #2: Major Version Upgrade (Contd) Multiple versions helps to save another downtime next year Prod 9.4 Prod 9.5 Prod 10 Prod 9.6 Multiple Upgrades back to back
  • 22. • PostgreSQL 10 supports inbuilt logical replication using publication/subscription • Pglogical Extension available in Amazon RDS for PostgreSQL 9.6 and 10 For source in Amazon RDS • Requires setting rds.logical_replication to “on” on source • Set role rds_replication to the user Trick #3: On-Premise to Amazon RDS replication Introducing inbuilt logical replication and pglogical extension 9.6 Amazon RDS 10 pglogical 10 10 10 Native Logical
  • 23. • Use IAM to control who can perform actions on Amazon RDS resources • Do not use AWS root credentials to manage Amazon RDS resources—you should create an IAM user for everyone, including yourself • Can use AWS multi-factor authentication (MFA) to provide extra level of protection • Can use IAM to control access to the database Trick #4: IAM Authentication Support for PostgreSQL Access and Password Management DBA and Ops Amazon RDS { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "rds-db:connect" ], "Resource": [ "arn:aws:rds-db:us-east- 2:1234567890:dbuser:db- 12ABC34DEFG5HIJ6KLMNOP78QR/jane_doe" ] } ] }
  • 24. Trick #5: Restrict Password changes on PostgreSQL Simplifies integration of home grown or 3rd party password management tools New database parameter to restrict password changes • rds.restrict_password_commands = on/off Flexibility to assign a role to allow certain users to • GRANT rds_password TO tom; Password Manager Amazon RDS
  • 25. Enable Amazon RDS Performance Insights and Enhanced Monitoring • DB load: average active sessions • Adjustable timeframe • Hour, day, week, and longer Enable auto_explain, pg_stat_statements extensions. Need libraries to shared_preload_libraries. (Requires restart) Trick #6: Performance Tuning Tuning results in lower resources and helps to save costs
  • 26. Set following values in db parameters • auto_explain.log_min_duration = 5000 • auto_explain.log_nested_statements = on Trick #6: Performance Tuning (Contd) Tuning results in lower resources and helps to save costs
  • 27. CREATE EXTENSION pg_stat_statements SELECT * from pg_stat_statements order by total_time DESC; -[ RECORD 2 ]-------+-------- userid | 16388 dbid | 16464 queryid | 4286627671 query | UPDATE pgbench_accounts SET abalance = abalance + ? WHERE aid = ?; calls | 165125 total_time | 5251.54200000001 min_time | 0.015 max_time | 5.558 mean_time | 0.0318034337623008 stddev_time | 0.0369181019548524 rows | 165125 Trick #6: Performance Tuning (Contd) Tuning results in lower resources and helps to save costs
  • 28. Connection Pools can be • Centralized (pgpool, pgbouncer) • Decentralized (C3P0, inbuilt application ones) Use intelligent minimums and maximums Use max_age or equivalent • Helps reclaim work_mem bloat Use max_idle or equivalent • Helps reduce idle processes and free up resources For large connections, verify hugepages = on • Better memory management and lower CPU utilization Trick #7: Connection Poolers Warm pool is good but can increase memory usage
  • 29. MVCC in PostgreSQL • DELETE operations mark a row as dead • UPDATE operations are essentially • Marking current row version as dead • Row with new version is added • Eventually, all dead rows need to be garbage collected VACUUM utility • Cleans up dead rows but does not release space to OS • FULL option also reorganizes the table to release space to OS Trick #8: Bloat Management Lean and Fit results in better performance also
  • 30. Reorganizes Table with a very short lock • Must have PRIMARY key or UNIQUE NOT-NULL key Quick Setup • CREATE EXTENSION pg_repack • Use pg_repack client utility using rds_superuser privileges with –k option pg_repack -h myproductiondb.XXXXXXXX.us-west- 2.rds.amazonaws.com -U pgadmin -k postgres Trick #8: Bloat Management (Contd) Lean and Fit results in better performance also
  • 31. For 24/7 constant load on Database server • AUTOVACUUM may not get a chance to finish its job For high number of tables • Increase autovacuum_max_workers from default 3 to higher number • Increase autovacuum_vacuum_cost_limit • Note: With this change, there may be performance impact For large tables use • Decrease autovacuum_vacuum_scale_factor from 0.2 (20%) to 0.05 (5%) • ALTER TABLE myablename SET autovacuum_scale_factor = 0.02 Trick #9: Preempt Transaction Wrap around This is not a drill