SlideShare a Scribd company logo
PostgreSQL: Understanding replication
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Welcome to PostgreSQL replication
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
What you will learn
How PostgreSQL writes data
What the transaction log does
How to set up streaming replication
How to handle Point-In-Time-Recovery
Managing conflicts
Monitoring replication
More advanced techniques
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
How PostgreSQL writes data
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Writing a row of data
Understanding how PostgreSQL writes data is key to
understanding replication
Vital to understand PITR
A lot of potential to tune the system
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Write the log first (1)
It is not possible to send data to a data table directly.
What if the system crashes during a write?
A data file could end up with broken data at potentially
unknown positions
Corruption is not an option
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Write the log first (2)
Data goes to the xlog (= WAL) first
WAL is short for “Write Ahead Log”
IMPORTANT: The xlog DOES NOT contain SQL
It contains BINARY changes
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
The xlog
The xlog consists of a set of 16 MB files
The xlog consists of various types of records (heap changes,
btree changes, etc.)
It has to be flushed to disk on commit to achieve durability
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Expert tip: Debugging the xlog
Change WAL DEBUG in src/include/pg config manual.h
Recompile PostgreSQL
NOTE: This is not for normal use but just for training purposes
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Enabling wal debug
test=# SET wal_debug TO on;
SET
test=# SET client_min_messages TO debug;
SET
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Observing changes
Every change will go to the screen now
It helps to understand how PostgreSQL works
Apart from debugging: The practical purpose is limited
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Making changes
Data goes to the xlog first
Then data is put into shared buffers
At some later point data is written to the data files
This does not happen instantly leaving a lot of room for
optimization and tuning
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
A consistent view of the data
Data is not sent to those data files instantly.
Still: End users will have a consistent view of the data
When a query comes in, it checks the I/O cache (=
shared buffers) and asks the data files only in case of a cache
miss.
xlog is about the physical not about the logical level
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Sustaining writes
We cannot write to the xlog forever without recycling it.
The xlog is recycled during a so called “checkpoint”.
Before the xlog can be recycled, data must be stored safely in
those data files
Checkpoints have a huge impact on performance
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Checkpoint parameters:
checkpoint timeout = 15min
max wal size = 5GB
min wal size = 800MB
checkpoint completion target = 0.5
checkpoint warning = 30s
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Checkpointing to frequently
Checkpointing is expensive
PostgreSQL warns about too frequent checkpoints
This is what checkpoint warning is good for
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
min wal size and max wal size (1)
This is a replacement for checkpoint segments
Now the xlog size is auto-tuned
The new configuration was introduced in PostgreSQL 9.5
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
min wal size and max wal size (2)
Instead of having a single knob (checkpoint segments) that both
triggers checkpoints, and determines how many checkpoints to
recycle, they are now separate concerns. There is still an internal
variable called CheckpointSegments, which triggers checkpoints.
But it no longer determines how many segments to recycle at a
checkpoint. That is now auto-tuned by keeping a moving average
of the distance between checkpoints (in bytes), and trying to keep
that many segments in reserve.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
min wal size and max wal size (3)
The advantage of this is that you can set max wal size very high,
but the system won’t actually consume that much space if there
isn’t any need for it. The min wal size sets a floor for that; you
can effectively disable the auto-tuning behavior by setting
min wal size equal to max wal size.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
How does it impact replication
The xlog has all the changes needed and can therefore be
used for replication.
Copying data files is not enough to achieve a consistent view
of the data
It has some implications related to base backups
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Setting up streaming replication
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
The basic process
S: Install PostgreSQL on the slave (no initdb)
M: Adapt postgresql.conf
M: Adapt pg hba.conf
M: Restart PostgreSQL
S: Pull a base backup
S: Start the slave
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Changing postgresql.conf
wal level: Ensure that there is enough xlog generated by the
master (recovering a server needs more xlog than just simple
crash-safety)
max wal senders: When a slave is streaming, connects to the
master and fetches xlog. A base backup will also need 1 / 2
wal senders
hot standby: This is not needed because it is ignored on the
master but it saves some work on the slave later on
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Changing pg hba.conf
Rules for replication have to be added.
Note that “all” databases does not include replication
A separate rule has to be added, which explicitly states
“replication” in the second column
Replication rules work just like any other pg hba.conf rule
Remember: The first line matching rules
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Restarting PostgreSQL
To activate those settings in postgresql.conf the master has to
be restarted.
If only pg hba.conf is changed, a simple SIGHUP (pg ctl
reload) is enough.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Using pg basebackup (1)
pg basebackup will fetch a copy of the data from the master
While pg basebackup is running, the master is fully
operational (no downtime needed)
pg basebackup connects through a database connection and
copies all data files as they are
In most cases this does not create a consistent backup
The xlog is needed to “repair” the base backup (this is exactly
what happens during xlog replay anyway)
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Using pg basebackup (2)
pg_basebackup -h master.com -D /slave 
--xlog-method=stream --checkpoint=fast -R
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
xlog-method: Self-contained backups
By default a base backup is not self-contained.
The database does not start up without additional xlog.
This is fine for Point-In-Time-Recovery because there is an
archive around.
For streaming it can be a problem.
–xlog-method=stream opens a second connection to fetch
xlog during the base backup
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
checkpoint=fast: Instant backups
By default pg basebackup starts as soon as the master
checkpoints.
This can take a while.
–checkpoint=fast makes the master check instantly.
In case of a small backup an instant checkpoint speeds things
up.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
-R: Generating a config file
For a simple streaming setup all PostgreSQL has to know is
already passed to pg basebackup (host, port, etc.).
-R automatically generates a recovery.conf file, which is quite
ok in most cases.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Backup throttling
–max-rate=RATE: maximum transfer rate to transfer data
directory (in kB/s, or use suffix “k” or “M”)
If your master is weak a pg basebackup running at full speed
can lead to high response times and disk wait.
Slowing down the backup can help to make sure the master
stays responsive.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Adjusting recovery.conf
A basic setup needs:
primary conninfo: A connect string pointing to the master
server
standby mode = on: Tells the system to stream instantly
Additional configuration parameters are available
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Starting up the slave
Make sure the slave has connected to the master
Make sure it has reached a consistent state
Check for wal sender and wal receiver processes
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Promoting a slave to master
Promoting a slave to a master is easy:
pg_ctl -D ... promote
After promotion recovery.conf will be renamed to
recovery.done
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
One word about security
So far replication has been done as superuser
This is not necessary
Creating a user, which can do just replication makes sense
CREATE ROLE foo ... REPLICATION ... NOSUPERUSER;
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Monitoring replication
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Simple checks
The most basic and most simplistic check is to check for
wal sender (on the master)
wal receiver (on the slave)
Without those processes the party is over
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
More detailed analysis
pg stat replication contains a lot of information
Make sure an entry for each slave is there
Check for replication lag
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Checking for replication lag
A sustained lag is not a good idea.
The distance between the sender and the receiver can be
measured in bytes
SELECT client_addr,
pg_xlog_location_diff(pg_current_xlog_location(),
sent_location)
FROM pg_stat_replication;
In asynchronous replication the replication lag can vary
dramatically (for example during CREATE INDEX, etc.)
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Creating large clusters
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Handling more than 2 nodes
A simple 2 node cluster is easy.
In case of more than 2 servers, life is a bit harder.
If you have two slaves and the master fails: Who is going to
be the new master?
Unless you want to resync all your data, you should better
elect the server containing most of the data already
Comparing xlog positions is necessary
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Timeline issues
When a slave is promoted the timeline ID is incremented
Master and slave have to be in the same timeline
In case of two servers it is important to connect one server to
the second one first and do the promotion AFTERWARDS.
This ensures that the timeline switch is already replicated
from the new master to the surviving slave.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Cascading slaves
Slaves can be connected to slaves
Cascading can make sense to reduce bandwidth requirements
Cascading can take load from the master
Use pg basebackup to fetch data from a slave as if it was a
master
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Conflicts
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
How conflicts happen
During replication conflicts can happen
Example: The master might want to remove a row still visible
to a reading transaction on the slave
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
What happens during a conflict
PostgreSQL will terminate a database connection after some
time
max standby archive delay = 30s
max standby streaming delay = 30s
Those settings define the maximum time the slave waits
during replay before replay is resumed.
In rare cases a connection might be aborted quite soon.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Reducing conflicts
Conflicts can be reduced nicely by setting
hot standby feedback.
The slave will send its oldest transaction ID to tell the master
that cleanup has to be deferred.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Making replication more reliable
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
What happens if a slave reboots?
If a slave is gone for too long, the master might recycle its
transaction log
The slave needs a full history of the xlog
Setting wal keep segments on the master helps to prevent the
master from recycling transaction log too early
I recommend to always use wal keep segments to make sure
that a slave can be started after a pg basebackup
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Making use of replication slots
Replication slots have been added in PostgreSQL 9.4
There are two types of replication slots:
Physical replication slots (for streaming)
Logical replication slots (for logical decoding)
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Configuring replication slots
Change max replication slots and restart the master
Run . . .
test=# SELECT *
FROM pg_create_physical_replication_slot(’some_name’);
slot_name | xlog_position
-----------+---------------
some_name |
(1 row)
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Tweaking the slave
Add this replication slot to primary slot name on the slave:
primary_slot_name = ’some_name’
The master will ensure that xlog is only recycled when it has
been consumed by the slave.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
A word of caution
If a slave is removed make sure the replication slot is dropped.
Otherwise the master might run out of disk space.
NEVER use replication slots without monitoring the size of
the xlog on the sender.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Key advantages of replication slots
The difference between master and slave can be arbitrary.
During bulk load or CREATE INDEX this can be essential.
It can help to overcome the problems caused by slow networks.
It can help to avoid resyncs.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Moving to synchronous replication
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Synchronous vs. asynchronous
Asynchronous replication: Commits on the slave can happen
long after the commit on the master.
Synchronous replication: A transaction has to be written to a
second server.
Synchronous replication potentially adds some network
latency to the scenery
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
The application name
During normal operations the application name setting can be
used to assign a name to a database connection.
In case of synchronous replication this variable is used to
determine synchronous candidates.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Configuring synchronous replication:
Master:
add names to synchronous standby names
Slave:
add an application name to your connect string in
primary conninfo
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Fail safety
Synchronous replication needs 2 active servers
If no two servers are left, replication will wait until a second
server is available.
Use AT LEAST 3 servers for synchronous replication to avoid
risk.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Point-In-Time-Recovery
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
What it does
PITR can be used to reach (almost) any point after a base
backup.
It is more of a backup strategy than a replication thing.
Replication and PITR can be combined.
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Configuring for PITR
S: create an archive (ideally this is not on the master)
M: Change postgresql.conf
set wal level
set max wal senders (if pg basebackup is desired)
set archive mode to on
set a proper archive command to archive xlog
M: adapt pg hba.conf (if pg basebackup is desired)
M: restart the master
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
pg basebackup, etc.
Perform a pg basebackup as performed before
–xlog-method=stream and -R are not needed
In the archive a .backup file will be available after
pg basebackup
You can delete all xlog files older than the oldest base backup
you want to keep.
The .backup file will guide you
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Restoring from a crash
Take a base backup.
Write a recovery.conf file:
restore command: Tell PostgreSQL where to find xlog
recovery target time (optional): Use a timestamp to tell the
system how far to recover
Start the server
Make sure the system has reached consistent state
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
More config options
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
recovery min apply delay: Delayed replay
This settings allows you to tell the slave that a certain delay is
desired.
Example: A stock broker might want to provide you with 15
minute old data
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
pause at recovery target
Make sure that the recovery does not stop at a specified point
in time.
Make PostgreSQL wait when a certain point is reached.
This is essential in case you do not know precisely how far to
recover
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
recovery target name
Sometimes you want to recover to a certain point in time,
which has been specified before.
To specify a point in time run . . .
SELECT pg_create_restore_point(’some_name’);
Use this name in recovery.conf to recover to this very specific
point
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Finally . . .
Hans-J¨urgen Sch¨onig
www.postgresql-support.de
Contact us . . .
Cybertec Sch¨onig & Sch¨onig GmbH
Gr¨ohrm¨uhlgasse 26
A-2700 Wiener Neustadt Austria
More than 15 years of PostgreSQL experience:
Training
Consulting
24x7 support
Hans-J¨urgen Sch¨onig
www.postgresql-support.de

More Related Content

What's hot (20)

MySQL Buffer Management
MySQL Buffer ManagementMySQL Buffer Management
MySQL Buffer Management
MIJIN AN
 
Ceph and RocksDB
Ceph and RocksDBCeph and RocksDB
Ceph and RocksDB
Sage Weil
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
Jean-François Gagné
 
PostgreSQL : Introduction
PostgreSQL : IntroductionPostgreSQL : Introduction
PostgreSQL : Introduction
Open Source School
 
The Complete MariaDB Server tutorial
The Complete MariaDB Server tutorialThe Complete MariaDB Server tutorial
The Complete MariaDB Server tutorial
Colin Charles
 
Spark shuffle introduction
Spark shuffle introductionSpark shuffle introduction
Spark shuffle introduction
colorant
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and Optimization
MariaDB plc
 
PostgreSQL Extensions: A deeper look
PostgreSQL Extensions:  A deeper lookPostgreSQL Extensions:  A deeper look
PostgreSQL Extensions: A deeper look
Jignesh Shah
 
Optimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceOptimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performance
MariaDB plc
 
Performance optimization for all flash based on aarch64 v2.0
Performance optimization for all flash based on aarch64 v2.0Performance optimization for all flash based on aarch64 v2.0
Performance optimization for all flash based on aarch64 v2.0
Ceph Community
 
