Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i826D-00015G-70 for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Sep 2019 12:51:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i826B-0000sy-Mw for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Sep 2019 12:51:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i826A-0000mZ-Lo for pgsql-hackers@lists.postgresql.org; Wed, 11 Sep 2019 12:51:51 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8266-0000Qt-Oj for pgsql-hackers@lists.postgresql.org; Wed, 11 Sep 2019 12:51:50 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 498277CC; Wed, 11 Sep 2019 08:51:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 11 Sep 2019 08:51:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=7j1ohkEJBSQ8W6+0TUdYNwGpGPjiiMMUhNKtCTX00r8=; b=NS/YqrII ykk3UTguHjy4XBml6iqxXHM3I4f+/Q80szVzwZoLxfSJ/U2jKCciSjcOVZ7sqNIM BnyZDfOvrinNQiB008B0ozNp03rJ2woMswM3mNX08yHXrVNW0Khn1QrloomgMPC7 J4RrPdw6LpbGqSl1SYQNo4hnUl3+Z8PxBVJ0xIMV/0jDRfWbsXfsO6RlKq6igTNS u/ZZO+kZOeQ+ak4UHJHyzCWWgHV4acT5zBXf4r3x0MO5wF5jAa0MHoJnMXSfBYLs CK6FQQspJdHTxEZDaAx0Kuk8byRCoc/cldqAOvzofJNdQjq5CsuNsTjD8MSrtaZF gMc04EqCt+kJFQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrtdefgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugfgjggfsehtkeertddtredunecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcufhhrohhmucdvnhgusfhurggurhgrnhhtuceorghlvhhhvghrrh gvsegrlhhvhhdrnhhoqdhiphdrohhrgheqnecuffhomhgrihhnpedvnhguqhhurggurhgr nhhtrdgtohhmnecukfhppeduledtrdduvddurddvledrfeenucfrrghrrghmpehmrghilh hfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghenucevlhhushht vghrufhiiigvpedt X-ME-Proxy: Received: from nimloth.alvh.no-ip.org (unknown [190.121.29.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 4C0B3D60065; Wed, 11 Sep 2019 08:51:42 -0400 (EDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 9D4A912086F; Wed, 11 Sep 2019 09:51:40 -0300 (-03) Date: Wed, 11 Sep 2019 09:51:40 -0300 From: Alvaro Herrera from 2ndQuadrant To: Amit Khandekar Cc: PostgreSQL Hackers Subject: Re: logical decoding : exceeded maxAllocatedDescs for .spill files Message-ID: <20190911125140.GA21034@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Sep-11, Amit Khandekar wrote: > I reproduced the error "exceeded maxAllocatedDescs (492) while trying > to open file ...", which was also discussed about in the thread [1]. > This issue is similar but not exactly the same as [1]. In [1], the > file for which this error used to show up was > "pg_logical/mappings/map...." , while here it's the .spill file. And > here the issue , in short, seems to be : The .spill file does not get > closed there and then, unlike in [1] where there was a file descriptor > leak. Uh-oh :-( Thanks for the reproducer -- I confirm it breaks things. > Looking at the code, what might be happening is, > ReorderBufferIterTXNInit()=>ReorderBufferRestoreChanges() opens the > files, but leaves them open if end of file is not reached. Eventually > if end of file is reached, it gets closed. The function returns back > without closing the file descriptor if reorder buffer changes being > restored are more than max_changes_in_memory. Probably later on, the > rest of the changes get restored in another > ReorderBufferRestoreChanges() call. But meanwhile, if there are a lot > of such files opened, we can run out of the max files that PG decides > to keep open (it has some logic that takes into account system files > allowed to be open, and already opened). Makes sense. > Offhand, what I am thinking is, we need to close the file descriptor > before returning from ReorderBufferRestoreChanges(), and keep track of > the file offset and file path, so that next time we can resume reading > from there. I think doing this all the time would make restore very slow -- there's a reason we keep the files open, after all. It would be better if we can keep the descriptors open as much as possible, and only close them if there's trouble. I was under the impression that using OpenTransientFile was already taking care of that, but that's evidently not the case. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services