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 1phC6h-0002AX-2O for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Mar 2023 16:23:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1phC6f-0005xg-Lh for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Mar 2023 16:23:33 +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 1phC6f-0005xX-Ak for pgsql-hackers@lists.postgresql.org; Tue, 28 Mar 2023 16:23:33 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1phC6c-0000KL-Nm for pgsql-hackers@postgresql.org; Tue, 28 Mar 2023 16:23:32 +0000 Received: by mail-wm1-x32d.google.com with SMTP id m6-20020a05600c3b0600b003ee6e324b19so7911768wms.1 for ; Tue, 28 Mar 2023 09:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1680020609; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=MPUoM6oBGZcsNGzqV9kZzaBIxDOfqjbNl1a9cxi5/EM=; b=Rf6NlubGq3lwP+MX6eTeG0uj5U+FH196wR1Cw6i8CZVEp4apMDMRB+3YBmxCjxFUsC 0RXrHrDt1IvaVtUIAZxEEit1V2CK8EU5Iz9m9iUufD82WqOYnq1P1jNJ0Z9QPzWhdikU R3pEcyR6D1dbiPZk8zGZaYXNSCNpDjh4LPcAnBnTaKZrNnT/+xZKEN/g5D8ZxHGR5xgD /WRbblZHU2wXbrZkk+8Rir0vIit+5LLX0geUcswZKX7CMsoCyyicZ7bEhNUBqROmWHqz wkPhUaVTAV613fImpk25Zb37KdGE4ba/AmGHeoiOJaUHER/YiVBsTbNrwC/jZJEJp5e0 8YyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680020609; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MPUoM6oBGZcsNGzqV9kZzaBIxDOfqjbNl1a9cxi5/EM=; b=KuEe1PvXrPaofsPs9xm6mYD7GREt3SEfOmvdkwGwSo8GUcVKGpf+rL39IKDNlsSn7X wIEBqkacOigsMZ09NGowPagEiPyXXGx5uk4/L3Z/miBB/DdbDTqP0ttyA4YKGsvEv7ww gfCdKtoqF6BB3pPqgByB9tMgG8D9Y7oGJH2mi90LNAFAOwE3kJSL2CA9EuR2Z9OQwO2y DqMb7WYARqaiwIzi0GV6NE1YhNGF74LHzS2N4Ccyr3wGQLmadNHPNORbM4HCRZGnzXsY Zk10U8CGJSn57g3JdbO8GxegQlKI7hSRgSFoWPkZZrjm0C92su5dEztGtZAz+yDxcaBZ L10g== X-Gm-Message-State: AO0yUKX7fnjVcNFrSKjxNJlJzSap72pRyJ2q9zf1KZg5x37JRj6KBn9q m4/l5E2oizKGjBPIi9n0P/j2pm0NCWPOh3G5aRkI3jnDnCl/SwcNMgJV+kQ1452CfdWiiOl4KAV vRBYMX9XISiYCUmYqfAHW5qriOlrZdIeyXcOK365RlgXJWu3CZM8QKjDCWSLEWeipfI+yXFhGZc r15xlHLn2hicrhJvFKiXxcva45g8l5ckZsW+Q2 X-Google-Smtp-Source: AK7set9WYOMo1q2VfXtraIWq7tPCWlVNYjhe+vopZX+9kZ8drnZ7WrIgYwXzQ3JjINBcu+NJlyeJmg== X-Received: by 2002:a1c:7c10:0:b0:3ee:289a:3c3a with SMTP id x16-20020a1c7c10000000b003ee289a3c3amr12385545wmc.30.1680020609494; Tue, 28 Mar 2023 09:23:29 -0700 (PDT) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id l32-20020a05600c1d2000b003ed29189777sm12976445wms.47.2023.03.28.09.23.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Mar 2023 09:23:28 -0700 (PDT) Message-ID: <0022dd9e-a439-d72f-d09b-ec512c23949b@enterprisedb.com> Date: Tue, 28 Mar 2023 18:23:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: zstd compression for pg_dump Content-Language: en-US To: Justin Pryzby Cc: Jacob Champion , pgsql-hackers@postgresql.org, gkokolatos@pm.me, Michael Paquier , Robert Haas , Peter Geoghegan , Peter Eisentraut , Heikki Linnakangas , Thomas Munro , Dipesh Pandit , Andrey Borodin , Mark Dilger References: <20230224191840.GD1653@telsasoft.com> <20230226012227.GK1653@telsasoft.com> <20230303185546.GE12850@telsasoft.com> <20230304165747.GH12850@telsasoft.com> <3d04afca-7d9d-c90f-5fef-5cf4fdb2173f@timescale.com> <0115b682-58f0-ea43-9ecd-c37a4495812e@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/27/23 19:28, Justin Pryzby wrote: > On Fri, Mar 17, 2023 at 03:43:31AM +0100, Tomas Vondra wrote: >> On 3/16/23 05:50, Justin Pryzby wrote: >>> On Fri, Mar 10, 2023 at 12:48:13PM -0800, Jacob Champion wrote: >>>> On Wed, Mar 8, 2023 at 10:59 AM Jacob Champion wrote: >>>>> I did some smoke testing against zstd's GitHub release on Windows. To >>>>> build against it, I had to construct an import library, and put that >>>>> and the DLL into the `lib` folder expected by the MSVC scripts... >>>>> which makes me wonder if I've chosen a harder way than necessary? >>>> >>>> It looks like pg_dump's meson.build is missing dependencies on zstd >>>> (meson couldn't find the headers in the subproject without them). >>> >>> I saw that this was added for LZ4, but I hadn't added it for zstd since >>> I didn't run into an issue without it. Could you check that what I've >>> added works for your case ? >>> >>>>> Parallel zstd dumps seem to work as expected, in that the resulting >>>>> pg_restore output is identical to uncompressed dumps and nothing >>>>> explodes. I haven't inspected the threading implementation for safety >>>>> yet, as you mentioned. >>>> >>>> Hm. Best I can tell, the CloneArchive() machinery is supposed to be >>>> handling safety for this, by isolating each thread's state. I don't feel >>>> comfortable pronouncing this new addition safe or not, because I'm not >>>> sure I understand what the comments in the format-specific _Clone() >>>> callbacks are saying yet. >>> >>> My line of reasoning for unix is that pg_dump forks before any calls to >>> zstd. Nothing zstd does ought to affect the pg_dump layer. But that >>> doesn't apply to pg_dump under windows. This is an opened question. If >>> there's no solid answer, I could disable/ignore the option (maybe only >>> under windows). >> >> I may be missing something, but why would the patch affect this? Why >> would it even affect safety of the parallel dump? And I don't see any >> changes to the clone stuff ... > > zstd supports using threads during compression, with -Z zstd:workers=N. > When unix forks, the child processes can't do anything to mess up the > state of the parent processes. > > But windows pg_dump uses threads instead of forking, so it seems > possible that the pg_dump -j threads that then spawn zstd threads could > "leak threads" and break the main thread. I suspect there's no issue, > but we still ought to verify that before declaring it safe. > OK. I don't have access to a Windows machine so I can't test that. Is it possible to disable the zstd threading, until we figure this out? >>> The function is first checking if it was passed a filename which already >>> has a suffix. And if not, it searches through a list of suffixes, >>> testing for an existing file with each suffix. The search with stat() >>> doesn't happen if it has a suffix. I'm having trouble seeing how the >>> hasSuffix() branch isn't dead code. Another opened question. >> >> AFAICS it's done this way because of this comment in pg_backup_directory >> >> * ... >> * ".gz" suffix is added to the filenames. The TOC files are never >> * compressed by pg_dump, however they are accepted with the .gz suffix >> * too, in case the user has manually compressed them with 'gzip'. >> >> I haven't tried, but I believe that if you manually compress the >> directory, it may hit this branch. > > That would make sense, but when I tried, it didn't work like that. > The filenames were all uncompressed names. Maybe it worked differently > in an older release. Or maybe it changed during development of the > parallel-directory-dump patch and it's actually dead code. > Interesting. Would be good to find out. I wonder if a little bit of git-log digging could tell us more. Anyway, until we confirm it's dead code, we should probably do what .gz does and have the same check for .lz4 and .zst files. > This is rebased over the updated compression API. > > It seems like I misunderstood something you said before, so now I put > back "supports_compression()". > Thanks! I need to do a bit more testing and review, but it seems pretty much RFC to me, assuming we can figure out what to do about threading. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company