From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael P. McDonnell <bzaks1424@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Hung Query with No Locking Issues
Date: Sun, 07 May 2023 17:25:34 -0400
Message-ID: <183988.1683494734@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHmCLHqDsYXQmNYROBQnFvtFnEkQxhD57Qz2h+wp4oOWRBYXVQ@mail.gmail.com>
References: <CAHmCLHqDsYXQmNYROBQnFvtFnEkQxhD57Qz2h+wp4oOWRBYXVQ@mail.gmail.com>
"Michael P. McDonnell" <bzaks1424@gmail.com> writes:
> I have 2 stored procedures that need to run back to back. It could
> convert to a single one - but it's easier from a maintenance perspective to
> keep them separated.
> The first procedure effectively is
> INSERT INTO table_b () SELECT ____ FROM _table_a_;
> COMMIT;
> Total execution time - about 180s. Nothing in the pg_locks table and
> nothing in the pg_stat_activity table suggests anything is hung over.
> The second procedure mutates table_b data into table_b_collapsed
> INSERT INTO table_c () SELECT _____ FROM _table_b_ JOIN _table_b as b1_
> JOIN _table_b as b2_ JOIN _table_b as b3_, etc...;
> COMMIT;
> The first time I run my second stored procedure - it hangs for up to 8
> hours.
> If I immediately cancel and re-run the second stored procedure it runs in 2
> seconds.
Perhaps an "ANALYZE table_b" in between would help.
regards, tom lane
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, bzaks1424@gmail.com
Subject: Re: Hung Query with No Locking Issues
In-Reply-To: <183988.1683494734@sss.pgh.pa.us>
References: <CAHmCLHqDsYXQmNYROBQnFvtFnEkQxhD57Qz2h+wp4oOWRBYXVQ@mail.gmail.com> <183988.1683494734@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