PostgreSQL 9.4 up and running.. Vasilis Ventirozos Database Administrator OmniTI

Similar documents
PostgreSQL 9.0 Streaming Replication under the hood Heikki Linnakangas

How To Run A Standby On Postgres (Postgres) On A Slave Server On A Standby Server On Your Computer (Mysql) On Your Server (Myscientific) (Mysberry) (

Managing SAS Web Infrastructure Platform Data Server High-Availability Clusters

PostgreSQL Backup Strategies

Be Very Afraid. Christophe Pettus PostgreSQL Experts Logical Decoding & Backup Conference Europe 2014

Backup and Recovery using PITR Mark Jones EnterpriseDB Corporation. All rights reserved. 1

Technical Paper. Configuring the SAS Web Infrastructure Platform Data Server for High Availability

Replication Security

PostgreSQL when it s not your job. Christophe Pettus PostgreSQL Experts, Inc. DjangoCon US 2012

PostgreSQL when it s not your job. Christophe Pettus PostgreSQL Experts, Inc. DjangoCon Europe 2012

PostgreSQL (System) Administration

Module 7. Backup and Recovery

Writing a Logical Decoding Plug-In. Christophe Pettus PostgreSQL Experts, Inc. FOSDEM 2015

EDB Backup and Recovery Tool Guide

MySQL Enterprise Backup

PGCon PostgreSQL Performance Pitfalls

IMPLEMENTATION OF CIPA - PUDUCHERRY UT SERVER MANAGEMENT. Client/Server Installation Notes - Prepared by NIC, Puducherry UT.

Administering your PostgreSQL Geodatabase

Managing rights in PostgreSQL

The Future of PostgreSQL High Availability Robert Hodges - Continuent, Inc. Simon Riggs - 2ndQuadrant

2. Boot using the Debian Net Install cd and when prompted to continue type "linux26", this will load the 2.6 kernel

Implementing the Future of PostgreSQL Clustering with Tungsten

Setting up PostgreSQL

Database Load Balancing MySQL 5.5 vs PostgreSQL 9.1

INSTALLATION MANUAL POSTGRESQL9

Product Brief. it s Backed Up

SQL Server 2012/2014 AlwaysOn Availability Group

Barman Backup and Recovery Manager for PostgreSQL Tutorial

Net/FSE Installation Guide v1.0.1, 1/21/2008

MySQL Administration and Management Essentials

Mastering PostgreSQL Administration

Using VMware vfabric Postgres

MIRRORING: START TO FINISH. Ryan Adams Blog - Twitter

Supported DBMS platforms DB2. Informix. Enterprise ArcSDE Technology. Oracle. GIS data. GIS clients DB2. SQL Server. Enterprise Geodatabase 9.

for QSS/OASIS Presented by Bill Genske Session 135

MySQL Backups: From strategy to Implementation

PostgreSQL database performance optimization. Qiang Wang

SharePlex for Oracle How to replicate databases. Jeffrey Surretsky Solutions Architect

Database Backup and Restore Mechanism. Presented by : Mary Meladath

LifeKeeper for Linux PostgreSQL Recovery Kit. Technical Documentation

Top 10 Reasons why MySQL Experts Switch to SchoonerSQL - Solving the common problems users face with MySQL

Using MySQL for Big Data Advantage Integrate for Insight Sastry Vedantam

High Availability with Postgres Plus Advanced Server. An EnterpriseDB White Paper

Module 14: Scalability and High Availability

Security and Control Issues within Relational Databases

Recovery Principles in MySQL Cluster 5.1

Sawmill Log Analyzer Best Practices!! Page 1 of 6. Sawmill Log Analyzer Best Practices

IGEL Universal Management. Installation Guide

Who did what, when, where and how MySQL Audit Logging. Jeremy Glick & Andrew Moore 20/10/14

Practical Cassandra. Vitalii

Database Resilience at ISPs. High-Availability. White Paper

Postgres Plus Cloud Database Getting Started Guide

Monitoring PostgreSQL database with Verax NMS

Digital Forensics Tutorials Acquiring an Image with FTK Imager

MySQL Backup IEDR

Architecture and Mode of Operation

Online Backup Client User Manual

Online Backup Client User Manual

White Paper. Alfresco Backup and Disaster Recovery

Connectivity. Alliance Access 7.0. Database Recovery. Information Paper

Postgres Enterprise Manager Installation Guide

Tushar Joshi Turtle Networks Ltd

SPI Backup via Remote Terminal

Installation Guide. Copyright (c) 2015 The OpenNMS Group, Inc. OpenNMS SNAPSHOT Last updated :19:20 EDT

DFW Backup Software. Whitepaper DFW Backup Agent

Database Scalability {Patterns} / Robert Treat

The PCI Compliant Database. Christophe Pettus PostgreSQL Experts, Inc. PGConf Silicon Valley 2015

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

1.0 Hardware Requirements:

Getting Started with Attunity CloudBeam for Azure SQL Data Warehouse BYOL

Zoner Online Backup. Whitepaper Zoner Backup Agent

4PSA Total Backup User's Guide. for Plesk and newer versions

Ahsay Backup Software. Whitepaper Ahsay Backup Agent

How To Choose Between A Relational Database Service From Aws.Com

Oracle Database 11g: Administration Workshop II DBA Release 2

Stellar Phoenix. SQL Database Repair 6.0. Installation Guide

RecoveryVault Express Client User Manual

Configuring an Alternative Database for SAS Web Infrastructure Platform Services

Performance Monitoring AlwaysOn Availability Groups. Anthony E. Nocentino

IUCLID 5 Guidance and Support

Postgres Plus Cloud Database Getting Started Guide

Maintaining the Content Server

How to Configure Double-Take on Microsoft Exchange Server

High Availability for VMware GSX Server

Configure and Run the HQ Server

Online Backup Client User Manual Mac OS

Online Backup Client User Manual Mac OS

Configuring Backup Settings Configuring and Managing Persistent Settings for RMAN Configuring Autobackup of Control File Backup optimization

Microsoft SQL Database Administrator Certification

IMPORTANT: The person who installs and sets up the PCS Axis database on the central database server

Polarion Application Lifecycle Management Platform. Installation Guide for Linux

VSS Backup Solution for Exchange Server 2007 and Symantec Backup Exec 12.5 using ETERNUS VSS Hardware Provider

MySQL Security for Security Audits

Online Backup Linux Client User Manual

Outline. Failure Types

Online Backup Client User Manual

Database migration. from Sybase ASE to PostgreSQL. Achim Eisele and Jens Wilke. 1&1 Internet AG

Whitepaper FailSafeSolutions Backup Agent

Connectivity. Alliance Access 7.0. Database Recovery. Information Paper

Transcription:

PostgreSQL 9.4 up and running.. Vasilis Ventirozos Database Administrator OmniTI 1

Who am I? DBA@OmniTI for the past 2.5 years PostgreSQL DBA since 7.x Working as DBA since 2001 (Informix, Postgres, MySQL, Oracle) Doesn t like Oracle!!! Blog: http://evol-monkey.blogspot.com Twitter: @vventirozos Email: vventirozos@omniti.com 2

Why PostgreSQL? Reliable Extensible Cross Platform Performance High Availability Development Pace $$ COST $$ 3

Use the source Luke! Why? Customize your own installation, no matter the distribution. Install only the necessary. How? Download source wget -c https://ftp.postgresql.org/pub/source/v9.4.5/postgresql-9.4.5.tar.gz Install dependencies sudo apt-get install build-essential sudo apt-get install libreadline6-dev sudo apt-get install zlib1g-dev Compile./configure --prefix=/opt/pgsql/9.4.5 --enable-debug make world make install-world 4

Make your life easier export PGDATA=/data/pgdata export PATH=$PATH:/opt/pgsql/9.4.5/bin init script can be found in : postgresql-9.4.5/contrib/start-scripts/linux Contrib packages are very useful: psql -c "create extension pageinspect;" template1 psql -c "create extension pg_stat_statements;" template1 psql -c "create extension pg_buffercache;" template1 5

Getting there.. initdb -D $PGDATA initializes a new database cluster (also supports data checksums) 6

Configuring..part 1.. $PGDATA/pg_hba.conf (host based authentication) local all all trust host all all 127.0.0.1/32 trust host all user 192.168.1.0/16 md5 hostssl all user-ssl 192.168.1.0/16 md5 host replication repuser 192.168.1.1/32 md5 hostssl replication repuser 192.168.1.2/32 md5 host all all 0.0.0.0/0 reject *(it s last for a reason) 7

$PGDATA/postgresql.conf, the basics listen_addresses = '*' shared_buffers = 25% of your RAM or up to 8GB maintenance_work_mem = ~1GB work_mem = depends! checkpoint_segments = ~100 archive_mode = on archive_command = '/bin/true' effective_cache_size = 75% of the ram, not allocated. protip: work_mem is per operation, not per statement! 8

Getting ready for replication wal_level = hot_standby max_wal_senders = 5 max_replication_slots = 5 hot_standby = on 9

Logging is important! log_destination = 'stderr' logging_collector = on log_directory = 'pg_log' log_filename = 'postgresql-%y-%m-%d_%h%m%s.log' log_min_duration_statement = 0 (too much spam!!) log_duration = on log_line_prefix = '%t [%r] [%p]: [%l-1] user=%u,db=%d,e=%e ' log_statement = 'all' log_temp_files = 0 10

Ready to start!! pg_ctl -D $PGDATA start (always check logs under $PGDATA/pg_log) 11

Adding a Streaming Replica On Master : psql -c "SELECT * FROM pg_create_physical_replication_slot('slave01_slot');" postgres psql -c "CREATE role repuser with replication login password 'password'; postgres Remember that pg_hba.conf entry? host replication repuser 192.168.1.2/32 md5 On Slave : pg_receivexlog -D. -S slave01_slot -v -h 192.168.1.1 -U repuser -W Password: pg_receivexlog: starting log streaming at 0/3E000000 (timeline 1) pg_receivexlog: finished segment at 0/3F000000 (timeline 1) ^Cpg_receivexlog: received interrupt signal, exiting pg_receivexlog: received interrupt signal, exiting PROTIP: This will activate the replica slot ;-) 12

WTF is a replica slot? Introduced in 9.4 remember this? : requested WAL segment 000000010000000C000000AE has already been removed. Now forget it :-) 13

