pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedLocking a table read-only temporarilty
2+ messages / 2 participants
[nested] [flat]
* Locking a table read-only temporarilty
@ 2022-03-31 19:20 Digimer <lists@alteeve.ca>
2022-04-01 07:04 ` Re: Locking a table read-only temporarilty Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 2+ messages in thread
From: Digimer @ 2022-03-31 19:20 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi all,</p>
<p> 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.</p>
<p> 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;</p>
<p><a class="moz-txt-link-freetext" href="https://www.postgresql.org/docs/10/explicit-locking.html">https://www.postgresql.org/docs/10/...;
<p> 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?</p>
<p>Thanks!</p>
<pre class="moz-signature" cols="72">--
Digimer
Papers and Projects: <a class="moz-txt-link-freetext" href="https://alteeve.com/w/">https://alteeve.com/w/</a;
"I am, somehow, less interested in the weight and convolutions of Einstein’s brain than in the near certainty that people of equal talent have lived and died in cotton fields and sweatshops." - Stephen Jay Gould</pre>
</body>
</html>
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Locking a table read-only temporarilty
2022-03-31 19:20 Locking a table read-only temporarilty Digimer <lists@alteeve.ca>
@ 2022-04-01 07:04 ` Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 2+ messages in thread
From: Laurenz Albe @ 2022-04-01 07:04 UTC (permalink / raw)
To: Digimer <lists@alteeve.ca>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2022-04-01 07:04 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-03-31 19:20 Locking a table read-only temporarilty Digimer <lists@alteeve.ca>
2022-04-01 07:04 ` Laurenz Albe <laurenz.albe@cybertec.at>
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