Re: How to explicitly lock and unlock tables in pgsql?

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to explicitly lock and unlock tables in pgsql?
Date: 2022-03-17 07:51:52
Message-ID: eed4b6bcda07d197f54a5ea4c1c1194c67778673.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On Wed, 2022-03-16 at 20:30 +0000, Shaozhong SHI wrote:
> Table locks present a barrier for progressing queries.
>
> How to explicitly lock and unlock tables in pgsql, so that we can guarantee the progress of running scripts?

You cannot unlock tables except by ending the transaction which took the lock.

The first thing you should do is to make sure that all your database transactions are short.

Also, you should nevr explicitly lock tables. Table locks are taken automatically
by the SQL statements you are executing.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2022-03-17 10:38:16 Re: PSQL bug?
Previous Message Japin Li 2022-03-17 00:08:19 Re: Support logical replication of DDLs

Browse pgsql-sql by date

  From Date Subject
Next Message Jayson Hreczuck 2022-03-17 13:21:18 Re: Apparently table locks are the key issue to see red flags
Previous Message Tom Lane 2022-03-16 21:06:34 Re: How to explicitly state unlock in sql?