Ready for pg_basebackup pg_basebackup works over the replication stream (no FW changes needed) it s fast! can be used for all kinds of backups. supports more than one formats and it can use compression. To create the replica you want to run something like : pg_basebackup -h <master ip> -D $PGDATA -X stream -P -U repuser 14

Last step.. I promise $PGDATA/recovery.conf standby_mode = 'on' primary_conninfo = 'host=<master IP> port=5432 user=repuser password=password application_name=slave01' trigger_file = '<a path>/failover.trigger' recovery_target_timeline = 'latest' primary_slot_name = 'slave01_slot' And finally. 15

Startup of slave pg_ctl -D $PGDATA start Slave will accept read only connections, a nice way to scale reads. (Always check logs) 16

Monitoring replication Monitoring is important amirite? =# SELECT application_name,sync_state,pg_xlog_location_diff(pg_current_xlog_insert_location(), flush_location) AS lag_byte FROM pg_stat_replication order by 1; application_name sync_state lag_byte ------------------+------------+---------- slave01 async 0 =# SELECT slot_name, active, pg_xlog_location_diff(pg_current_xlog_insert_location(), restart_lsn) AS retained_bytes FROM pg_replication_slots order by 1; slot_name active retained_bytes --------------+--------+---------------- slave01_slot t 0 17

