pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gautam Bellary <gautam@pulsasensors.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Assistance with an out of shared memory error
Date: Thu, 13 Jan 2022 18:35:55 -0500
Message-ID: <3297903.1642116955@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+MVzH2N65_JzJyC4p8C4EC9k29C=VAi9eAnZdWWFV-co4c0+w@mail.gmail.com>
References: <CA+MVzH2N65_JzJyC4p8C4EC9k29C=VAi9eAnZdWWFV-co4c0+w@mail.gmail.com>

Gautam Bellary <gautam@pulsasensors.com> writes:
> I've got a PL/pgSQL function (regenerate_gateway_last_seen, attached) that
> loops through all partitions of 2 tables ("Measure" and "ValuelessMeasure",
> schema attached) selecting data from each into another table
> ("GatewayLastSeenNew"). Occasionally the function runs to completion, but
> usually it errors with the message copied below. I'd appreciate any advice
> to help understand why I'm seeing this and if increasing
> max_locks_per_transaction, changing another configuration value, or
> changing how the function works would improve reliability.

Yes, you ought to raise max_locks_per_transaction ...

> 2. max_locks_per_transaction is being hit in the transaction - this also
> seems unlikely because max_locks_per_transaction is set to the default
> value of 64, but there are ~8000 partitions to consider and I expect the
> resulting GatewayLastSeenNew table to have thousands of rows.

... or else reduce the number of partitions you're using.  (People
frequently seem to think that more partitions are free.  That is
extremely not true.  I generally think that if you're using more
than a few dozen partitions per table, you are making a mistake.)

> If I was
> taking locks that would contribute towards that ceiling of 64 I'd expect
> this to fail every time, instead of failing often but not always as I
> observe.

You misinterpret what that parameter does: it is not a hard per-session
limit.  This error appears when the shared lock-table pool overflows, so
you can (usually) take a lot more than 64 locks before running into
trouble.  It matters what else is going on in the database.

> 3. The max size of the lock table is being exceeded - my understanding is
> that the lock table has room for max_locks_per_transaction *
> (max_connections + max_prepared_transactions) locks, which would be 64 *
> (200 + 0) = 12800 for my current configuration. I used 'SELECT COUNT(*)
> FROM PG_LOCKS' while the function was running and observe values as high as
> 21758, so if this is the issue it seems like I might not be estimating the
> max size of the lock table correctly or only specific locks contribute to
> that.

I don't recall for sure, but I think that the lock table has one entry per
lockable object, while the pg_locks view shows separate entries for
different lock modes on the same object.

			regards, tom lane





view thread (5+ messages)  latest in thread

Message-ID: <3297903.1642116955@sss.pgh.pa.us>
Permalink:  ../3297903.1642116955@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3297903.1642116955@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, gautam@pulsasensors.com
  Subject: Re: Assistance with an out of shared memory error
  In-Reply-To: <3297903.1642116955@sss.pgh.pa.us>
  References: <CA+MVzH2N65_JzJyC4p8C4EC9k29C=VAi9eAnZdWWFV-co4c0+w@mail.gmail.com> <3297903.1642116955@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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