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 1kVpe8-0004xN-BN for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Oct 2020 05:29:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kVpe7-00038E-9p for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Oct 2020 05:29:47 +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 1kVpe6-000387-V7 for pgsql-hackers@lists.postgresql.org; Fri, 23 Oct 2020 05:29:47 +0000 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVpe3-0001bV-P6 for pgsql-hackers@lists.postgresql.org; Fri, 23 Oct 2020 05:29:46 +0000 Received: by mail-io1-xd43.google.com with SMTP id p7so415092ioo.6 for ; Thu, 22 Oct 2020 22:29:43 -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:mime-version:content-disposition :user-agent; bh=/evpj8ZwXyqWqH85AGQMStRlNienpJ8Dh60i5ysW1AE=; b=nzFLnapjdMRTs9VOzbwHJOAY8p3TPAXH7EwmT7IjzlMY8bBPI5s8FusLREWcUYidWD VOwJSclBvbEbgIGI00emY2UTJd3i1ItLFfZCFEZcBY2iDIFxF+eYRtnu5yFrxmM4eawr iUC5ntroag3Matiy/zftkFpBWCkAz43Dfq8P4YlfNJ4WC2UbUmKdKFjEJallGZJVHHrw I0YMwpXBJe+KYwUT97RnExKgwfOE2P1mEw1dyItWgj91zb/X51OvmOjBMVxAnJ2PK0ec bG6Q0Uy4w1vxuo0YOQOF9OIMDLVi8W+oIhBhnjpnqhYY6IT3jEuzZwu4hwfViweFXDVP BKTA== 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:mime-version :content-disposition:user-agent; bh=/evpj8ZwXyqWqH85AGQMStRlNienpJ8Dh60i5ysW1AE=; b=mZPMl4OtpHYMuQ3zUh7YrUDlFtj6tmuXI215Sg8zYV/Rpkxmp6Gz4WCkHT75yHbIkN ckXKx4eWF5qPpVUBQeUAq9u517MHPJTiEPNDSkCrNj4ZAHCbPCcC56zenLkCq4+z3gpb SaI8HHquZ67Glqr/h6qsKPjQy+C7EOrui30BOK8OQcQf8dM8mb4r53lu7ypfGKKcin+D TA2D3GTslZ0HfN0hpo9HdtExQOBEpFL4snr0ZT045OW4cRJ8aMUjF9Ka/w/e7XpRbuJT uAA6mBpY8z0Y1+0RfracbBP7YGTeyV1sUOvcJKwdd+n84hAS3M0Ib8bns3zQ29VSq5yq 65JQ== X-Gm-Message-State: AOAM531poOGJpgtzOL/2NZGzz4mQRRFRbyS7Hma5T83c3R3ouk6oj4fL qqvq+k+PaCYsWnmPcmIcdGiIXA== X-Google-Smtp-Source: ABdhPJzVdVy7rF8OnXKEzXldx8CztisUT+W/jqGwdUho7+ukSO9HR7xAvL5MFeLMgLbKlTfunddglg== X-Received: by 2002:a5e:dc4d:: with SMTP id s13mr422221iop.139.1603430982036; Thu, 22 Oct 2020 22:29:42 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id r3sm146227iog.55.2020.10.22.22.29.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2020 22:29:41 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 58F738008E3; Fri, 23 Oct 2020 00:29:40 -0500 (CDT) Date: Fri, 23 Oct 2020 00:29:40 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: David Rowley , pgsql-hackers@lists.postgresql.org Subject: pg_dump, ATTACH, and independently restorable child partitions Message-ID: <20201023052940.GE9241@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. |psql postgres -c 'DROP TABLE IF EXISTS t' -c 'CREATE TABLE t(i int) PARTITION BY RANGE(i)' -c 'CREATE TABLE t1 PARTITION OF t FOR VALUES FROM (1)TO(2)' |pg_dump postgres -Fc -t t1 >dump.t1 |psql postgres -c 'DROP TABLE t' |pg_restore -d postgres ./dump.t1 |pg_restore: while PROCESSING TOC: |pg_restore: from TOC entry 457; 1259 405311409 TABLE t1 pryzbyj |pg_restore: error: could not execute query: ERROR: relation "public.t" does not exist |Command was: CREATE TABLE public.t1 ( | i integer |); |ALTER TABLE ONLY public.t ATTACH PARTITION public.t1 FOR VALUES FROM (1) TO (2); | |pg_restore: error: could not execute query: ERROR: relation "public.t1" does not exist |Command was: ALTER TABLE public.t1 OWNER TO pryzbyj; | |pg_restore: from TOC entry 4728; 0 405311409 TABLE DATA t1 pryzbyj |pg_restore: error: could not execute query: ERROR: relation "public.t1" does not exist |Command was: COPY public.t1 (i) FROM stdin; |pg_restore: warning: errors ignored on restore: 3 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 Telsasoft does a lot of dynamic DDL, so this happens sometimes due to columns added or promoted. Up to now, when this has come up, I've run: pg_restore |grep -v 'ATTACH PARTITION' |psql. Am I missing something ? The idea of being independently restorable maybe originated with Tom's comment here: https://www.postgresql.org/message-id/30049.1555537881%40sss.pgh.pa.us -- Justin