Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKmBV-00038T-TB for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Dec 2017 14:20:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKmBV-0001Iq-CB for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Dec 2017 14:20:57 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eKmBV-0001Ig-6n for pgsql-bugs@lists.postgresql.org; Fri, 01 Dec 2017 14:20:57 +0000 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eKmBS-0006j7-00 for pgsql-bugs@postgresql.org; Fri, 01 Dec 2017 14:20:56 +0000 Received: by mail-wr0-x235.google.com with SMTP id z18so10302063wrb.8 for ; Fri, 01 Dec 2017 06:20:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=kIP8BTwpxh/3rzgwVnv2pLl5Mi8f7c4hG3767zlQXug=; b=tGKEvcjRvuXw2jr3WzpxWvAhcXXcwAUUh9BAy/gkblbRj79BDx0nDTKJS91TY1rS3P VCx3yFzMXmeupwE4aacFQMc7fgE07OBl8gK6Dt4MNH0H8+BhNPabubD+M0fwIVR53ugU Vuzt3zXma35KsYZwoDakhVZJfSZ7nTPUe92P04JedGp7s1yi89bxtA6spx8xISxky+fH /YySnLGSa0Bixc/0AAzJbJe/tYM5PZjaMGOSguJCzvWxTf5ZKuOWtWB32E+0QSTfMcjF U5E6q0QZQddBnb2pNAjCvKs2BeuRy5VdAtKKy86RV8wKpeBQHU0I1kEy3OIYgp8qc8NR zO4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kIP8BTwpxh/3rzgwVnv2pLl5Mi8f7c4hG3767zlQXug=; b=X1P/lThe85JQo2GOj6YIprcHvew6C7jh5LMUX3IJEqiYQmVIGmqJ+kXZI+usc0s+OP nJ6xqEbieuPQRHMemHBHfS2ljjIbi+B854ypkUt5jkMRy5JrSn2bdcftTnyh+D2JMFlD e+SG1/9Fw4DSuN5IZ4LJOWg7XZ/e2NY3FYA13t8I8z78HiDVsQvshtd4t7oF7OdtRLRd 3bCZXmdB3OR4kQP+l1z1UO/3Ak6/K3q2WJmt0+TQRNakfu4bBqIsZFGqdp0RQQqJ+r74 8Q5qjBi9rwwf2Qx4Fmcx5yXr53cSokRi5rGqhWka72pZuLxEzYf0IsxOgsbpBnrb2k0i OKfw== X-Gm-Message-State: AJaThX7oGev53J76QHv2HNDAfDcSpSiOQvNQqgISMWDo38vtGamVihu5 mwBgflYaenWCEAin+ppxjL1VWkk1ev0mWznxgBCqm91oualPVkqbz1kg7uAWMKZ9AYB14v5sSG2 iOdW26dJwc40/AK2Q6uuyw81SPGAcJscjNjRPDclNFy4Tgg3MsAJHKbJbZXFbVYV8CXU1rS6xD/ 6q2bhw X-Google-Smtp-Source: AGs4zMYGYrS/m6VcIjY/uwv1a52Eqe2TCCaq3M33l37reoouoU+Bt3RGE+9mhfO2V4jvIyAy4GNK0A== X-Received: by 10.223.199.133 with SMTP id l5mr5760253wrg.20.1512138052680; Fri, 01 Dec 2017 06:20:52 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id d23sm1203323wma.48.2017.12.01.06.20.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Dec 2017 06:20:47 -0800 (PST) Subject: Re: BUG #14940: Duplicated records inspite of primary key and unique constraint To: sergey.frolov@smetarik.ru, pgsql-bugs@postgresql.org References: <20171201124533.27099.26427@wrigleys.postgresql.org> From: Tomas Vondra Message-ID: Date: Fri, 1 Dec 2017 15:20:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171201124533.27099.26427@wrigleys.postgresql.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/01/2017 01:45 PM, sergey.frolov@smetarik.ru wrote: > The following bug has been logged on the website: > > Bug reference: 14940 > Logged by: sergey frolov > Email address: sergey.frolov@smetarik.ru > PostgreSQL version: 9.6.6 > Operating system: Windows 10, 64 > Description: > > Hi, I have noticed duplicated records inspite of primary key and unique > constraint. > > select version () > PostgreSQL 9.6.6, compiled by Visual C++ build 1800, 64-bit > > The DDL is > CREATE TABLE nb.nb_basedtl > ( > id integer NOT NULL, > base_id integer NOT NULL, > norm_id integer NOT NULL, > ... > CONSTRAINT pk_nb_basedtl PRIMARY KEY (id), > CONSTRAINT unq_nb_basedtl UNIQUE (norm_id, base_id), > .... > > The problem is > > select ctid,xmin,xmax, id, base_id, norm_id from nb.nb_basedtl where id = > 11658502 ;-- expected ONE row > > (0,49);364507;0;11658502;269;46203 > (0,49);370881;0;11658502;269;46203 > (0,49);370882;0;11658502;269;46203 > > > select (select count(1) from nb.nb_basedtl), (select count(1) from (select > id, count(1) from nb.nb_basedtl group by id having count(1) > 1 ) t ) > 3586895;50 > Seems like some sort of data corruption, but it's impossible to say how the database got into this state. You'll have to tell us more about the system. Did it crash in the past? What sort of filesystem/storage does it use? How old is the database/which PostgreSQL versions was it running (e.g. it may be a new system loaded last week, or it may be an old system started on 9.0 and upgraded using pg_upgrade). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services