public inbox for [email protected]  
help / color / mirror / Atom feed
a lot of session wait on lock relation
6+ messages / 4 participants
[nested] [flat]

* a lot of session wait on lock relation
@ 2025-05-15 08:27 James Pang <[email protected]>
  2025-05-15 09:31 ` Re: a lot of session wait on lock relation Chetan <[email protected]>
  2025-05-15 12:08 ` Re: a lot of session wait on lock relation Laurenz Albe <[email protected]>
  0 siblings, 2 replies; 6+ messages in thread

From: James Pang @ 2025-05-15 08:27 UTC (permalink / raw)
  To: [email protected]

Hi,
   PGv 15.10,  many session coming in doing "insert into tablexxx
values...." in parallel, this is a range partition tables, total 12
partitions plus one default partition, only three btree indexes, no others
constraints ,no foreign key. but we see hundreds of session waiting on
"lock:relation", why inserts into partition table cause "relation lock" ?

Thanks,

James


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: a lot of session wait on lock relation
  2025-05-15 08:27 a lot of session wait on lock relation James Pang <[email protected]>
@ 2025-05-15 09:31 ` Chetan <[email protected]>
  1 sibling, 0 replies; 6+ messages in thread

From: Chetan @ 2025-05-15 09:31 UTC (permalink / raw)
  To: James Pang <[email protected]>; +Cc: [email protected]

Hi James,

Could share the related test setup details?
Would like to look into this.

Thanks,
Chetan


On Thu, 15 May 2025 at 09:27, James Pang <[email protected]> wrote:

> Hi,
>    PGv 15.10,  many session coming in doing "insert into tablexxx
> values...." in parallel, this is a range partition tables, total 12
> partitions plus one default partition, only three btree indexes, no others
> constraints ,no foreign key. but we see hundreds of session waiting on
> "lock:relation", why inserts into partition table cause "relation lock" ?
>
> Thanks,
>
> James
>


-- 
-- 
Regards,
Chetan

+353899475147
+919665562626


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: a lot of session wait on lock relation
  2025-05-15 08:27 a lot of session wait on lock relation James Pang <[email protected]>
@ 2025-05-15 12:08 ` Laurenz Albe <[email protected]>
  2025-05-15 13:24   ` Re: a lot of session wait on lock relation Tom Lane <[email protected]>
  1 sibling, 1 reply; 6+ messages in thread

From: Laurenz Albe @ 2025-05-15 12:08 UTC (permalink / raw)
  To: James Pang <[email protected]>; [email protected]

On Thu, 2025-05-15 at 16:27 +0800, James Pang wrote:
> PGv 15.10,  many session coming in doing "insert into tablexxx values...." in parallel,
> this is a range partition tables, total 12 partitions plus one default partition,
> only three btree indexes, no others constraints ,no foreign key. but we see hundreds
> of session waiting on "lock:relation", why inserts into partition table cause "relation lock" ?

Something else does; use the pg_blocking_pids() function with the process ID of
a blocked backend to find out who is holding the lock.

If you have hundreds of sessions, you are allowing to many connections.

Yours,
Laurenz Albe





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: a lot of session wait on lock relation
  2025-05-15 08:27 a lot of session wait on lock relation James Pang <[email protected]>
  2025-05-15 12:08 ` Re: a lot of session wait on lock relation Laurenz Albe <[email protected]>
@ 2025-05-15 13:24   ` Tom Lane <[email protected]>
  2025-05-15 13:32     ` Re: a lot of session wait on lock relation James Pang <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2025-05-15 13:24 UTC (permalink / raw)
  To: Laurenz Albe <[email protected]>; +Cc: James Pang <[email protected]>; [email protected]

Laurenz Albe <[email protected]> writes:
> On Thu, 2025-05-15 at 16:27 +0800, James Pang wrote:
>> why inserts into partition table cause "relation lock" ?

> Something else does; use the pg_blocking_pids() function with the process ID of
> a blocked backend to find out who is holding the lock.

More specifically: the inserts are only trying to get a shared lock.
If they are blocked, it's because some other operation is already
holding an exclusive lock on the table and is not letting go.
Look for uncommitted DDL changes.

