Best Practices for Becoming an Exceptional Postgres DBA

48
© 2014 EDB All rights reserved. 1 DBA Best Practices – Becoming an Exceptional Postgres DBA Marc Linster | August 27, 2014

description

Drawing from our teams who support hundreds of Postgres instances and production database systems for customers worldwide, this presentation provides real-real best practices from the nation's top DBAs. Learn top-notch monitoring and maintenance practices, get resource planning advice that can help prevent, resolve, or eliminate common issues, learning top database tuning tricks for increasing system performance and ultimately, gain greater insight into how to improve your effectiveness as a DBA.

Transcript of Best Practices for Becoming an Exceptional Postgres DBA

Page 1: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EDB All rights reserved. 1

DBA Best Practices – Becoming an Exceptional Postgres DBA Marc Linster | August 27, 2014

Page 2: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 2

•  EnterpriseDB Overview •  Best Practice Expertise •  The Postgres DBA Role

−  Monitoring −  Maintenance −  Capacity Planning −  Configuration Tuning −  Deployment Planning

•  Professional Development •  Summary and Resources •  Q&A

Agenda

We will take one quick-poll during the webinar to gather group data on best practices of interest

Page 3: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 3

Brief EDB Overview

Page 4: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 4

POSTGRES innovation

ENTERPRISE reliability

24/7 support

Services & training

Enterprise-class features & tools

Indemnification

Product road-map

Control

Thousands of developers

Fast development

cycles

Low cost

No vendor lock-in

Advanced features

Enabling commercial adoption of Postgres

Page 5: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 5

Postgres Plus Advanced Server Postgres Plus

Cloud Database

High Availability Performance Management

REMOTE DBA 24x7

SUPPORT PROFESSIONAL

SERVICES

TRAINING

EDB Serves All Your Postgres Needs

PostgreSQL

Security

Page 6: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 6

EDB Customers EDB currently has over 2,500 total customers including 50 of the Fortune 500 and 98 of the Forbes Global 2000

Page 7: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 7

Best Practice Expertise

Page 8: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 8

•  Remote DBA Services

•  Architectural Health Checks

•  Postgres Support Tickets

•  Postgres Training

Hundreds of Postgres Instances Supported

When •  ~70% support calls are at

deployment, post-deployment •  Remote DBA and AHC are

post-deployment What •  How to perform DBA tasks •  Which product tools or

features to use

Page 9: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 9

When and Where do Users Need Help?

0%

10%

20%

30%

40%

50%

60%

70%

80%

90%

100%

POC Dev Deployment Maintenance

Tuning

Product Awareness

How to

Enhancements

Corruption

Bug

Page 10: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 10

Where Do Users Need Help # Tickets Phase Category POC Dev Deployment Maintenance Grand Total Connectors 0% 2% 1% 0% 3%

Bug 0% 0% 0% 0% 1% How to 0% 1% 0% 0% 1% Product Awareness 0% 1% 0% 0% 1%

Database 10% 9% 17% 37% 73% Bug 1% 2% 1% 2% 6% Corruption 0% 0% 0% 2% 2% Enhancements 0% 0% 0% 0% 1%

How to 4% 3% 6%   10%   23%  Product Awareness 4% 3% 8%   15%   31%  Tuning 0% 0% 1% 7%   9%  

Replication 1% 4% 4% 2% 12% Bug 0% 1% 0% 0% 2% How to 0% 0% 3% 1% 4% Product Awareness 1% 2% 1% 0% 4% Tuning 0% 0% 0% 1% 1%

Utilities 1% 3% 6% 3% 12% Bug 0% 1% 1% 0% 2% Enhancements 0% 0% 0% 0% 0% How to 1% 1% 3% 1% 6% Product Awareness 0% 1% 3% 1% 5%

Grand Total 12% 17% 28% 42% 100%

Page 11: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 11

Dep

loym

ent/D

atab

ase/

Pro

duct

Aw

aren

ess

& H

ow T

o

• How to set up connection pooling?

