pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Do not decode TOAST data for table rewrites
6+ messages / 1 participants
[nested] [flat]

* pgsql: Do not decode TOAST data for table rewrites
@ 2018-11-28 01:00  Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tomas Vondra @ 2018-11-28 01:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Do not decode TOAST data for table rewrites

During table rewrites (VACUUM FULL and CLUSTER), the main heap is logged
using XLOG / FPI records, and thus (correctly) ignored in decoding.
But the associated TOAST table is WAL-logged as plain INSERT records,
and so was logically decoded and passed to reorder buffer.

That has severe consequences with TOAST tables of non-trivial size.
Firstly, reorder buffer has to keep all those changes, possibly spilling
them to a file, incurring I/O costs and disk space.

Secondly, ReoderBufferCommit() was stashing all those TOAST chunks into
a hash table, which got discarded only after processing the row from the
main heap.  But as the main heap is not decoded for rewrites, this never
happened, so all the TOAST data accumulated in memory, resulting either
in excessive memory consumption or OOM.

The fix is simple, as commit e9edc1ba already introduced infrastructure
(namely HEAP_INSERT_NO_LOGICAL flag) to skip logical decoding of TOAST
tables, but it only applied it to system tables.  So simply use it for
all TOAST data in raw_heap_insert().

That would however solve only the memory consumption issue - the TOAST
changes would still be decoded and added to the reorder buffer, and
spilled to disk (although without TOAST tuple data, so much smaller).
But we can solve that by tweaking DecodeInsert() to just ignore such
INSERT records altogether, using XLH_INSERT_CONTAINS_NEW_TUPLE flag,
instead of skipping them later in ReorderBufferCommit().

Review: Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/flat/1a17c643-e9af-3dba-486b-fbe31bc1823a%402ndquadrant.com
Backpatch: 9.4-, where logical decoding was introduced

Branch
------
REL9_4_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c1a5caea82694006047b6193e924ffbbabc87193

Modified Files
--------------
src/backend/access/heap/rewriteheap.c    |  9 ++++-----
src/backend/replication/logical/decode.c | 26 ++++++++++++++++----------
2 files changed, 20 insertions(+), 15 deletions(-)



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

* pgsql: Do not decode TOAST data for table rewrites
@ 2018-11-28 01:03  Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tomas Vondra @ 2018-11-28 01:03 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Do not decode TOAST data for table rewrites

During table rewrites (VACUUM FULL and CLUSTER), the main heap is logged
using XLOG / FPI records, and thus (correctly) ignored in decoding.
But the associated TOAST table is WAL-logged as plain INSERT records,
and so was logically decoded and passed to reorder buffer.

That has severe consequences with TOAST tables of non-trivial size.
Firstly, reorder buffer has to keep all those changes, possibly spilling
them to a file, incurring I/O costs and disk space.

Secondly, ReoderBufferCommit() was stashing all those TOAST chunks into
a hash table, which got discarded only after processing the row from the
main heap.  But as the main heap is not decoded for rewrites, this never
happened, so all the TOAST data accumulated in memory, resulting either
in excessive memory consumption or OOM.

The fix is simple, as commit e9edc1ba already introduced infrastructure
(namely HEAP_INSERT_NO_LOGICAL flag) to skip logical decoding of TOAST
tables, but it only applied it to system tables.  So simply use it for
all TOAST data in raw_heap_insert().

That would however solve only the memory consumption issue - the TOAST
changes would still be decoded and added to the reorder buffer, and
spilled to disk (although without TOAST tuple data, so much smaller).
But we can solve that by tweaking DecodeInsert() to just ignore such
INSERT records altogether, using XLH_INSERT_CONTAINS_NEW_TUPLE flag,
instead of skipping them later in ReorderBufferCommit().

Review: Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/flat/1a17c643-e9af-3dba-486b-fbe31bc1823a%402ndquadrant.com
Backpatch: 9.4-, where logical decoding was introduced

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/77d2815e4579af2ab148e6601cd7fe28f02a0d81

Modified Files
--------------
src/backend/access/heap/rewriteheap.c           |  9 ++++-----
src/backend/replication/logical/decode.c        | 24 +++++++++++++++---------
src/backend/replication/logical/reorderbuffer.c | 15 +++++----------
3 files changed, 24 insertions(+), 24 deletions(-)



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

* pgsql: Do not decode TOAST data for table rewrites
@ 2018-11-28 01:03  Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tomas Vondra @ 2018-11-28 01:03 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Do not decode TOAST data for table rewrites

During table rewrites (VACUUM FULL and CLUSTER), the main heap is logged
using XLOG / FPI records, and thus (correctly) ignored in decoding.
But the associated TOAST table is WAL-logged as plain INSERT records,
and so was logically decoded and passed to reorder buffer.

That has severe consequences with TOAST tables of non-trivial size.
Firstly, reorder buffer has to keep all those changes, possibly spilling
them to a file, incurring I/O costs and disk space.

Secondly, ReoderBufferCommit() was stashing all those TOAST chunks into
a hash table, which got discarded only after processing the row from the
main heap.  But as the main heap is not decoded for rewrites, this never
happened, so all the TOAST data accumulated in memory, resulting either
in excessive memory consumption or OOM.

The fix is simple, as commit e9edc1ba already introduced infrastructure
(namely HEAP_INSERT_NO_LOGICAL flag) to skip logical decoding of TOAST
tables, but it only applied it to system tables.  So simply use it for
all TOAST data in raw_heap_insert().

That would however solve only the memory consumption issue - the TOAST
changes would still be decoded and added to the reorder buffer, and
spilled to disk (although without TOAST tuple data, so much smaller).
But we can solve that by tweaking DecodeInsert() to just ignore such
INSERT records altogether, using XLH_INSERT_CONTAINS_NEW_TUPLE flag,
instead of skipping them later in ReorderBufferCommit().

Review: Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/flat/1a17c643-e9af-3dba-486b-fbe31bc1823a%402ndquadrant.com
Backpatch: 9.4-, where logical decoding was introduced

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b86d148ae339be7937ba8aa707de6905314a78c4

Modified Files
--------------
src/backend/access/heap/rewriteheap.c           |  9 ++++-----
src/backend/replication/logical/decode.c        | 24 +++++++++++++++---------
src/backend/replication/logical/reorderbuffer.c | 15 +++++----------
3 files changed, 24 insertions(+), 24 deletions(-)



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

* pgsql: Do not decode TOAST data for table rewrites
@ 2018-11-28 01:03  Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tomas Vondra @ 2018-11-28 01:03 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Do not decode TOAST data for table rewrites

During table rewrites (VACUUM FULL and CLUSTER), the main heap is logged
using XLOG / FPI records, and thus (correctly) ignored in decoding.
But the associated TOAST table is WAL-logged as plain INSERT records,
and so was logically decoded and passed to reorder buffer.

That has severe consequences with TOAST tables of non-trivial size.
Firstly, reorder buffer has to keep all those changes, possibly spilling
them to a file, incurring I/O costs and disk space.

Secondly, ReoderBufferCommit() was stashing all those TOAST chunks into
a hash table, which got discarded only after processing the row from the
main heap.  But as the main heap is not decoded for rewrites, this never
happened, so all the TOAST data accumulated in memory, resulting either
in excessive memory consumption or OOM.

The fix is simple, as commit e9edc1ba already introduced infrastructure
(namely HEAP_INSERT_NO_LOGICAL flag) to skip logical decoding of TOAST
tables, but it only applied it to system tables.  So simply use it for
all TOAST data in raw_heap_insert().

That would however solve only the memory consumption issue - the TOAST
changes would still be decoded and added to the reorder buffer, and
spilled to disk (although without TOAST tuple data, so much smaller).
But we can solve that by tweaking DecodeInsert() to just ignore such
INSERT records altogether, using XLH_INSERT_CONTAINS_NEW_TUPLE flag,
instead of skipping them later in ReorderBufferCommit().

Review: Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/flat/1a17c643-e9af-3dba-486b-fbe31bc1823a%402ndquadrant.com
Backpatch: 9.4-, where logical decoding was introduced

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4e7395d83faf02d0b64b1da69d0c1be53b76f802

Modified Files
--------------
src/backend/access/heap/rewriteheap.c           |  9 ++++-----
src/backend/replication/logical/decode.c        | 24 +++++++++++++++---------
src/backend/replication/logical/reorderbuffer.c | 15 +++++----------
3 files changed, 24 insertions(+), 24 deletions(-)



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

* pgsql: Do not decode TOAST data for table rewrites
@ 2018-11-28 01:04  Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tomas Vondra @ 2018-11-28 01:04 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Do not decode TOAST data for table rewrites

During table rewrites (VACUUM FULL and CLUSTER), the main heap is logged
using XLOG / FPI records, and thus (correctly) ignored in decoding.
But the associated TOAST table is WAL-logged as plain INSERT records,
and so was logically decoded and passed to reorder buffer.

That has severe consequences with TOAST tables of non-trivial size.
Firstly, reorder buffer has to keep all those changes, possibly spilling
them to a file, incurring I/O costs and disk space.

