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 1papUo-0004qb-CH for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Mar 2023 03:02:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1papUk-0007Iq-WB for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Mar 2023 03:02:06 +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 1papUk-0007Ih-KM for pgsql-hackers@lists.postgresql.org; Sat, 11 Mar 2023 03:02:06 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1papUe-0000K9-2d for pgsql-hackers@lists.postgresql.org; Sat, 11 Mar 2023 03:02:05 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 16so4133843pge.11 for ; Fri, 10 Mar 2023 19:01:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678503718; 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=o55U7XU0khyLV3bpw3F+UbaxGz3ke5Tnle2y1D6uz3Q=; b=R8FlH93w/IRJ8ASksMNO+3e0RPKyRZbh08KP0Epc3pCSvTrVgPCrI7alffBCGAV76z yS+090Jx9JgKTRq7OEx0uwZnsgNE/enaOF9gEV5IKq5GX/IyIyJVXEMlFZvSHuzG34vx rDFhQpqGdeTCA1hP+Ieb3Q9FoA2anGbih/PL7q9rJe/ZZiYkRYQ51U+EjtFbN8/QbSRU TQwRkktwAwA8jXyKvvKmKSSku9u6+J6WvmWDKI98SpVeZbKesYI0o0f7iyc79t0pqd8N GcRSj2hUgen+1O6p6jNHjQXBc6TSIT5SCWtECHTAWrdfaTdK+UyCxcdjySeEejKzhKzJ sR0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678503718; 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=o55U7XU0khyLV3bpw3F+UbaxGz3ke5Tnle2y1D6uz3Q=; b=18gBg+KafWiKMalCe2MzCBlGyQkCy4W7Z8TPk2Ax2Atsw9HwsagpGr2ejvS5q36IvP fDMTgMrX2Q1aVXe5D7lKChymx0GIwjJ1iNg6ytMK71QskIXLgDZOQ3W5c++Qi6EnVkKt oyjNEUqFm8sUj9XsLAQ6m4zukMdAQ4zf6ao/7z07ixYS1aLfPtt3qdHtk7UvIAFiFCyU ME35Hjn2vw7xjorQTJ/7TxkvALU9Fy3ES78iuGUvd3vkPjFBjEWVUobBRWBaX6HIck0W DUsIaLV3/sfc63oKaz9Lkop8IR+erlXyHYjgdNK9ATC37Hh8718kF7cx4XPzmPY8+H+w Qh3w== X-Gm-Message-State: AO0yUKXrw213OwMfNSh7L6mIdvz4Pnt1iYwh748Zr1bOsQCiUOdwvwyt dPmF8GQYR8+7DGDg4PQWorM= X-Google-Smtp-Source: AK7set8S6oT+lVetqUV/rEGm1mMrzxWo7FoSYD/Z0MBqv4Ff37l2mi9Jpv6l7wM2THBEHah44E/pWA== X-Received: by 2002:a05:6a00:10d3:b0:622:6cc8:2393 with SMTP id d19-20020a056a0010d300b006226cc82393mr374189pfu.5.1678503718335; Fri, 10 Mar 2023 19:01:58 -0800 (PST) Received: from jrouhaud (2001-b011-1005-7577-f429-b80e-6535-5d13.dynamic-ip6.hinet.net. [2001:b011:1005:7577:f429:b80e:6535:5d13]) by smtp.gmail.com with ESMTPSA id e26-20020aa7825a000000b005d296facfa3sm476172pfn.36.2023.03.10.19.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 19:01:57 -0800 (PST) Date: Sat, 11 Mar 2023 11:01:54 +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: <20230311030154.pg63uspio35h4a6t@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1912821.1676402493@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Feb 14, 2023 at 02:21:33PM -0500, Tom Lane wrote: > Here's a set of draft patches around this issue. > > 0001 does what I last suggested, ie force load-via-partition-root for > leaf tables underneath a partitioned table with a partitioned-by-hash > enum column. It wasn't quite as messy as I first feared, although we do > need a new query (and pg_dump now knows more about pg_partitioned_table > than it used to). > > I was a bit unhappy to read this in the documentation: > > It is best not to use parallelism when restoring from an archive made > with this option, because pg_restore will > not know exactly which partition(s) a given archive data item will > load data into. This could result in inefficiency due to lock > conflicts between parallel jobs, or perhaps even restore failures due > to foreign key constraints being set up before all the relevant data > is loaded. > > This made me wonder if this could be a usable solution at all, but > after thinking for awhile, I don't see how the claim about foreign key > constraints is anything but FUD. pg_dump/pg_restore have sufficient > dependency logic to prevent that from happening. I think we can just > drop the "or perhaps ..." clause here, and tolerate the possible > inefficiency as better than failing. Working on some side project that can cause dump of hash partitions to be routed to a different partition, I realized that --load-via-partition-root can indeed cause deadlock in such case without FK dependency or anything else. The problem is that each worker will perform a TRUNCATE TABLE ONLY followed by a copy of the original partition's data in a transaction, and that obviously will lead to deadlock if the original and locked partition and the restored partition are different.