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



Similar documents
PostgreSQL 9.0 Streaming Replication under the hood Heikki Linnakangas

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

Module 7. Backup and Recovery

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

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

Implementing the Future of PostgreSQL Clustering with Tungsten

Database Hardware Selection Guidelines

PostgreSQL Backup Strategies

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

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

Managing SAS Web Infrastructure Platform Data Server High-Availability Clusters

Comparing MySQL and Postgres 9.0 Replication

Outline. Failure Types

Administering your PostgreSQL Geodatabase

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

Barman Backup and Recovery Manager for PostgreSQL Tutorial

Postgres Plus Cloud Database Getting Started Guide

PGCon PostgreSQL Performance Pitfalls

Postgres Plus Cloud Database Getting Started Guide

A Shared-nothing cluster system: Postgres-XC

EDB Backup and Recovery Tool Guide

Monitoring PostgreSQL database with Verax NMS

Configuring Apache Derby for Performance and Durability Olav Sandstå

Near Real Time Indexing Kafka Message to Apache Blur using Spark Streaming. by Dibyendu Bhattacharya

PostgreSQL (System) Administration

Monitor the Heck Out Of Your Database

Database Replication with MySQL and PostgreSQL

Module 14: Scalability and High Availability

DB2 9 for LUW Advanced Database Recovery CL492; 4 days, Instructor-led

Recovery Principles in MySQL Cluster 5.1

SQL Server 2014

Products for the registry databases and preparation for the disaster recovery

Setting up PostgreSQL

Administering a Microsoft SQL Server 2000 Database

LifeKeeper for Linux PostgreSQL Recovery Kit. Technical Documentation

Check Please! What your Postgres database wishes you would monitor. / Presentation

Appendix A Core Concepts in SQL Server High Availability and Replication

Boost SQL Server Performance Buffer Pool Extensions & Delayed Durability

Mind Q Systems Private Limited

MS Administering Microsoft SQL Server Databases

SQL Server 2012 Database Administration With AlwaysOn & Clustering Techniques

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

Designing Database Solutions for Microsoft SQL Server 2012 MOC 20465

SQL Server AlwaysOn (HADRON)

Administering a Microsoft SQL Server 2000 Database

PROTECTING AND ENHANCING SQL SERVER WITH DOUBLE-TAKE AVAILABILITY

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

Basic knowledge of the Microsoft Windows operating system and its core functionality Working knowledge of Transact-SQL and relational databases

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

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

SQL Server for Database Administrators Course Syllabus

Course 20462C: Administering Microsoft SQL Server Databases

Oracle Database 10g: Backup and Recovery 1-2

MOC Administering Microsoft SQL Server 2014 Databases

This article Includes:

Implementing Microsoft SQL Server 2008 Exercise Guide. Database by Design

Administering Microsoft SQL Server Databases

A SURVEY OF POPULAR CLUSTERING TECHNOLOGIES

for QSS/OASIS Presented by Bill Genske Session 135

Designing and Deploying Messaging Solutions with Microsoft Exchange Server 2010 Service Pack B; 5 days, Instructor-led

Module 07. Log Shipping

Mastering PostgreSQL Administration

Administering a Microsoft SQL Server 2000 Database

Administering a SQL Database Infrastructure

Administering a SQL Database Infrastructure 20764; 5 Days; Instructor-led

IGEL Universal Management. Installation Guide

Pervasive PSQL Meets Critical Business Requirements

Configuring an OpenNMS Stand-by Server

High Availability for Internet Information Server Using Double-Take 4.x

Administering Microsoft SQL Server Databases

Designing a Data Solution with Microsoft SQL Server 2014

Would-be system and database administrators. PREREQUISITES: At least 6 months experience with a Windows operating system.

Greenplum Database 4.2 System Administrator Guide. Rev: A15

Administering Microsoft SQL Server Databases MOC 20462

AVALANCHE MC 5.3 AND DATABASE MANAGEMENT SYSTEMS

Microsoft SQL Database Administrator Certification

