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 1kWPho-0005R1-3e for pgsql-hackers@arkaria.postgresql.org; Sat, 24 Oct 2020 20:00:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kWPhk-0005MM-Rd for pgsql-hackers@arkaria.postgresql.org; Sat, 24 Oct 2020 19:59:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWPhk-0005MC-Gi for pgsql-hackers@lists.postgresql.org; Sat, 24 Oct 2020 19:59:56 +0000 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kWPhg-00032u-UC for pgsql-hackers@lists.postgresql.org; Sat, 24 Oct 2020 19:59:55 +0000 Received: by mail-io1-xd44.google.com with SMTP id b15so5926856iod.13 for ; Sat, 24 Oct 2020 12:59:52 -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=srDxscKUEKtB/UXnQJY3jAJFdPXUclekpRxOK0SCsTs=; b=sftJSs/cDb3lbZ0OkHLsuENhzSglpu0bWRATL7tFgvpzNZypcfgouIv4cMDuMUycpo kYfcL2gjP3vzKUcPz+bj/vA2oL5bXichlc/Q/FsyVGDe9bgZOYRmJZsGs97Dm29QlfLN rWYBTsduuiSD/+lCsPV/fZvPYn93/tc+MWjUiSY7bG9CM+79DRkA15Uvq1e4yJsUcd3S X9WktL8oa/P7Yid/GO8AUHC6vj+AZpZhqFq5M2GgilIaqeqLjF+H6kKdEHbMcTTJEKDn 39eJ4wd1j2SZMXrxTkmEgkNtzJkiyIQ89A7Fsnp4NdyCYNkpPYDotha8vYEIJDCXWtZw 0Cdg== 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=srDxscKUEKtB/UXnQJY3jAJFdPXUclekpRxOK0SCsTs=; b=GHr4UNb5TIXCDYsm3H4qa2JXohv6UDk0IreFVsXNBgQUaX3E4P3BJgAxtzH71t9oAE J7tJ3L+22h6tTV598c2rGHn1qW/xN3uq4gcrD5crd3NLQaqkAxP3Gjyd1r1+rv52+pGL psC/YUs/qTquxvuMN9kFLmOWDK7BPfentTO/gPqUGn8DJdcXJbdd52tLVdsg6M0TSaLx v895UBziMxhupn/90FrbpBIoMVmR0MK9/UcxG7EclO5vitcN5k+JKpsbzuyaZhn3VmB8 fgFITthzzkRyZcWKgiFgSdYa7pJgySvHCppCTfp9DSmNOjf7HNwzfKX3+sXLwjM1ZMKK lTNw== X-Gm-Message-State: AOAM5336Kk4qwWFSj+axafRE4Kz/sW4hkDYLDAofOzdj+xZPdxNU1a/2 Z3gBoPvIYbSnusN9ywBIE9dBr4wOsCWtUQ== X-Google-Smtp-Source: ABdhPJytaS++pMqNcfDho/H7UB6Y6fdhIEVD/e+nNjC6u4M1umIjz0n7OB7fdrUmMubhBZ+fkQLoCw== X-Received: by 2002:a05:6602:1248:: with SMTP id o8mr6131320iou.138.1603569591766; Sat, 24 Oct 2020 12:59:51 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id h125sm2872065iof.53.2020.10.24.12.59.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Oct 2020 12:59:50 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 87300800665; Sat, 24 Oct 2020 14:59:49 -0500 (CDT) Date: Sat, 24 Oct 2020 14:59:49 -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: <20201024195949.GL9241@telsasoft.com> References: <20201023052940.GE9241@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="McpcKDxJRrEJVmOH" Content-Disposition: inline In-Reply-To: <20201023052940.GE9241@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 --McpcKDxJRrEJVmOH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. -- Justin --McpcKDxJRrEJVmOH Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-pg_dump-Allow-child-partitions-to-be-independently-r.patch" From 4ca8cf7de0e575b0175fbc3a5797b75857bd2fab Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sat, 24 Oct 2020 14:51:18 -0500 Subject: [PATCH] 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 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 40844fa1e7..8a783f1d3e 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15676,6 +15676,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 " : "", @@ -15896,6 +15903,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) -- 2.17.0 --McpcKDxJRrEJVmOH--