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 1pbdcZ-0002o4-AC for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Mar 2023 08:33:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pbdcW-0004YT-SJ for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Mar 2023 08:33:28 +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 1pbdcW-0004YK-Gc for pgsql-hackers@lists.postgresql.org; Mon, 13 Mar 2023 08:33:28 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pbdcR-0004Il-7e for pgsql-hackers@lists.postgresql.org; Mon, 13 Mar 2023 08:33:27 +0000 Received: by mail-pj1-x1035.google.com with SMTP id fy10-20020a17090b020a00b0023b4bcf0727so3386630pjb.0 for ; Mon, 13 Mar 2023 01:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678696401; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=celxd6r0jhKRhvvTdfStjemoFPNyvB4Q3qtO6tqce7Y=; b=VaNioM7c/gwhTn+X7SPnGwWAyhrtaRNsKn4Tq68KzWbwcz7ItoZF3xufiDe2lg3wjf bbRRVpECzvx4ZXLS6V1MPO56xWZa2iTHPgaisSZn2KbOp0HjfBVpRjz+K1HDIfKP7kkg A0buQAGDaAix8RTtBmgQSMfqvR7UT7pP2nhZLkewcgQaTJ1YA5F/Ozvgke54Dn0vFJkK bi4WqH7ItJzO2TCiqnosNuWfI9Us882CVnlCKKLDeQfHcD9AgrfPoyyDVSr8iqTb0rGc KXebxV0wVn/SGGppTnJjOuGzRYEc4aTCx89b0F9t57RRHGpWo1nm2zOJqoDEqBKoxNv7 urtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678696401; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=celxd6r0jhKRhvvTdfStjemoFPNyvB4Q3qtO6tqce7Y=; b=SfRZR9kh74de10RWC0whdQ6gUnnPYr9effurziHNEo+BQygaRCeAWr2nhucTXb4RuS YNlppAa/XFm4lK63Bsax4nttkSt8TyCP6OHoUMZhdQde0h2CMWfVqXHj0YyxzStnK3v7 scwKs0fNvCMFcKFs7zd/ys2jUq/zi4T84Bfu9gXgIj7+ZLA7Z3GmP78ffZ9/7QwliFny olDhJtX8ifhAlEv3x+CJjnHM2MJi5B8r7hY13PrvEdOR3WpTPZ7jdvHPZTI8rzO0rnK9 X3RgY6PdTtNU9BTpjGW3D+yC0vsMaueDSHx/F0RzRkQQ6YYwRLeoLqmRzxPtCTgsiTfg uixw== X-Gm-Message-State: AO0yUKVsjzPwSWK35VRKCus9Vi4i5iJhsVtlDZhmlAU12bIMPjHeIVLi 6TC2Uc1gKc9e0q2pXNl4MeY= X-Google-Smtp-Source: AK7set/+SYZIencdcQYV/677CDBqpiGL2EFkzkEZ4e27eP4ayl7Adf+HY5/pNSlxzbTnLEclI8xyvg== X-Received: by 2002:a05:6a20:3ca4:b0:d4:a1a7:715 with SMTP id b36-20020a056a203ca400b000d4a1a70715mr1679360pzj.47.1678696400743; Mon, 13 Mar 2023 01:33:20 -0700 (PDT) Received: from jrouhaud (2001-b011-1005-7577-65b8-f05f-2a60-b72a.dynamic-ip6.hinet.net. [2001:b011:1005:7577:65b8:f05f:2a60:b72a]) by smtp.gmail.com with ESMTPSA id a4-20020a630b44000000b004fb95c8f63esm3809099pgl.44.2023.03.13.01.33.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 01:33:20 -0700 (PDT) Date: Mon, 13 Mar 2023 16:33:14 +0800 From: Julien Rouhaud To: Tom Lane Cc: Andrew Dunstan , Alvaro Herrera , David Rowley , Peter Geoghegan , Robert Haas , pgsql-hackers@lists.postgresql.org, Andrew Subject: Re: pg_dump versus hash partitioning Message-ID: <20230313083314.pivmgfu36fi4eu2n@jrouhaud> References: <1425446.1675291093@sss.pgh.pa.us> <1440373.1675299790@sss.pgh.pa.us> <1533086.1675349554@sss.pgh.pa.us> <1912821.1676402493@sss.pgh.pa.us> <20230311030154.pg63uspio35h4a6t@jrouhaud> <1078804.1678504214@sss.pgh.pa.us> <20230311033232.g6jgkuzxdawepsbe@jrouhaud> <1602203.1678650412@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1602203.1678650412@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Mar 12, 2023 at 03:46:52PM -0400, Tom Lane wrote: > Julien Rouhaud writes: > > The BEGIN + TRUNCATE is only there to avoid generating WAL records just in case > > the wal_level is minimal. I don't remember if that optimization still exists, > > but if yes we could avoid doing that if the server's wal_level is replica or > > higher? That's not perfect but it would help in many cases. > > After thinking about this, it seems like a better idea is to skip the > TRUNCATE if we're doing load-via-partition-root. In that case it's > clearly a dangerous thing to do regardless of deadlock worries, since > it risks discarding previously-loaded data that came over from another > partition. (IOW this seems like an independent, pre-existing bug in > load-via-partition-root mode.) It's seems quite unlikely to be able to actually truncate already restored data without eventually going into a deadlock, but it's still possible so agreed. > The trick is to detect in pg_restore whether pg_dump chose to do > load-via-partition-root. If we have a COPY statement we can fairly > easily examine it to see if the target table is what we expect or > something else. However, if the table was dumped as INSERT statements > it'd be far messier; the INSERTs are not readily accessible from the > code that needs to make the decision. > > What I propose we do about that is further tweak things so that > load-via-partition-root forces dumping via COPY. AFAIK the only > compelling use-case for dump-as-INSERTs is in transferring data > to a non-Postgres database, which is a context in which dumping > partitioned tables as such is pretty hopeless anyway. It seems acceptable to me. > (I wonder if > we should have some way to dump all the contents of a partitioned > table as if it were unpartitioned, to support such migration.) (this would be nice to have) > An alternative could be to extend the archive TOC format to record > directly whether a given TABLE DATA object loads data via partition > root or normally. Potentially we could do that without an archive > format break by defining te->defn for TABLE DATA to be empty for > normal dumps (as it is now) or something like "-- load via partition root" > for the load-via-partition-root case. However, depending on examination > of the COPY command would already work for the vast majority of existing > archive files, so I feel like it might be the preferable choice. Given that this approach wouldn't help with existing dump files (at least if using COPY, in any case the one using INSERT are doomed), so I'm slightly in favor of the first approach, and later add an easy and non magic incantation way to produce dumps that don't depend on partitioning. It would mean that you would only be able to produce such dumps using pg16 client binaries, but such version would also work with older server versions so it doesn't seem like a huge problem in the long run.