pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Edilmar Alves <edilmaralves@intersite.com.br>
To: pgsql-performance@lists.postgresql.org
Subject: Slow pg_publication_tables with many schemas and tables
Date: Thu, 26 Sep 2019 16:37:02 -0400
Message-ID: <5e771308-25dc-15a5-a60d-d86beab71d3d@intersite.com.br> (raw)

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#ec144ebcd8a829010fc82a7f...

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.








view thread (3+ messages)  latest in thread

Message-ID: <5e771308-25dc-15a5-a60d-d86beab71d3d@intersite.com.br>
Permalink:  ../5e771308-25dc-15a5-a60d-d86beab71d3d@intersite.com.br/
Also on:    postgresql.org/message-id/5e771308-25dc-15a5-a60d-d86beab71d3d@intersite.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: edilmaralves@intersite.com.br, pgsql-performance@lists.postgresql.org
  Subject: Re: Slow pg_publication_tables with many schemas and tables
  In-Reply-To: <5e771308-25dc-15a5-a60d-d86beab71d3d@intersite.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox