Re: pg_dump, ATTACH, and independently restorable child partitions

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: David Rowley <drowley(at)postgresql(dot)org>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pg_dump, ATTACH, and independently restorable child partitions
Date: 2020-11-20 15:20:55
Message-ID: 20201120152055.GF24784@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 06, 2020 at 11:18:35PM -0300, Alvaro Herrera wrote:
> On 2020-Oct-24, Justin Pryzby wrote:
>
> > On Fri, Oct 23, 2020 at 12:29:40AM -0500, Justin Pryzby wrote:
>
> > > Now that I look, it seems like this is calling PQexec(), which sends a single,
> > > "simple" libpq message with:
> > > |CREATE TABLE ..; ALTER TABLE .. ATTACH PARTITION;
> > > ..which is transactional, so when the 2nd command fails, the CREATE is rolled back.
> > > https://www.postgresql.org/docs/9.5/libpq-exec.html#LIBPQ-EXEC-MAIN
> >
> > The easy fix is to add an explicit begin/commit.
>
> Hmm, I think this throws a warning when used with "pg_restore -1",
> right? I don't think that's sufficient reason to discard the idea, but
> it be better to find some other way.

Worse, right ? It'd commit in the middle and then continue outside of a txn.
I guess there's no test case for this :(

> I have no ideas ATM :-(

1. Maybe pg_restore ExecuteSqlCommandBuf() should (always?) call
ExecuteSimpleCommands() instead of ExecuteSqlCommand(). It doesn't seem to
break anything (although that surprised me).

2. Otherwise, the createStmt would need to be split into a createStmt2 or a
char *createStmt[], which I think would then require changing the output
format. It seems clearly better to keep the sql commands split up initially
than to reverse engineer them during restore.

I tried using \x01 to separate commands, and strtok to split them to run them
individually. But that breaks the pg_dumpall tests. As an experiment, I used
\x00, which is somewhat invasive but actually works.

Obviously patching pg_dump will affect only future backups, and the pg_restore
patch allows independently restoring parent tables in existing dumps.

--
Justin

Attachment Content-Type Size
v2-0001-pg_restore-parse-and-run-separately-SQL-commands.patch text/x-diff 1.5 KB
v2-0002-pg_dump-Allow-child-partitions-to-be-independentl.patch text/x-diff 26.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2020-11-20 15:29:44 Re: VACUUM (DISABLE_PAGE_SKIPPING on)
Previous Message Gilles Darold 2020-11-20 15:18:38 Re: Issue with server side statement-level rollback