pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: 黄宁 <huangning0722@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: cursor with hold must be save to disk?
Date: Fri, 14 Apr 2023 08:11:06 -0700
Message-ID: <536e4668-7c3a-c474-c819-5f10c31c61bb@aklaver.com> (raw)
In-Reply-To: <CAKgrFs9Uq5FUMO6qQQDx0pPQyzkDqw-dGJc=VMupzuLbQ0b=jw@mail.gmail.com>
References: <CAKgrFs9Uq5FUMO6qQQDx0pPQyzkDqw-dGJc=VMupzuLbQ0b=jw@mail.gmail.com>

On 4/14/23 04:04, 黄宁 wrote:
> i want to use cursor with hold ,but when I declare a curosr , it takes a 
> long time to save the result set to disk. can i save the query state in 
> memory? and fetch forward the next result.
> 

 From the docs:

https://www.postgresql.org/docs/current/sql-declare.html

A cursor created with WITH HOLD is closed when an explicit CLOSE command 
is issued on it, or the session ends. In the current implementation, the 
rows represented by a held cursor are copied into a temporary file or 
memory area so that they remain available for subsequent transactions.

So I am going to guess the cursor query is holding a large amount of data.

To get a more specific answer you will need to provide:

1) Postgres version.

2) The complete DECLARE command being used.

3) An indication of the amount of data being retrieved.

4) The actual time for a 'long time'.

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (4+ messages)  latest in thread

Message-ID: <536e4668-7c3a-c474-c819-5f10c31c61bb@aklaver.com>
Permalink:  ../536e4668-7c3a-c474-c819-5f10c31c61bb@aklaver.com/
Also on:    postgresql.org/message-id/536e4668-7c3a-c474-c819-5f10c31c61bb@aklaver.com

 · 

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: adrian.klaver@aklaver.com, huangning0722@gmail.com
  Subject: Re: cursor with hold must be save to disk?
  In-Reply-To: <536e4668-7c3a-c474-c819-5f10c31c61bb@aklaver.com>
  References: <CAKgrFs9Uq5FUMO6qQQDx0pPQyzkDqw-dGJc=VMupzuLbQ0b=jw@mail.gmail.com> <536e4668-7c3a-c474-c819-5f10c31c61bb@aklaver.com>

* 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