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 1mO0Ox-0000JS-Bh for pgsql-docs@arkaria.postgresql.org; Wed, 08 Sep 2021 16:26:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mO0Ow-0002B9-3f for pgsql-docs@arkaria.postgresql.org; Wed, 08 Sep 2021 16:26:18 +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 1mO0Ov-0002Av-RQ for pgsql-docs@lists.postgresql.org; Wed, 08 Sep 2021 16:26:17 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mO0Os-0007qx-TL for pgsql-docs@lists.postgresql.org; Wed, 08 Sep 2021 16:26:17 +0000 Received: by mail-wr1-x42d.google.com with SMTP id z4so4168936wrr.6 for ; Wed, 08 Sep 2021 09:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=oXEF2lgHGoDDohH8Nf0MvuJ5XZljbnNslh4T53j/znE=; b=ajdxlgVIDlK46MRjKKwcwH4zcN3SQp1D3E8jMu4BqpyfkWt6ZHG9Rw5MBeo1ORldIB LJ0kos1ZvEEw9yhqWpZ5WP0T6baTTiCQrFWgqzIEekhqloJK0QJvHZU/GBScDorxqCr8 UylvP3EKyLUbOfNSy02P+E8yHbm7xrpf196zofXR/D3Jr8irZwcI5zgZSunZRgfXDsoM CcInqU7Tm8QmudwqnRfothsXoja2wtKRHGYuU2BvELBb3uT8Yq7st9JYrZmhRHH07x9P xC7wkdZYRlmuqf5CwEshwZ5VK4SCk8IpdQWxwnyV4kz3GlW4liaE7DPNDjyaI72vRt4Y +OIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=oXEF2lgHGoDDohH8Nf0MvuJ5XZljbnNslh4T53j/znE=; b=icHxfSzwIHPBFQzq4GAwbiwgg09LWYLSRK8KSn1uAoEb6se+q4jmkte2TzoQqAf7MV eSTszLV/YsPcz23yvIa/zIr5WDomuWdiDN6p3SJuRTvSaiZBsE1Nb4GIOEzi94PNnIa8 euWUa1qI8UFHqWjHGMpZmXNNbW7AGbc32F/MyLDkABrKUIpilIbI8MWvcXYAic2CInBU K5pceE86CLNmM/TII0M7mYh71cHf7/vEaISoC8O4DfSjmwKPIQAdM+vaBZ5Xz23PYXtZ sAQt4no3ydIfkN2tFwy0SjPCVAmBnezGG/iPYIxChGWujf+WFIs3+JR+RXnEVTcLXsiM 0EcA== X-Gm-Message-State: AOAM533hLWeRjJiiVLWyFmq0g5XzYryUu0qO4grwbrlN91IWWpPQ3tX6 YtUiQGpAmGNYdYMGW2Y3VGeGYg== X-Google-Smtp-Source: ABdhPJwZAM0uIB0If9/8aVu3QI31W2gXb6FtEgXn69uONJ/UDBDiZIBSFMidvrSOFf9mig/TZx4hdQ== X-Received: by 2002:a5d:4ed2:: with SMTP id s18mr5105339wrv.41.1631118373599; Wed, 08 Sep 2021 09:26:13 -0700 (PDT) Received: from localhost.localdomain (dynamic-e3idp9ypd5y53w856-pd01.res.v6.highway.a1.net. [2001:871:5c:ceb6:9dfd:359e:3051:683a]) by smtp.gmail.com with ESMTPSA id r26sm2397412wmh.27.2021.09.08.09.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 09:26:13 -0700 (PDT) Message-ID: Subject: Re: Warn against transaction level advisory locks for emulating "flat file" DBMS locking strategies From: Laurenz Albe To: me@jix.one, pgsql-docs@lists.postgresql.org Date: Wed, 08 Sep 2021 18:26:12 +0200 In-Reply-To: <163108943900.696.7027791431029866787@wrigleys.postgresql.org> References: <163108943900.696.7027791431029866787@wrigleys.postgresql.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2021-09-08 at 08:23 +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/13/explicit-locking.html > Description: > > The docs mention "For example, a common use of advisory locks is to emulate > pessimistic locking strategies typical of so-called “flat file” data > management systems" which is exactly what I wanted to use to port some code > from using SQLite to using PostgreSQL. (The code in question requires > serializable transactions and cannot not handle retries.) > > The next paragraph explains session and transaction level advisory locks and > mentions that transaction level locks are "often more convenient than the > session-level behavior". This seemed to be true for this use case, so I > chose to use them. > > Later I discovered that obtaining a transaction level lock as first > statement _within_ a transaction is not sufficient to emulate global > pessimistic locking and can occasionally still result in serialization > failures. I don't see how that is related to session-level vs. transaction level locks. erhaps you can explain your case in some more detail. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com