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 1hydt0-0006eD-Qs for pgsql-general@arkaria.postgresql.org; Fri, 16 Aug 2019 15:11:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hydsz-0005jA-Nz for pgsql-general@arkaria.postgresql.org; Fri, 16 Aug 2019 15:11:25 +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 1hydsz-0005hY-E0 for pgsql-general@lists.postgresql.org; Fri, 16 Aug 2019 15:11:25 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hydsr-0002xH-SI for pgsql-general@postgresql.org; Fri, 16 Aug 2019 15:11:25 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id D8D631662F180 for ; Fri, 16 Aug 2019 08:11:15 -0700 (MST) Date: Fri, 16 Aug 2019 08:11:15 -0700 (MST) From: PegoraroF10 To: pgsql-general@postgresql.org Message-ID: <1565968275886-0.post@n3.nabble.com> In-Reply-To: <19659.1565966519@sss.pgh.pa.us> References: <1565879436637-0.post@n3.nabble.com> <1565896167022-0.post@n3.nabble.com> <88609b1c-1653-6d4c-c1b4-883e109f5b93@aklaver.com> <1565963536657-0.post@n3.nabble.com> <19659.1565966519@sss.pgh.pa.us> Subject: Re: slow queries on system tables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk As I told you before, these queries cannot be changed because the driver creates them.=20 As I cannot change them how can I help Postgres to run it faster, just that= . My log_min_duration_statement =3D 500ms, so I find SQL some dozens of this = sql inside it daily, but I=C2=B4m sure this sql is used thousands and thousands= a day. =20 duration: 566.415 ms execute PRSTMTST1590201604/PORTALST1590201604: SELECT current_database() AS TABLE_CATALOG, n.nspname AS TABLE_SCHEMA, t.relname A= S TABLE_NAME, t.oid AS TABLE_OID, current_database() AS INDEX_CATALOG, n.nspname AS INDEX_SCHEMA, c.relname AS INDEX_NAME, c.oid AS INDEX_OID, a.attname AS COLUMN_NAME, a.attnum AS COLUMN_POSITION,indoption[index] & 1 AS DESCENDING , indisunique::integer AS UNIQUE FROM (SELECT generate_series(0, indnatts - 1), indrelid, indexrelid, indkey, indoption= , indisunique, indisprimary FROM pg_index i) i(index, indrelid, indexrelid, indkey, indoption, indisunique, indisprimary) INNER JOIN pg_class c ON c.oid =3D indexrelid INNER JOIN pg_class t ON t.oid =3D indrelid INNER = JOIN pg_namespace n ON n.oid =3D t.relnamespace INNER JOIN pg_attribute a ON a.attrelid =3D indrelid AND a.attnum =3D indkey[index] WHERE n.nspname LIKE 'f10_0275, public' AND t.relname LIKE 'sys_var' ORDER BY indisprimary::integer DESC, n.nspname, t.relname, c.relname, a.attnum QUERY PLAN Sort (cost=3D260362.69..260362.69 rows=3D1 width=3D470) (actual time=3D59.526..59.527 rows=3D0 loops=3D1) Sort Key: ((i.indisprimary)::integer) DESC, n.nspname, t.relname, c.relname, a.attnum Sort Method: quicksort Memory: 25kB -> Nested Loop (cost=3D1003.58..260362.68 rows=3D1 width=3D470) (actual time=3D59.519..59.519 rows=3D0 loops=3D1) -> Nested Loop (cost=3D1003.44..260360.98 rows=3D1 width=3D238) (= actual time=3D5.251..58.872 rows=3D424 loops=3D1) -> Gather (cost=3D1003.02..260360.42 rows=3D1 width=3D174) = (actual time=3D5.232..72.894 rows=3D424 loops=3D1) Workers Planned: 1 Workers Launched: 1 -> Nested Loop (cost=3D3.02..259360.32 rows=3D1 width= =3D174) (actual time=3D8.357..48.200 rows=3D212 loops=3D2) Join Filter: (t.oid =3D a.attrelid) -> Hash Join (cost=3D2.59..259357.51 rows=3D4 width=3D138) (actual time=3D8.322..46.124 rows=3D212 loops=3D2) Hash Cond: (i.indrelid =3D t.oid) -> ProjectSet (cost=3D0.00..258260.16 rows=3D51008000 width=3D66) (actual time=3D0.011..33.557 rows=3D53694 loops= =3D2) -> Parallel Seq Scan on pg_index i= =20 (cost=3D0.00..2710.08 rows=3D51008 width=3D64) (actual time=3D0.007..6.804 rows=3D43564 loops=3D2) -> Hash (cost=3D2.44..2.44 rows=3D12 widt= h=3D72) (actual time=3D7.614..7.615 rows=3D210 loops=3D2) Buckets: 1024 Batches: 1 Memory Usage: 30kB -> Index Scan using pg_class_relname_nsp_index on pg_class t (cost=3D0.42..2.44 rows=3D12 widt= h=3D72) (actual time=3D0.029..7.556 rows=3D210 loops=3D2) Index Cond: ((relname >=3D 'sys'::name) AND (relname < 'syt'::name)) Filter: (relname ~~ 'sys_account'::text) Rows Removed by Filter: 1696 -> Index Scan using pg_attribute_relid_attnum_index on pg_attribute a (cost=3D0.42..0.69 rows= =3D1 width=3D70) (actual time=3D0.009..0.009 rows=3D1 loops=3D424) Index Cond: ((attrelid =3D i.indrelid) AND (attnum =3D (i.indkey)[(generate_series(0, (i.indnatts - 1)))])) -> Index Scan using pg_class_oid_index on pg_class c=20 (cost=3D0.42..0.56 rows=3D1 width=3D68) (actual time=3D0.005..0.005 rows=3D= 1 loops=3D424) Index Cond: (oid =3D i.indexrelid) -> Index Scan using pg_namespace_oid_index on pg_namespace n=20 (cost=3D0.14..0.92 rows=3D1 width=3D68) (actual time=3D0.001..0.001 rows=3D= 0 loops=3D424) Index Cond: (oid =3D t.relnamespace) Filter: (nspname ~~ 'f10_0511, public'::text) Rows Removed by Filter: 1 Planning Time: 1.176 ms Execution Time: 76.031 ms -- Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.h= tml