Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kYBHq-0006cM-5u for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Oct 2020 17:00:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBHp-0001q6-4b for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Oct 2020 17:00:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kYBHo-0001ps-QP for pgsql-hackers@lists.postgresql.org; Thu, 29 Oct 2020 17:00:28 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kYBHl-0006zw-F6 for pgsql-hackers@lists.postgresql.org; Thu, 29 Oct 2020 17:00:28 +0000 Received: by mail-il1-x132.google.com with SMTP id n5so3763347ile.7 for ; Thu, 29 Oct 2020 10:00:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/+vjlFlaMgVMTpVdxdoI3VfYvPM7O+A4/BFDZ34e63I=; b=mpjqdqJawzAyVne4vBxfu1jfK9KjgdIvWmKSFT5uxDMPMAAhZ4O4BDbSU9XLVVcGeN uoD/FmAWwiUjljZfsC9j9a16y5+hbhW3waaSLpquCVZUvLaNRpKwU8fa5nVk/8kKuYKf Lxyf/NDisVvDABkfePgscojh5iovkVWiR3YHMcrybh25ckUL336MS84okybRqrqb0I9b DST6oLE49vWfyn4mma5UxRd/tWB5ExUAN5PPHJx8ZWSQ01AVAvJa29WPPrdEsIvcVCQX E7RZMuSkmD3khRxsZ6HT/QQ9s/pa6gY4QihWrZXvkEnIppC1Qo8T71WCRWMMPYGUJj5j qOlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/+vjlFlaMgVMTpVdxdoI3VfYvPM7O+A4/BFDZ34e63I=; b=WF/NFot3efMCWkoLgo7vuq5kkVcrS3FAyWnfjICi82kembMPSXz74C8ZRAVygLpyOq OMkRwwGfcnOaOBa/ovQLuw76U04yfwMuOXgxf2BL/ffeSdcpknN6ipq8jVzdqzWZpAUx 8K4bgiIUeEZzn9qAE3tdcZWEDVqwFYgqWpiGb/r35AN2mDYYk9LxFIoVSENAC0/62att 3IJ5RzBw7LWgFivVJhWjuNLkoq5hWr4YXKKWfag8l+1CsEyKCaMLowgK/ixUBnv7YNaM P4YIO+9AdxJoH1a02dHoY2a8fMgvZUU8Kz8ROr7SHEuAmrX2F+u3YQHt8P3iBWnf/Kdp RQVQ== X-Gm-Message-State: AOAM533SEXTE/G+z1RvMojt2cAdD8/4CanskImUcwLpTJ/Y/Dt18GQ96 WEOVYKvcqbVsH1bZy8aazZjfNQ== X-Google-Smtp-Source: ABdhPJwMquiMmnDhgVe4igesWvznl8+jhJUgTdhnQecx3s2ktKbMp3A1Qk5bOYJGp8zKRCI+9c/95Q== X-Received: by 2002:a92:db84:: with SMTP id f4mr3931373ilp.3.1603990823508; Thu, 29 Oct 2020 10:00:23 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id b3sm2516337iot.37.2020.10.29.10.00.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2020 10:00:22 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 12F14800665; Thu, 29 Oct 2020 12:00:21 -0500 (CDT) Date: Thu, 29 Oct 2020 12:00:20 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: David Rowley , pgsql-hackers@lists.postgresql.org Subject: Re: pg_dump, ATTACH, and independently restorable child partitions Message-ID: <20201029170020.GA31710@telsasoft.com> References: <20201023052940.GE9241@telsasoft.com> <20201024195949.GL9241@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="n8g4imXOkfNTN/H1" Content-Disposition: inline In-Reply-To: <20201024195949.GL9241@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Oct 24, 2020 at 02:59:49PM -0500, Justin Pryzby wrote: > On Fri, Oct 23, 2020 at 12:29:40AM -0500, Justin Pryzby wrote: > > Since this commit, pg_dump CREATEs tables and then ATTACHes them: > > > > |commit 33a53130a89447e171a8268ae0b221bb48af6468 > > |Author: Alvaro Herrera > > |Date: Mon Jun 10 18:56:23 2019 -0400 > > | > > | Make pg_dump emit ATTACH PARTITION instead of PARTITION OF (reprise) > > |... > > | This change also has the advantage that the partition is restorable from > > | the dump (as a standalone table) even if its parent table isn't > > | restored. > > > > I like the idea of child tables being independently restorable, but it doesn't > > seem to work. > ... > > 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. Now with updated test script. -- Justin --n8g4imXOkfNTN/H1 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-pg_dump-Allow-child-partitions-to-be-independentl.patch" From 8e34426bf7d863e3e8878a2e31c64ca999ec4464 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sat, 24 Oct 2020 14:51:18 -0500 Subject: [PATCH v2] pg_dump: Allow child partitions to be independently restored ..even if the parent doesn't exist, or has missing/incompatible columns This seems to have been intended by commit 33a53130a --- src/bin/pg_dump/pg_dump.c | 8 ++++++++ src/bin/pg_dump/t/002_pg_dump.pl | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 03f9d4d9e8..4767418849 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15651,6 +15651,13 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) binary_upgrade_set_pg_class_oids(fout, q, tbinfo->dobj.catId.oid, false); + /* + * Use explicit transaction commands so that failure in a + * following command in the same txn doesn't cause ROLLBACK of + * the "CREATE TABLE". + */ + appendPQExpBufferStr(q, "begin;\n"); + appendPQExpBuffer(q, "CREATE %s%s %s", tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ? "UNLOGGED " : "", @@ -15871,6 +15878,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) } else appendPQExpBufferStr(q, ";\n"); + appendPQExpBufferStr(q, "commit;\n"); /* Materialized views can depend on extensions */ if (tbinfo->relkind == RELKIND_MATVIEW) diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index ec63662060..90dc2c5ae9 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -2343,6 +2343,7 @@ my %tests = ( regexp => qr/^ \Q-- Name: measurement;\E.*\n \Q--\E\n\n + \Qbegin;\E\n \QCREATE TABLE dump_test.measurement (\E\n \s+\Qcity_id integer NOT NULL,\E\n \s+\Qlogdate date NOT NULL,\E\n @@ -2351,6 +2352,7 @@ my %tests = ( \s+\QCONSTRAINT measurement_peaktemp_check CHECK ((peaktemp >= '-460'::integer))\E\n \)\n \QPARTITION BY RANGE (logdate);\E\n + \Qcommit;\E\n /xm, like => { %full_runs, %dump_test_schema_runs, section_pre_data => 1, }, -- 2.17.0 --n8g4imXOkfNTN/H1--