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 1krmCC-0000G0-1M for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Dec 2020 18:15:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1krmC9-0001wK-Bj for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Dec 2020 18:15:37 +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 1krmC8-0001wC-VZ for pgsql-hackers@lists.postgresql.org; Tue, 22 Dec 2020 18:15:37 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1krmC5-00016x-C5 for pgsql-hackers@lists.postgresql.org; Tue, 22 Dec 2020 18:15:36 +0000 Received: by mail-ed1-x52c.google.com with SMTP id dk8so13842268edb.1 for ; Tue, 22 Dec 2020 10:15:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=QKW/6JPILRoL/gCrTI4pGrqUeFLBJ0K/bcz/ppHLgM4=; b=flfFGdybnEv2RldC5nHoh1rzbymJAdLL/Tl7PxQqbwfqD2pwFhymUTyKWUx+EUeLx0 9runQTQo7VPv3pX4E19GbdVamcdOxvj0w96hUdrlnXbjznIxe07CA5rNksOt3tjsO1Ja +dyZQbkyBYSqBdyYkS4ZZflDL7vRuzH9bfxMRY4Zw3qxBPLcagUgNiLJmGNKeOzMX2fn h6Qz13dKgPhXL+E6UMfZ4BkGboAREj9ctKv0qmLaO143I5KdCI0IvgYgwqcazFrZn0J6 jrDSJDVZCynCjXIFkyfCXm5UIXHa0RxSlGTt7wA9hBK+4SPXQB7/kPgNSEXqfHcetsMY YbEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QKW/6JPILRoL/gCrTI4pGrqUeFLBJ0K/bcz/ppHLgM4=; b=lFymNvBvCteda2UdDAhPXloM0XNV7VlL92A2/XucOCx0PnVfp006uTMz3SVVMcUsN7 lYo/xExXwee02HBK+8Y1lHWSqV8AZYxw1AccPWvqgW1AE/OEvAVtMJDbdy7QvA3gO/mS 9gUJIC1Wc4wLFuONGimrRfWLD3cdaVgzyAk/g8dtjnooIuNJ7JB1/Yw4McslH1GP8uYp AGs5uoQIb/DbYIzuynwPk73YXoGKyoXTEccpGCjLd6ZdXVUw38SobtzhvOlgTqHRIhQO hORsMhVihuXm4t6gfqgZJxVVOrTPTfVFkxRG/iOsqXB1pNfY8egrT4XZjOLX1FHKvgOc YnVw== X-Gm-Message-State: AOAM531FDlRXKKGJG0zejU+4hn7LPQV/ssTUKHmHxyIgdltZ+iCjbTFn gOGPmj+wQOIMZvS8BPLTSXXPrPrWqpwGdcGU/GZP8+kNDzv81VcwX4jER+/R56gnh2F4cEvbisq jXYpgxaS8MdXtWV37YXtvFoMI4L5aBCmCEuKFOthqUHJx/nGr48i/X/SdWZ4Ynp/aGg8hy1RzRD eppV9Raq2TBm91JYueZa6ESDuBbBJ9WhCo/bJxTVn0oWJv5RLof4+A0wzWNPgNZoiBR/jU/kmuR vr4auSQ1uflAhKi9VGO6Jo0lCpdwXPtFMxEtdOZEz1BpQ2seJRDn2Ln X-Google-Smtp-Source: ABdhPJx4sbKXakqizQ+SneKGAQZAOP0ruzjA2FX4y0R7AtZlXo7w0TIlpzNRhW6bxrUgAOMaicC6XQ== X-Received: by 2002:aa7:c886:: with SMTP id p6mr21901732eds.352.1608660931763; Tue, 22 Dec 2020 10:15:31 -0800 (PST) Received: from [10.137.0.19] (ip-86-49-249-71.net.upcbroadband.cz. [86.49.249.71]) by smtp.gmail.com with ESMTPSA id cb14sm10797575ejb.105.2020.12.22.10.15.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Dec 2020 10:15:30 -0800 (PST) Subject: Re: libpq compression To: Robert Haas , Daniil Zakhlystov Cc: Konstantin Knizhnik , Denis Smirnov , Andrey Borodin , PostgreSQL Hackers References: <612f227d-cb27-9238-5922-1500f8b2eb96@postgrespro.ru> <160623927937.7563.15974279758478581796.pgcf@coridan.postgresql.org> <6811D196-E2FB-40CC-B1C9-F19427FBF675@yandex-team.ru> <93027ee4-fefa-a8ca-2cc7-245c912bf824@postgrespro.ru> <62527092-16BD-479F-B503-FA527AF3B0C2@yandex-team.ru> From: Tomas Vondra Message-ID: Date: Tue, 22 Dec 2020 19:15:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US 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: Precedence: bulk On 12/22/20 6:56 PM, Robert Haas wrote: > On Tue, Dec 22, 2020 at 6:24 AM Daniil Zakhlystov > wrote: >> When using bidirectional compression, Postgres resource usage correlates with the selected compression level. For example, here is the Postgresql application memory usage: >> >> No compression - 1.2 GiB >> >> ZSTD >> zstd:1 - 1.4 GiB >> zstd:7 - 4.0 GiB >> zstd:13 - 17.7 GiB >> zstd:19 - 56.3 GiB >> zstd:20 - 109.8 GiB - did not succeed >> zstd:21, zstd:22 > 140 GiB >> Postgres process crashes (out of memory) > > Good grief. So, suppose we add compression and support zstd. Then, can > unprivileged user capable of connecting to the database can negotiate > for zstd level 1 and then choose to actually send data compressed at > zstd level 22, crashing the server if it doesn't have a crapton of > memory? Honestly, I wouldn't blame somebody for filing a CVE if we > allowed that sort of thing to happen. I'm not sure what the solution > is, but we can't leave a way for a malicious client to consume 140GB > of memory on the server *per connection*. I assumed decompression > memory was going to measured in kB or MB, not GB. Honestly, even at > say L7, if you've got max_connections=100 and a user who wants to make > trouble, you have a really big problem. > > Perhaps I'm being too pessimistic here, but man that's a lot of memory. > Maybe I'm just confused, but my assumption was this means there's a memory leak somewhere - that we're not resetting/freeing some piece of memory, or so. Why would zstd need so much memory? It seems like a pretty serious disadvantage, so how could it become so popular? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company