pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Partitioned tables and locks
4+ messages / 3 participants
[nested] [flat]

* Partitioned tables and locks
@ 2019-12-19 10:04 James Sewell <james.sewell@jirotech.com>
  2019-12-19 13:38 ` Re: Partitioned tables and locks Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: James Sewell @ 2019-12-19 10:04 UTC (permalink / raw)
  To: pgsql-general

Is it expected that a lock on a partitioned table will take out 2 locks per
child regardless of the number of children which are excluded at plan time?

For example I can select count(*) from a table with 3500 partitions in
transaction, and see 7000 AccessShareLocks show up till I finish the
transaction.

Bonus question - sometimes if I query pg_locks fast enough I can see ~30K
locks - how could this possibly be the case. This is on an otherwise idle
system.

Cheers,
James

-- 
The contents of this email are confidential and may be subject to legal or 
professional privilege and copyright. No representation is made that this 
email is free of viruses or other defects. If you have received this 
communication in error, you may not copy or distribute any part of it or 
otherwise disclose its contents to anyone. Please advise the sender of your 
incorrect receipt of this correspondence.

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

* Re: Partitioned tables and locks
  2019-12-19 10:04 Partitioned tables and locks James Sewell <james.sewell@jirotech.com>
@ 2019-12-19 13:38 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-12-19 21:42   ` Re: Partitioned tables and locks James Sewell <james.sewell@jirotech.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2019-12-19 13:38 UTC (permalink / raw)
  To: James Sewell <james.sewell@jirotech.com>; +Cc: pgsql-general

James Sewell <james.sewell@jirotech.com> writes:
> Is it expected that a lock on a partitioned table will take out 2 locks per
> child regardless of the number of children which are excluded at plan time?

Depends on the details of your query, and on which PG version you're
using, but it's by no means surprising for each child table to get
locked.  (I'm not sure where *two* locks would come from, though.)

If you're working with massively partitioned tables, increasing
max_locks_per_transaction is a good idea.

			regards, tom lane





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

* Re: Partitioned tables and locks
  2019-12-19 10:04 Partitioned tables and locks James Sewell <james.sewell@jirotech.com>
  2019-12-19 13:38 ` Re: Partitioned tables and locks Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-12-19 21:42   ` James Sewell <james.sewell@jirotech.com>
  2019-12-19 22:38     ` Re: Partitioned tables and locks Michael Lewis <mlewis@entrata.com>
  0 siblings, 1 reply; 4+ messages in thread

From: James Sewell @ 2019-12-19 21:42 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

> Is it expected that a lock on a partitioned table will take out 2 locks
> per
> > child regardless of the number of children which are excluded at plan
> time?
>
> Depends on the details of your query, and on which PG version you're
> using, but it's by no means surprising for each child table to get
> locked.  (I'm not sure where *two* locks would come from, though.)


The queries were just select count(*) both with a where clause which
excludes some partitions and without, I’m on 11.

The table has over 3K partitions

>
>
> If you're working with massively partitioned tables, increasing
> max_locks_per_transaction is a good idea.


It’s 256 at the moment, with 600 connections - guess I need more.
-- 
James Sewell,
Chief Architect

Suite 112, Jones Bay Wharf, 26-32 Pirrama Road, Pyrmont NSW 2009
P (+61) 2 8099 9000  W www.jirotech.com  F (+61) 2 8099 9099

-- 
The contents of this email are confidential and may be subject to legal or 
professional privilege and copyright. No representation is made that this 
email is free of viruses or other defects. If you have received this 
communication in error, you may not copy or distribute any part of it or 
otherwise disclose its contents to anyone. Please advise the sender of your 
incorrect receipt of this correspondence.

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

* Re: Partitioned tables and locks
  2019-12-19 10:04 Partitioned tables and locks James Sewell <james.sewell@jirotech.com>
  2019-12-19 13:38 ` Re: Partitioned tables and locks Tom Lane <tgl@sss.pgh.pa.us>
  2019-12-19 21:42   ` Re: Partitioned tables and locks James Sewell <james.sewell@jirotech.com>
@ 2019-12-19 22:38     ` Michael Lewis <mlewis@entrata.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Michael Lewis @ 2019-12-19 22:38 UTC (permalink / raw)
  To: James Sewell <james.sewell@jirotech.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general

I don't recall the details, but I know v12 included significant
enhancements to lock relations later in the process such that when
targeting relatively few of the partitions, it can be a major performance
boost.

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


end of thread, other threads:[~2019-12-19 22:38 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-12-19 10:04 Partitioned tables and locks James Sewell <james.sewell@jirotech.com>
2019-12-19 13:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-12-19 21:42   ` James Sewell <james.sewell@jirotech.com>
2019-12-19 22:38     ` Michael Lewis <mlewis@entrata.com>

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