Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vE8bz-0063AI-5c for pgsql-general@arkaria.postgresql.org; Wed, 29 Oct 2025 16:01:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vE8by-0025vX-3Q for pgsql-general@arkaria.postgresql.org; Wed, 29 Oct 2025 16:01:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vE8bx-0025vP-Oj for pgsql-general@lists.postgresql.org; Wed, 29 Oct 2025 16:01:20 +0000 Received: from fhigh-a8-smtp.messagingengine.com ([103.168.172.159]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vE8bu-004uTi-2V for pgsql-general@lists.postgresql.org; Wed, 29 Oct 2025 16:01:20 +0000 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 467B314000C1; Wed, 29 Oct 2025 12:01:17 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Wed, 29 Oct 2025 12:01:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1761753677; x=1761840077; bh=AglHACgEj3OwwsdPc8gdfkEl2phHB3u9bHhV7uEZUx0=; b= lVrmL0LV2fL/Ae8Ahzam2/srkdZyNcujGzq7JtMIbuC9ng3P4bEA5CzvYMoSKz4w kUlbZHPdiKZmRTauuZEDm0Oubq+2ryxXGPTissGBHPEHHXMHAkl8xvympzUePSuw 4+2gmsiSCfPq7O4cZHUN4uXcUgBbIRjOsOQ9yWlqScxsTnrOI6ifNdc49aAqHlir SUqxArYbtMPWPMsb0xqtCs4WS7qZwevNXp16BlaLRBYHDaSYVAG9FiIDqgxjLU6O 5rN0Jh8MtGuI8ykLaP8j3YgJB9yC5+HcCOtmwaNgApTPJsaxlD3kuxNs01yRa+TU R6VIphEKdm8+wVfq3ZBDjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1761753677; x=1761840077; bh=A glHACgEj3OwwsdPc8gdfkEl2phHB3u9bHhV7uEZUx0=; b=ut35C5BvBMhS+c94K YiR9PE0YV6OTF9ijtHJIiN6NeGZoBjsyY3HiofOhxkRh2PBl5dJZDlta7b+OvuIh hOzCVdazNSQOLzIOVlFb2K+fx0WBYCdPNy/4LPfdgmfd/uFtYzSgXWP/5V4p/9X2 Oo/86yfqyyQRqljZaZp0kYyngKHk/F6St/+p+AnyC7Kmj71PEZUp2uU62kXsvw6d kEaoEJdtKhn+2YpUsaNe2brT9WByY03pq/zAGObPw4v73PDDeuFUwgC9ZNombsO2 e848jvGy4pawuN3byUk0XLDZ7HVBw9OzuYCdXvKj5MksTI+DauV67GvScgQnLvbr 7aTiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduieegudeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffvfhfhjggtgfesthejredttddvjeenucfhrhhomheprfgvthgvrhcu gfhishgvnhhtrhgruhhtuceophgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgqeenuc ggtffrrghtthgvrhhnpeehiedvhfeuhfeugefgfeehgeejtdevuefhtefhueefvddugfdt ueehgfefudfhffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehpvghtvghrsegvihhsvghnthhrrghuthdrohhrghdpnhgspghrtghpthhtohep vddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheptgholhhinhhthhgrrhhtsehgmh grihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdr phhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 Oct 2025 12:01:13 -0400 (EDT) Message-ID: Date: Wed, 29 Oct 2025 17:01:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Two sequences associated with one identity column To: Colin 't Hart , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 29.10.25 12:27, Colin 't Hart wrote: > One of my clients has a database in which a single identity column > (called "id" in that table) has two sequences associated with it(!) > > Both sequences display > > Sequence for identity column: ..id > > when described with \d in psql. > > > Inserting fails with "ERROR: more than one owned sequence found", as > does trying to alter the table to drop the identity on that column. > > > Trying to drop either sequence results in > > ERROR: cannot drop sequence because column id of table > requires it > HINT: You can drop column id of table instead. > > while trying to alter either sequence "owned by none" results in > > ERROR: cannot change ownership of identity sequence > DETAIL: Sequence "" is linked to table "". > > > How do we fix this? I presume we need to update the catalog directly > to dissociate one of the sequences and after that drop the orphaned > sequence. I don't know how one would get into this situation, but I can fake it like this: create table t1 (a int, b int generated always as identity); select * from pg_depend where refclassid = 'pg_class'::regclass and refobjid = 't1'::regclass; classid | objid | objsubid | refclassid | refobjid | refobjsubid | deptype ---------+-------+----------+------------+----------+-------------+--------- 1247 | 16388 | 0 | 1259 | 16386 | 0 | i 1259 | 16384 | 0 | 1259 | 16386 | 2 | i (2 rows) The second entry is the dependency between the sequence and the table. 1259 is pg_class, the numbers 16384 and 16386 are the OIDs of the sequence and the table, and 2 is the column number. Now create another sequence and manually insert a dependency record: create sequence sx; insert into pg_depend values (1259, 'sx'::regclass, 0, 1259, 16386, 2, 'i'); Now you have the same breakage: insert into t1 (a) values (1); ERROR: more than one owned sequence found To fix this, remove the extra dependency record: delete from pg_depend where (classid, objid, objsubid) = ('pg_class'::regclass, 'sx'::regclass, 0) and (refclassid, refobjid, refobjsubid) = ('pg_class'::regclass, 't1'::regclass, 2) and deptype = 'i';