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 1jMxRi-0006Vf-0f for pgsql-general@arkaria.postgresql.org; Fri, 10 Apr 2020 17:28:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jMxRe-0005mC-UD for pgsql-general@arkaria.postgresql.org; Fri, 10 Apr 2020 17:27:58 +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 1jMxRe-0005m5-Mq for pgsql-general@lists.postgresql.org; Fri, 10 Apr 2020 17:27:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jMxRb-0003tu-Bw for pgsql-general@postgresql.org; Fri, 10 Apr 2020 17:27:58 +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 03AHRjLX008354; Fri, 10 Apr 2020 13:27:45 -0400 From: Tom Lane To: "Andrus" cc: "pgsql-general" Subject: Re: Huge number of pg_temp and pg_toast_temp schemas In-reply-to: <6F99845517EB402E9269BD6767CCE53C@dell2> References: <6F99845517EB402E9269BD6767CCE53C@dell2> Comments: In-reply-to "Andrus" message dated "Fri, 10 Apr 2020 19:32:37 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8352.1586539665.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 10 Apr 2020 13:27:45 -0400 Message-ID: <8353.1586539665@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Andrus" writes: > Hi! > Postgres 12 database contains huge number of pg_temp and pg_toast_temp s= chemas named > pg_temp_1 .. pg_temp_126 > and > pg_toast_temp_1 .. pg_toast_temp_126 This is an unsurprising state, if you routinely have a hundred-plus connections that sometimes create temp tables. Each such session needs schemas to keep its temp tables in. The temp tables are deleted at session exit, but we don't bother to remove the schema entries, figuring that they'll probably be needed again later, and a couple of rows in pg_namespace is negligible overhead anyway. > How to delete them automatically and prevent appear in future? You can't (well, if you're a superuser you could drop those schemas, but you can't prevent them from being recreated when needed). And it's really not worth trying. If you do try you're pretty likely to break concurrent usage of temp tables. > Cluster stopped since disk decomes full and streaming async replication= is used. Maybe one of those or some other factor created or > continues to create those schemas. Postgres 12.2 in Debian 10 is used. It's entirely possible that some temp table took up too much disk space, but ~250 rows in pg_namespace is not the cause of that problem. regards, tom lane