SlideShare une entreprise Scribd logo
1  sur  30
Migrating Rant & Rave to PostgreSQL
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2014
Fun Things to do with Logical Decoding
Mike Fowler
PGDay UK 2015
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Overview
● What is Logical Decoding?
● Replications Slots
● Output Plugins
● Enabling Logical Decoding
● What does Logical Decoding make possible?
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
About Me
● Head of Systems Engineering at Rant & Rave
● Been using PostgreSQL for over 10 years (since 7.4)
● Contributed some XML support
– XMLEXISTS/xpath_exists()
– xml_is_well_formed()
● Contributed a number of bugfixes to the JDBC
driver
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
What is Logical Decoding?
“The process of extracting all persistent changes to
a database's tables into a coherent, easy to
understand format which can be interpreted
without detailed knowledge of the database's
internal state”
“Implemented by decoding the contents of the
write-ahead log, which describe changes on a
storage level, into an application-specific form such
as a stream of tuples or SQL statements”
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
No, really - what is Logical Decoding?
● The results of logical decoding give a perspective on the
logical changes made during a transaction
● The process of logical decoding allows human
understanding of the physical changes made during a
transaction
● Achieved by creating a replication slot with a plugin to
produce data for a receiver
– Basic example plugin available in contrib
– New utility pg_recvlogical to consume plugin output
– Can roll your own to match your requirements
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Some PostgreSQL Basics
● PostgreSQL is a transactional database
● All changes in PostgreSQL are recorded in a Write
Ahead Log (WAL) before any data on disk is actually
changed
● The WAL is the key to replication
– Essentially log based binary replication
– Master runs the walsender to transmit new segments
– Slaves run walreceivers to receive the segments
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
A Basic Example
We'll use a simple table called sample:
CREATE TABLE sample (
id SERIAL PRIMARY KEY,
data JSON,
captured TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
);
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
A Basic Example
INSERT INTO sample (data)
VALUES
('{"beverage":"coffee","temp":96}');
● The backend takes our INSERT and calculates the
values for the omitted columns id and captured
● The backend also determines exactly what needs to
be changed on disk and commits this to the WAL
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Replication Slots
● 9.4 introduced replication slots
● Capability to retain WAL segments on the server
instead of relying on continuous archiving
● Allows master to retain segments even when a
slave is offline
● There are two types of replication slot
– Physical
– Logical
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Logical Replication Slots
● Entries in a logical slot are WAL segments that have
been decoded by means of an output plugin
● Output plugins are responsible for transforming the
data from the WAL into the format the consumer of
a logical replication slot desires
● contrib/test_decoding is a working example of the
interface and can be used to play
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Output Plugin Rules
● Only transactions that have been successfully
flushed to disk are decoded
● Transactions that are rolled back never get decoded
● Changes to UNLOGGED or TEMPORARY tables are
also not decoded
● Concurrent transactions are decoded in commit
order
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Making an Output Plugin
● Consists of building a shared library that implements a number of
functions as detailed in section 46.6 of the manual
– An initialization function
– Transaction begin, row change and transaction end callbacks
– Optional plugin start & stop callbacks
– 9.5 also adds an optional origin filter callback
● For a given transaction the begin & end is called once with the row
change called for each changed row even if multiple rows were
changed in a single statement
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Output Plugin Considerations
● Keep the plugin simple
– It's running as part of your database
– It's going to process all your changes
● Offload complex filter/analysis to the slot consumer
● Drop the slot if it's no longer in use to stop using
server resourcesSELECT
pg_drop_replication_slot('pgday_slot');
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Enabling Logical Decoding
● Enable replication slots (will require restart)
– wal_level must be set to 'logical'
– max_replication_slots must be at least 1
● Create a replication slot
pgday15=# SELECT * FROM
pg_create_logical_replication_slot('pgday_slot',
'test_decoding');
slot_name | xlog_position
------------+---------------
pgday_slot | 0/16C9A78
(1 row)
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Revisiting the Basic Example
We used a simple table called sample:
CREATE TABLE sample (
id SERIAL PRIMARY KEY,
data JSON,
captured TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
);
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Revisiting the Basic Example
INSERT INTO sample (data)
VALUES ('{"beverage":"coffee","temp":96}');
● The backend took our INSERT and calculated the values for
the omitted columns id and captured
● The backend also determined exactly what needed to be
changed on disk and committed it to the WAL
● This time the test_decoding plugin was invoked when the
WAL segment entered the logical replication slot
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Consuming the Plugin Output
● All data from the plugin will remain in the slot until
consumed
● Data can be consumed in two ways
– SQL interface
● Useful for experimentation and demonstration
● Can be used to form a basic programmatic integration with non-C
applications (e.g. Java using JDBC)
– pg_recvlogical
● Similar to pg_receivexlog
● Can be used to output to a file for later consumption
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
The Output from our Example
pgday15=# SELECT * FROM
pg_logical_slot_get_changes('pgday_slot', NULL, NULL);
location | xid | data
-----------+-----+----------------------------------
0/16C9ED0 | 723 | BEGIN 723
0/16C9ED0 | 723 | table public.sample: INSERT:
id[integer]:1
data[json]:'{"beverage":"coffee","temp":96}'
captured[timestamp without tz]:'2015-07-03 19:52:39.497161'
0/16CA000 | 723 | COMMIT 723
(3 rows)
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
pg_recvlogical
● Use pg_recvlogical to record to a single file
– -f option to specify output file
– -F to specify frequency of fsync in seconds
● Run pg_recvlogical on a separate server
– -h to specify hostname or ip
– -p port
● Can also create/delete slots
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Some simple LD Use Cases
● Trigger-less auditing
– Keep a record of all changes in transaction order
– Change only query log
● Trigger auditing
● Basic throughput analysis
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Limitations of test_decoding
● Only details the new/changed row
● No detail of a WHERE clause
● No timestamps in output to help cross reference
● Changed indexes don't make for easy reading
table public.sample: UPDATE: old-key: id[integer]:3 new-tuple: id[integer]:4
data[json]:'{"beverage":"coffee","temp":96}' captured[timestamp without time
zone]:'2015-07-07 00:07:56.305964'
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Enhancing test_decoding
● Plugins can use most of backend infrastructure
– Can use output functions
– Read only access to relations
– Can not use anything that requires a transaction
● Information logged to WAL can be tuned with
REPLICA IDENTITY
– Can be adjusted per table with ALTER TABLE
– DEFAULT keeps old value of PRIMARY KEY
– USING INDEX will keep values of columns covered
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Example: decoder_raw
● Enhanced version of test_decoding by Michael Paquier
● Appends WHERE clauses based on data derived from
REPLICA IDENTITY
– If DEFAULT, PRIMARY KEY column(s) appear in WHERE
● Removes the commit number from BEGIN and COMMIT
● Available on Git Hub
https://github.com/michaelpq/pg_plugins/tree/master/decoder_r
aw
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
decoder_raw Output
=# SELECT slot_name
FROM
pg_create_logical_replication_slot('custom_slot',
'decoder_raw');
slot_name
--------------
custom_slot
(1 row)
=# CREATE TABLE aa (a int primary key, b text);
CREATE TABLE
=# INSERT INTO aa VALUES (1, 'aa'), (2, 'bb');
INSERT 0 2
=# UPDATE aa SET b = 'cc' WHERE a = 1;
UPDATE 1
=# DELETE FROM aa WHERE a = 1;
DELETE 1
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
decoder_raw Output
=# SELECT data
FROM pg_logical_slot_peek_changes('custom_slot',
NULL, NULL, 'include-transaction', 'on');
data
----------------------------------------------------
BEGIN;
COMMIT;
BEGIN;
INSERT INTO public.aa (a, b) VALUES (1, 'aa');
INSERT INTO public.aa (a, b) VALUES (2, 'bb');
COMMIT;
BEGIN;
UPDATE public.aa SET a = 1, b = 'cc' WHERE a = 1 ;
COMMIT;
BEGIN;
DELETE FROM public.aa WHERE a = 1 ;
COMMIT;
(12 rows)
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Partial Replication
● Can be achieved in two ways
– Plugin can filter out unneeded tables
– Slot consumer can discard unneeded tables
● Useful if you have write notes independent of a
cluster
● Streaming partial replication is possible
– If output of plugin is well structured pg_recvlogical
could be piped straight into a psql client
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Full Statement Replication
● Changes can be streamed to other DBMS platforms
– Allows replication to non-PostgreSQL servers
– Useful for keeping a backup during a migration to
PostgreSQL
● Differs from most versions of statement replication
– The master computes the statement and determines the
changes
– Values of columns have already been computed so will be
identical (e.g. CURRENT_TIMESTAMP)
Fun Things to do with Logical Decoding
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2015
Conclusion
● Logical Decoding exposes meta-data about
committed transactions
● Plugins can be written to enrich and format the
meta-data for placement in replication slots
● Data in replication slots can be consumed by
external programs using SQL or
pg_recvlogical to perform a number of useful
tasks
Migrating Rant & Rave to PostgreSQL
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2014
Questions?
Mike Fowler
PGDay UK 2015
Migrating Rant & Rave to PostgreSQL
Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com
PGDayUK 2014
Thank you!
Mike Fowler
PGDay UK 2015