• How to set up hot standby and streaming replica?

• How to add table spaces? • How to partition? • How to upgrade from major

version? • What should I monitor? • How do I reduce downtime? M

aint

enan

ce/D

atab

ase/

Pro

duct

Aw

aren

ess

& H

ow T

o • How to find bloat in tables & indexes?

• How to enable auditing selectively without performance impact?

• What are the effects of changes to the values of postgresql.conf file parameters wal_writer_delay, bgwriter_delay?

• What is the correct configuration of hba_conf?

Select Top Support and RDBA Questions (not in rank order)

Page 12: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 12

Monitoring

Maintenance

Performance Tuning

Capacity Management

Security

Deployment

Training & Professional Development

Building Blocks of the DBA Role

Page 13: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 13

The Postgres DBA Role

Page 14: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EDB All rights reserved. 14

•  Postgres is very reliable and stable

•  You can translate your existing DBA skills to Postgres

•  Key areas for Postgres DBAs −  Bloat management −  Vacuum setup −  OS configuration −  Storage sub-system configuration −  Backup – logical and physical −  HA Setup −  pg_hba.conf and other security settings −  Monitoring

Taking on the Postgres DBA Role

Page 15: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EDB All rights reserved. 15

•  Begin with assessing the health of the DB - Architectural Health Check (AHC) −  Performance −  Maintenance Tasks – index management, bloat reduction −  Availability – backup strategies, recovery, replication and

failover −  Scalability and support for business and data growth −  Upgrade planning

•  Establish monitoring •  Focus on list of items uncovered in health check

Postgres DBA Role – An Approach

Page 16: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EDB All rights reserved. 16

•  Technical architecture – OS, application, database

•  Indexes and bloat

•  Configuration tuning – OS, database −  Memory −  Write-ahead log −  Background worker −  Query −  Logging −  Checkpoint −  Vacuum

−  Query performance −  Security

Architectural Health Check Process

•  DR plan −  Backup strategy – logical and physical −  HA solutions – warm standby/log

shipping, hot standby, streaming and cascading replication

•  Performance tuning −  Reindexing −  Partitioning

•  Resource management −  Connections −  CPU

•  Hardware and OS configuration −  File system options

Page 17: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 17

Monitoring and Maintenance

Page 18: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 18

Maintenance Highlights from 20+ AHCs

Unused Indexes

39%

Bloated Indexes

30%

Bloated Tables 13%

Missing Indexes

9% Missing

PK 9%

Bloat management (43%) is a key

production problem

specific to Postgres

Page 19: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 19

General Monitoring Recommendations Description Frequency Alerting Criteria /

Parameters monitored Load average, disk space and checking for .ready files

Every 10 minutes

(i) When load average is above threshold (ii) When disk space is below threshold (iii) When .ready(pg_xlog/archive_status/*.ready) files count is beyond threshold

Postgres instance is running and connection count

Every minute (i) When postgres instance is not running (ii) When number of connection is reached to value of max_connections (iii) When number of connections crosses threshold

Long running and waiting queries in database

Every 10 minutes

(i) When any query is running for longer than threshold (ii) When any query is in state of "idle in transaction" for more than threshold (iii) When any query is waiting for more than threshold

Bloats for tables and indexes

Once a day (i) When database tables and/or indexes individually bloated more than critical threshold (ii) When transaction ID wrap around is approaching

Is connection pooler running

Every 10 minutes

If pgbouncer or pgPool process is not running

Is streaming replication in sync with primary

Every 5 minutes

(i) When lag detected on streaming cluster exceeds threshold

Page 20: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 20

•  Open source plug-in check_postgres.pl!−  http://bucardo.org/

•  PostgreSQL Statistics Collector - pg_stat_xxx views −  pg_stat_activity - details of open connections and running

transactions −  pg_stat_database - details of databases −  pg_stat_user_* - details of tables, indexes and functions −  pg_locks - list of current locks being held

•  Database object size functions −  pg_*_size - disk space used by a tablespace, database,

relation or total_relation (includes indexes and toasted data)

Monitoring Tools (if you can’t use PEM)

Page 21: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 21 © 2011 EnterpriseDB . All rights reserved.

Postgres Enterprise Manager

•  Postgres Enterprise Manager (PEM) Tool −  Monitor real-time alerts −  Historical reports −  Identify poorly running SQL statements  

•  Top Features −  Capacity Manager −  Audit Manager −  Postgres Expert −  SQL Profiler −  Alert Manager −  Log Manager −  Web Client −  Graphical Dashboards for I/O, Memory & user activity

Page 22: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 22 © 2011 EnterpriseDB . All rights reserved.

PEM Features

•  Global dashboards with up-to-date status (up/down/performance) of all your servers

•  Ability to create performance thresholds for each key metric e.g. memory, storage, etc.

•  Any threshold violation results in an alert being sent to a centralized dashboard

•  All key performance-related statistics are automatically collected and retained

•  Forecast resource usage in the future

•  Identify and tune poorly running SQL statements

•  SNMP integration

•  Audit Logging for Postgres Plus Advanced Server instances

Page 23: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 23

Capacity Management

Page 24: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 24

•  Use cases: −  Consumption projection:

−  At current consumption rates when will I drop below 100MB of disk? −  At the consumption rate of the past 3 days when will I drop below 1 GB of

disk space? −  Point in Time Activity

−  Users were complaining of performance problems from 3 to 4 PM today. What was going on in the system, the database, how many users were connected?

−  We get a load spike every day at 11. What was happing at the time of the load spike?

−  Root cause for slower Query Performance −  Queries that access the employ table seem to be taking longer and longer.

View the growth of the number of dead tuples in the table, see what kind of scans have been executing against the table (index or sequential)

−  Activity monitoring −  Which database on the server is the most active? What kind of growth is it

seeing?

•  With PEM, you can: −  Evaluate past performance −  View trends with thresholds on certain values −  Plot metrics

Capacity Management

Page 25: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 25

Sample PEM Report – Disk Space Available

25 © 2011 EnterpriseDB . All rights reserved.

Extrapolated Data Actual Data

Page 26: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 26

Security

Page 27: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 27

•  Conceptual Layers −  Authentication −  Authorization −  Auditing − Data Security −  SQL Injection Attacks

Security Auditing

•  Approach −  Secure physical access − Network access

limitation − Host access limitation − Database access

limitation − Data access limitation

Page 28: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 28

Security Best Practices for PostgreSQL Security Best Practices for PostgreSQL and Postgres Plus Advanced Server

Executive Summary ................................................................3

Introduction ….........................................................................4

Postgres Security Features within the Above Framework ......6

Authentication .........................................................6

Authorization ….......................................................7

Accounting/Auditing ................................................8

Data Security ….......................................................9

SQL Injection Attacks ............................................10

Postgres Plus Advanced Server Security Features ..............11

Further Reading and Useful Links ........................................12

About EnterpriseDB ..............................................................12

© 2013 EnterpriseDB Corporation. All rights reserved. EnterpriseDB and Postgres Plus are trademarks of EnterpriseDB Corporation. Other names may be trademarks of their respective owners. http://www.enterprisedb.com

Page: 2

Table of Contents

Disclaimer The following is intended as an outline of EnterpriseDB’s general product direction. It is intended for informational purposes only, and it should not be relied upon in making purchasing decisions. This information may not be incorporated into any contract. It is not a commitment or obligation on the part of EnterpriseDB to release, launch or deliver any updates, modifications, material, code or functional improvements and may change at EnterpriseDB’s sole discretion.

http://info.enterprisedb.com/rs/enterprisedb/images/Whitepapers_Security_BP_PostgreSQL_and_Postgres_Plus_AS.pdf

Page 29: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 29

Quick Poll Database Priorities

Page 30: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 30

•  Question: What is your current database priority?

•  Answer choices: a.  Resolving a current performance issue b.  Architecture – migration, capacity planning, upgrade c.  Preparing for production deployment d.  Monitoring for ongoing database health e.  Establishing routine maintenance practices

Audience Quick Poll #1

Page 31: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 31

Parameter Tuning for Performance

Page 32: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 32

Performance Improvement Recommendations in: •  Optimizing memory usage

−  Adjusting shared_buffers −  work_mem * max_connections

•  vm.dirty_bytes and vm.dirty_background_bytes •  Understanding the storage

−  effective_io_concurrency

•  Identifying problem queries - pgbadger and SQL Profiler

The following analysis is based on a set of 20 AHCs executed in 2013

Lessons From AHC and RDBA

Page 33: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 33

0%#

10%#

20%#

30%#

40%#

50%#

60%#

70%#

80%#

90%#

100%#

effec0ve_cache_size#

shared_buffers#

bgwriter_lru_maxpages#

wal_buffers#

maintenance_work_mem#

bgwriter_lru_mul0plier#

work_mem#

random_page_cost#

checkpoint_segments#

cpu_tuple_cost#

checkpoint_comple0on_target#

checkpoint_0meout#

log_line_prefix#

log_lock_waits#

log_min_dura0on_statement#

autovacuum_vacuum_scale_factor#

checkpoint_w

arning#

autovacuum_vacuum_cost_delay#

autovacuum_vacuum_threshold#

autovacuum_nap0me#

log_autovacuum_min_dura0on#

Top$Database$Parameter$Adjustments$3$Ordered$by$Frequency$

Red bars: experts expected top parameters, including vacuum_cost_limit, log_line_prefix, log_min_duration_statement, log_checkpoints

Top Database Parameter Adjustments – Ordered by Frequency

Page 34: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 34

Kernel Parameters

0

2

4

6

8

10

12

14

16

Page 35: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 35

Issue: •  Performance issues - speed Root Causes •  Slow, memory-hungry queries,

improper indexes Results

Customer Case Study

Use Case: Supply Chain Logistics IT Provider SaaS Warehouse Management System

Change Areas •  Indexing improvements •  Query tuning or rewrites

Page 36: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 36

Issue: •  Intermittent timeouts Root Cause •  Parameter configuration

•  Enabled −  vm.dirty_bytes −  vm.dirty_background_bytes −  vm.zone_reclaim_mode

•  Disabled −  vm.overcommit_memory −  vm.swappiness −  redhat_transparent_hugepage

Customer Case Study

Use Case: Global MLS Platform – Reporting System

Change Areas •  Kernel parameters •  Database memory parameters

•  Increased −  work_mem −  maintenance_work_mem

•  Reduced −  shared_buffers

•  wal_buffers 32MB •  wal_level “archive”

Page 37: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 37

Deployment Planning

Page 38: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 38

•  Why do you need backup and recovery? Backup and Recovery Strategies protect you in case of: −  Catastrophic Device Failure −  Site Failure −  Maintenance −  Operator Error −  Compliance −  Data Corruption

•  Multiple components: −  Logical backup provides granularity in objects (tables, table

spaces, databases) −  Physical backups provide granularity in time for PITR −  Cold/off-line backups −  Hot/on-line backup, with WAL archiving

Backup and Recovery Strategies

Page 39: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 39

Backup and Standby

hot 47%

warm 23%

None 18%

cold 12%

Standby Approach Physical

Only 36%

Logical Only 29%

Physical and

Logical 14%

FS Snapshot

7%

None 14%

Backup Approach 43% of customers could not execute PITR (prior to AHC) – some had NO backup in place

30% of customers would have been slow or unable to recover from failure

Page 40: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 40

•  Backup Strategy Framework −  Logical backup after structural changes or

major updates of reference/meta data −  Physical backup (daily…) −  WAL file archiving −  Combine Backup/Recovery and Streaming Replication −  Uses replica to offload hot backup and logical backup

•  Consider −  Allowable PITR timeframe −  Data retention policy −  Test, test, test −  Periodic backup validation

•  Advanced solutions, such as RHCS, Veritas Clustering , EFM and EDB BART augment the basic capabilities

Backup and Recovery Best Practices

Page 41: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 41

Stage: post-production Primary Issue: •  Outage due to replication

failure - insufficient log info to determine true root cause

Potential Pain Points •  Concerns have reached limits

of scale and meeting anticipated growth demands

Recommendations •  Backup and recovery strategies

−  Implement continuous archive recovery in addition to streaming replication

−  Revised backup strategy with PITR

−  Tune auto-vacuum settings and manually vacuum large tables

•  Indexes – create concurrent indexes, REINDEX to reduce bloat

•  Parameter tuning – various for kernel, memory settings and WALs

Customer Case Study

Use Case: on-line advertising service with hosted chat

Page 42: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 42

•  Types of Storage Systems −  Direct Attached Storage (DAS) −  Storage Area Network (SAN) w. Fiber Channel −  Storage Area Network (SAN) w. iSCSI −  Network File System (NFS)

•  DAS: Fast and low latency •  SAN: Fast, expensive (w. Fiber Channel), scalable, can

include redundancy and smart file system operations •  NFS: Not an optimal solution for PostgreSQL data files

File System and Storage Subsystem

Page 43: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 43

Summary and Useful Resources

Page 44: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 44

•  Postgres DBAs need to focus on −  Config file settings, especially understanding memory configs −  Storage subsystem configuration −  OS Configuration −  Bloat & vacuum −  Backup - logical and physical −  HA setup −  Monitoring - see the Freight Train before it hits you!

•  Tools, tools, tools – Get the right tools

•  Most problems occur when moving to production −  Get ready early −  Get trained before MTP −  New Postgres DBA -- consider RDBA to help you get started

Summary

Page 45: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 45

•  Training & Certification −  Classroom Comprehensive Admin - Bangalore – Sept 15-19 −  Comprehensive Admin Live Online – NA- with Bruce Momjian – PostgreSQL Guru

and community leader – Oct 6-10 −  Live Online EMEA – Adv. PostgreSQL Admin – with 9.4 Highlights – Oct 13-15

•  Get the team (developer, DBA, Infrastructure) ready to thrive with Postgres

•  EDB Knowledge Base

•  Blogs −  Robert Haas – EDB Chief Architect Database Server (http://rhaas.blogspot.com/) −  Vibhor Kumar – EDB Database Consultant (http://vibhorkumar.wordpress.com/)

•  User groups and Meetups – almost all major cities −  http://www.postgresql.org/community/user-groups/ −  http://postgresql.meetup.com/

•  PostgresOpen 2014 - Sept 17-19 Chicago

•  PostgreSQL Conference Europe 2014 - Oct 21-24 Madrid

What You Can Do

Page 46: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 46

Architectural Health Check

•  Review of database, OS, env. settings

•  Guidance on tuning, backup, high availability strategies

Remote DBA Services

•  24 x 7 monitoring

•  Supplemental staff

•  Architectural health check

•  Access to Postgres expertise

Kick Start

•  Training •  Flex

consulting •  Developer

subscription

Training and Certification

•  Flexible formats: on-demand, live virtual, on-site

•  Continuing education and Postgres certification

How We Can Help

Whitepapers and Recorded Webinars http://www.enterprisedb.com/resources-community

Page 47: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 47

For all attendees we are providing a special offer on related DBA services including training.

Please complete an inquiry form on-line and mention this webinar, or speak to your account manager

−  EDB’s regional sales offices found on enterprisedb.com: −  US +1 781-357-3390 or 1-877-377-4352 −  EMEA +31 (0) 70 36 11 774 −  JAPAN +81-50-5532-7038 −  KOREA +82-2-6007-2500 −  PAKISTAN +92-51-8358874 −  INDIA +91-20-30589500/01

−  Send email to [email protected]

−  http://www.enterprisedb.com/general-inquiry-form

Special Offers for Attendees

Page 48: Best Practices for Becoming an Exceptional Postgres DBA

© 2014 EnterpriseDB Corporation. All rights reserved. 48

Q&A