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 1hECVp-0000CO-Jp for pgsql-general@arkaria.postgresql.org; Wed, 10 Apr 2019 12:39:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hECVo-00040z-42 for pgsql-general@arkaria.postgresql.org; Wed, 10 Apr 2019 12:39:32 +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 1hECVn-0003yl-Q8 for pgsql-general@lists.postgresql.org; Wed, 10 Apr 2019 12:39:31 +0000 Received: from [195.159.176.226] (helo=blaine.gmane.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hECVl-0003Ou-JI for pgsql-general@postgresql.org; Wed, 10 Apr 2019 12:39:31 +0000 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hECVj-000XRR-Ro for pgsql-general@postgresql.org; Wed, 10 Apr 2019 14:39:27 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Thomas Kellerer Subject: pg_indexes doesn't show indexes for partitioned tables - bug or intended? Date: Wed, 10 Apr 2019 14:39:22 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 X-Mozilla-News-Host: news://news.gmane.org:119 Content-Language: en-GB X-Host-Lookup-Failed: Reverse DNS lookup failed for 195.159.176.226 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk In Postgres 11.2, indexes defined on partitioned tables do not show up in pg_indexes (the actual indexes for the partitions however do show up). E.g.: CREATE TABLE base_table ( column1 varchar(50) NOT NULL, column2 integer NOT NULL, column3 integer not null, part_key bigint NOT NULL ) PARTITION BY HASH (part_key); CREATE UNIQUE INDEX idx_one ON base_table (column1, column2, part_key); The following select returns nothing: select * from pg_indexes where tablename = 'base_table'; This is caused by the fact that pg_indexes only returns information for regular tables and materialized views ("relkind in ('r','m')") and regular indexes (relkind = 'i') If the conditions on the relkind for the "table class" to include 'p' as well, and the relkind for the "index class" is changed to return 'i' and 'I', then those indexes are listed in pg_indexes as well: SELECT n.nspname AS schemaname, c.relname AS tablename, i.relname AS indexname, t.spcname AS tablespace, pg_get_indexdef(i.oid) AS indexdef FROM pg_index x JOIN pg_class c ON c.oid = x.indrelid JOIN pg_class i ON i.oid = x.indexrelid LEFT JOIN pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_tablespace t ON t.oid = i.reltablespace WHERE (c.relkind in ('r','m','p')) --<< add 'p' to the list AND i.relkind in ('i', 'I') --<< add 'I' to the list Is leaving out the indexes defined on the partitioned table intended or a bug? Regards Thomas