pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: PGSQL DBA <pgsqldba.1987@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: How to Handle Sequences in Logical Bi-Directional Replication
Date: Thu, 13 Jun 2024 09:15:43 +0200
Message-ID: <186ddb32d1f5e6bc46fdd6546fcc225a4d2dc3b6.camel@cybertec.at> (raw)
In-Reply-To: <CAKaKWS8guhPRv_x9YtXLk3U4RWotOREAv5CnUff1HAWuLAfrMA@mail.gmail.com>
References: <CAKaKWS8guhPRv_x9YtXLk3U4RWotOREAv5CnUff1HAWuLAfrMA@mail.gmail.com>

On Thu, 2024-06-13 at 09:23 +0800, PGSQL DBA wrote:
> I am reaching out to seek your guidance and expertise on handling sequences
> in a bi-directional logical replication setup.
> 
> I am planning to set up two PostgreSQL-16 database servers with logical bi-directional
> replication, using the `origin=none` configuration. In this setup, my application will
> be connecting to either of the database servers for DML operations.

You will have to resolve conflicts manually.

> Given this scenario, I am looking for the best practices to handle sequence values to
> ensure consistency and avoid conflicts. Specifically, I would like to understand:
> 
> 1. How to configure sequences to avoid duplicate values in both database servers.

On server 1:

  CREATE TABLE tab (
     id bigint BENERATED ALWAYS AS IDENTITY (START 1 INCREMENT 2)
               PRIMARY KEY,
     ...
  );

On server 2:

  CREATE TABLE tab (
     id bigint BENERATED ALWAYS AS IDENTITY (START 2 INCREMENT 2)
               PRIMARY KEY,
     ...
  );

Yours,
Laurenz Albe





view thread (5+ messages)  latest in thread

Message-ID: <186ddb32d1f5e6bc46fdd6546fcc225a4d2dc3b6.camel@cybertec.at>
Permalink:  ../186ddb32d1f5e6bc46fdd6546fcc225a4d2dc3b6.camel@cybertec.at/
Also on:    postgresql.org/message-id/186ddb32d1f5e6bc46fdd6546fcc225a4d2dc3b6.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: laurenz.albe@cybertec.at, pgsqldba.1987@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: How to Handle Sequences in Logical Bi-Directional Replication
  In-Reply-To: <186ddb32d1f5e6bc46fdd6546fcc225a4d2dc3b6.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox