public inbox for [email protected]  
help / color / mirror / Atom feed
From: Adrian Klaver <[email protected]>
To: Rumpi Gravenstein <[email protected]>
Cc: Colin 't Hart <[email protected]>
Cc: PostgreSQL General <[email protected]>
Subject: Re: Two sequences associated with one identity column
Date: Thu, 30 Oct 2025 09:32:57 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAEpg1wBP7U6CiaJFz1LeH3A01jRgg6iZsyrmFk_jEHKfWgesdg@mail.gmail.com>
References: <CAMon-aTbZC5k2pLpijk5x+h__LV08DzpoJtHBgZGkOKJNJ91pw@mail.gmail.com>
	<[email protected]>
	<CAMon-aTMgbwC9j-wY8iX5kZ4=KXzCXc-Wpwx3viid8hQ_bJkoQ@mail.gmail.com>
	<[email protected]>
	<CAMon-aQ0Zs-Otkp1=zk3WYt7Am-_oQHKEmD_rZ1CNGBAgM_jzw@mail.gmail.com>
	<[email protected]>
	<CAMon-aQNPQ86-swjmpiryy3s_yKaWsZbzysrbn7e1xPc3JM3fg@mail.gmail.com>
	<[email protected]>
	<CAEpg1wBP7U6CiaJFz1LeH3A01jRgg6iZsyrmFk_jEHKfWgesdg@mail.gmail.com>

On 10/30/25 08:22, Rumpi Gravenstein wrote:
> I've seen two indexes created on the same table/column when you create a 
> primary key as part of table create ddl and then also run a separate 
> create index statement for the same table/column.

Yes it is possible to create two indexes on a given table column, the 
issue here though is, from this post:

https://www.postgresql.org/message-id/CAMon-aQ0Zs-Otkp1%3Dzk3WYt7Am-_oQHKEmD_rZ1CNGBAgM_jzw%40mail.g...

The two indexes are coming from:

--
-- Name: <sequence1>; Type: SEQUENCE; Schema: <schema>; Owner: <owner>
--


ALTER TABLE <schema>.<tablename> ALTER COLUMN id ADD GENERATED ALWAYS
AS IDENTITY (
     SEQUENCE NAME <schema>.<sequence1>
     START WITH 1
     INCREMENT BY 1
     NO MINVALUE
     NO MAXVALUE
     CACHE 1
);


--
-- Name: <sequence2>; Type: SEQUENCE; Schema: <schema>; Owner: <owner>
--


ALTER TABLE <schema>.<tablename> ALTER COLUMN id ADD GENERATED ALWAYS
AS IDENTITY (
     SEQUENCE NAME <schema>.<sequence2>
     START WITH 1
     INCREMENT BY 1
     NO MINVALUE
     NO MAXVALUE
     CACHE 1
);

That is two GENERATED ALWAYS AS IDENTITY sequences being created for the 
PK. That should not happen.



> 
> On Thu, Oct 30, 2025 at 10:42 AM Adrian Klaver 
> <[email protected] <mailto:[email protected]>> wrote:
> 
>     On 10/30/25 01:55, Colin 't Hart wrote:
>      >           relname          | relnamespace | relpersistence
>      > --------------------------+--------------+----------------o
>      >   <sequence1>  |    524799410 | p
>      >   <sequence2>  |    524799410 | p
>      > (2 rows)
>      >
> 
>     Well so much for that guess. I was exploring the idea that the sequence
>     may have been unlogged at some point and you had both a logged(p) and
>     unlogged(u) instance of each.
> 
> 
>     -- 
>     Adrian Klaver
>     [email protected] <mailto:[email protected]>
> 
> 
> 
> 
> -- 
> Rumpi Gravenstein


-- 
Adrian Klaver
[email protected]






view thread (2+ messages)

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: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Two sequences associated with one identity column
  In-Reply-To: <[email protected]>

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

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