Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pnL56-0000Rr-3I for pgsql-general@arkaria.postgresql.org; Fri, 14 Apr 2023 15:11:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pnL53-0006T4-A4 for pgsql-general@arkaria.postgresql.org; Fri, 14 Apr 2023 15:11:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pnL51-0006Sv-KT for pgsql-general@lists.postgresql.org; Fri, 14 Apr 2023 15:11:16 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pnL4w-002scd-R0 for pgsql-general@postgresql.org; Fri, 14 Apr 2023 15:11:15 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 6F5D65C0004; Fri, 14 Apr 2023 11:11:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 14 Apr 2023 11:11:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1681485067; x=1681571467; bh=2qPnGaeYN9tI3CxE/LC633SqMnI8cb54/tm 1xMri8FQ=; b=oyuwwWFobXY3m4oaC9pYrLMUVezRg0zZHXdlmjb4yyBZjYDqwTe rHddDUhhoW51wkPmaPul6HrxzKuI4A0DcTt8/0f7AsFv6Wew7xW95nFG4RshC7kK uCCerauMGfMfLOs1+UUPUsJXFQ86+j9N1oThvn6i9n/5ma46fBNdYVsHo2yHjTFK Est9cPH7QzwNju0h39PXwNjWbhPk2HRr534xZVhiFnjgei40Va7rbzC05iU1nz+X x3K3iqloN6Myuqwf7dSvMgziTP2DjM38BhnWSOEL6Frh7XyV0Vl42ew2NUGa0QOJ P3vM2rdEcT8kmYjOS6RvOWKQWzpewEldlqQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1681485067; x= 1681571467; bh=2qPnGaeYN9tI3CxE/LC633SqMnI8cb54/tm1xMri8FQ=; b=F JU1a80o4yTWkWioiDn81moX2LUbXlaH60axaqpHGyOA1g41IvgBG883O2WWdpBt9 VUu4/F7EyZTVDGIOUeg7TxIwcYbM1Pg1/TPoVbHx4/1AMhPjH79jab1+R4CLGd9T HqTywlmN+Rx7Cito8vyeeO4+OJ1X5pGcJJ+tf0K+UbzTfzYfl0CinL+txiOiCUCJ b5WR9QJjlszm7dHXlTvTGokfJyLZ6vNMT/WEel/bqo0OEP2czF5hBHdFwdPLHG9K PNveVQLs6ouRPc4fAPfCY8I9kvQ3bNgMd9X0bLesFvqKJnGkO1TpbSm2YS5Nszh+ 4pV3DT2HnREcyzxbLgnDQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeltddgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepleekgeejhf ekteehfeduveetheeivdduheekudelteefvdffueehtddvgedtfeefnecuffhomhgrihhn pehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgt ohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Apr 2023 11:11:06 -0400 (EDT) Message-ID: <536e4668-7c3a-c474-c819-5f10c31c61bb@aklaver.com> Date: Fri, 14 Apr 2023 08:11:06 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: cursor with hold must be save to disk? To: =?UTF-8?B?6buE5a6B?= , pgsql-general@postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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