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 1maPvc-0001nV-Be for pgsql-general@arkaria.postgresql.org; Tue, 12 Oct 2021 22:07:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1maPvb-0000YE-8m for pgsql-general@arkaria.postgresql.org; Tue, 12 Oct 2021 22:07:19 +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 1maPva-0000Vz-Ly for pgsql-general@lists.postgresql.org; Tue, 12 Oct 2021 22:07:18 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1maPvX-0007T4-0d for pgsql-general@lists.postgresql.org; Tue, 12 Oct 2021 22:07:18 +0000 Received: by mail-ed1-x532.google.com with SMTP id z20so1701346edc.13 for ; Tue, 12 Oct 2021 15:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=yLiszVWI6FWmPPXHG4rRe8F9UZT00lp+UgtqW264VLI=; b=G0nQEeZK/p3LRIoOTSdI0uNOfUqilhYAZvxMZqXmwEqHEDhZftAHGKPhLv336+p27L UgkVN6papEDcPoCLU40G8LlGEj0pacd5UCYP81813DgHI/1w/x9qBpUn1URfObk3iOUR AW1l1hfVXqrsrfA31f2E2Ee5pBUEM6JICiEw5Ry4UDLxZO2etTRIRmuugIbig/lXk5d+ MvmVgXy+ZUZUAYyyU+jDO1sfT+5B6983noS1LVmVozu4FtNHMc3GRjWAoGW0Rdd1hCNH hNH3lzKgEUNah8FzJgxF7uRg3AnA9Mje9r41lKWM6ex19xN+/db4TemVYkLE0B9fn+4e kmFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=yLiszVWI6FWmPPXHG4rRe8F9UZT00lp+UgtqW264VLI=; b=zEp6X6MwjtEeeSEJngq9a+8aG1Jm8B3oLZiiMQ0BiL8F39EaAwQU9av1RXbf3HdGU2 tfZJ/Lvqrx0UlY1nUds3pvy2QTrp7nwROlwrdfOGMcHyZGj5RB9KDtjqiBYeMjTEZMOk K1ZghkbJi8pZwq/gK4/C5Gmd0g6L3SEI3H1178ed24742Siy6XQVFNkqKGUMSI8znn83 yIW9eIDJFTEF8lup/Ql8XLetF2QaPkjJPPeV3t1XB/Yx1WkRDhtXmG8pxqRJg5uRGYQb XnNsMKcADohLHN3cZgDonlH5Q/J65ScR8FwA07wGKdd+ZGNg/ALsVRxLINAa5+rYUyC2 Nlyg== X-Gm-Message-State: AOAM533KQWei56rwB7iY5vUo51g2jxflTvFIy1MiLkoWWPcR55GW6RUw Mx3abHJWHtusuY9bkS0ZGUQ7egSxREsfATUAC0rOtYHZkoLDUmsALzzbKiCmD1/NR80qgleDQei oEem/IYBca9l/ShPCZqaI98IsfYc484qLC5TV/Zquby1qKURqH6cLtMriWY7gwOyyJTx1kWBrP+ Ted9DaMQR98iXumSonYATP6/M/0O9bDFVa8NXgFQZv4uXNbfkaoASF X-Google-Smtp-Source: ABdhPJxLsw8DtMg7P45lARbGKjHYR5MwngePa/agMWQQAotK6uo+hARWlpqHYXYa15nDVGqsjc3lkw== X-Received: by 2002:a05:6402:14cc:: with SMTP id f12mr3655711edx.242.1634076433662; Tue, 12 Oct 2021 15:07:13 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-251-104.net.upcbroadband.cz. [86.49.251.104]) by smtp.gmail.com with ESMTPSA id o12sm6525941edw.84.2021.10.12.15.07.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Oct 2021 15:07:13 -0700 (PDT) Message-ID: <0f5ff36a-7fdb-41d2-bf0f-0219eb0a56d9@enterprisedb.com> Date: Wed, 13 Oct 2021 00:07:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: Avg/max size of these JSON docs in Postgres Content-Language: en-US To: Michael Lewis , Simon Riggs Cc: Ram Pratap Maurya , "pgsql-general@lists.postgresql.org" , Manu Saxena References: From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed 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 10/12/21 21:21, Michael Lewis wrote: > On Tue, Oct 12, 2021 at 12:51 PM Simon Riggs > > wrote: > > On Tue, 12 Oct 2021 at 18:53, Michael Lewis > wrote: > > > > On Tue, Oct 12, 2021 at 1:43 AM Simon Riggs > > > wrote: > >> > >> On Tue, 12 Oct 2021 at 08:14, Ram Pratap Maurya > >> > wrote: > >> > >> > Confirm what is Avg/max size of these JSON docs in Postgres. > >> > >> JSON and JSONB datatypes can both be max 1GB in size. > > > > That is per row. > > No, that is per column. > > > Yes, sorry. My attempt at clarification only muddled things. Each column > within each row can be up to 1GB in size is how I understand the limit. But you're kinda right, actually. It very much is per-tuple, because in various places we form tuples with all the data inline. Consider for example this: create table t (a text, b text); alter table t alter column a set storage extended; alter table t alter column b set storage extended; insert into t select repeat(md5('a'), 512*1024*1024/32), repeat(md5('b'), 512*1024*1024/32); ERROR: invalid memory alloc request size 1073741880 Clearly, both values are only 512MB (no compression). Yet it fails, simply because tts_virtual_copy_heap_tuple calls heap_form_tuple to form a tuple with all values and also the tuple header. But this succeeds, because the values are 64B shorter, leaving enough space for the tuple header etc. insert into t select repeat(md5('a'), 512*1024*1024/32 - 2), repeat(md5('b'), 512*1024*1024/32); And you can even select the data: select * from t; You can even do this: update t set a = repeat(md5('a'), 512*1024*1024/32); which works, so now you have a row with two 512MB values. But then you'll face this: select * from t; ERROR: out of memory DETAIL: Cannot enlarge string buffer containing 536870922 bytes by 536870912 more bytes. because printtup() builds a huge string with all the data (and if the columns had compression, this would be decompressed, because it goes to the client). So yeah, there's an explicit 1GB limit per value, but having rows close to the 1GB limit is going to cause all sorts of unpredictable and rather painful issues :-( regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company