pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: André Hänsel <andre@webkr.de>
To: pgsql-general@lists.postgresql.org
Subject: Issues with upserts
Date: Wed, 13 Jul 2022 15:35:54 +0200
Message-ID: <032201d896bd$7a948a10$6fbd9e30$@webkr.de> (raw)

The wiki entry https://wiki.postgresql.org/wiki/UPSERT kind of suggests that
with the introduction of ON CONFLICT DO UPDATE the problem of upserts is
solved. But is it?

 

A common use case for upserts is to keep a table up to date from an external
data source. So you might have a cron job that runs a relatively large batch
of upserts every couple of minutes.

 

I have found that this use case is not adequately covered by ON CONFLICT DO
UPDATE for two reasons:

- New versions are created for all rows, even if the data is identical. This
quickly fills up the WAL and puts unnecessary load on the tablespace drives.

- If the conflict target is not the serial column, the sequence backing the
serial column gets incremented for every row. This quickly reaches the point
where the serial for new rows exceeds the range of an integer.

 

Does this mean I have to SELECT the data first and do the conflict check in
the application or is there a better SQL-only way?

view thread (7+ messages)  latest in thread

Message-ID: <032201d896bd$7a948a10$6fbd9e30$@webkr.de>
Permalink:  ../032201d896bd$7a948a10$6fbd9e30$@webkr.de/
Also on:    postgresql.org/message-id/032201d896bd$7a948a10$6fbd9e30$@webkr.de

 · 

reply

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: andre@webkr.de
  Subject: Re: Issues with upserts
  In-Reply-To: <032201d896bd$7a948a10$6fbd9e30$@webkr.de>
  References: <032201d896bd$7a948a10$6fbd9e30$@webkr.de>

* 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