Getting ready for PostgreSQL 9.1

Backup and Recovery. What Backup, Recovery, and Disaster Recovery Mean to Your SQL Anywhere Databases

MOC 20462C: Administering Microsoft SQL Server Databases

DocAve 6 High Availability

Network Registrar Data Backup and Recovery Strategies

Backup Exec System Recovery 7.0 Best Practices

BACKUP SECURITY GUIDELINE

MySQL Enterprise Backup

Eloquence Training What s new in Eloquence B.08.00

High Availability Using Raima Database Manager Server

Microsoft Exchange 2003 Disaster Recovery Operations Guide

Derby: Replication and Availability

Oracle Data Guard for High Availability and Disaster Recovery

High Availability Solutions for the MariaDB and MySQL Database

Microsoft SQL Server 2014: MS SQL Server Administering Databases

White Paper for Data Protection with Synology Snapshot Technology. Based on Btrfs File System

MIRRORING: START TO FINISH. Ryan Adams Blog - Twitter

Nimble Storage Best Practices for Microsoft SQL Server

High Availability Database Solutions. for PostgreSQL & Postgres Plus

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

Implementing Microsoft Azure Infrastructure Solutions

Transcription:

The Magic of Hot Streaming Replication BRUCE MOMJIAN POSTGRESQL 9.0 offers new facilities for maintaining a current standby server and for issuing read-only queries on the standby server. This tutorial covers these new facilities. Creative Commons Attribution License http://momjian.us/presentations Last updated: September, 2015 1 / 22

Introduction How does WAL combined with a disk image enable standby servers? (review) How do you configure continuous archiving? How do you configure a streaming, read-only server? Multi-Server complexities Primary/Standby synchronization complexities The Magic of Hot, Streaming Replication 2 / 22

Write-Ahead Logging (xlog) Postgres Backend Postgres Backend Postgres Backend Recovery Query and Checkpoint Operations Transaction Durability PostgreSQL Shared Buffer Cache Write Ahead Log fsync Kernel Disk Buffer Cache fsync Disk Blocks The Magic of Hot, Streaming Replication 3 / 22

Pre-9.0 Continuous Archiving / Point-In-Time Recovery (PITR) 02:00 09:00 11:00 13:00 WAL WAL WAL File System Level Backup Continuous Archive (WAL) The Magic of Hot, Streaming Replication 4 / 22

PITR Backup Procedures 1. wal_level = archive 2. archive_mode = on 3. archive_command = cp -i %p /mnt/server/pgsql/%f < /dev/null 4. SELECT pg_start_backup( label ); 5. Perform file system-level backup (can be inconsistent) 6. SELECT pg_stop_backup(); The Magic of Hot, Streaming Replication 5 / 22

PITR Recovery 17:00 17:30 17:40 17:55 WAL WAL WAL File System Continuous Level Backup Archive (WAL) The Magic of Hot, Streaming Replication 6 / 22

PITR Recovery Procedures 1. Stop postmaster 2. Restore file system-level backup 3. Make adjustments as outlined in the documentation 4. Create recovery.conf 5. restore_command = cp /mnt/server/pgsql/%f %p 6. Start the postmaster The Magic of Hot, Streaming Replication 7 / 22

Disadvantages Only complete 16MB files can be shipped archive_timeout can be used to force more frequent shipping (this increases archive storage requirements) No queries on the standby The Magic of Hot, Streaming Replication 8 / 22

9.0 Streaming Replication / Hot Standby Changes are streamed to the standby, greatly reducing log shipping delays Standby can accept read-only queries The Magic of Hot, Streaming Replication 9 / 22

Streaming Replication Differs from PITR File system backup is restored immediately on the standby server WAL files are streamed to the slave WAL files can also be archived if point-in-time recovery (PITR) is desired The Magic of Hot, Streaming Replication 10 / 22

How Does Streaming Replication Work? 02:00 09:00 11:00 13:00 WAL WAL WAL File System Level Backup Standby Server The Magic of Hot, Streaming Replication 11 / 22

