Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnox5-0005ep-OA for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Aug 2018 17:42:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fnox3-0001Hy-NW for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Aug 2018 17:42:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnox3-0001Hq-Ch for pgsql-hackers@lists.postgresql.org; Thu, 09 Aug 2018 17:42:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnox0-0007SJ-RR for pgsql-hackers@postgresql.org; Thu, 09 Aug 2018 17:42:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w79HgH4i012171; Thu, 9 Aug 2018 13:42:17 -0400 From: Tom Lane To: Tomas Vondra cc: PostgreSQL-development Subject: Re: logical decoding / rewrite map vs. maxAllocatedDescs In-reply-to: <738a590a-2ce5-9394-2bef-7b1caad89b37@2ndquadrant.com> References: <738a590a-2ce5-9394-2bef-7b1caad89b37@2ndquadrant.com> Comments: In-reply-to Tomas Vondra message dated "Thu, 09 Aug 2018 19:31:00 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12169.1533836537.1@sss.pgh.pa.us> Date: Thu, 09 Aug 2018 13:42:17 -0400 Message-ID: <12170.1533836537@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tomas Vondra writes: > While investigating an issue with rewrite maps in logical decoding, I > found it's pretty darn trivial to hit this: > ERROR: 53000: exceeded maxAllocatedDescs (492) while trying to open > file "pg_logical/mappings/map-4000-4eb-1_60DE1E08-5376b5-537c6b" > This happens because we seem to open the mapping files and keep them > open until the next checkpoint, at which point we fsync + close. It sounds like whoever wrote that code was completely impervious to the API spec for AllocateFile(): * Note that files that will be open for any significant length of time * should NOT be handled this way, since they cannot share kernel file * descriptors with other files; there is grave risk of running out of FDs * if anyone locks down too many FDs. Perhaps these files should be accessed through fd.c's VFD infrastructure rather than ignoring it. Reinventing it is especially not the way to go. > Furthermore, the situation is made worse by opening the same file > repeatedly, under different file descriptor. That's just stupid :-( Note that the limit on maxAllocatedDescs is based on the kernel limit on how many files a process can have open, so assuming you can increase it is not going to end well. regards, tom lane