Logical replication with temporary tables

From: Stuart Campbell <stuart(dot)campbell(at)ridewithvia(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Logical replication with temporary tables
Date: 2024-07-03 00:47:32
Message-ID: CAAZ6SnzRU=qo2nedBa6ESOHfV=WaRJk+UW5DUrxkVMu6Gjpwng@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I'm trying to use a blue/green deployment in Amazon RDS, which uses
Postgres logical replication to keep blue and green environments in sync.

Some parts of our app use temporary tables, and in some cases we CREATE
INDEX on those tables and sometimes DROP and recreate them.

The CREATE INDEX and DROP TABLE statements are causing problems with the
blue/green replication. (They are detected by RDS, and cause the deployment
to be marked as "degraded" and subsequently unusable.)

My (limited) understanding is that this happens because CREATE TEMPORARY
TABLE doesn't get written to the WAL, but the other statements do.

My question is whether there is some workaround that will let me create
indexes on a temporary table, and also let me drop the temporary table, in
a way that doesn't end up "degrading" replication? (Presumably that means
avoiding writing to the WAL?)

I've discovered that I can at least create a primary key inline as part of
the temporary table definition, which gives me a way to create a single
(unique) index, i.e.:

CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, …)

But I haven't discovered a way to drop the table, or to create other
indexes.

Cheers,
Stuart

--
This communication and any attachments may contain confidential information
and are intended to be viewed only by the intended recipients. If you have
received this message in error, please notify the sender immediately by
replying to the original message and then delete all copies of the email
from your systems.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christophe Pettus 2024-07-03 00:49:57 Re: Logical replication with temporary tables
Previous Message Christophe Pettus 2024-07-02 22:13:28 Re: Accommodating alternative column values