pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Digimer <lists@alteeve.ca>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Locking a table read-only temporarilty
Date: Fri, 01 Apr 2022 09:04:05 +0200
Message-ID: <0311af4e66c5da4cfbe8de926d3d41be79f3fc80.camel@cybertec.at> (raw)
In-Reply-To: <90ea94e3-7021-7d94-66ad-8b62b030a700@alteeve.ca>
References: <90ea94e3-7021-7d94-66ad-8b62b030a700@alteeve.ca>

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






view thread (2+ messages)

Message-ID: <0311af4e66c5da4cfbe8de926d3d41be79f3fc80.camel@cybertec.at>
Permalink:  ../0311af4e66c5da4cfbe8de926d3d41be79f3fc80.camel@cybertec.at/
Also on:    postgresql.org/message-id/0311af4e66c5da4cfbe8de926d3d41be79f3fc80.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, lists@alteeve.ca
  Subject: Re: Locking a table read-only temporarilty
  In-Reply-To: <0311af4e66c5da4cfbe8de926d3d41be79f3fc80.camel@cybertec.at>
  References: <90ea94e3-7021-7d94-66ad-8b62b030a700@alteeve.ca> <0311af4e66c5da4cfbe8de926d3d41be79f3fc80.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