Allow REPLICA IDENTITY with CREATE TABLE statement

Started by Kirill Reshkeover 1 year ago2 messageshackers

Thread notes

1 note#feature#minor#enhancement
hackorum-bot#feature#minor#enhancement
hackorum-bot
1 day ago

@global #feature #minor #enhancement

#feature#minor#enhancement
Jump to latest
#1Kirill Reshke
reshkekirill@gmail.com

Hi hackers!

In the nearby thread[0]/messages/by-id/202508061804.wwf4zc7npayp@alvherre.pgsql, enhancements for CREATE TABLE LIKE/REPLICA
IDENTITY were proposed.

To me, it makes sense to copy the replica identity definition if

INCLUDING INDEXES or INCLUDING CONSTRAINTS is given.

I agree that this can be beneficial.

But I decided to start with some simpler task, which is also sane (to
my belief) and can be used to improve user experience with this
feature. This is to allow you to specify REPLICA IDENTITY with CREATE
TABLE statement. Currently, it requires 2 (two) DDL statements to
define RI for relation (that is CREATE TABLE + ALTER TABLE). My patch
indent to enhance this.

This was actually proposed 12 years ago in the original thread, see
[1]: /messages/by-id/20131021181629.GI2968@awork2.anarazel.de -- Best regards, Kirill Reshke
replication to work, so was abandoned.

My v1 patch misses documentation and tests, yes, but this is just the
initial version to receive feedback, if this has a chance of being
committed or not, and general thoughts on the subject.

WDYT?

[0]: /messages/by-id/202508061804.wwf4zc7npayp@alvherre.pgsql
[1]: /messages/by-id/20131021181629.GI2968@awork2.anarazel.de -- Best regards, Kirill Reshke
--
Best regards,
Kirill Reshke

Attachments:

t52052_1
0001-Allow-to-explicitly-set-REPLICA-IDENTITY-with-relati.patchapplication/octet-stream; name=0001-Allow-to-explicitly-set-REPLICA-IDENTITY-with-relati.patchDownload+43-27
#2Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Kirill Reshke (#1)
Re: Allow REPLICA IDENTITY with CREATE TABLE statement

On Thu, Aug 7, 2025 at 6:31 PM Kirill Reshke <reshkekirill@gmail.com> wrote:

Hi hackers!

In the nearby thread[0], enhancements for CREATE TABLE LIKE/REPLICA
IDENTITY were proposed.

To me, it makes sense to copy the replica identity definition if

INCLUDING INDEXES or INCLUDING CONSTRAINTS is given.

I agree that this can be beneficial.

But I decided to start with some simpler task, which is also sane (to
my belief) and can be used to improve user experience with this
feature. This is to allow you to specify REPLICA IDENTITY with CREATE
TABLE statement. Currently, it requires 2 (two) DDL statements to
define RI for relation (that is CREATE TABLE + ALTER TABLE). My patch
indent to enhance this.

This was actually proposed 12 years ago in the original thread, see
[1]. But at that time this was not considered vital for logical
replication to work, so was abandoned.

My v1 patch misses documentation and tests, yes, but this is just the
initial version to receive feedback, if this has a chance of being
committed or not, and general thoughts on the subject.

I bumped into this requirement recently when working for a customer
case. The previous discussion isn't thorough and doesn't show that we
didn't want this feature that time. +1 for the feature.

I haven't reviewed the patches though.

--
Best Wishes,
Ashutosh Bapat