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 1pXPUn-0000Fh-Fg for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Mar 2023 16:40:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pXPUm-0005dq-8c for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Mar 2023 16:40:00 +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 1pXPUl-0005dg-V1 for pgsql-hackers@lists.postgresql.org; Wed, 01 Mar 2023 16:39:59 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pXPUj-0003OS-0s for pgsql-hackers@lists.postgresql.org; Wed, 01 Mar 2023 16:39:59 +0000 Received: by mail-wr1-x42b.google.com with SMTP id v16so11082154wrn.0 for ; Wed, 01 Mar 2023 08:39:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; 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=wIzTVd/gBcIs5u3Nckc7LCUAFcl+JZvesTEvDv53DnI=; b=k9tHv4ynmTe3j2dCWKbMYAn4S6zrhSLNcpkR0zhjkrDOIVySOHiCx0ypuow5j8gW2i QkhLW+N3dfKkHyJNTTrdx2qEl+6TDebzRWdNG7SPn/uENNJl9OTFCDFkUYFL5LVT5Byn 4FaAI7cRWRuc4vWcjNgqkkiENiboUVrWMdGvAsNKTR+Lq+z6qoBkXyS8rmRLSsX26lCW xM1BDHqkZEbVCfzCRyUE9HLpqi4SFLwmn5jXERCCfExIOaUPSoWw9ALetQw6s1zujdED WWF5Js6njaifsul074CS4YX7SSTjmzKn/7iFKQVLNjjKUf+2iZ+ZN9FQEKNgxPUXYuQ2 h2tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=wIzTVd/gBcIs5u3Nckc7LCUAFcl+JZvesTEvDv53DnI=; b=JbMvSKYJbLR0yItUXmVdeoGYQK1+naglWXfsKi6VenAOkMoEWuEX1VKF3DK4JmePRs tz64aK2XUkWCNxsQG9dQlsW5q4yqpw8Mo5xZQK7zMNlAK4jS/DLhPE4K6hls6Xm6k8fr FnU3vbM/ETG3xfzYxZc4nwiigJiUwqkmWVshLdw7K77L+8zZAt6IqxoqKDz6qTroN4df rJkKKcm1EJeMukJQdFDzr3/5P9ldHEvW2NzWhmVUfPua0qVjZfVTtPGhuSbRRM/XL7Xb l4rMt8Swla+28LOidaM4LAneoksKVwdEYwXP1tDUhLHcWoaVgUFFRuAkIQmT4fwek/pl HRSw== X-Gm-Message-State: AO0yUKXMNiqo/249q2ldtOSC2yqaukhQ1G4TCpPmod5T6Ei2M+4PMQ5S YP8qM/jaPmhC2oOowZ2mJa9fc3xHNTUjDPhmlaA+B+8hzweFh91a6C5Pw8DC/zCnPu9YIdFHxG3 te/kQ3l9E8iMJvWqoDjGfJhtmi5zfRHuzpQEg4ln417kKDBKBxkh9fHcKH43h5Ya4Kys51it8Hw Ph81Yp7bMvOa4zmZfHfLv77WlfacaSfol/aEqKiKa+RL2ZPpIsaiSN X-Google-Smtp-Source: AK7set+wPL2VBIMl4PDEl8xKOqMTVpOINVAzUIokY7G822IFj5B6Q3x2ey8DECuh4Qm2E+yxzyRY3g== X-Received: by 2002:a5d:5967:0:b0:2c7:17db:bf5c with SMTP id e39-20020a5d5967000000b002c717dbbf5cmr5294140wri.25.1677688795521; Wed, 01 Mar 2023 08:39:55 -0800 (PST) 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 l8-20020adff488000000b002c557f82e27sm13182296wro.99.2023.03.01.08.39.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Mar 2023 08:39:55 -0800 (PST) Message-ID: <09b37949-cfe5-29bb-cbb1-498ee5700b61@enterprisedb.com> Date: Wed, 1 Mar 2023 17:39:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: Add LZ4 compression in pg_dump Content-Language: en-US To: Justin Pryzby , gkokolatos@pm.me Cc: Michael Paquier , shiy.fnst@fujitsu.com, pgsql-hackers@lists.postgresql.org, Rachel Heaton References: <535565cd-b69f-c064-a845-15c0fc44db4a@enterprisedb.com> <22cb80ed-ec87-54c7-fd5b-cdcf79766bb1@enterprisedb.com> <8421f53d-c9f7-c02e-3278-9f9522a8e8f3@enterprisedb.com> <20230224015115.GS1653@telsasoft.com> <20230225050214.GH1653@telsasoft.com> <20230225140553.GI1653@telsasoft.com> <20230227044910.GO1653@telsasoft.com> From: Tomas Vondra In-Reply-To: <20230227044910.GO1653@telsasoft.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 2/27/23 05:49, Justin Pryzby wrote: > On Sat, Feb 25, 2023 at 08:05:53AM -0600, Justin Pryzby wrote: >> On Fri, Feb 24, 2023 at 11:02:14PM -0600, Justin Pryzby wrote: >>> I have some fixes (attached) and questions while polishing the patch for >>> zstd compression. The fixes are small and could be integrated with the >>> patch for zstd, but could be applied independently. >> >> One more - WriteDataToArchiveGzip() says: > > One more again. > > The LZ4 path is using non-streaming mode, which compresses each block > without persistent state, giving poor compression for -Fc compared with > -Fp. If the data is highly compressible, the difference can be orders > of magnitude. > > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -Z lz4 -Fp |wc -c > 12351763 > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -Z lz4 -Fc |wc -c > 21890708 > > That's not true for gzip: > > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -t t1 -Z gzip -Fc |wc -c > 2118869 > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -t t1 -Z gzip -Fp |wc -c > 2115832 > > The function ought to at least use streaming mode, so each block/row > isn't compressioned in isolation. 003 is a simple patch to use > streaming mode, which improves the -Fc case: > > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -Z lz4 -Fc |wc -c > 15178283 > > However, that still flushes the compression buffer, writing a block > header, for every row. With a single-column table, pg_dump -Fc -Z lz4 > still outputs ~10% *more* data than with no compression at all. And > that's for compressible data. > > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -t t1 -Fc -Z lz4 |wc -c > 12890296 > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -t t1 -Fc -Z none |wc -c > 11890296 > > I think this should use the LZ4F API with frames, which are buffered to > avoid outputting a header for every single row. The LZ4F format isn't > compatible with the LZ4 format, so (unlike changing to the streaming > API) that's not something we can change in a bugfix release. I consider > this an Opened Item. > > With the LZ4F API in 004, -Fp and -Fc are essentially the same size > (like gzip). (Oh, and the output is three times smaller, too.) > > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -t t1 -Z lz4 -Fp |wc -c > 4155448 > $ ./src/bin/pg_dump/pg_dump -h /tmp postgres -t t1 -Z lz4 -Fc |wc -c > 4156548 > Thanks. Those are definitely interesting improvements/optimizations! I suggest we track them as a separate patch series - please add them to the CF app (I guess you'll have to add them to 2023-07 at this point, but we can get them in, I think). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company