pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Avg/max size of these JSON docs in Postgres
8+ messages / 5 participants
[nested] [flat]

* Avg/max size of these JSON docs in Postgres
@ 2021-10-12 06:42  Ram Pratap Maurya <ram.maurya@lavainternational.in>
  0 siblings, 1 reply; 8+ messages in thread

From: Ram Pratap Maurya @ 2021-10-12 06:42 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; +Cc: Manu Saxena <manu.saxena@lavainternational.in>

Hi Team,

Confirm what is Avg/max size of these JSON docs in Postgres.



Regards,
Ram Pratap.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Avg/max size of these JSON docs in Postgres
@ 2021-10-12 07:43  Simon Riggs <simon.riggs@enterprisedb.com>
  parent: Ram Pratap Maurya <ram.maurya@lavainternational.in>
  0 siblings, 1 reply; 8+ messages in thread

From: Simon Riggs @ 2021-10-12 07:43 UTC (permalink / raw)
  To: Ram Pratap Maurya <ram.maurya@lavainternational.in>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; Manu Saxena <manu.saxena@lavainternational.in>

On Tue, 12 Oct 2021 at 08:14, Ram Pratap Maurya
<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.

-- 
Simon Riggs                http://www.EnterpriseDB.com/





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Avg/max size of these JSON docs in Postgres
@ 2021-10-12 17:53  Michael Lewis <mlewis@entrata.com>
  parent: Simon Riggs <simon.riggs@enterprisedb.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Michael Lewis @ 2021-10-12 17:53 UTC (permalink / raw)
  To: Simon Riggs <simon.riggs@enterprisedb.com>; +Cc: Ram Pratap Maurya <ram.maurya@lavainternational.in>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; Manu Saxena <manu.saxena@lavainternational.in>

On Tue, Oct 12, 2021 at 1:43 AM Simon Riggs <simon.riggs@enterprisedb.com>
wrote:

> On Tue, 12 Oct 2021 at 08:14, Ram Pratap Maurya
> <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.

Just to confirm- The compression associated with TOAST is only if the value
can fit in line, right? Columns don't get stored out-of-line in a toast
table as a compressed value as I read the documentation. I suppose that
would make reads a bit crazy.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Avg/max size of these JSON docs in Postgres
@ 2021-10-12 18:14  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Michael Lewis <mlewis@entrata.com>
  1 sibling, 0 replies; 8+ messages in thread

From: Tom Lane @ 2021-10-12 18:14 UTC (permalink / raw)
  To: Michael Lewis <mlewis@entrata.com>; +Cc: Simon Riggs <simon.riggs@enterprisedb.com>; Ram Pratap Maurya <ram.maurya@lavainternational.in>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; Manu Saxena <manu.saxena@lavainternational.in>

Michael Lewis <mlewis@entrata.com> writes:
> Just to confirm- The compression associated with TOAST is only if the value
> can fit in line, right? Columns don't get stored out-of-line in a toast
> table as a compressed value as I read the documentation. I suppose that
> would make reads a bit crazy.

The default behavior is first to compress any large field value(s),
and then if the row is still too big, push them out-of-line in
compressed form.  You can modify that strategy on a per-column
basis if need be, but I've seldom heard good reasons to.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Avg/max size of these JSON docs in Postgres
@ 2021-10-12 18:51  Simon Riggs <simon.riggs@enterprisedb.com>
  parent: Michael Lewis <mlewis@entrata.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Simon Riggs @ 2021-10-12 18:51 UTC (permalink / raw)
  To: Michael Lewis <mlewis@entrata.com>; +Cc: Ram Pratap Maurya <ram.maurya@lavainternational.in>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; Manu Saxena <manu.saxena@lavainternational.in>

On Tue, 12 Oct 2021 at 18:53, Michael Lewis <mlewis@entrata.com> wrote:
>
> On Tue, Oct 12, 2021 at 1:43 AM Simon Riggs <simon.riggs@enterprisedb.com> wrote:
>>
>> On Tue, 12 Oct 2021 at 08:14, Ram Pratap Maurya
>> <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.

-- 
Simon Riggs                http://www.EnterpriseDB.com/





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Avg/max size of these JSON docs in Postgres
@ 2021-10-12 19:21  Michael Lewis <mlewis@entrata.com>
  parent: Simon Riggs <simon.riggs@enterprisedb.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Michael Lewis @ 2021-10-12 19:21 UTC (permalink / raw)
  To: Simon Riggs <simon.riggs@enterprisedb.com>; +Cc: Ram Pratap Maurya <ram.maurya@lavainternational.in>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; Manu Saxena <manu.saxena@lavainternational.in>

On Tue, Oct 12, 2021 at 12:51 PM Simon Riggs <simon.riggs@enterprisedb.com>
wrote:

> On Tue, 12 Oct 2021 at 18:53, Michael Lewis <mlewis@entrata.com> wrote:
> >
> > On Tue, Oct 12, 2021 at 1:43 AM Simon Riggs <
> simon.riggs@enterprisedb.com> wrote:
> >>
> >> On Tue, 12 Oct 2021 at 08:14, Ram Pratap Maurya
> >> <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.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Avg/max size of these JSON docs in Postgres
@ 2021-10-12 22:07  Tomas Vondra <tomas.vondra@enterprisedb.com>
  parent: Michael Lewis <mlewis@entrata.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Tomas Vondra @ 2021-10-12 22:07 UTC (permalink / raw)
  To: Michael Lewis <mlewis@entrata.com>; Simon Riggs <simon.riggs@enterprisedb.com>; +Cc: Ram Pratap Maurya <ram.maurya@lavainternational.in>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; Manu Saxena <manu.saxena@lavainternational.in>

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





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Avg/max size of these JSON docs in Postgres
@ 2021-10-13 07:40  Simon Riggs <simon.riggs@enterprisedb.com>
  parent: Tomas Vondra <tomas.vondra@enterprisedb.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Simon Riggs @ 2021-10-13 07:40 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@enterprisedb.com>; +Cc: Michael Lewis <mlewis@entrata.com>; Ram Pratap Maurya <ram.maurya@lavainternational.in>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; Manu Saxena <manu.saxena@lavainternational.in>

On Tue, 12 Oct 2021 at 23:07, Tomas Vondra
<tomas.vondra@enterprisedb.com> wrote:

> 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 :-(

Sounds worth mentioning in doc/src/sgml/limits.sgml

-- 
Simon Riggs                http://www.EnterpriseDB.com/





^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2021-10-13 07:40 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 06:42 Avg/max size of these JSON docs in Postgres Ram Pratap Maurya <ram.maurya@lavainternational.in>
2021-10-12 07:43 ` Simon Riggs <simon.riggs@enterprisedb.com>
2021-10-12 17:53   ` Michael Lewis <mlewis@entrata.com>
2021-10-12 18:14     ` Tom Lane <tgl@sss.pgh.pa.us>
2021-10-12 18:51     ` Simon Riggs <simon.riggs@enterprisedb.com>
2021-10-12 19:21       ` Michael Lewis <mlewis@entrata.com>
2021-10-12 22:07         ` Tomas Vondra <tomas.vondra@enterprisedb.com>
2021-10-13 07:40           ` Simon Riggs <simon.riggs@enterprisedb.com>

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