Re: Cursor with hold for select

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Bindra Bambharoliya <bindra(dot)bambharoliya(at)gmail(dot)com>, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Cursor with hold for select
Date: 2024-03-23 13:33:39
Message-ID: ea2d4ef840e4288ce87331300d3eaf492e34e841.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Fri, 2024-03-22 at 21:54 +0530, Bindra Bambharoliya wrote:
> I am facing issue with postgresql 11.17 version.
> When I use normal select it executes within 15 seconds.
> When use same query with begin; cursor "sql1" hold for select....
> Fetch 100 to "sql1"  it takes 3 minutes and sometime not executing even in 10 minutes. And I need to kill it.
> What could be the root cause. And how can we over one form this.

The reason could be that PostgreSQL plans statements in a cursor so that
the first 10% of the result are returned as fast as possible, rather than
for the shortest time to retrieve the whole result set.

But WITH HOLD cursors are materialized at COMMIT, so the whole result set
gets calculated.

You may experience better performance if you set "cursor_tuple_fraction = 1.0".

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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2024-03-23 16:37:22 Re: create index concurrently blocked by other query
Previous Message James Pang 2024-03-23 13:29:55 create index concurrently blocked by other query