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 1u2pvI-006e21-12 for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Apr 2025 11:18:20 +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 1u2pvG-00AaEv-D9 for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Apr 2025 11:18:18 +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 1u2pvG-00AaEn-2Z for pgsql-bugs@lists.postgresql.org; Thu, 10 Apr 2025 11:18:18 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u2pvE-004VhS-0Q for pgsql-bugs@lists.postgresql.org; Thu, 10 Apr 2025 11:18:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:To:Sender:From:Date:Cc:Content-Transfer-Encoding: Content-ID:Content-Description; bh=1qFrmoGZb9qyykXldX9MMjz0GAhxlv9LAsamlkncq6I=; b=EV9BzlYlT7sm9wvTEEYyurQOCu 39vHQ9ioVx0PSkaCcfQdWbfCFsSsbMbNeFYY7wA5K+o1NmCV163KA87U88N/7DqsLGTurak1+wczR JHJRbp2qM9RmhcMP2tpmQtcUo3bg7LW/0hADyqNSww2J7J4GrbUHNF+xQ34rCFUnzi0U=; Received: from depesz by depesz.com with local (Exim 4.96) (envelope-from ) id 1u2pvD-002izQ-0P; Thu, 10 Apr 2025 13:18:15 +0200 Date: Thu, 10 Apr 2025 13:18:15 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: gweatherby@uchc.edu, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18886: identity duplicate key Message-ID: Reply-To: depesz@depesz.com References: <18886-7a7ebc1b03f6ad9c@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <18886-7a7ebc1b03f6ad9c@postgresql.org> Supersedes: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Apr 09, 2025 at 11:04:20PM +0000, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 18886 > Logged by: Gerard Weatherby > Email address: gweatherby@uchc.edu > PostgreSQL version: 17.2 > Operating system: Ubuntu 24 > Description: > > I observed this: > > registry=# SELECT last_value, is_called FROM performance.vm_load_id_seq; > last_value | is_called > ------------+----------- > 12935994 | t > (1 row) > > registry=# \d performance.vm_load > Table "performance.vm_load" > Column | Type | Collation | Nullable | > Default > -----------+--------------------------+-----------+----------+------------------------------ > id | integer | | not null | generated > always as identity > vm_id | integer | | not null | > load15 | double precision | | not null | > idle | double precision | | not null | > stat_time | timestamp with time zone | | not null | > Indexes: > "vm_load_pk" PRIMARY KEY, btree (id) > "vm_load_id_vm_id_stat_time_index" btree (id, vm_id, stat_time) > "vm_load_stat_time_index" btree (stat_time) > Foreign-key constraints: > "vm_load_virtual_machines_id_fk" FOREIGN KEY (vm_id) REFERENCES > performance.virtual_machines(id) ON UPDATE RESTRICT ON DELETE RESTRICT > > registry=# INSERT INTO performance.vm_load(vm_id,load15,idle,stat_time) > values(437,0.0,94.31128026560856,'2025-04-09T22:25:26.326639+00:00'::timestamptz) > ; > ERROR: duplicate key value violates unique constraint "vm_load_pk" > DETAIL: Key (id)=(1314208) already exists. > > Unable to figure out what was going on, I did this, and it seemed to fix the > issue: You must have inserted some rows specifying value for id column. In such case identity/sequence is not updated, so afterwards you will get duplicate errors, as sequence returns (as new/next) value that already exists in table. Solution: select setval('performance.vm_load_id_seq'::regclass, max(id) + 1 ) from performance.vm_load; and find whatever was doing these inserts, and fix it. Also, please note that this mailing list for reporting bugs in PostgreSQL, and your situation doesn't qualify as such. It's simple operator/programmer error. Best regards, depesz