pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Jim Vanns <jvanns@ilm.com>
To: pgsql-general@postgresql.org
Subject: Re: For temporary tables; truncate vs on commit delete all
Date: Wed, 22 Mar 2023 14:55:05 +0100
Message-ID: <a6ffb5db391c609862931cf2f1de2e36870476f5.camel@cybertec.at> (raw)
In-Reply-To: <CAH7vdhOJLi9eSr_i0KkEG60prha=y=VjY7KvMOa-p3WUwTZUTg@mail.gmail.com>
References: <CAH7vdhOJLi9eSr_i0KkEG60prha=y=VjY7KvMOa-p3WUwTZUTg@mail.gmail.com>

On Wed, 2023-03-22 at 11:59 +0000, Jim Vanns wrote:
> Does anyone have any idea which is generally better (by better I mean
> most efficient/quickest!) in this simple scenario? I have a temporary
> table which I wish to retain for the duration of a long-running
> session. However, for each transaction it must be purged. So, is it
> better to;
> 
> a) Always CREATE TEMPORARY TABLE + ON COMMIT DROP for every transaction or;
> b) TRUNCATE TABLE or;
> c) ON COMMIT DELETE ROWS
> 
> Both b & c avoid re-creating the table each time but at the cost of an
> explicit purge of some form.
> I would assume that despite its name, the latter, example c, is more
> akin to a truncation? Or does it actually perform a deletion?

b) or c) are best.
Yes, ON COMMIT DELETE ROWS will truncate the temporary table.

Creating too many temporary tables in a short time can lead to bloat
in "pg_attribute".

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com





view thread (2+ messages)

Message-ID: <a6ffb5db391c609862931cf2f1de2e36870476f5.camel@cybertec.at>
Permalink:  ../a6ffb5db391c609862931cf2f1de2e36870476f5.camel@cybertec.at/
Also on:    postgresql.org/message-id/a6ffb5db391c609862931cf2f1de2e36870476f5.camel@cybertec.at

 · 

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: laurenz.albe@cybertec.at, jvanns@ilm.com
  Subject: Re: For temporary tables; truncate vs on commit delete all
  In-Reply-To: <a6ffb5db391c609862931cf2f1de2e36870476f5.camel@cybertec.at>
  References: <CAH7vdhOJLi9eSr_i0KkEG60prha=y=VjY7KvMOa-p3WUwTZUTg@mail.gmail.com> <a6ffb5db391c609862931cf2f1de2e36870476f5.camel@cybertec.at>

* 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