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 1naBKQ-0004X8-Iw for pgsql-general@arkaria.postgresql.org; Fri, 01 Apr 2022 07:04:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1naBKP-0002NI-4e for pgsql-general@arkaria.postgresql.org; Fri, 01 Apr 2022 07:04:13 +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 1naBKO-0002N9-Nz for pgsql-general@lists.postgresql.org; Fri, 01 Apr 2022 07:04:12 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1naBKL-00040U-Gk for pgsql-general@lists.postgresql.org; Fri, 01 Apr 2022 07:04:11 +0000 Received: by mail-wr1-x434.google.com with SMTP id w21so2853964wra.2 for ; Fri, 01 Apr 2022 00:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=tCW0EEw7bolY4Jt64ilsna3Kcyq7K13cq+kUl7RyR2I=; b=ibBWwaZJJ+UrwV1uLDtD/R7NAzZozTiklspB2QNVwuxo8rGqg4JUmUttkNRvEg0bx1 Yzhu5+WTrnx5RW8IkxGKDUmXRzv5FCCZjfeNb9sx9FKPWCF/gpf0FM1g5vWq7KAOGqOo 0TU59xhQurmolEvmqr7hIUPhfiPawHlAhXhXDPsSgZw/8m0hHm3Scl5mFOTgZXZ16/GP g4VNu+sohxV6LhFXXM8fL1MsrQLMta0fVJRXzuGmkEFBuM4E9DwEp+E87jrhBUon8IRd zx5xiIdHMUqzxI1Ab0PDLtaPrj6FSMMYLwfa4K8Fn/kcL9qCa/JXxbxkf1hCNR2ybTWY d+Wg== 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=tCW0EEw7bolY4Jt64ilsna3Kcyq7K13cq+kUl7RyR2I=; b=pcDNdymF0iOZ5szVOLej9xtcQdSDEf7yMD8Ra2RL6u53yMnY34qVAWwMIiQCMxFxxb Okb49++m/CWr+V+D+/M/1zXJ7GAiHo4NOPK55LFeaT38O5V5C17BlyXnK4lZ4bhHP86z ervaJPX1AjOAZTxb2TPS5fpZ41X2CpPyi4r8J9Z0UVDe+ZCey+vCwjjQ3PNqn9CSZUlZ 5bAsBe60Zha3glkUHMY6j5Ap8FAMD44YHoCl+iwXSYMbtXByddDPme+sI18s2Y5pVQxY JBA4lp6FCTu5SsUzM6evhtUIX2Vi7f75boP3F4nK6a2sIyH/s5jPMJ8uG+BguWH482XH WHlQ== X-Gm-Message-State: AOAM530dzXXi8C67fcNH42zyQdzML29wL22znMKutDWsWseEfej2gHCr KEmVdrhSH3I95rbHyl1P27NU4w== X-Google-Smtp-Source: ABdhPJx709ub4xa0SnHmq7mG/V+r7zm56CJYwm5R+Mc+gfCBRXT696DR53eA41L12koBv/+ygHXBhQ== X-Received: by 2002:adf:8063:0:b0:205:e19e:2bc1 with SMTP id 90-20020adf8063000000b00205e19e2bc1mr6599620wrk.177.1648796647184; Fri, 01 Apr 2022 00:04:07 -0700 (PDT) Received: from localhost.localdomain (91-115-145-142.adsl.highway.telekom.at. [91.115.145.142]) by smtp.gmail.com with ESMTPSA id m3-20020a5d64a3000000b00203ed35b0aesm2136623wrp.108.2022.04.01.00.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 00:04:06 -0700 (PDT) Message-ID: <0311af4e66c5da4cfbe8de926d3d41be79f3fc80.camel@cybertec.at> Subject: Re: Locking a table read-only temporarilty From: Laurenz Albe To: Digimer , "pgsql-general@lists.postgresql.org" Date: Fri, 01 Apr 2022 09:04:05 +0200 In-Reply-To: <90ea94e3-7021-7d94-66ad-8b62b030a700@alteeve.ca> References: <90ea94e3-7021-7d94-66ad-8b62b030a700@alteeve.ca> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-3.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 Thu, 2022-03-31 at 15:20 -0400, Digimer wrote: > I've been looking up locking, and perhaps I'm being dense, but I'm struggling to figure out > how to create a lock to make a table read-only for a short period of time. > I want to set a table to be read-only, so that any other clients that try to UPDATE > or INSERT will hold until the lock is released. I've been reading; > https://www.postgresql.org/docs/10/explicit-locking.html >   But I'm not sure which lock would be what I want, and I don't see how to release > the lock when finished. Could someone hit me with a clue-stick? You'd have to start a transaction and LOCK tab IN SHARE MODE; Commit the transaction to release the lock. However, it is a bad idea to keep transactions with high locks open for a long time. Your real problem might have a better answer. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com