PostgreSQL 9.0 Streaming Replication under the hood Heikki Linnakangas



Similar documents
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) (

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

Module 7. Backup and Recovery

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

Managing SAS Web Infrastructure Platform Data Server High-Availability Clusters

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

Comparing MySQL and Postgres 9.0 Replication

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

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

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

Implementing the Future of PostgreSQL Clustering with Tungsten

Administering your PostgreSQL Geodatabase

PostgreSQL Backup Strategies

High Availability Database Solutions. for PostgreSQL & Postgres Plus

Postgres Plus xdb Replication Server with Multi-Master User s Guide

LifeKeeper for Linux PostgreSQL Recovery Kit. Technical Documentation

Managing rights in PostgreSQL

EDB Backup and Recovery Tool Guide

Setting up PostgreSQL

PGCon PostgreSQL Performance Pitfalls

Using LDAP Authentication in a PowerCenter Domain

Secure Web Gateway Version 11.7 High Availability

Database Replication with MySQL and PostgreSQL

plproxy, pgbouncer, pgbalancer Asko Oja

EDB Failover Manager Guide. Failover Manager Version 2.0.3

Postgres Plus Cloud Database Getting Started Guide

Tushar Joshi Turtle Networks Ltd

Netezza PureData System Administration Course

Technical Notes. PostgreSQL backups with NetWorker. Release number REV 01. June 30, u Audience u Requirements...

11. Configuring the Database Archiving Mode.

How to Set Up pgagent for Postgres Plus. A Postgres Evaluation Quick Tutorial From EnterpriseDB

AVALANCHE MC 5.3 AND DATABASE MANAGEMENT SYSTEMS

A SURVEY OF POPULAR CLUSTERING TECHNOLOGIES

CA ARCserve and CA XOsoft r12.5 Best Practices for protecting Microsoft Exchange

Getting ready for PostgreSQL 9.1

This appendix describes the following procedures: Cisco ANA Registry Backup and Restore Oracle Database Backup and Restore

Pivotal Greenplum Command Center

A Shared-nothing cluster system: Postgres-XC

Postgres Plus Cloud Database Getting Started Guide

VMware vsphere Data Protection

Monitor the Heck Out Of Your Database

The elephant called PostgreSQL

Barman Backup and Recovery Manager for PostgreSQL Tutorial

SQL 2012 Installation Guide. Manually installing an SQL Server 2012 instance

TSM for Windows Installation Instructions: Download the latest TSM Client Using the following link:

GlobalSCAPE DMZ Gateway, v1. User Guide

Connectivity. Alliance Access 7.0. Database Recovery. Information Paper

Architecture and Mode of Operation

Managing User Accounts

Monitoring PostgreSQL database with Verax NMS

Connectivity. Alliance Access 7.0. Database Recovery. Information Paper

MarkLogic Server. Database Replication Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

SQL Server 2012/2014 AlwaysOn Availability Group

Configuring an OpenNMS Stand-by Server

PostgreSQL (System) Administration

Pivotal Greenplum Database

Appendix A Core Concepts in SQL Server High Availability and Replication

PRODUCT DOCUMENTATION. Greenplum Database. Version 4.3. Administrator Guide. Rev: A Pivotal Software, Inc.

Restore and Recovery Tasks. Copyright 2009, Oracle. All rights reserved.

Availability Digest. MySQL Clusters Go Active/Active. December 2006

Backup and Restore of CONFIGURATION Object on Windows 2008

Postgres Enterprise Manager Installation Guide

SQL Server AlwaysOn (HADRON)

Managing User Accounts

MIRRORING: START TO FINISH. Ryan Adams Blog - Twitter

This article Includes:

Application Continuity with BMC Control-M Workload Automation: Disaster Recovery and High Availability Primer

WhatsUp Gold v16.3 Installation and Configuration Guide

3. PGCluster. There are two formal PGCluster Web sites.

NetBrain Enterprise Edition 6.0a NetBrain Server Backup and Failover Setup

HA / DR Jargon Buster High Availability / Disaster Recovery

Importing data from Linux LDAP server to HA3969U

SAP HANA Backup and Recovery (Overview, SPS08)

Administering and Managing Log Shipping

High Availability Solutions for the MariaDB and MySQL Database

Greenplum Performance Monitor 4.0 Administrator Guide

SteelEye Protection Suite for Windows Microsoft SQL Server Recovery Kit. Administration Guide

Configure SQL database mirroring

Release Notes. LiveVault. Contents. Version Revision 0

Informix Dynamic Server May Availability Solutions with Informix Dynamic Server 11

Availability Guide for Deploying SQL Server on VMware vsphere. August 2009

Oracle Data Guard for High Availability and Disaster Recovery

Configuring High Availability for VMware vcenter in RMS Distributed Setup

Disaster Recovery on the Sun Cobalt RaQ 3 Server Appliance with Third-Party Software

Release Notes LS Retail Data Director August 2011

SQL Server for Database Administrators Course Syllabus

RoboMail Mass Mail Software

Postgres Enterprise Manager Getting Started Guide

Symantec NetBackup for Microsoft SQL Server Administrator's Guide

DSView 4 Management Software Transition Technical Bulletin

McAfee Endpoint Encryption Hot Backup Implementation

Agenda. ! Strengths of PostgreSQL. ! Strengths of Hadoop. ! Hadoop Community. ! Use Cases

DISASTER RECOVERY WITH AWS

PATROL Console Server and RTserver Getting Started

High Availability and Disaster Recovery for Exchange Servers Through a Mailbox Replication Approach

Lab 2: PostgreSQL Tutorial II: Command Line

Transcription:

PostgreSQL 9.0 Streaming Replication under the hood Heikki Linnakangas yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 1

Built-in replication Streaming Replication Allow WAL records to be streamed to standby as they're generated Hot Standby Allow read-only queries in standby server 1 + 1 = 3 yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 2

Existing solutions pg_standby WAL File-based Have to wait for full segment to fill up Slony Trigger-based yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 3

Record-based log-shipping < 9.0 PostgreSQL directly supports file-based log shipping as described above. It is also possible to implement record-based log shipping, though this requires custom development. - PostgreSQL user manual Poll using pg_xlogfile_name_offset() Skytools Doesn't work nicely with Hot Standby yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 4

Streaming Replication WAL records are shipped from master as they're generated Similar to record-based log shipping in previous versions: Asynchronous Needs file-based archiving too But: No custom development required Works well with Hot Standby yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 5

File-based replication archive_command Archive restore_command Master Slave Data flow yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 6

Streaming replication archive_command Archive restore_command Master Streaming replication Slave Data flow yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 7

Walkthrough 1.Set up master and WAL archiving 2. Set up standby server yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 8

Walkthrough: Set up master $:~/pgsql.cvshead$ bin/initdb D data master The files belonging to this database system will be owned by user "hlinnaka". This user must also own the server process.... Success. You can now start the database server using: or bin/postgres D data master bin/pg_ctl D data master l logfile start yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 9

Walkthrough: Configure master Open postgresql.conf in master Enable archiving: archive_mode = on archive_command = 'cp i %p /home/hlinnaka/pgsql.cvshead/walarchive/%f < /dev/null' Enable replication connections from standby: max_wal_senders = 5 yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 10

Walkthrough: Start master Start master and take base backup: $ bin/pg_ctl start D data master server starting $ bin/psql postgres c "SELECT pg_start_backup('mybackup', true)" pg_start_backup 0/1000020 (1 row) $ cp a data master/ data standby $ bin/psql postgres c "SELECT pg_stop_backup()" pg_stop_backup 0/10000D0 (1 row) yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 11

Walkthrough 1. Set up master and WAL archiving 2.Set up standby server yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 12

Walkthrough: Prepare standby Clean up clutter left over from master: $ rm data standby/postmaster.pid datastandby/pg_xlog/* Change port in postgresql.conf: port = 5433 yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 13

Walkthrough: Prepare standby Create data standby/recovery.conf: restore_command = 'cp /home/hlinnaka/pgsql.cvshead/walarchive/%f %p' standby_mode = 'true' primary_conninfo = 'host=localhost port=5432' trigger_file='/tmp/standby trigger' yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 14

Walkthrough: Start standby $ bin/postmaster D data standby LOG: database system was interrupted; last known up at 2010 02 03 16:34:24 EET LOG: starting archive recovery LOG: restore_command = 'cp /home/hlinnaka/pgsql.cvshead/walarchive/%f %p' LOG: standby_mode = 'true' LOG: primary_conninfo = 'host=localhost port=5432' LOG: trigger_file = '/tmp/standby trigger' LOG: restored log file "000000010000000000000003" from archive LOG: automatic recovery in progress LOG: initializing recovery connections LOG: redo starts at 0/3000020 LOG: consistent recovery state reached at 0/4000000 LOG: database system is ready to accept read only connections LOG: restored log file "000000010000000000000004" from archive LOG: restored log file "000000010000000000000005" from archive cp: cannot stat `/home/hlinnaka/pgsql.cvshead/walarchive/000000010000000000000006': No such file or directory yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 15

Walkthrough: Standby running $ ps ax grep postgres 17451 pts/4 S 0:00 /home/hlinnaka/pgsql.cvshead/bin/postgres D data master 17455? Ss 0:00 postgres: writer process 17456? Ss 0:00 postgres: wal writer process 17457? Ss 0:00 postgres: autovacuum launcher process 17458? Ss 0:00 postgres: archiver process last was 000000010000000000000005 17459? Ss 0:00 postgres: stats collector process 17573? Ss 0:00 postgres: startup process recovering 000000010000000000000006 17576? Ss 0:00 postgres: writer process 17578? Ss 0:00 postgres: stats collector process 17584? Ss 0:00 postgres: wal receiver process streaming 0/6014708 17585? Ss 0:49 postgres: wal sender process hlinnaka 127.0.0.1(56056) streaming 0/6014708 yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 16

Walkthrough: Standby running Master Standby $ psql postgres psql (8.5devel) Type "help" for help. $ PGPORT=5433 psql postgres psql (8.5devel) Type "help" for help. postgres=# CREATE TABLE foo (id int4); CREATE TABLE postgres=# SELECT * FROM foo; id (0 rows) yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 17

Walkthrough: It works! Master Standby postgres=# INSERT INTO foo VALUES (1); INSERT 0 1 postgres=# SELECT * FROM foo; id 1 (1 row) yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 18

Walkthrough: Summary 1. Set up master and WAL archiving 1. Set up Continuous WAL Archiving 2. Set max_wal_senders in postgresql.conf 3. Start up and take base backup 2. Set up standby server 1. Restore base backup 2. Create recovery.conf 3. Start standby yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 19

Failover Failover can be triggered by creating the trigger file specified in recovery.conf: trigger_file='/tmp/standby-trigger' New timeline is created Existing read-only connections stay connected, and become normal read-write connections yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 20

Failover LOG: trigger file found: /tmp/standby trigger FATAL: terminating walreceiver process due to administrator command LOG: redo done at 0/60147C0 LOG: last completed transaction was at log time 2000 01 01 02:21:05.209196+02 cp: cannot stat `/home/hlinnaka/pgsql.cvshead/walarchive/000000010000000000000006': No such file or directory cp: cannot stat `/home/hlinnaka/pgsql.cvshead/walarchive/00000002.history': No such file or directory LOG: selected new timeline ID: 2 LOG: archive recovery complete LOG: autovacuum launcher started LOG: database system is ready to accept connections yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 21

Failover considerations Designed to be simple and integrated with 3 rd party high availability tools Heartbeat Shoot The Other Node In The Head Need to restore from base backup to make the old master as a standby yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 22

Monitoring pg_last_xlog_receive_location() How much WAL have we safely received from master? Determines how much data you will lose if the master dies pg_last_xlog_replay_location() How far have we replayed? Determines how old data the results to read-only queries are based on yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 23

Security considerations All normal libpq authentication methods available SSL Certificate based authentication Streaming replication requires a user with superuser privileges Edit pg_hba.conf to control access yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 24

Example pg_hba.conf: # TYPE DATABASE USER CIDR ADDRESS METHOD host replication rep_user 192.168.1.117 md5 host replication all 0.0.0.0/0 reject # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust psql: CREATE USER rep_user SUPERUSER PASSWORD 'strong' yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 25

Advanced: Look, no archive! WAL archiving is still required To take an online backup To allow standby to catch up if the connection is lost for a long time You can do streaming replication without a shared archive, if you don't care about the above yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 26

Advanced: replacing pg_standby You can set standby_mode='true', without streaming replication WAL file-based replication, like pg_standby, but without pg_standby restore_command = 'cp /home/hlinnaka/pgsql.cvshead/walarchive/%f %p' standby_mode = 'true' trigger_file='/tmp/standby trigger' yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 27

Under the hood Streaming replication is implemented with two new server processes Walsender in master Walreceiver in standby $ ps ax 28016? Ss 0:00 postgres: wal receiver process streaming 0/7000574 28017? Ss 0:00 postgres: wal sender process rep_user 127.0.0.1(33104) streaming 0/7000574 yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 28

Protocol Walreceiver process in standby connects using libpq Using replication=on Primary server launches a walsender process to serve the connection, instead of a regular backend. Walsender accepts a small set of special replication related commands: IDENTIFY_SYSTEM Server replies with TLI and system identifier START_REPLICATION XXX/XXX Server goes into COPY OUT mode, and starts to stream WAL yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 29

Future Allow base backup to be taken and transferred through the streaming connection Allow reliable operation without archive Synchronous mode Cascading slaves Archiving from slave Stand-alone tools to stream WAL or take a base backup yright 2009 EnterpriseDB Corporation. All rights Reserved. <presentation title goes here, edit in the slide master > Slide: 30