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 1hyGoY-000822-5N for pgsql-general@arkaria.postgresql.org; Thu, 15 Aug 2019 14:33:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hyGoX-0003yP-3c for pgsql-general@arkaria.postgresql.org; Thu, 15 Aug 2019 14:33:17 +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 1hyGm9-0004Qf-Nk for pgsql-general@lists.postgresql.org; Thu, 15 Aug 2019 14:30:49 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hyGly-0003b5-PL for pgsql-general@postgresql.org; Thu, 15 Aug 2019 14:30:49 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id A0A78165B7106 for ; Thu, 15 Aug 2019 07:30:36 -0700 (MST) Date: Thu, 15 Aug 2019 07:30:36 -0700 (MST) From: PegoraroF10 To: pgsql-general@postgresql.org Message-ID: <1565879436637-0.post@n3.nabble.com> Subject: 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 The driver I=C2=B4m using does some queries on system tables and obviously = I cannot change them because are driver inside. These two queries are usually fast, but sometimes they take 8 or 15 times more to run. The question is, can I change something on these tables ? Can i create an index, can I load them into cache ? What can I do to speed up if I cannot change the way thes= e queries are written ? Extracted from pg_stat_statements: Query 1 - calls: 200000 times, min_time ~ 20ms, mean_time ~ 50ms, max_time = ~ 480ms SELECT current_database() AS TABLE_CATALOG, n.nspname AS TABLE_SCHEMA, t.relname AS 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($2, indnatts - $3), indrelid, indexrelid, indkey, =20 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 = =20 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 $4 AND t.relname LIKE $5 ORDER BY indisprimary::integer DESC, n.nspname, t.relname, c.relname, a.attnum Query 1 - calls: 20000 times, min_time ~ 70ms, mean_time ~ 95ms, max_time ~ 170ms. SELECT pg_attribute.attname FROM pg_index, pg_class, pg_attribute WHERE upper(pg_class.relname) =3D $1 AND indrelid =3D pg_class.oid AND pg_attribute.attrelid =3D pg_class.oid AND pg_attribute.attnum =3D any(pg_index.indkey) AND indisprimary -- Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.h= tml