Use "COPY table TO" for partitioned tables in initial table synchronization. master github/master
authorMasahiko Sawada <msawada@postgresql.org>
Thu, 20 Nov 2025 22:50:27 +0000 (14:50 -0800)
committerMasahiko Sawada <msawada@postgresql.org>
Thu, 20 Nov 2025 22:50:27 +0000 (14:50 -0800)
Commit 4bea91f added support for "COPY table TO" with partitioned
tables. This commit enhances initial table synchronization in logical
replication to use "COPY table TO" for partitioned tables if possible,
instead of "COPY (SELECT ...) TO" variant, improving performance.

Author: Ajin Cherian <itsajin@gmail.com>
Discussion: https://postgr.es/m/CAFPTHDY=w+xmEof=yyjhbDzaLxhBkoBzKcksEofXcT6EcjMbtQ@mail.gmail.com

src/backend/replication/logical/tablesync.c

index dcc6124cc7308c73eaacb43cc57c583d9d4e38d2..fa8e3bf969a92349e0faa071914e5073d9d8cca2 100644 (file)
@@ -1068,8 +1068,9 @@ copy_table(Relation rel)
    /* Start copy on the publisher. */
    initStringInfo(&cmd);
 
-   /* Regular table with no row filter or generated columns */
-   if (lrel.relkind == RELKIND_RELATION && qual == NIL && !gencol_published)
+   /* Regular or partitioned table with no row filter or generated columns */
+   if ((lrel.relkind == RELKIND_RELATION || lrel.relkind == RELKIND_PARTITIONED_TABLE)
+       && qual == NIL && !gencol_published)
    {
        appendStringInfo(&cmd, "COPY %s",
                         quote_qualified_identifier(lrel.nspname, lrel.relname));