Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1peyvo-0001TF-Ri for pgsql-general@arkaria.postgresql.org; Wed, 22 Mar 2023 13:55:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1peyvm-0001kn-NC for pgsql-general@arkaria.postgresql.org; Wed, 22 Mar 2023 13:55:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1peyvm-0001ke-CL for pgsql-general@lists.postgresql.org; Wed, 22 Mar 2023 13:55:10 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1peyvj-0004uv-DO for pgsql-general@postgresql.org; Wed, 22 Mar 2023 13:55:10 +0000 Received: by mail-ed1-x52c.google.com with SMTP id h8so73288704ede.8 for ; Wed, 22 Mar 2023 06:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; t=1679493306; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=6RaG+ua2SNMqXBBBuD8lMbmYBUwFBoWCDMyHbDHLot4=; b=04lXh7IbwENi6iltlmN3COdftVpdln7VQfw6XOaWczDWhkcX8ptJaVBW9OXtp6AwTx Sv7hdAqgBmeNTgPsg/d78HcRTX+xLipoqb1OJXQFLgjGBcCwCLxGw710dQo3b1JCf5Pr JwQNPAXEQ+vgPjZ7L/Yn1/UXEA9aNmZBDC/wK5OyYhVxxjMV00TGpe0p4yFHzr00p3BQ NmAF/cPHhVCDY3jKK1CKdp3CUCUPoWtG1URpl7eV9x+e4SpN0yZiBH+jzUzpE4KUAvD6 hrikH+6uGIomA6KwwKQyPqYUydhDS9NfmFW48MWh4tI8E4MroVAkGbWvjv14J0oWgRDE vjcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679493306; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6RaG+ua2SNMqXBBBuD8lMbmYBUwFBoWCDMyHbDHLot4=; b=a5wsFMJkn4Hl2T2HIRCHgrcQj5pPuXXmNkDm8EcvNrkGrSyPpTB+y/5tu6cNS+4n2u esM7/qMkPl4/vsntIOBexTY1EG34M9dn2SHrMYkFYy9xkA6zpdtdrQEflsSolQflcKQk KxynEMYS00kx96F+0XXXXRIZANvf7KxhJpb5HfbyaouUfKUGSqLGrI7v07agKWy0FBsi MHAx8whPOvbbv7n+5rBA/eNQQj1bnmsm9trdiDsfN2pCU2Xc3EbXMqAbg5qpYD47+R08 LvzF+CIkj35FT51yR8i04ysrCKYiccIYvTWCbCar7amKw28V/y9KJlTMxXVEbC2PJ+TH wETw== X-Gm-Message-State: AO0yUKWbwJqQO75ybfYZ/sDconRNcqgFE0daZvLiryFkY4GH2NXX/L1T U8MPMjrl/5R3vBjpGSm8tT5oVUjh8aCjNvk/f4I= X-Google-Smtp-Source: AK7set/8JdMNOPZmBvTpb0yorUV5nz5mVdOZ2r0xLBpfVoCvMbndDqKBMZ/U6CAfr4ETMXTrwRQRmQ== X-Received: by 2002:a17:906:344f:b0:8b1:75a0:e5c6 with SMTP id d15-20020a170906344f00b008b175a0e5c6mr7113379ejb.18.1679493306214; Wed, 22 Mar 2023 06:55:06 -0700 (PDT) Received: from localhost.localdomain ([88.116.133.170]) by smtp.gmail.com with ESMTPSA id ja21-20020a170907989500b0093338259b2bsm5712558ejc.207.2023.03.22.06.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 06:55:05 -0700 (PDT) Message-ID: Subject: Re: For temporary tables; truncate vs on commit delete all From: Laurenz Albe To: Jim Vanns , pgsql-general@postgresql.org Date: Wed, 22 Mar 2023 14:55:05 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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; >=20 > a) Always CREATE TEMPORARY TABLE + ON COMMIT DROP for every transaction o= r; > b) TRUNCATE TABLE or; > c) ON COMMIT DELETE ROWS >=20 > 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 --=20 Cybertec | https://www.cybertec-postgresql.com