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 1iDaVl-0001SM-2n for pgsql-performance@arkaria.postgresql.org; Thu, 26 Sep 2019 20:37:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iDaVj-0007Q1-VY for pgsql-performance@arkaria.postgresql.org; Thu, 26 Sep 2019 20:37:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iDaVj-0007Pn-Ju for pgsql-performance@lists.postgresql.org; Thu, 26 Sep 2019 20:37:11 +0000 Received: from p3plsmtpa08-06.prod.phx3.secureserver.net ([173.201.193.107]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iDaVd-0005gA-W0 for pgsql-performance@lists.postgresql.org; Thu, 26 Sep 2019 20:37:10 +0000 Received: from edilmar.intersite.com.br ([179.185.88.140]) by :SMTPAUTH: with ESMTPSA id DaVaiu4ms29RUDaVbiJlPf; Thu, 26 Sep 2019 13:37:04 -0700 To: pgsql-performance@lists.postgresql.org From: Edilmar Alves Subject: Slow pg_publication_tables with many schemas and tables Message-ID: <5e771308-25dc-15a5-a60d-d86beab71d3d@intersite.com.br> Date: Thu, 26 Sep 2019 16:37:02 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-CMAE-Envelope: MS4wfL/8cRImibFrwncP4ICVIr7pkF+rMW8d8sUIOxrr3GG8vNR2vYd5OG0NWPXksyXGqNnMYuk7g9y44/EnJyOj+dp1rKTUyPYJVhwTT10LWHLRFCg1lJJQ Ewk2kDjti9na1Mnh+NHKsW2oroIEU7Ew0ZsSoZa+qOQ6Q9UOmsEFSk6MjkRgYPUqte1dksKUlMDEGLZstCkHWToMS3TOd2wx8OQuoh3SCRFW1zrHFWpeuESy qNgTvsdhl7u3FRuO9gs+v84ky7gQvDjWVU+sbpPEaKk= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I use PG 11.5 into CentOS6 server, with 50 schemas, exactly equals in tables structure, and more than 400 tables/schema. Then, there is more than 20000 tables. I found the discussion in pgsql-general thread: https://www.postgresql.org/message-id/flat/11566.1558463253%40sss.pgh.pa.us#ec144ebcd8a829010fc82a7fe2abfd3f but thread was closed. Then, I sent here in performance list my problem. ------------------------------------- I changed the original PG view like said in the above thread: CREATE OR REPLACE VIEW pg_catalog.pg_publication_tables AS SELECT P.pubname AS pubname, N.nspname AS schemaname, C.relname AS tablename FROM pg_publication P, pg_class C JOIN pg_namespace N ON (N.oid = C.relnamespace), LATERAL pg_get_publication_tables(P.pubname) WHERE C.oid = pg_get_publication_tables.relid; but the problem continues. It is very slow to process the query used by replication system: SELECT DISTINCT t.schemaname, t.tablename FROM pg_catalog.pg_publication_tables t WHERE t.pubname IN ('mypubschema'); ------------------------------------- Then, in my case I created a publication for each schema and all tables with the same same of the schema, creating 50 publications. After this, I changed the view above to this: CREATE OR REPLACE VIEW pg_catalog.pg_publication_tables AS SELECT p.pubname, c.schemaname, c.tablename FROM pg_publication p JOIN pg_tables c ON p.pubname = c.schemaname; And the query below became very fast: SELECT DISTINCT t.schemaname, t.tablename FROM pg_catalog.pg_publication_tables t WHERE t.pubname IN ('mypubschema'); My problem was solved but I think next version of pg should verify this problem to find a general solution.