MariaDB MaxScale
MariaDB MaxScaleMariaDB MaxScale
MariaDB MaxScale
MariaDB plc
 
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
Jean-François Gagné
 
How to set up orchestrator to manage thousands of MySQL servers
How to set up orchestrator to manage thousands of MySQL serversHow to set up orchestrator to manage thousands of MySQL servers
How to set up orchestrator to manage thousands of MySQL servers
Simon J Mudd
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
Morgan Tocker
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
Mydbops
 
Postgresql Database Administration Basic - Day1
Postgresql  Database Administration Basic  - Day1Postgresql  Database Administration Basic  - Day1
Postgresql Database Administration Basic - Day1
PoguttuezhiniVP
 
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and OrchestratorAlmost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Jean-François Gagné
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
Federico Campoli
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
Kernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringKernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uring
Anne Nicolas
 
MySQL Buffer Management
MySQL Buffer ManagementMySQL Buffer Management
MySQL Buffer Management
MIJIN AN
 
Ceph and RocksDB
Ceph and RocksDBCeph and RocksDB
Ceph and RocksDB
Sage Weil
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
Jean-François Gagné
 
The Complete MariaDB Server tutorial
The Complete MariaDB Server tutorialThe Complete MariaDB Server tutorial
The Complete MariaDB Server tutorial
Colin Charles
 
