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 1krmmu-0001Ps-O1 for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Dec 2020 18:53:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1krmmt-0001G1-KP for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Dec 2020 18:53:35 +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 1krmmt-0001Fu-Db for pgsql-hackers@lists.postgresql.org; Tue, 22 Dec 2020 18:53:35 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1krmmo-0006LO-9W for pgsql-hackers@lists.postgresql.org; Tue, 22 Dec 2020 18:53:34 +0000 Received: by mail-ej1-x630.google.com with SMTP id ga15so19621165ejb.4 for ; Tue, 22 Dec 2020 10:53:29 -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=WrwSQA+T6ZogJihugUQprZ98LgSuCKCLHDDyySRMp0c=; b=Mn8i9aQHGTWe5T913xsIv10oSZ60LI5G5DRNuKmzQiZmK21ZzG9KCOTXAWPmpu8NPB WR9vuiP2MyQp8xPTOftZ4yjqtLmP6eM3/P89IN3PeBaEDufPajsWVoNYNXQkwOasLJaJ XE2YIHSOskKiu8JIY3AYWSsNrdhrRUF8pDlaPdkMS2OOQdkGLKz6omw9Po47S3mzjco5 iht4n4RLNUG1rsg50gb/aNPtquOhdw/Owztxhc5N3IPEoSxDKUCsBjaweBNjPXyeVIiG TGyaC/cyq8cZrKvOfmyd3yTqxKLK47rZyXgA8L65g2mLbsHRIg+xedmtkHtsmPaSNccR e3Jg== 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=WrwSQA+T6ZogJihugUQprZ98LgSuCKCLHDDyySRMp0c=; b=W6LQciH4I9oQvl5NWyeqEALrVPndKyVS842dg6IhwYm9sUDj4OIXoK1KB4w3ZGOD8i 5+xtyI119W0v673tK1PSUFVMis7OoC9mHPrAgTmyvcuHlvQug7h9WNmMcZA9OPjBahXD t09w/EmemB5dqprdFnDjhw5J2IKMVjFYgNV4tGz4Wl4iJCS1+c7Llp7EF5KQ50SMk7r/ 4DvPM0+0o5Ig2pIWeZQ/fAki1E3PStashttPi0hYdqOSj/ZPZcfB9ESwlxK9oqXCa8yg q1z9nPaD3AIXJMfNoiq2fH2UwFn6Pcq7X8C8W+T8VMRV7EPjgy+0WUjx7ZQ2vEJAtaFj O99w== X-Gm-Message-State: AOAM532fgTMSiIGdb3tXA1gMettrLIXQyeqDZI7LVWap8VbCx81l/1cH gmdOvuX1paeI9bg7psc4S0eXEZ7PlyUh6oJABu0T3rwU4hQyim24B5hjo4oNY2t8d/Gh7CkPMUD C2ocsKIv9YtYFtr1dwy2h2ZzEA/70a4xxO4zkRT3hunmS+FBaUGvzujZFg4uoR6KZtouOs7qEe3 8niIgZ37GZ2k/8o8qjvdpiGiWaIDCH/52us7dRJPcaSeSU5MScasBYmD9h2XQIv7PZxwYPQm0oR sWwVsKUlRGoyHfRTB5Rv/xaAeu77uEJ0gePYUfgwAawI5dAdQQbX9IW X-Google-Smtp-Source: ABdhPJyUFgbIX9TqrtAFNfgl9UPXL3MrV9YC0NUz7gWzHcK3B17yPgyjKlvL7VQ2iYVZYKE6Lql5bg== X-Received: by 2002:a17:906:1955:: with SMTP id b21mr21001010eje.236.1608663207468; Tue, 22 Dec 2020 10:53:27 -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 i15sm10809960ejj.28.2020.12.22.10.53.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Dec 2020 10:53:26 -0800 (PST) Subject: Re: libpq compression To: Andrey Borodin Cc: Robert Haas , Daniil Zakhlystov , Konstantin Knizhnik , Denis Smirnov , 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: <579f308e-c46c-2e79-3f90-9846450a3d71@enterprisedb.com> Date: Tue, 22 Dec 2020 19:53:17 +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: 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: Precedence: bulk On 12/22/20 7:31 PM, Andrey Borodin wrote: > > >> 22 дек. 2020 г., в 23:15, Tomas Vondra написал(а): >> >> >> >> 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? > > AFAIK it's 700 clients. Does not seem like super high price for big traffic\latency reduction. > I don't see aby benchmark results in this thread, allowing me to make that conclusion, and I find it hard to believe that 200MB/client is a sensible trade-off. It assumes you have that much memory, and it may allow easy DoS attack (although maybe it's not worse than e.g. generating a lot of I/O or running expensive function). Maybe allowing limiting the compression level / decompression buffer size in postgresql.conf would be enough. Or maybe allow disabling such compression algorithms altogether. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company