Live Streaming Replication Primary Standby /pg_xlog Network /pg_xlog archive command WAL Archive Directory restore command The Magic of Hot, Streaming Replication 12 / 22

Enable Streaming to the Standby Enable the proper WAL contents: wal_level = hot_standby Enable the ability to stream WAL to the standby: max_wal_senders = 1 Retain WAL files needed by the standby: wal_keep_segments = 50 The Magic of Hot, Streaming Replication 13 / 22

Enable Standby Connection Permissions Add permission for replication to pg_hba.conf: host replication postgres 127.0.0.1/32 trust Start the primary server: pg_ctl -l /u/pg/data/server.log start The Magic of Hot, Streaming Replication 14 / 22

Perform a WAL-Supported File System Backup Start psql and issue: SELECT pg_start_backup( testing ); Copy the database /u/pg/data to a new directory, /u/pg/data2: cp -p -R /u/pg/data /u/pg/data2 Dash-p preserves ownership. The copy is inconsistent, but that is okay (WAL replay will correct that). Signal the backup is complete from psql: SELECT pg_stop_backup(); The Magic of Hot, Streaming Replication 15 / 22

Configure the Standby Remove /data2/postmaster.pid so the standby server does not see the primary server s pid as its own: rm /u/pg/data2/postmaster.pid (This is only necessary because we are testing with the primary and slave on the same computer.) Edit postgresql.conf on the standby and change the port to 5433 port = 5433 Enable hot standby in postgresql.conf: hot_standby = on The Magic of Hot, Streaming Replication 16 / 22

Configure the Standby For Streaming Replication Create recovery.conf: cp /u/pg/share/recovery.conf.sample /u/pg/data2/recovery.conf Enable streaming in recovery.conf: standby_mode = on primary_conninfo = host=localhost port=5432 Start the standby server: PGDATA=/u/pg/data2 pg_ctl -l /u/pg/data2/server.log start The Magic of Hot, Streaming Replication 17 / 22

Test Streaming Replication and Hot Standby $ psql -p 5432 -c CREATE TABLE streamtest(x int) postgres $ psql -p 5433 -c \d postgres List of relations Schema Name Type Owner --------+------------+-------+---------- public streamtest table postgres (1 row) $ psql -p 5432 -c INSERT INTO streamtest VALUES (1) postgres INSERT 0 1 $ psql -p 5433 -c INSERT INTO streamtest VALUES (1) postgres ERROR: cannot execute INSERT in a read-only transaction The Magic of Hot, Streaming Replication 18 / 22

Additional Complexities Multi-server permissions Stream from /pg_xlog and the continuous archive directory if archive_mode is enabled on the primary The Magic of Hot, Streaming Replication 19 / 22

Primary/Standby Synchronization Issues The primary server can take actions that cause long-running queries on the standby to be cancelled. Specifically, the cleanup of unnecessary rows that are still of interest to long-running queries on the standby can cause long-running queries to be cancelled on the standby. Standby query cancellation can be minimized in two ways: 1. Delay cleanup of old records on the primary with vacuum_defer_cleanup_age in postgresql.conf. 2. Delay application of WAL logs on the standby with max_standby_streaming_delay and max_standby_archive_delay in postgresql.conf. The default is 30 seconds; -1 causes application to delay indefinitely to prevent query cancellation. This also delays changes from appearing on the standby and can lengthen the time required for failover to the slave. The Magic of Hot, Streaming Replication 20 / 22

Postgres 9.1 Improvements Replication can be synchronous Standby feedback prevents the master from removing rows needed on the standby New tool to a create standby server using a Postgres database connection New streaming replication monitoring and control tools 9.2 improvements include allowing standbys to stream to other standbys. 9.3 will allow secondary standbys to more easily reconnect to a promoted standby. The Magic of Hot, Streaming Replication 21 / 22

Conclusion http://momjian.us/presentations Manet, Bar at Folies Bergère The Magic of Hot, Streaming Replication 22 / 22