agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: Shaozhong SHI <shishaozhong@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: How to explicitly lock and unlock tables in pgsql?
Date: Fri, 18 Mar 2022 23:48:41 +0100
Message-ID: <3cc08f35825c14458c4cd345ef449211d37ddc49.camel@cybertec.at> (raw)
In-Reply-To: <CAHyXU0wK9NVMv+JRBYk26HqeDXn=5XoNCdBB=MC81A9KjRz6Tg@mail.gmail.com>
References: <CA+i5JwZPLEiOQxFy3q=5HKWYLkfs8VBvHxY03osiW4xy_OoKxw@mail.gmail.com>
	<eed4b6bcda07d197f54a5ea4c1c1194c67778673.camel@cybertec.at>
	<CAHyXU0wK9NVMv+JRBYk26HqeDXn=5XoNCdBB=MC81A9KjRz6Tg@mail.gmail.com>

On Fri, 2022-03-18 at 11:38 -0500, Merlin Moncure wrote:
> > Also, you should nevr explicitly lock tables.  Table locks are taken automatically
> > by the SQL statements you are executing.
> 
> Isn't that a bit of overstatement?
> LOCK table foo;
> 
> Locks the table, with the benefit you can choose the lockmode to
> decide what is and is not allowed to run after you lock it.  The main
> advantage vs automatic locking is preemptively blocking things so as
> to avoid deadlocks.

Yes, that was an overstatement.
But I find that 90% of the time when people explicitly lock a table
it is not the correct solution.

Yours,
Laurenz Albe






view thread (6+ messages)

Message-ID: <3cc08f35825c14458c4cd345ef449211d37ddc49.camel@cybertec.at>
Permalink:  ../3cc08f35825c14458c4cd345ef449211d37ddc49.camel@cybertec.at/
Also on:    postgresql.org/message-id/3cc08f35825c14458c4cd345ef449211d37ddc49.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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: laurenz.albe@cybertec.at, mmoncure@gmail.com, shishaozhong@gmail.com, pgsql-general@lists.postgresql.org
  Subject: Re: How to explicitly lock and unlock tables in pgsql?
  In-Reply-To: <3cc08f35825c14458c4cd345ef449211d37ddc49.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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox