Exploring conflict handling with PGD v5.7.0
In a multi-master architecture like PGD, conflicts happen. PGD is built to handle them.
A conflict can occur when one database node has an update from an application to a row and another node has a different update to the same row. This type of conflict is called a row-level conflict. Conflicts aren't errors. Resolving them effectively is core to how Postgres Distributed maintains consistency.
The best way to handle conflicts is to prevent them! Use PGD's Always-on architecture with proxies to ensure that your applications write to the same server in the cluster. is When conflicts occur, though, it's useful to know how PGD resolves them, how you can control that resolution, and how you can find out that they're happening. Row insertion and row updates are two actions that can cause conflicts.
To see how it works, you need to open a command line view of all the servers.
Your quick start configuration
This exploration assumes that you created your PGD cluster using the quick start for Docker, the quick start for AWS, or the quick start for Linux hosts.
At the end of each quick start, you'll have a cluster with four nodes and these roles:
| Host name | Host role |
|---|---|
| kaboom | PGD data node and pgd-proxy co-host |
| kaftan | PGD data node and pgd-proxy co-host |
| kaolin | PGD data node and pgd-proxy co-host |
| kapok | Barman backup node |
You'll use these hostnames throughout this exercise.
Installing xpanes
Xpanes optional
We recommend the xpanes utility for this exercise. It allows you to easily switch between multiple terminal sessions. If you prefer to use multiple terminals, tmux or another terminal multiplexer, you can do so. Just make sure you can easily switch between multiple terminal sessions.
You'll use xpanes, a utility that allows you to quickly create multiple terminal sessions that you can easily switch between. It isn't installed by default, so you'll have to install it. Start by connecting to the kaboom node with ssh:
cd democluster && ssh -F ssh_config kaboom
If you're running the quick start on Docker, you'll be using Rocky Linux, a Red Hat derivative. To perform the xpanes install, run:
dnf -y install xpanes
If you're running the quick start on AWS, you'll be using Debian Linux. To perform the xpanes install, run:
wget https://github.com/greymd/tmux-xpanes/releases/download/v4.1.4/tmux-xpanes_v4.1.4.deb sudo apt -y install ./tmux-xpanes*.deb rm tmux-xpanes*.deb
Connecting to four servers
You need to be logged in as the enterprisedb user to allow authentication to work:
sudo -iu enterprisedb
Then, run the following command to connect to three database servers and a proxy server:
xpanes -d -c "psql postgresql://enterprisedb@{}/bdrdb?sslmode=require" "kaboom:5444" "kaftan:5444" "kaolin:5444" "kaboom:6432"
xpanes takes the command after -c and uses the values in the arguments that follow to create a command to run. That means that, after you run it, there will be four panes. Three panes will be connected to the database nodes kaboom, kaftan, and kaolin on port 5444. One will be connected to the pgd-proxy running on kaboom on port 6432. Each one will be logged into the database as enterprisedb.
Press Control-b followed by q to briefly display the numeric values for each pane.
To switch the focus between the panes, you can use Control-b and the cursor keys to navigate between them. Or you can use Control-b followed by q and the number of the pane you want to focus on. We'll show both ways.
Move to the bottom-left pane using Control-b