Re: Locking a table read-only temporarilty

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Digimer <lists(at)alteeve(dot)ca>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Locking a table read-only temporarilty
Date: 2022-04-01 07:04:05
Message-ID: 0311af4e66c5da4cfbe8de926d3d41be79f3fc80.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message spiral 2022-04-01 07:06:46 weird issue with occasional stuck queries
Previous Message Daniele Varrazzo 2022-04-01 06:48:08 Re: Does PGDG apt repository support ARM64?