Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLW5M-0005KR-Ek for pgsql-general@arkaria.postgresql.org; Fri, 27 Jan 2023 21:16:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pLW5J-0006Et-Dp for pgsql-general@arkaria.postgresql.org; Fri, 27 Jan 2023 21:16:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLW5I-0006D8-UI for pgsql-general@lists.postgresql.org; Fri, 27 Jan 2023 21:16:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLW5C-00029s-1k for pgsql-general@lists.postgresql.org; Fri, 27 Jan 2023 21:16:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 30RLGOQs3570423; Fri, 27 Jan 2023 16:16:24 -0500 From: Tom Lane To: Rumpi Gravenstein cc: PostgreSQL Subject: Re: Indexes mysteriously change to ON ONLY In-reply-to: References: <3567881.1674852814@sss.pgh.pa.us> Comments: In-reply-to Rumpi Gravenstein message dated "Fri, 27 Jan 2023 16:01:31 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3570421.1674854184.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 27 Jan 2023 16:16:24 -0500 Message-ID: <3570422.1674854184@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Rumpi Gravenstein writes: > We are using the pg_indexes view (indexdef) to retrieve the index > definition. Ah. > Are you saying that as a normal part of building an index, there are sho= rt > periods of time where the pg_indexes view will show the index with ON ON= LY > specified? No, there's no "short periods", this is what it shows. That's partly because the output is designed for pg_dump to use. But there's a reasonably good argument for it anyway, which is that if you just say "create index" then that's effectively a macro for building the whole partitioned index set. That pg_indexes entry is only about the top-level "virtual" index, and there are other entries for the leaf indexes. For example, regression=3D# create table foo (f1 int primary key) partition by list (f1= ); CREATE TABLE regression=3D# create table foo_1 partition of foo for values in (1); CREATE TABLE regression=3D# create table foo_2 partition of foo for values in (2); CREATE TABLE regression=3D# select tablename,indexname,indexdef from pg_indexes where i= ndexname like 'foo%'; tablename | indexname | indexdef = = -----------+------------+-------------------------------------------------= ----------------- foo | foo_pkey | CREATE UNIQUE INDEX foo_pkey ON ONLY public.foo = USING btree (f1) foo_1 | foo_1_pkey | CREATE UNIQUE INDEX foo_1_pkey ON public.foo_1 U= SING btree (f1) foo_2 | foo_2_pkey | CREATE UNIQUE INDEX foo_2_pkey ON public.foo_2 U= SING btree (f1) (3 rows) If you wanted to reconstruct this from individual parts, as pg_dump does, you'd issue those commands and then connect them together with ATTACH PARTITION commands. regards, tom lane