Contenu connexe

Similaire à Fun Things to do with Logical Decoding

Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Morgan Tocker
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PGConf APAC
 
Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)NerdWalletHQ
 
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...StreamNative
 
Automated Performance Testing
Automated Performance TestingAutomated Performance Testing
Automated Performance TestingLars Thorup
 
The internals of gporca optimizer
The internals of gporca optimizerThe internals of gporca optimizer
The internals of gporca optimizerXin Zhang
 
Logical replication with pglogical
Logical replication with pglogicalLogical replication with pglogical
Logical replication with pglogicalUmair Shahid
 
MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...
MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...
MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...Boško Devetak
 
Debugging Planning Issues Using Calcite's Built-in Loggers
Debugging Planning Issues Using Calcite's Built-in LoggersDebugging Planning Issues Using Calcite's Built-in Loggers
Debugging Planning Issues Using Calcite's Built-in LoggersStamatis Zampetakis
 
Yahoo: Experiences with MySQL GTID and Multi Threaded Replication
Yahoo: Experiences with MySQL GTID and Multi Threaded ReplicationYahoo: Experiences with MySQL GTID and Multi Threaded Replication
Yahoo: Experiences with MySQL GTID and Multi Threaded ReplicationYashada Jadhav
 
Exploring plsql new features best practices september 2013
Exploring plsql new features best practices   september 2013Exploring plsql new features best practices   september 2013
Exploring plsql new features best practices september 2013Andrejs Vorobjovs
 
MySQL 5.6 - Operations and Diagnostics Improvements
MySQL 5.6 - Operations and Diagnostics ImprovementsMySQL 5.6 - Operations and Diagnostics Improvements
MySQL 5.6 - Operations and Diagnostics ImprovementsMorgan Tocker
 
Meg bernal insight2014 4219
Meg bernal insight2014 4219Meg bernal insight2014 4219
Meg bernal insight2014 4219Peter Schouboe
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Jaime Crespo
 
Travelling in time with SQL Server 2016 - Damian Widera
Travelling in time with SQL Server 2016 - Damian WideraTravelling in time with SQL Server 2016 - Damian Widera
Travelling in time with SQL Server 2016 - Damian WideraITCamp
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGPablo Garbossa
 
How to build TiDB
How to build TiDBHow to build TiDB
How to build TiDBPingCAP
 
2015 09-02 - transaction log prototype
2015 09-02 - transaction log prototype2015 09-02 - transaction log prototype
2015 09-02 - transaction log prototypeDavid Heath
 

Similaire à Fun Things to do with Logical Decoding (20)

Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
 
Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)
 
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
 
Automated Performance Testing
Automated Performance TestingAutomated Performance Testing
Automated Performance Testing
 
The internals of gporca optimizer
The internals of gporca optimizerThe internals of gporca optimizer
The internals of gporca optimizer
 
Logical replication with pglogical
Logical replication with pglogicalLogical replication with pglogical
Logical replication with pglogical
 
MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...
MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...
MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...
 