Spark shuffle introduction
Spark shuffle introductionSpark shuffle introduction
Spark shuffle introduction
colorant
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and Optimization
MariaDB plc
 
PostgreSQL Extensions: A deeper look
PostgreSQL Extensions:  A deeper lookPostgreSQL Extensions:  A deeper look
PostgreSQL Extensions: A deeper look
Jignesh Shah
 
Optimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceOptimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performance
MariaDB plc
 
Performance optimization for all flash based on aarch64 v2.0
Performance optimization for all flash based on aarch64 v2.0Performance optimization for all flash based on aarch64 v2.0
Performance optimization for all flash based on aarch64 v2.0
Ceph Community
 
MariaDB MaxScale
MariaDB MaxScaleMariaDB MaxScale
MariaDB MaxScale
MariaDB plc
 
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
Jean-François Gagné
 
How to set up orchestrator to manage thousands of MySQL servers
How to set up orchestrator to manage thousands of MySQL serversHow to set up orchestrator to manage thousands of MySQL servers
How to set up orchestrator to manage thousands of MySQL servers
Simon J Mudd
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
Morgan Tocker
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
Mydbops
 
Postgresql Database Administration Basic - Day1
Postgresql  Database Administration Basic  - Day1Postgresql  Database Administration Basic  - Day1
Postgresql Database Administration Basic - Day1
PoguttuezhiniVP
 
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and OrchestratorAlmost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Jean-François Gagné
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
Federico Campoli
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
Kernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringKernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uring
Anne Nicolas
 

Viewers also liked (20)

Really Big Elephants: PostgreSQL DW
Really Big Elephants: PostgreSQL DWReally Big Elephants: PostgreSQL DW
Really Big Elephants: PostgreSQL DW
PostgreSQL Experts, Inc.
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4
Denish Patel
 
Managing a 14 TB reporting datawarehouse with postgresql
Managing a 14 TB reporting datawarehouse with postgresql Managing a 14 TB reporting datawarehouse with postgresql
Managing a 14 TB reporting datawarehouse with postgresql
Soumya Ranjan Subudhi
 
5min analyse
5min analyse5min analyse
5min analyse
Hans-Jürgen Schönig
 
PostgreSQL: Joining 1 million tables
PostgreSQL: Joining 1 million tablesPostgreSQL: Joining 1 million tables
PostgreSQL: Joining 1 million tables
Hans-Jürgen Schönig
 
PostgreSQL instance encryption: More database security
PostgreSQL instance encryption: More database securityPostgreSQL instance encryption: More database security
PostgreSQL instance encryption: More database security
Hans-Jürgen Schönig
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Experts, Inc.
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Jignesh Shah
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
Command Prompt., Inc
 
Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)
Denish Patel
 
Open source data_warehousing_overview
Open source data_warehousing_overviewOpen source data_warehousing_overview
Open source data_warehousing_overview
Alex Meadows
 
Top 10 database optimization tips
Top 10 database optimization tipsTop 10 database optimization tips
Top 10 database optimization tips
raviwriter
 
Tales from production with postgreSQL at scale
Tales from production with postgreSQL at scaleTales from production with postgreSQL at scale
Tales from production with postgreSQL at scale
Soumya Ranjan Subudhi
 
Walbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction logWalbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction log
Hans-Jürgen Schönig
 
PostgreSQL: Eigene Aggregate schreiben
PostgreSQL: Eigene Aggregate schreibenPostgreSQL: Eigene Aggregate schreiben
PostgreSQL: Eigene Aggregate schreiben
Hans-Jürgen Schönig
 
Explain explain
Explain explainExplain explain
Explain explain
Hans-Jürgen Schönig
 
