SlideShare a Scribd company logo
1 of 70
Download to read offline
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

How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015PostgreSQL-Consulting
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1Federico Campoli
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 
PostGreSQL Performance Tuning
PostGreSQL Performance TuningPostGreSQL Performance Tuning
PostGreSQL Performance TuningMaven Logix
 
PostgreSQL Extensions: A deeper look
PostgreSQL Extensions:  A deeper lookPostgreSQL Extensions:  A deeper look
PostgreSQL Extensions: A deeper lookJignesh Shah
 
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and FanoutOpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and FanoutSaju Madhavan
 
Postgres connections at scale
Postgres connections at scalePostgres connections at scale
Postgres connections at scaleMydbops
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Alexey Lesovsky
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundMasahiko Sawada
 
Ceph RBD Update - June 2021
Ceph RBD Update - June 2021Ceph RBD Update - June 2021
Ceph RBD Update - June 2021Ceph Community
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniZalando Technology
 
Patroni: Kubernetes-native PostgreSQL companion
Patroni: Kubernetes-native PostgreSQL companionPatroni: Kubernetes-native PostgreSQL companion
Patroni: Kubernetes-native PostgreSQL companionAlexander Kukushkin
 
Ceph scale testing with 10 Billion Objects
Ceph scale testing with 10 Billion ObjectsCeph scale testing with 10 Billion Objects
Ceph scale testing with 10 Billion ObjectsKaran Singh
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep InternalEXEM
 
Working with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBWorking with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBScaleGrid.io
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationCommand Prompt., Inc
 

What's hot (20)

How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
PostGreSQL Performance Tuning
PostGreSQL Performance TuningPostGreSQL Performance Tuning
PostGreSQL Performance Tuning
 
PostgreSQL Extensions: A deeper look
PostgreSQL Extensions:  A deeper lookPostgreSQL Extensions:  A deeper look
PostgreSQL Extensions: A deeper look
 
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and FanoutOpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
 
Postgres connections at scale
Postgres connections at scalePostgres connections at scale
Postgres connections at scale
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparound
 
Ceph RBD Update - June 2021
Ceph RBD Update - June 2021Ceph RBD Update - June 2021
Ceph RBD Update - June 2021
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
Patroni: Kubernetes-native PostgreSQL companion
Patroni: Kubernetes-native PostgreSQL companionPatroni: Kubernetes-native PostgreSQL companion
Patroni: Kubernetes-native PostgreSQL companion
 
Ceph scale testing with 10 Billion Objects
Ceph scale testing with 10 Billion ObjectsCeph scale testing with 10 Billion Objects
Ceph scale testing with 10 Billion Objects
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
Working with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBWorking with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDB
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 

Viewers also liked

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.4Denish 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
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practiceAlexey Lesovsky
 
PostgreSQL: Joining 1 million tables
PostgreSQL: Joining 1 million tablesPostgreSQL: Joining 1 million tables
PostgreSQL: Joining 1 million tablesHans-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 securityHans-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 - SCALEPostgreSQL 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 EnvironmentsJignesh 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_overviewAlex Meadows
 
Top 10 database optimization tips
Top 10 database optimization tipsTop 10 database optimization tips
Top 10 database optimization tipsraviwriter
 
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 scaleSoumya Ranjan Subudhi
 
Walbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction logWalbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction logHans-Jürgen Schönig
 
PostgreSQL: Eigene Aggregate schreiben
PostgreSQL: Eigene Aggregate schreibenPostgreSQL: Eigene Aggregate schreiben
PostgreSQL: Eigene Aggregate schreibenHans-Jürgen Schönig
 
Materialized views in PostgreSQL
Materialized views in PostgreSQLMaterialized views in PostgreSQL
Materialized views in PostgreSQLAshutosh Bapat
 
Pattern driven Enterprise Architecture
Pattern driven Enterprise ArchitecturePattern driven Enterprise Architecture
Pattern driven Enterprise ArchitectureWSO2
 

Viewers also liked (20)

Really Big Elephants: PostgreSQL DW
Really Big Elephants: PostgreSQL DWReally Big Elephants: PostgreSQL DW
Really Big Elephants: PostgreSQL DW
 
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
 
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
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practice
 
5min analyse
5min analyse5min analyse
5min analyse
 
PostgreSQL: Joining 1 million tables
PostgreSQL: Joining 1 million tablesPostgreSQL: Joining 1 million tables
PostgreSQL: Joining 1 million tables
 
PostgreSQL instance encryption: More database security
PostgreSQL instance encryption: More database securityPostgreSQL instance encryption: More database security
PostgreSQL instance encryption: More database security
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
 
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
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
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)
 
Open source data_warehousing_overview
Open source data_warehousing_overviewOpen source data_warehousing_overview
Open source data_warehousing_overview
 
Top 10 database optimization tips
Top 10 database optimization tipsTop 10 database optimization tips
Top 10 database optimization tips
 
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
 
Walbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction logWalbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction log
 
PostgreSQL: Eigene Aggregate schreiben
PostgreSQL: Eigene Aggregate schreibenPostgreSQL: Eigene Aggregate schreiben
PostgreSQL: Eigene Aggregate schreiben
 
Explain explain
Explain explainExplain explain
Explain explain
 
PostgreSQL: The NoSQL way
PostgreSQL: The NoSQL wayPostgreSQL: The NoSQL way
PostgreSQL: The NoSQL way
 
Materialized views in PostgreSQL
Materialized views in PostgreSQLMaterialized views in PostgreSQL
Materialized views in PostgreSQL
 
Pattern driven Enterprise Architecture
Pattern driven Enterprise ArchitecturePattern driven Enterprise Architecture
Pattern driven Enterprise Architecture
 

Similar to PostgreSQL Replication Tutorial

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
 
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 ClusterSrihari Sriraman
 
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRestPGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRestPGDay.Amsterdam
 
PostgreSQL: Data analysis and analytics
PostgreSQL: Data analysis and analyticsPostgreSQL: Data analysis and analytics
PostgreSQL: Data analysis and analyticsHans-Jürgen Schönig
 
Nancy CLI. Automated Database Experiments
Nancy CLI. Automated Database ExperimentsNancy CLI. Automated Database Experiments
Nancy CLI. Automated Database ExperimentsNikolay Samokhvalov
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2PgTraining
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...javier ramirez
 
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...Flink Forward
 
Oracle: Binding versus caging
Oracle: Binding versus cagingOracle: Binding versus caging
Oracle: Binding versus cagingBertrandDrouvot
 
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptxBuilt-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptxnadirpervez2
 
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...Flink Forward
 
Malo Denielou - No shard left behind: Dynamic work rebalancing in Apache Beam
Malo Denielou - No shard left behind: Dynamic work rebalancing in Apache BeamMalo Denielou - No shard left behind: Dynamic work rebalancing in Apache Beam
Malo Denielou - No shard left behind: Dynamic work rebalancing in Apache BeamFlink Forward
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Apache Traffic Server
Apache Traffic ServerApache Traffic Server
Apache Traffic Serversupertom
 
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New FeaturesAmazon Web Services
 
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 GulecFIRAT GULEC
 
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLWebinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLSeveralnines
 
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Ontico
 
Performance Tuning Cheat Sheet for MongoDB
Performance Tuning Cheat Sheet for MongoDBPerformance Tuning Cheat Sheet for MongoDB
Performance Tuning Cheat Sheet for MongoDBSeveralnines
 
Advanced off heap ipc
Advanced off heap ipcAdvanced off heap ipc
Advanced off heap ipcPeter Lawrey
 

Similar to PostgreSQL Replication Tutorial (20)

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...
 
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
 
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRestPGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
 
PostgreSQL: Data analysis and analytics
PostgreSQL: Data analysis and analyticsPostgreSQL: Data analysis and analytics
PostgreSQL: Data analysis and analytics
 
Nancy CLI. Automated Database Experiments
Nancy CLI. Automated Database ExperimentsNancy CLI. Automated Database Experiments
Nancy CLI. Automated Database Experiments
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
 
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
 
Oracle: Binding versus caging
Oracle: Binding versus cagingOracle: Binding versus caging
Oracle: Binding versus caging
 
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptxBuilt-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
 
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
 
Malo Denielou - No shard left behind: Dynamic work rebalancing in Apache Beam
Malo Denielou - No shard left behind: Dynamic work rebalancing in Apache BeamMalo Denielou - No shard left behind: Dynamic work rebalancing in Apache Beam
Malo Denielou - No shard left behind: Dynamic work rebalancing in Apache Beam
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Apache Traffic Server
Apache Traffic ServerApache Traffic Server
Apache Traffic Server
 
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
 
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
 
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLWebinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
 
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
 
Performance Tuning Cheat Sheet for MongoDB
Performance Tuning Cheat Sheet for MongoDBPerformance Tuning Cheat Sheet for MongoDB
Performance Tuning Cheat Sheet for MongoDB
 
Advanced off heap ipc
Advanced off heap ipcAdvanced off heap ipc
Advanced off heap ipc
 

Recently uploaded

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 

Recently uploaded (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 

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