Secondly, ReoderBufferCommit() was stashing all those TOAST chunks into
a hash table, which got discarded only after processing the row from the
main heap.  But as the main heap is not decoded for rewrites, this never
happened, so all the TOAST data accumulated in memory, resulting either
in excessive memory consumption or OOM.

The fix is simple, as commit e9edc1ba already introduced infrastructure
(namely HEAP_INSERT_NO_LOGICAL flag) to skip logical decoding of TOAST
tables, but it only applied it to system tables.  So simply use it for
all TOAST data in raw_heap_insert().

That would however solve only the memory consumption issue - the TOAST
changes would still be decoded and added to the reorder buffer, and
spilled to disk (although without TOAST tuple data, so much smaller).
But we can solve that by tweaking DecodeInsert() to just ignore such
INSERT records altogether, using XLH_INSERT_CONTAINS_NEW_TUPLE flag,
instead of skipping them later in ReorderBufferCommit().

Review: Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/flat/1a17c643-e9af-3dba-486b-fbe31bc1823a%402ndquadrant.com
Backpatch: 9.4-, where logical decoding was introduced

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f8397c955e54d7093a81b2a84ba44898c6566203

Modified Files
--------------
src/backend/access/heap/rewriteheap.c           |  9 ++++-----
src/backend/replication/logical/decode.c        | 24 +++++++++++++++---------
src/backend/replication/logical/reorderbuffer.c | 15 +++++----------
3 files changed, 24 insertions(+), 24 deletions(-)



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

* pgsql: Do not decode TOAST data for table rewrites
@ 2018-11-28 01:04  Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tomas Vondra @ 2018-11-28 01:04 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Do not decode TOAST data for table rewrites

During table rewrites (VACUUM FULL and CLUSTER), the main heap is logged
using XLOG / FPI records, and thus (correctly) ignored in decoding.
But the associated TOAST table is WAL-logged as plain INSERT records,
and so was logically decoded and passed to reorder buffer.

That has severe consequences with TOAST tables of non-trivial size.
Firstly, reorder buffer has to keep all those changes, possibly spilling
them to a file, incurring I/O costs and disk space.

Secondly, ReoderBufferCommit() was stashing all those TOAST chunks into
a hash table, which got discarded only after processing the row from the
main heap.  But as the main heap is not decoded for rewrites, this never
happened, so all the TOAST data accumulated in memory, resulting either
in excessive memory consumption or OOM.

The fix is simple, as commit e9edc1ba already introduced infrastructure
(namely HEAP_INSERT_NO_LOGICAL flag) to skip logical decoding of TOAST
tables, but it only applied it to system tables.  So simply use it for
all TOAST data in raw_heap_insert().

That would however solve only the memory consumption issue - the TOAST
changes would still be decoded and added to the reorder buffer, and
spilled to disk (although without TOAST tuple data, so much smaller).
But we can solve that by tweaking DecodeInsert() to just ignore such
INSERT records altogether, using XLH_INSERT_CONTAINS_NEW_TUPLE flag,
instead of skipping them later in ReorderBufferCommit().

Review: Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/flat/1a17c643-e9af-3dba-486b-fbe31bc1823a%402ndquadrant.com
Backpatch: 9.4-, where logical decoding was introduced

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f69c959df0db311badf609bce3ad3efde2309389

Modified Files
--------------
src/backend/access/heap/rewriteheap.c           |  9 ++++-----
src/backend/replication/logical/decode.c        | 24 +++++++++++++++---------
src/backend/replication/logical/reorderbuffer.c | 15 +++++----------
3 files changed, 24 insertions(+), 24 deletions(-)



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


end of thread, other threads:[~2018-11-28 01:04 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28 01:00 pgsql: Do not decode TOAST data for table rewrites Tomas Vondra <tomas.vondra@postgresql.org>
2018-11-28 01:03 pgsql: Do not decode TOAST data for table rewrites Tomas Vondra <tomas.vondra@postgresql.org>
2018-11-28 01:03 pgsql: Do not decode TOAST data for table rewrites Tomas Vondra <tomas.vondra@postgresql.org>
2018-11-28 01:03 pgsql: Do not decode TOAST data for table rewrites Tomas Vondra <tomas.vondra@postgresql.org>
2018-11-28 01:04 pgsql: Do not decode TOAST data for table rewrites Tomas Vondra <tomas.vondra@postgresql.org>
2018-11-28 01:04 pgsql: Do not decode TOAST data for table rewrites Tomas Vondra <tomas.vondra@postgresql.org>

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