Debugging Planning Issues Using Calcite's Built-in Loggers
Debugging Planning Issues Using Calcite's Built-in LoggersDebugging Planning Issues Using Calcite's Built-in Loggers
Debugging Planning Issues Using Calcite's Built-in Loggers
 
Yahoo: Experiences with MySQL GTID and Multi Threaded Replication
Yahoo: Experiences with MySQL GTID and Multi Threaded ReplicationYahoo: Experiences with MySQL GTID and Multi Threaded Replication
Yahoo: Experiences with MySQL GTID and Multi Threaded Replication
 
Plpgsql russia-pgconf
Plpgsql russia-pgconfPlpgsql russia-pgconf
Plpgsql russia-pgconf
 
Exploring plsql new features best practices september 2013
Exploring plsql new features best practices   september 2013Exploring plsql new features best practices   september 2013
Exploring plsql new features best practices september 2013
 
MySQL 5.6 - Operations and Diagnostics Improvements
MySQL 5.6 - Operations and Diagnostics ImprovementsMySQL 5.6 - Operations and Diagnostics Improvements
MySQL 5.6 - Operations and Diagnostics Improvements
 
Meg bernal insight2014 4219
Meg bernal insight2014 4219Meg bernal insight2014 4219
Meg bernal insight2014 4219
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
 
Travelling in time with SQL Server 2016 - Damian Widera
Travelling in time with SQL Server 2016 - Damian WideraTravelling in time with SQL Server 2016 - Damian Widera
Travelling in time with SQL Server 2016 - Damian Widera
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
 
How to build TiDB
How to build TiDBHow to build TiDB
How to build TiDB
 
2015 09-02 - transaction log prototype
2015 09-02 - transaction log prototype2015 09-02 - transaction log prototype
2015 09-02 - transaction log prototype
 
OOW13 Exadata and ODI with Parallel
OOW13 Exadata and ODI with ParallelOOW13 Exadata and ODI with Parallel
OOW13 Exadata and ODI with Parallel
 

Plus de Mike Fowler

From Warehouses to Lakes: The Value of Streams
From Warehouses to Lakes: The Value of StreamsFrom Warehouses to Lakes: The Value of Streams
From Warehouses to Lakes: The Value of StreamsMike Fowler
 
From Warehouses to Lakes: The Value of Streams
From Warehouses to Lakes: The Value of StreamsFrom Warehouses to Lakes: The Value of Streams
From Warehouses to Lakes: The Value of StreamsMike Fowler
 
Getting Started with Machine Learning on AWS
Getting Started with Machine Learning on AWSGetting Started with Machine Learning on AWS
Getting Started with Machine Learning on AWSMike Fowler
 
Building with Firebase
Building with FirebaseBuilding with Firebase
Building with FirebaseMike Fowler
 
Reducing Pager Fatigue Using a Serverless ML Bot
Reducing Pager Fatigue Using a Serverless ML BotReducing Pager Fatigue Using a Serverless ML Bot
Reducing Pager Fatigue Using a Serverless ML BotMike Fowler
 
Getting started with Machine Learning
Getting started with Machine LearningGetting started with Machine Learning
Getting started with Machine LearningMike Fowler
 
Migrating with Debezium
Migrating with DebeziumMigrating with Debezium
Migrating with DebeziumMike Fowler
 
Leveraging Automation for a Disposable Infrastructure
Leveraging Automation for a Disposable InfrastructureLeveraging Automation for a Disposable Infrastructure
Leveraging Automation for a Disposable InfrastructureMike Fowler
 
Migrating PostgreSQL to the Cloud
Migrating PostgreSQL to the CloudMigrating PostgreSQL to the Cloud
Migrating PostgreSQL to the CloudMike Fowler
 
Shaping Clouds with Terraform
Shaping Clouds with TerraformShaping Clouds with Terraform
Shaping Clouds with TerraformMike Fowler
 
Elephants in the Cloud
Elephants in the CloudElephants in the Cloud
Elephants in the CloudMike Fowler
 
Google Cloud & Your Data
Google Cloud & Your DataGoogle Cloud & Your Data
Google Cloud & Your DataMike Fowler
 