PostgreSQL: The NoSQL way
PostgreSQL: The NoSQL wayPostgreSQL: The NoSQL way
PostgreSQL: The NoSQL way
Hans-Jürgen Schönig
 
Materialized views in PostgreSQL
Materialized views in PostgreSQLMaterialized views in PostgreSQL
Materialized views in PostgreSQL
Ashutosh Bapat
 
Pattern driven Enterprise Architecture
Pattern driven Enterprise ArchitecturePattern driven Enterprise Architecture
Pattern driven Enterprise Architecture
WSO2
 
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
Alexey Lesovsky
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4
Denish Patel
 
Managing a 14 TB reporting datawarehouse with postgresql
Managing a 14 TB reporting datawarehouse with postgresql Managing a 14 TB reporting datawarehouse with postgresql
Managing a 14 TB reporting datawarehouse with postgresql
Soumya Ranjan Subudhi
 
PostgreSQL: Joining 1 million tables
PostgreSQL: Joining 1 million tablesPostgreSQL: Joining 1 million tables
PostgreSQL: Joining 1 million tables
Hans-Jürgen Schönig
 
PostgreSQL instance encryption: More database security
PostgreSQL instance encryption: More database securityPostgreSQL instance encryption: More database security
PostgreSQL instance encryption: More database security
Hans-Jürgen Schönig
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Experts, Inc.
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Jignesh Shah
 
Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)
Denish Patel
 
Open source data_warehousing_overview
Open source data_warehousing_overviewOpen source data_warehousing_overview
Open source data_warehousing_overview
Alex Meadows
 
Top 10 database optimization tips
Top 10 database optimization tipsTop 10 database optimization tips
Top 10 database optimization tips
raviwriter
 
Tales from production with postgreSQL at scale
Tales from production with postgreSQL at scaleTales from production with postgreSQL at scale
Tales from production with postgreSQL at scale
Soumya Ranjan Subudhi
 
Walbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction logWalbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction log
Hans-Jürgen Schönig
 
PostgreSQL: Eigene Aggregate schreiben
PostgreSQL: Eigene Aggregate schreibenPostgreSQL: Eigene Aggregate schreiben
PostgreSQL: Eigene Aggregate schreiben
Hans-Jürgen Schönig
 
Materialized views in PostgreSQL
Materialized views in PostgreSQLMaterialized views in PostgreSQL
Materialized views in PostgreSQL
Ashutosh Bapat
 
Pattern driven Enterprise Architecture
Pattern driven Enterprise ArchitecturePattern driven Enterprise Architecture
Pattern driven Enterprise Architecture
WSO2
 
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
Alexey Lesovsky
 
Ad

Similar to PostgreSQL Replication Tutorial (20)

Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
Michael Renner
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
Denish Patel
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)
Denish Patel
 
Replication in PostgreSQL tutorial given in Postgres Conference 2019
Replication in PostgreSQL tutorial given in Postgres Conference 2019Replication in PostgreSQL tutorial given in Postgres Conference 2019
Replication in PostgreSQL tutorial given in Postgres Conference 2019
Abbas Butt
 
PG_Phsycal_logical_study_Replication.pptx
PG_Phsycal_logical_study_Replication.pptxPG_Phsycal_logical_study_Replication.pptx
PG_Phsycal_logical_study_Replication.pptx
ankitmodidba
 
PostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetPostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication Cheatsheet
Alexey Lesovsky
 
Built in physical and logical replication in postgresql-Firat Gulec
Built in physical and logical replication in postgresql-Firat GulecBuilt in physical and logical replication in postgresql-Firat Gulec
Built in physical and logical replication in postgresql-Firat Gulec
FIRAT GULEC
 
How to Replicate PostgreSQL Database
How to Replicate PostgreSQL DatabaseHow to Replicate PostgreSQL Database
How to Replicate PostgreSQL Database
SangJin Kang
 
9.6_Course Material-Postgresql_002.pdf
9.6_Course Material-Postgresql_002.pdf9.6_Course Material-Postgresql_002.pdf
9.6_Course Material-Postgresql_002.pdf
sreedb2
 
Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008
Robert Treat
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
Mydbops
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
PostgreSQL-Consulting
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
PgTraining
 
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
Aleksander Alekseev
 
Backup-Recovery in PostgreSQL
Backup-Recovery in PostgreSQLBackup-Recovery in PostgreSQL
Backup-Recovery in PostgreSQL
Ashnik Pte Ltd
 
On The Building Of A PostgreSQL Cluster
On The Building Of A PostgreSQL ClusterOn The Building Of A PostgreSQL Cluster
On The Building Of A PostgreSQL Cluster
Srihari Sriraman
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Command Prompt., Inc
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
Michael Renner
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
Denish Patel
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)
Denish Patel
 
Replication in PostgreSQL tutorial given in Postgres Conference 2019
Replication in PostgreSQL tutorial given in Postgres Conference 2019Replication in PostgreSQL tutorial given in Postgres Conference 2019
Replication in PostgreSQL tutorial given in Postgres Conference 2019
Abbas Butt
 
PG_Phsycal_logical_study_Replication.pptx
PG_Phsycal_logical_study_Replication.pptxPG_Phsycal_logical_study_Replication.pptx
PG_Phsycal_logical_study_Replication.pptx
ankitmodidba
 
PostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetPostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication Cheatsheet
Alexey Lesovsky
 
Built in physical and logical replication in postgresql-Firat Gulec
Built in physical and logical replication in postgresql-Firat GulecBuilt in physical and logical replication in postgresql-Firat Gulec
Built in physical and logical replication in postgresql-Firat Gulec
FIRAT GULEC
 
How to Replicate PostgreSQL Database
How to Replicate PostgreSQL DatabaseHow to Replicate PostgreSQL Database
How to Replicate PostgreSQL Database
SangJin Kang
 
9.6_Course Material-Postgresql_002.pdf
9.6_Course Material-Postgresql_002.pdf9.6_Course Material-Postgresql_002.pdf
9.6_Course Material-Postgresql_002.pdf
sreedb2
 
Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008
Robert Treat
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
Mydbops
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
PostgreSQL-Consulting
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
PgTraining
 
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
Aleksander Alekseev
 
Backup-Recovery in PostgreSQL
Backup-Recovery in PostgreSQLBackup-Recovery in PostgreSQL
Backup-Recovery in PostgreSQL
Ashnik Pte Ltd
 
On The Building Of A PostgreSQL Cluster
On The Building Of A PostgreSQL ClusterOn The Building Of A PostgreSQL Cluster
On The Building Of A PostgreSQL Cluster
Srihari Sriraman
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Command Prompt., Inc
 
Ad

Recently uploaded (20)

Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Maximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdfMaximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdf
Elena Mia
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Maximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdfMaximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdf
Elena Mia
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 

PostgreSQL Replication Tutorial

  • 1. PostgreSQL: Understanding replication Hans-J¨urgen Sch¨onig www.postgresql-support.de Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 2. Welcome to PostgreSQL replication Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 3. What you will learn How PostgreSQL writes data What the transaction log does How to set up streaming replication How to handle Point-In-Time-Recovery Managing conflicts Monitoring replication More advanced techniques Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 4. How PostgreSQL writes data Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 5. Writing a row of data Understanding how PostgreSQL writes data is key to understanding replication Vital to understand PITR A lot of potential to tune the system Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 6. Write the log first (1) It is not possible to send data to a data table directly. What if the system crashes during a write? A data file could end up with broken data at potentially unknown positions Corruption is not an option Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 7. Write the log first (2) Data goes to the xlog (= WAL) first WAL is short for “Write Ahead Log” IMPORTANT: The xlog DOES NOT contain SQL It contains BINARY changes Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 8. The xlog The xlog consists of a set of 16 MB files The xlog consists of various types of records (heap changes, btree changes, etc.) It has to be flushed to disk on commit to achieve durability Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 9. Expert tip: Debugging the xlog Change WAL DEBUG in src/include/pg config manual.h Recompile PostgreSQL NOTE: This is not for normal use but just for training purposes Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 10. Enabling wal debug test=# SET wal_debug TO on; SET test=# SET client_min_messages TO debug; SET Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 11. Observing changes Every change will go to the screen now It helps to understand how PostgreSQL works Apart from debugging: The practical purpose is limited Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 12. Making changes Data goes to the xlog first Then data is put into shared buffers At some later point data is written to the data files This does not happen instantly leaving a lot of room for optimization and tuning Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 13. A consistent view of the data Data is not sent to those data files instantly. Still: End users will have a consistent view of the data When a query comes in, it checks the I/O cache (= shared buffers) and asks the data files only in case of a cache miss. xlog is about the physical not about the logical level Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 14. Sustaining writes We cannot write to the xlog forever without recycling it. The xlog is recycled during a so called “checkpoint”. Before the xlog can be recycled, data must be stored safely in those data files Checkpoints have a huge impact on performance Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 15. Checkpoint parameters: checkpoint timeout = 15min max wal size = 5GB min wal size = 800MB checkpoint completion target = 0.5 checkpoint warning = 30s Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 16. Checkpointing to frequently Checkpointing is expensive PostgreSQL warns about too frequent checkpoints This is what checkpoint warning is good for Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 17. min wal size and max wal size (1) This is a replacement for checkpoint segments Now the xlog size is auto-tuned The new configuration was introduced in PostgreSQL 9.5 Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 18. min wal size and max wal size (2) Instead of having a single knob (checkpoint segments) that both triggers checkpoints, and determines how many checkpoints to recycle, they are now separate concerns. There is still an internal variable called CheckpointSegments, which triggers checkpoints. But it no longer determines how many segments to recycle at a checkpoint. That is now auto-tuned by keeping a moving average of the distance between checkpoints (in bytes), and trying to keep that many segments in reserve. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 19. min wal size and max wal size (3) The advantage of this is that you can set max wal size very high, but the system won’t actually consume that much space if there isn’t any need for it. The min wal size sets a floor for that; you can effectively disable the auto-tuning behavior by setting min wal size equal to max wal size. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 20. How does it impact replication The xlog has all the changes needed and can therefore be used for replication. Copying data files is not enough to achieve a consistent view of the data It has some implications related to base backups Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 21. Setting up streaming replication Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 22. The basic process S: Install PostgreSQL on the slave (no initdb) M: Adapt postgresql.conf M: Adapt pg hba.conf M: Restart PostgreSQL S: Pull a base backup S: Start the slave Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 23. Changing postgresql.conf wal level: Ensure that there is enough xlog generated by the master (recovering a server needs more xlog than just simple crash-safety) max wal senders: When a slave is streaming, connects to the master and fetches xlog. A base backup will also need 1 / 2 wal senders hot standby: This is not needed because it is ignored on the master but it saves some work on the slave later on Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 24. Changing pg hba.conf Rules for replication have to be added. Note that “all” databases does not include replication A separate rule has to be added, which explicitly states “replication” in the second column Replication rules work just like any other pg hba.conf rule Remember: The first line matching rules Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 25. Restarting PostgreSQL To activate those settings in postgresql.conf the master has to be restarted. If only pg hba.conf is changed, a simple SIGHUP (pg ctl reload) is enough. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 26. Using pg basebackup (1) pg basebackup will fetch a copy of the data from the master While pg basebackup is running, the master is fully operational (no downtime needed) pg basebackup connects through a database connection and copies all data files as they are In most cases this does not create a consistent backup The xlog is needed to “repair” the base backup (this is exactly what happens during xlog replay anyway) Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 27. Using pg basebackup (2) pg_basebackup -h master.com -D /slave --xlog-method=stream --checkpoint=fast -R Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 28. xlog-method: Self-contained backups By default a base backup is not self-contained. The database does not start up without additional xlog. This is fine for Point-In-Time-Recovery because there is an archive around. For streaming it can be a problem. –xlog-method=stream opens a second connection to fetch xlog during the base backup Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 29. checkpoint=fast: Instant backups By default pg basebackup starts as soon as the master checkpoints. This can take a while. –checkpoint=fast makes the master check instantly. In case of a small backup an instant checkpoint speeds things up. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 30. -R: Generating a config file For a simple streaming setup all PostgreSQL has to know is already passed to pg basebackup (host, port, etc.). -R automatically generates a recovery.conf file, which is quite ok in most cases. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 31. Backup throttling –max-rate=RATE: maximum transfer rate to transfer data directory (in kB/s, or use suffix “k” or “M”) If your master is weak a pg basebackup running at full speed can lead to high response times and disk wait. Slowing down the backup can help to make sure the master stays responsive. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 32. Adjusting recovery.conf A basic setup needs: primary conninfo: A connect string pointing to the master server standby mode = on: Tells the system to stream instantly Additional configuration parameters are available Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 33. Starting up the slave Make sure the slave has connected to the master Make sure it has reached a consistent state Check for wal sender and wal receiver processes Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 34. Promoting a slave to master Promoting a slave to a master is easy: pg_ctl -D ... promote After promotion recovery.conf will be renamed to recovery.done Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 35. One word about security So far replication has been done as superuser This is not necessary Creating a user, which can do just replication makes sense CREATE ROLE foo ... REPLICATION ... NOSUPERUSER; Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 37. Simple checks The most basic and most simplistic check is to check for wal sender (on the master) wal receiver (on the slave) Without those processes the party is over Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 38. More detailed analysis pg stat replication contains a lot of information Make sure an entry for each slave is there Check for replication lag Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 39. Checking for replication lag A sustained lag is not a good idea. The distance between the sender and the receiver can be measured in bytes SELECT client_addr, pg_xlog_location_diff(pg_current_xlog_location(), sent_location) FROM pg_stat_replication; In asynchronous replication the replication lag can vary dramatically (for example during CREATE INDEX, etc.) Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 40. Creating large clusters Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 41. Handling more than 2 nodes A simple 2 node cluster is easy. In case of more than 2 servers, life is a bit harder. If you have two slaves and the master fails: Who is going to be the new master? Unless you want to resync all your data, you should better elect the server containing most of the data already Comparing xlog positions is necessary Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 42. Timeline issues When a slave is promoted the timeline ID is incremented Master and slave have to be in the same timeline In case of two servers it is important to connect one server to the second one first and do the promotion AFTERWARDS. This ensures that the timeline switch is already replicated from the new master to the surviving slave. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 43. Cascading slaves Slaves can be connected to slaves Cascading can make sense to reduce bandwidth requirements Cascading can take load from the master Use pg basebackup to fetch data from a slave as if it was a master Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 45. How conflicts happen During replication conflicts can happen Example: The master might want to remove a row still visible to a reading transaction on the slave Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 46. What happens during a conflict PostgreSQL will terminate a database connection after some time max standby archive delay = 30s max standby streaming delay = 30s Those settings define the maximum time the slave waits during replay before replay is resumed. In rare cases a connection might be aborted quite soon. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 47. Reducing conflicts Conflicts can be reduced nicely by setting hot standby feedback. The slave will send its oldest transaction ID to tell the master that cleanup has to be deferred. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 48. Making replication more reliable Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 49. What happens if a slave reboots? If a slave is gone for too long, the master might recycle its transaction log The slave needs a full history of the xlog Setting wal keep segments on the master helps to prevent the master from recycling transaction log too early I recommend to always use wal keep segments to make sure that a slave can be started after a pg basebackup Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 50. Making use of replication slots Replication slots have been added in PostgreSQL 9.4 There are two types of replication slots: Physical replication slots (for streaming) Logical replication slots (for logical decoding) Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 51. Configuring replication slots Change max replication slots and restart the master Run . . . test=# SELECT * FROM pg_create_physical_replication_slot(’some_name’); slot_name | xlog_position -----------+--------------- some_name | (1 row) Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 52. Tweaking the slave Add this replication slot to primary slot name on the slave: primary_slot_name = ’some_name’ The master will ensure that xlog is only recycled when it has been consumed by the slave. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 53. A word of caution If a slave is removed make sure the replication slot is dropped. Otherwise the master might run out of disk space. NEVER use replication slots without monitoring the size of the xlog on the sender. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 54. Key advantages of replication slots The difference between master and slave can be arbitrary. During bulk load or CREATE INDEX this can be essential. It can help to overcome the problems caused by slow networks. It can help to avoid resyncs. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 55. Moving to synchronous replication Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 56. Synchronous vs. asynchronous Asynchronous replication: Commits on the slave can happen long after the commit on the master. Synchronous replication: A transaction has to be written to a second server. Synchronous replication potentially adds some network latency to the scenery Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 57. The application name During normal operations the application name setting can be used to assign a name to a database connection. In case of synchronous replication this variable is used to determine synchronous candidates. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 58. Configuring synchronous replication: Master: add names to synchronous standby names Slave: add an application name to your connect string in primary conninfo Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 59. Fail safety Synchronous replication needs 2 active servers If no two servers are left, replication will wait until a second server is available. Use AT LEAST 3 servers for synchronous replication to avoid risk. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 61. What it does PITR can be used to reach (almost) any point after a base backup. It is more of a backup strategy than a replication thing. Replication and PITR can be combined. Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 62. Configuring for PITR S: create an archive (ideally this is not on the master) M: Change postgresql.conf set wal level set max wal senders (if pg basebackup is desired) set archive mode to on set a proper archive command to archive xlog M: adapt pg hba.conf (if pg basebackup is desired) M: restart the master Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 63. pg basebackup, etc. Perform a pg basebackup as performed before –xlog-method=stream and -R are not needed In the archive a .backup file will be available after pg basebackup You can delete all xlog files older than the oldest base backup you want to keep. The .backup file will guide you Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 64. Restoring from a crash Take a base backup. Write a recovery.conf file: restore command: Tell PostgreSQL where to find xlog recovery target time (optional): Use a timestamp to tell the system how far to recover Start the server Make sure the system has reached consistent state Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 65. More config options Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 66. recovery min apply delay: Delayed replay This settings allows you to tell the slave that a certain delay is desired. Example: A stock broker might want to provide you with 15 minute old data Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 67. pause at recovery target Make sure that the recovery does not stop at a specified point in time. Make PostgreSQL wait when a certain point is reached. This is essential in case you do not know precisely how far to recover Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 68. recovery target name Sometimes you want to recover to a certain point in time, which has been specified before. To specify a point in time run . . . SELECT pg_create_restore_point(’some_name’); Use this name in recovery.conf to recover to this very specific point Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 69. Finally . . . Hans-J¨urgen Sch¨onig www.postgresql-support.de
  • 70. Contact us . . . Cybertec Sch¨onig & Sch¨onig GmbH Gr¨ohrm¨uhlgasse 26 A-2700 Wiener Neustadt Austria More than 15 years of PostgreSQL experience: Training Consulting 24x7 support Hans-J¨urgen Sch¨onig www.postgresql-support.de