Synchronous VS Asynchronous Synchronous means that master has to get a confirmation from one server that transaction made it there before it commits. synchronous_commit = on synchronous_standby_names = 'server1,server2,server3.' Remember.. being paranoid equals delays... 18

omg noes, Master db died!! Pre-Failover check list (if you can..) Active transactions Making sure no one will connect from now on. Replication Lag 19

Failover is easy, failback is not! From slave : pg_ctl promote, or touch the trigger file yeah, that s it... 20

So, ex-master is now ok? A Demoted server is USELESS! (sorry) Add as a new slave (rebuild) Promote Rebuild the new slave again 21

Backups But, i have a replica, i should be ok NOPE! User mistakes Application errors Bugz Corruptions 22

To dump.. pg_dumps pros Small Allows partial restore Fast (or not) can be done from slave cons Frozen in time, no PITR Slow (size matters!) Has to be repeated 23

Or not to dump.. Continuous backups with archiving pros PITR It s incremental It s easy..pitr.. cons Needs disk space.. sometimes, A LOT.. Doesn t allow partial restore 24

Other backup tools pg_basebackup http://www.postgresql.org/docs/9.4/static/app-pgbasebackup.html OmniPITR https://github.com/omniti-labs/omnipitr protip: backups can run from your slave 25

Restoring is more important.. Always validate backups by restoring them.- 26

Reporting pgbadger https://github.com/dalibo/pgbadger tail n mail https://bucardo.org/wiki/tail_n_mail system monitoring https://github.com/omniti-labs/system_monitoring 27

Integration Logical Decoding, introduced in 9.4 test_decoding the default plugin wal2json shows the changes in JSON format decoder_raw reconstructs the query that has applied the change. =# SELECT * FROM pg_create_logical_replication_slot('my_slot', 'test_decoding'); slot_name xlog_position -----------+--------------- my_slot 0/16CB0F8 (1 row) =# UPDATE aa SET c = 3 WHERE (a, b) = (1, 1); UPDATE 1 =# SELECT * FROM pg_logical_slot_get_changes('my_slot', NULL, NULL); location xid data -----------+------+----------------------------------------------------------------- 0/1728D50 1013 BEGIN 1013 0/1728D50 1013 table public.aa: UPDATE: a[integer]:1 b[integer]:1 c[integer]:3 0/1728E70 1013 COMMIT 1013 (3 rows) 28

Integration example 29

Questions? 30