Re: pg_dump, ATTACH, and independently restorable child partitions
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: David Rowley <drowley@postgresql.org>, pgsql-hackers@lists.postgresql.org
Date: 2020-11-20T15:20:55Z
Lists: pgsql-hackers
Attachments
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
Commits
-
pg_dump: label INDEX ATTACH ArchiveEntries with an owner.
- 9f15188a1b82 11.11 landed
- 9eabfe300a22 14.0 landed
- 436d9c5cabfc 12.6 landed
- 0011c5a0fdac 13.2 landed
-
Dump ALTER TABLE ... ATTACH PARTITION as a separate ArchiveEntry.
- 9a4c0e36fbd6 14.0 landed
-
Make pg_dump emit ATTACH PARTITION instead of PARTITION OF (reprise)
- 33a53130a894 12.0 cited