More details about that at [1].

			regards, tom lane

[1] https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-TABLES





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: a lot of session wait on lock relation
  2025-05-15 08:27 a lot of session wait on lock relation James Pang <[email protected]>
  2025-05-15 12:08 ` Re: a lot of session wait on lock relation Laurenz Albe <[email protected]>
  2025-05-15 13:24   ` Re: a lot of session wait on lock relation Tom Lane <[email protected]>
@ 2025-05-15 13:32     ` James Pang <[email protected]>
  2025-05-15 13:43       ` Re: a lot of session wait on lock relation James Pang <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: James Pang @ 2025-05-15 13:32 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Laurenz Albe <[email protected]>; [email protected]

thanks, we are checking  partition   maintain jobs ,that hold access
exclusive lock.

Tom Lane <[email protected]> 於 2025年5月15日週四 下午9:24寫道:

> Laurenz Albe <[email protected]> writes:
> > On Thu, 2025-05-15 at 16:27 +0800, James Pang wrote:
> >> why inserts into partition table cause "relation lock" ?
>
> > Something else does; use the pg_blocking_pids() function with the
> process ID of
> > a blocked backend to find out who is holding the lock.
>
> More specifically: the inserts are only trying to get a shared lock.
> If they are blocked, it's because some other operation is already
> holding an exclusive lock on the table and is not letting go.
> Look for uncommitted DDL changes.
>
> More details about that at [1].
>
>                         regards, tom lane
>
> [1]
> https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-TABLES
>
>
>


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: a lot of session wait on lock relation
  2025-05-15 08:27 a lot of session wait on lock relation James Pang <[email protected]>
  2025-05-15 12:08 ` Re: a lot of session wait on lock relation Laurenz Albe <[email protected]>
  2025-05-15 13:24   ` Re: a lot of session wait on lock relation Tom Lane <[email protected]>
  2025-05-15 13:32     ` Re: a lot of session wait on lock relation James Pang <[email protected]>
@ 2025-05-15 13:43       ` James Pang <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: James Pang @ 2025-05-15 13:43 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Laurenz Albe <[email protected]>; [email protected]

Thanks, we are checking the partition maintain job , we have 12 partitions
, each week one partition there is a default partition attached with this
table and huge rows in default partition too , default partition has
primary key that include partition key (time range based) too.  partition
job detach/drop old partition and add/attach new partition each week.
  when add/attach new partition , with default partition to verify that it
contains no records which should be located in the partition being
attached,  it will full scan or use partition key(part of primary key) scan
instead ?  primary key (columa, partitionkey).

Thanks,

James

James Pang <[email protected]> 於 2025年5月15日週四 下午9:32寫道:

> thanks, we are checking  partition   maintain jobs ,that hold access
> exclusive lock.
>
> Tom Lane <[email protected]> 於 2025年5月15日週四 下午9:24寫道:
>
>> Laurenz Albe <[email protected]> writes:
>> > On Thu, 2025-05-15 at 16:27 +0800, James Pang wrote:
>> >> why inserts into partition table cause "relation lock" ?
>>
>> > Something else does; use the pg_blocking_pids() function with the
>> process ID of
>> > a blocked backend to find out who is holding the lock.
>>
>> More specifically: the inserts are only trying to get a shared lock.
>> If they are blocked, it's because some other operation is already
>> holding an exclusive lock on the table and is not letting go.
>> Look for uncommitted DDL changes.
>>
>> More details about that at [1].
>>
>>                         regards, tom lane
>>
>> [1]
>> https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-TABLES
>>
>>
>>


^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2025-05-15 13:43 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-05-15 08:27 a lot of session wait on lock relation James Pang <[email protected]>
2025-05-15 09:31 ` Chetan <[email protected]>
2025-05-15 12:08 ` Laurenz Albe <[email protected]>
2025-05-15 13:24   ` Tom Lane <[email protected]>
2025-05-15 13:32     ` James Pang <[email protected]>
2025-05-15 13:43       ` James Pang <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox