From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Michael Lewis <mlewis@entrata.com>
To: Simon Riggs <simon.riggs@enterprisedb.com>
Cc: Ram Pratap Maurya <ram.maurya@lavainternational.in>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Cc: Manu Saxena <manu.saxena@lavainternational.in>
Subject: Re: Avg/max size of these JSON docs in Postgres
Date: Wed, 13 Oct 2021 00:07:11 +0200
Message-ID: <0f5ff36a-7fdb-41d2-bf0f-0219eb0a56d9@enterprisedb.com> (raw)
In-Reply-To: <CAHOFxGo1MBesgpz_ooyoCjdkWHd9ZvemZ4r5=WeOg7VFTg_ACw@mail.gmail.com>
References: <KL1PR0601MB4433DFB74306A5F18BBB069FF0B69@KL1PR0601MB4433.apcprd06.prod.outlook.com>
<CANbhV-HQ+JpxhN8QrVbLBM3cUdzur43PFtvXSBCR3aLXjCQxWQ@mail.gmail.com>
<CAHOFxGobn9REnhU0dd=yRvPQ5a_qj97GRr1vxCOdafOfUTjd+A@mail.gmail.com>
<CANbhV-ESaegZ0dgWRWS6bd_E-GWZOmcV_YCo85F802cUoz-rDg@mail.gmail.com>
<CAHOFxGo1MBesgpz_ooyoCjdkWHd9ZvemZ4r5=WeOg7VFTg_ACw@mail.gmail.com>
On 10/12/21 21:21, Michael Lewis wrote:
> On Tue, Oct 12, 2021 at 12:51 PM Simon Riggs
> <simon.riggs@enterprisedb.com <mailto:simon.riggs@enterprisedb.com>> wrote:
>
> On Tue, 12 Oct 2021 at 18:53, Michael Lewis <mlewis@entrata.com
> <mailto:mlewis@entrata.com>> wrote:
> >
> > On Tue, Oct 12, 2021 at 1:43 AM Simon Riggs
> <simon.riggs@enterprisedb.com <mailto:simon.riggs@enterprisedb.com>>
> wrote:
> >>
> >> On Tue, 12 Oct 2021 at 08:14, Ram Pratap Maurya
> >> <ram.maurya@lavainternational.in
> <mailto:ram.maurya@lavainternational.in>> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tomas.vondra@enterprisedb.com, mlewis@entrata.com, simon.riggs@enterprisedb.com, ram.maurya@lavainternational.in, manu.saxena@lavainternational.in
Subject: Re: Avg/max size of these JSON docs in Postgres
In-Reply-To: <0f5ff36a-7fdb-41d2-bf0f-0219eb0a56d9@enterprisedb.com>
References: <KL1PR0601MB4433DFB74306A5F18BBB069FF0B69@KL1PR0601MB4433.apcprd06.prod.outlook.com> <CANbhV-HQ+JpxhN8QrVbLBM3cUdzur43PFtvXSBCR3aLXjCQxWQ@mail.gmail.com> <CAHOFxGobn9REnhU0dd=yRvPQ5a_qj97GRr1vxCOdafOfUTjd+A@mail.gmail.com> <CANbhV-ESaegZ0dgWRWS6bd_E-GWZOmcV_YCo85F802cUoz-rDg@mail.gmail.com> <CAHOFxGo1MBesgpz_ooyoCjdkWHd9ZvemZ4r5=WeOg7VFTg_ACw@mail.gmail.com> <0f5ff36a-7fdb-41d2-bf0f-0219eb0a56d9@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox