Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 1 PostgreSQL 9.0 Streaming Replication under the hood Heikki Linnakangas.

Slides:



Advertisements
Similar presentations
INTRODUCTION TO ORACLE Lynnwood Brown System Managers LLC Backup and Recovery Copyright System Managers LLC 2008 all rights reserved.
Advertisements

FlareCo Ltd ALTER DATABASE AdventureWorks SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS Slide 1.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 12: Managing and Implementing Backups and Disaster Recovery.
Genie Backup ManagerServer 7.0 Product Profile. Copyright© Genie-Soft Corporation All rights reserved. Overview GBM Server 7.0 is a fully integrated.
Backup and Recovery Part 1.
9 Copyright © Oracle Corporation, All rights reserved. Oracle Recovery Manager Overview and Configuration.
Reliable MySQL Using Replication Issac Goldstand Mirimar Networks
Oracle9i Database Administrator: Implementation and Administration
Introduction to Oracle Backup and Recovery
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 12: Managing and Implementing Backups and Disaster Recovery.
70-293: MCSE Guide to Planning a Microsoft Windows Server 2003 Network, Enhanced Chapter 14: Problem Recovery.
20 Copyright © 2004, Oracle. All rights reserved. Database Recovery.
Building Highly Available Systems with SQL Server™ 2005 Vineet Gupta Evangelist – Data and Integration Microsoft Corp.
13 Copyright © Oracle Corporation, All rights reserved. RMAN Complete Recovery.
1 Introduction to PostgreSQL. 2 Documents PostgreSQL 8 for Windows (*) Beginning Databases with PostgreSQL From Novice to Professional, Second Edition.
High-Availability Methods Lesson 25. Skills Matrix.
Remote Desktop Services Remote Desktop Connection Remote Desktop Protocol Remote Assistance Remote Server Administration T0ols.
11 Copyright © Oracle Corporation, All rights reserved. RMAN Backups.
11 Copyright © Oracle Corporation, All rights reserved. RMAN Backups.
INSTALLING MICROSOFT EXCHANGE SERVER 2003 CLUSTERS AND FRONT-END AND BACK ‑ END SERVERS Chapter 4.
© Continuent 2010 Building Tungsten Clusters with PostgreSQL Hot Standby and Streaming Replication Linas Virbalas and Alex Alexander Continuent, Inc.
It is one of the techniques to create a stand by server. Introduced in SQL 2000,enhanced in It is a High Availability as well as Disaster recovery.
15 Copyright © 2005, Oracle. All rights reserved. Performing Database Backups.
Chapter 8 Implementing Disaster Recovery and High Availability Hands-On Virtual Computing.
Maintaining a Mirrored Database Tips and Tricks by Paul G. Hiles.
16 Copyright © 2007, Oracle. All rights reserved. Performing Database Recovery.
ITN Wake Tech1 ITN270 Advanced Internet Databases Lecture 15. General MySQL Administration Topics: –Securing a New MySQL Installation –MySQL Server.
The protection of the DB against intentional or unintentional threats using computer-based or non- computer-based controls. Database Security – Part 2.
11 DISASTER RECOVERY Chapter 13. Chapter 13: DISASTER RECOVERY2 OVERVIEW  Back up server data using the Backup utility and the Ntbackup command  Restore.
7 Copyright © 2004, Oracle. All rights reserved. Recovering from Noncritical Losses.
A Brief Documentation.  Provides basic information about connection, server, and client.
Chapter 10 Chapter 10: Managing the Distributed File System, Disk Quotas, and Software Installation.
1 © 2005 Cisco Systems, Inc. All rights reserved. 111 © 2004, Cisco Systems, Inc. All rights reserved. CNIT 221 Security 2 ver.2 Module 8 City College.
PostgreSQL Installation By: Keerthi Nelaturu Previous version by Ahmed Jeddah & Miguel Garzon.
10 Copyright © Oracle Corporation, All rights reserved. User-Managed Backups.
Cloud Computing Computer Science Innovations, LLC.
Overview of Oracle Backup and Recovery Darl Kuhn, Regis University.
12 Copyright © Oracle Corporation, All rights reserved. User-Managed Complete Recovery.
Unicenter NSM Debugging Tips & Tricks -Release r11.
6 Copyright © 2007, Oracle. All rights reserved. Performing User-Managed Backup and Recovery.
2 Copyright © 2007, Oracle. All rights reserved. Configuring for Recoverability.
Distributed DBMS, Query Processing and Optimization
2 Copyright © 2006, Oracle. All rights reserved. Configuring Recovery Manager.
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
19 Copyright © 2004, Oracle. All rights reserved. Database Backups.
20 Copyright © 2006, Oracle. All rights reserved. Best Practices and Operational Considerations.
4 Copyright © 2004, Oracle. All rights reserved. Managing the Oracle Instance.
Vacuum ● Records deleted or obsoloted by an update are not reclaimed as free space and cannot be reused ● Vacuum claims that space for the system to reuse,
DBMS ● What are they? ● Why used ● Examples? – Oracle – Access – MySQL – Postgres – SQLServer – Sqlite.
19 Copyright © 2008, Oracle. All rights reserved. Security.
Administrating a Database
Turgay Sahtiyan Istanbul, Turkey
Backup and Recovery.
Maintaining Online Redo Log Files
Navigating the options for Data Redundancy
Chapter 5 : Designing Windows Server-Level Security Processes
Is 221: Database Administration
Using EDB Postgres Replication Server to Offload Oracle Reporting Workloads to Postgres Matthew Lewandowski.
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Working at a Small-to-Medium Business or ISP – Chapter 7
Working at a Small-to-Medium Business or ISP – Chapter 7
What’s new in SQL Server 2016 Availability Groups
Provisioning and Automating High Availability Postgres on AWS EC2
Working at a Small-to-Medium Business or ISP – Chapter 7
Database Backup and recovery
Performing Database Recovery
Chapter 11 Managing Databases with SQL Server 2000
Administrating a Database
Presentation transcript:

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 1 PostgreSQL 9.0 Streaming Replication under the hood Heikki Linnakangas

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 2 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 = 3

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 3 Existing solutions pg_standby – WAL File-based – Have to wait for full segment to fill up Slony – Trigger-based

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 4 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 5 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 6 File-based replication Master Archive Slave archive_command restore_command Data flow

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 7 Streaming replication Master Archive Slave archive_command restore_command Streaming replication Data flow

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 8 Walkthrough 1.Set up master and WAL archiving 2.Set up standby server

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 9 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: bin/postgres -D data-master or bin/pg_ctl -D data-master -l logfile start

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 10 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 11 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 / (1 row) $ cp -a data-master/ data-standby $ bin/psql postgres -c "SELECT pg_stop_backup()" pg_stop_backup /10000D0 (1 row)

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 12 Walkthrough 1.Set up master and WAL archiving 2.Set up standby server

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 13 Walkthrough: Prepare standby Clean up clutter left over from master: $ rm data-standby/postmaster.pid data-standby/pg_xlog/* Change port in postgresql.conf: port = 5433

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 14 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'

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 15 Walkthrough: Start standby $ bin/postmaster -D data-standby LOG: database system was interrupted; last known up at :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 " " from archive LOG: automatic recovery in progress LOG: initializing recovery connections LOG: redo starts at 0/ LOG: consistent recovery state reached at 0/ LOG: database system is ready to accept read only connections LOG: restored log file " " from archive LOG: restored log file " " from archive cp: cannot stat `/home/hlinnaka/pgsql.cvshead/walarchive/ ': No such file or directory

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 16 Walkthrough: Standby running $ ps ax| grep postgres pts/4 S 0:00 /home/hlinnaka/pgsql.cvshead/bin/postgres -D data- master ? Ss 0:00 postgres: writer process ? Ss 0:00 postgres: wal writer process ? Ss 0:00 postgres: autovacuum launcher process ? Ss 0:00 postgres: archiver process last was ? Ss 0:00 postgres: stats collector process ? Ss 0:00 postgres: startup process recovering ? Ss 0:00 postgres: writer process ? Ss 0:00 postgres: stats collector process ? Ss 0:00 postgres: wal receiver process streaming 0/ ? Ss 0:49 postgres: wal sender process hlinnaka (56056) streaming 0/

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 17 Walkthrough: Standby running Master $ psql postgres psql (8.5devel) Type "help" for help. postgres=# CREATE TABLE foo (id int4); CREATE TABLE Standby $ PGPORT=5433 psql postgres psql (8.5devel) Type "help" for help. postgres=# SELECT * FROM foo; id ---- (0 rows)

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 18 Walkthrough: It works! Master postgres=# INSERT INTO foo VALUES (1); INSERT 0 1 Standby postgres=# SELECT * FROM foo; id (1 row)

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 19 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 20 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 21 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 :21: cp: cannot stat `/home/hlinnaka/pgsql.cvshead/walarchive/ ': No such file or directory cp: cannot stat `/home/hlinnaka/pgsql.cvshead/walarchive/ his tory': 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 22 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 23 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 24 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 25 Example pg_hba.conf: # TYPE DATABASE USER CIDR-ADDRESS METHOD hostreplicationrep_user md5 host replication all /0 reject # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all /32 trust # IPv6 local connections: host all all ::1/128 trust psql: CREATE USER rep_user SUPERUSER PASSWORD 'strong'

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 26 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 27 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'

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 28 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/ –28017 ? Ss 0:00 postgres: wal sender process rep_user (33104) streaming 0/ –

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 29 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

Copyright 2009 EnterpriseDB Corporation. All rights Reserved. Slide: 30 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