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 1ot2eJ-0007hU-K6 for pgsql-admin@arkaria.postgresql.org; Thu, 10 Nov 2022 08:11:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ot2eH-0003bl-7U for pgsql-admin@arkaria.postgresql.org; Thu, 10 Nov 2022 08:10:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ot2eG-0003YF-Qt for pgsql-admin@lists.postgresql.org; Thu, 10 Nov 2022 08:10:56 +0000 Received: from mout2.freenet.de ([2001:748:100:40::2:4]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ot2eD-00085B-GF for pgsql-admin@lists.postgresql.org; Thu, 10 Nov 2022 08:10:55 +0000 Received: from [195.4.92.122] (helo=sub3.freenet.de) by mout2.freenet.de with esmtpa (ID rumayer@freenet.de) (port 25) (Exim 4.94.2 #2) id 1ot2e9-0028I4-Dh for pgsql-admin@lists.postgresql.org; Thu, 10 Nov 2022 09:10:48 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freenet.de; s=mjaymdexmjqk; h=In-Reply-To:References:To:Subject:From:MIME-Version:Date: Message-ID:Content-Type:Sender:Reply-To:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=GGLTu0Ku/Urk16HesVyC9E6y47IQNmB3KdOs2eXi+dE=; b=Zpu9jhAnP0hIo3DvFlO29Mgn6s Jd70tg9GdtjgEST2fuukTNRcOGSwSBwyvZSTi2nh2wIFmQb3IsG7sO2uzyE5Dwzf1NhczSy1zWHJ4 qoyxkomVdwUGEVRB1WJPl2Bb+PIhFnIGjsHfbDfQylSsUNnr+F8qcbycklsvpgSr8rn8gfMADwaFt I8wD1zObYSShdrRugMNRmKcANIvhF/N4DgtwB325jcjyjIcB9kno4pTFEY8rJTD0cddKJilk2KrRc Hy4H7YfGfBG93SrN7XG8ViPHIHj3tJ+iLh902LzeYgR9MZLJ5W020lCB+sW4FApxVFdlUEmX6P0oe JU/IMrZQ==; Received: from service.hus-soft.de ([217.86.192.129]:54162 helo=[10.51.11.212]) by sub3.freenet.de with esmtpsa (ID rumayer@freenet.de) (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (port 465) (Exim 4.94.2 #2) id 1ot2e4-000Tnq-FO for pgsql-admin@lists.postgresql.org; Thu, 10 Nov 2022 09:10:48 +0100 Content-Type: multipart/alternative; boundary="------------B9jAPyoA3IWzQGnE3pLo08qM" Message-ID: Date: Thu, 10 Nov 2022 09:10:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 From: Reinhard Mayer Subject: Re: Persistent changes in rolled-back transactions To: pgsql-admin@lists.postgresql.org References: Content-Language: en-US In-Reply-To: X-FN-MUUID: 16680678440E222CB2B624O X-Originated-At: 217.86.192.129!54162 X-Scan-TS: Thu, 10 Nov 2022 09:10:44 +0100 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------B9jAPyoA3IWzQGnE3pLo08qM Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/10/22 02:07, Wells Oliver wrote: > I've noticed serials still maintain incremented values even when a > transaction is rolled back. Are there other similar persistent changes > to be aware of? If we relax the word "persistence" then I would mention advisory_locks: You can request an advisory lock with pg_advisory_lock() and pg_advisory_xact_lock(). The lock obtained by pg_advisory_lock() will survive a rollback: postgres=# begin; BEGIN postgres=*# select pg_advisory_lock(1);  pg_advisory_lock ------------------ (1 row) postgres=*# select pg_advisory_xact_lock(2);  pg_advisory_xact_lock ----------------------- (1 row) postgres=*# select objid from pg_locks where locktype = 'advisory';  objid -------      2      1 (2 rows) postgres=*# rollback ; ROLLBACK postgres=# select objid from pg_locks where locktype = 'advisory';  objid -------      1 (1 rows) ========== Reinhard > > -- > Wells Oliver > wells.oliver@gmail.com --------------B9jAPyoA3IWzQGnE3pLo08qM Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 11/10/22 02:07, Wells Oliver wrote:
I've noticed serials still maintain incremented values even when a transaction is rolled back. Are there other similar persistent changes to be aware of?


If we relax the word "persistence" then I would mention advisory_locks:

You can request an advisory lock with pg_advisory_lock() and pg_advisory_xact_lock().

The lock obtained by pg_advisory_lock() will survive a rollback:



postgres=# begin;
BEGIN

postgres=*# select pg_advisory_lock(1);       
 pg_advisory_lock
------------------
 
(1 row)

postgres=*# select pg_advisory_xact_lock(2);
 pg_advisory_xact_lock
-----------------------
 
(1 row)

postgres=*# select objid from pg_locks where locktype = 'advisory';
 objid
-------
     2
     1
(2 rows)


postgres=*# rollback ;
ROLLBACK

postgres=# select objid from pg_locks where locktype = 'advisory';
 objid
-------
     1
(1 rows)


==========

Reinhard



--
--------------B9jAPyoA3IWzQGnE3pLo08qM--