Hosted PostgreSQL
Hosted PostgreSQLHosted PostgreSQL
Hosted PostgreSQLMike Fowler
 
Disposable infrastructure
Disposable infrastructureDisposable infrastructure
Disposable infrastructureMike Fowler
 
Handling XML and JSON in the Database
Handling XML and JSON in the DatabaseHandling XML and JSON in the Database
Handling XML and JSON in the DatabaseMike Fowler
 

Plus de Mike Fowler (15)

From Warehouses to Lakes: The Value of Streams
From Warehouses to Lakes: The Value of StreamsFrom Warehouses to Lakes: The Value of Streams
From Warehouses to Lakes: The Value of Streams
 
From Warehouses to Lakes: The Value of Streams
From Warehouses to Lakes: The Value of StreamsFrom Warehouses to Lakes: The Value of Streams
From Warehouses to Lakes: The Value of Streams
 
Getting Started with Machine Learning on AWS
Getting Started with Machine Learning on AWSGetting Started with Machine Learning on AWS
Getting Started with Machine Learning on AWS
 
Building with Firebase
Building with FirebaseBuilding with Firebase
Building with Firebase
 
Reducing Pager Fatigue Using a Serverless ML Bot
Reducing Pager Fatigue Using a Serverless ML BotReducing Pager Fatigue Using a Serverless ML Bot
Reducing Pager Fatigue Using a Serverless ML Bot
 
Getting started with Machine Learning
Getting started with Machine LearningGetting started with Machine Learning
Getting started with Machine Learning
 
Migrating with Debezium
Migrating with DebeziumMigrating with Debezium
Migrating with Debezium
 
Leveraging Automation for a Disposable Infrastructure
Leveraging Automation for a Disposable InfrastructureLeveraging Automation for a Disposable Infrastructure
Leveraging Automation for a Disposable Infrastructure
 
Migrating PostgreSQL to the Cloud
Migrating PostgreSQL to the CloudMigrating PostgreSQL to the Cloud
Migrating PostgreSQL to the Cloud
 
Shaping Clouds with Terraform
Shaping Clouds with TerraformShaping Clouds with Terraform
Shaping Clouds with Terraform
 
Elephants in the Cloud
Elephants in the CloudElephants in the Cloud
Elephants in the Cloud
 
Google Cloud & Your Data
Google Cloud & Your DataGoogle Cloud & Your Data
Google Cloud & Your Data
 
Hosted PostgreSQL
Hosted PostgreSQLHosted PostgreSQL
Hosted PostgreSQL
 
Disposable infrastructure
Disposable infrastructureDisposable infrastructure
Disposable infrastructure
 
Handling XML and JSON in the Database
Handling XML and JSON in the DatabaseHandling XML and JSON in the Database
Handling XML and JSON in the Database
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 

Dernier (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 

Fun Things to do with Logical Decoding

  • 1. Migrating Rant & Rave to PostgreSQL Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2014 Fun Things to do with Logical Decoding Mike Fowler PGDay UK 2015
  • 2. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Overview ● What is Logical Decoding? ● Replications Slots ● Output Plugins ● Enabling Logical Decoding ● What does Logical Decoding make possible?
  • 3. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 About Me ● Head of Systems Engineering at Rant & Rave ● Been using PostgreSQL for over 10 years (since 7.4) ● Contributed some XML support – XMLEXISTS/xpath_exists() – xml_is_well_formed() ● Contributed a number of bugfixes to the JDBC driver
  • 4. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 What is Logical Decoding? “The process of extracting all persistent changes to a database's tables into a coherent, easy to understand format which can be interpreted without detailed knowledge of the database's internal state” “Implemented by decoding the contents of the write-ahead log, which describe changes on a storage level, into an application-specific form such as a stream of tuples or SQL statements”
  • 5. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 No, really - what is Logical Decoding? ● The results of logical decoding give a perspective on the logical changes made during a transaction ● The process of logical decoding allows human understanding of the physical changes made during a transaction ● Achieved by creating a replication slot with a plugin to produce data for a receiver – Basic example plugin available in contrib – New utility pg_recvlogical to consume plugin output – Can roll your own to match your requirements
  • 6. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Some PostgreSQL Basics ● PostgreSQL is a transactional database ● All changes in PostgreSQL are recorded in a Write Ahead Log (WAL) before any data on disk is actually changed ● The WAL is the key to replication – Essentially log based binary replication – Master runs the walsender to transmit new segments – Slaves run walreceivers to receive the segments
  • 7. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 A Basic Example We'll use a simple table called sample: CREATE TABLE sample ( id SERIAL PRIMARY KEY, data JSON, captured TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
  • 8. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 A Basic Example INSERT INTO sample (data) VALUES ('{"beverage":"coffee","temp":96}'); ● The backend takes our INSERT and calculates the values for the omitted columns id and captured ● The backend also determines exactly what needs to be changed on disk and commits this to the WAL
  • 9. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Replication Slots ● 9.4 introduced replication slots ● Capability to retain WAL segments on the server instead of relying on continuous archiving ● Allows master to retain segments even when a slave is offline ● There are two types of replication slot – Physical – Logical
  • 10. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Logical Replication Slots ● Entries in a logical slot are WAL segments that have been decoded by means of an output plugin ● Output plugins are responsible for transforming the data from the WAL into the format the consumer of a logical replication slot desires ● contrib/test_decoding is a working example of the interface and can be used to play
  • 11. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Output Plugin Rules ● Only transactions that have been successfully flushed to disk are decoded ● Transactions that are rolled back never get decoded ● Changes to UNLOGGED or TEMPORARY tables are also not decoded ● Concurrent transactions are decoded in commit order
  • 12. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Making an Output Plugin ● Consists of building a shared library that implements a number of functions as detailed in section 46.6 of the manual – An initialization function – Transaction begin, row change and transaction end callbacks – Optional plugin start & stop callbacks – 9.5 also adds an optional origin filter callback ● For a given transaction the begin & end is called once with the row change called for each changed row even if multiple rows were changed in a single statement
  • 13. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Output Plugin Considerations ● Keep the plugin simple – It's running as part of your database – It's going to process all your changes ● Offload complex filter/analysis to the slot consumer ● Drop the slot if it's no longer in use to stop using server resourcesSELECT pg_drop_replication_slot('pgday_slot');
  • 14. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Enabling Logical Decoding ● Enable replication slots (will require restart) – wal_level must be set to 'logical' – max_replication_slots must be at least 1 ● Create a replication slot pgday15=# SELECT * FROM pg_create_logical_replication_slot('pgday_slot', 'test_decoding'); slot_name | xlog_position ------------+--------------- pgday_slot | 0/16C9A78 (1 row)
  • 15. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Revisiting the Basic Example We used a simple table called sample: CREATE TABLE sample ( id SERIAL PRIMARY KEY, data JSON, captured TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
  • 16. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Revisiting the Basic Example INSERT INTO sample (data) VALUES ('{"beverage":"coffee","temp":96}'); ● The backend took our INSERT and calculated the values for the omitted columns id and captured ● The backend also determined exactly what needed to be changed on disk and committed it to the WAL ● This time the test_decoding plugin was invoked when the WAL segment entered the logical replication slot
  • 17. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Consuming the Plugin Output ● All data from the plugin will remain in the slot until consumed ● Data can be consumed in two ways – SQL interface ● Useful for experimentation and demonstration ● Can be used to form a basic programmatic integration with non-C applications (e.g. Java using JDBC) – pg_recvlogical ● Similar to pg_receivexlog ● Can be used to output to a file for later consumption
  • 18. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 The Output from our Example pgday15=# SELECT * FROM pg_logical_slot_get_changes('pgday_slot', NULL, NULL); location | xid | data -----------+-----+---------------------------------- 0/16C9ED0 | 723 | BEGIN 723 0/16C9ED0 | 723 | table public.sample: INSERT: id[integer]:1 data[json]:'{"beverage":"coffee","temp":96}' captured[timestamp without tz]:'2015-07-03 19:52:39.497161' 0/16CA000 | 723 | COMMIT 723 (3 rows)
  • 19. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 pg_recvlogical ● Use pg_recvlogical to record to a single file – -f option to specify output file – -F to specify frequency of fsync in seconds ● Run pg_recvlogical on a separate server – -h to specify hostname or ip – -p port ● Can also create/delete slots
  • 20. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Some simple LD Use Cases ● Trigger-less auditing – Keep a record of all changes in transaction order – Change only query log ● Trigger auditing ● Basic throughput analysis
  • 21. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Limitations of test_decoding ● Only details the new/changed row ● No detail of a WHERE clause ● No timestamps in output to help cross reference ● Changed indexes don't make for easy reading table public.sample: UPDATE: old-key: id[integer]:3 new-tuple: id[integer]:4 data[json]:'{"beverage":"coffee","temp":96}' captured[timestamp without time zone]:'2015-07-07 00:07:56.305964'
  • 22. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Enhancing test_decoding ● Plugins can use most of backend infrastructure – Can use output functions – Read only access to relations – Can not use anything that requires a transaction ● Information logged to WAL can be tuned with REPLICA IDENTITY – Can be adjusted per table with ALTER TABLE – DEFAULT keeps old value of PRIMARY KEY – USING INDEX will keep values of columns covered
  • 23. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Example: decoder_raw ● Enhanced version of test_decoding by Michael Paquier ● Appends WHERE clauses based on data derived from REPLICA IDENTITY – If DEFAULT, PRIMARY KEY column(s) appear in WHERE ● Removes the commit number from BEGIN and COMMIT ● Available on Git Hub https://github.com/michaelpq/pg_plugins/tree/master/decoder_r aw
  • 24. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 decoder_raw Output =# SELECT slot_name FROM pg_create_logical_replication_slot('custom_slot', 'decoder_raw'); slot_name -------------- custom_slot (1 row) =# CREATE TABLE aa (a int primary key, b text); CREATE TABLE =# INSERT INTO aa VALUES (1, 'aa'), (2, 'bb'); INSERT 0 2 =# UPDATE aa SET b = 'cc' WHERE a = 1; UPDATE 1 =# DELETE FROM aa WHERE a = 1; DELETE 1
  • 25. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 decoder_raw Output =# SELECT data FROM pg_logical_slot_peek_changes('custom_slot', NULL, NULL, 'include-transaction', 'on'); data ---------------------------------------------------- BEGIN; COMMIT; BEGIN; INSERT INTO public.aa (a, b) VALUES (1, 'aa'); INSERT INTO public.aa (a, b) VALUES (2, 'bb'); COMMIT; BEGIN; UPDATE public.aa SET a = 1, b = 'cc' WHERE a = 1 ; COMMIT; BEGIN; DELETE FROM public.aa WHERE a = 1 ; COMMIT; (12 rows)
  • 26. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Partial Replication ● Can be achieved in two ways – Plugin can filter out unneeded tables – Slot consumer can discard unneeded tables ● Useful if you have write notes independent of a cluster ● Streaming partial replication is possible – If output of plugin is well structured pg_recvlogical could be piped straight into a psql client
  • 27. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Full Statement Replication ● Changes can be streamed to other DBMS platforms – Allows replication to non-PostgreSQL servers – Useful for keeping a backup during a migration to PostgreSQL ● Differs from most versions of statement replication – The master computes the statement and determines the changes – Values of columns have already been computed so will be identical (e.g. CURRENT_TIMESTAMP)
  • 28. Fun Things to do with Logical Decoding Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2015 Conclusion ● Logical Decoding exposes meta-data about committed transactions ● Plugins can be written to enrich and format the meta-data for placement in replication slots ● Data in replication slots can be consumed by external programs using SQL or pg_recvlogical to perform a number of useful tasks
  • 29. Migrating Rant & Rave to PostgreSQL Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2014 Questions? Mike Fowler PGDay UK 2015
  • 30. Migrating Rant & Rave to PostgreSQL Mike Fowler, mike@mlfowler.com mike.fowler@rantandrave.com PGDayUK 2014 Thank you! Mike Fowler PGDay UK 2015

Notes de l'éditeur

  1. <number>
  2. <number>
  3. <number>