Re: Cursor with hold for select - Mailing list pgsql-admin

From Laurenz Albe
Subject Re: Cursor with hold for select
Date
Msg-id ea2d4ef840e4288ce87331300d3eaf492e34e841.camel@cybertec.at
Whole thread Raw
In response to Cursor with hold for select  (Bindra Bambharoliya <bindra.bambharoliya@gmail.com>)
List 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



pgsql-admin by date:

Previous
From: James Pang
Date:
Subject: create index concurrently blocked by other query
Next
From: Tom Lane
Date:
Subject: Re: create index concurrently blocked by other query