Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1isAEy-0001wR-AL for pgsql-general@arkaria.postgresql.org; Thu, 16 Jan 2020 18:51:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1isAEv-0001Ig-St for pgsql-general@arkaria.postgresql.org; Thu, 16 Jan 2020 18:51:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1isAEv-0001Gx-Fu for pgsql-general@lists.postgresql.org; Thu, 16 Jan 2020 18:51:33 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1isAEq-0003Cw-5I for pgsql-general@lists.postgresql.org; Thu, 16 Jan 2020 18:51:32 +0000 Received: by mail-wr1-x441.google.com with SMTP id z7so20215410wrl.13 for ; Thu, 16 Jan 2020 10:51:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=oDGFC/gI72lfoGZZOki5rfawZOBfJCe88/m6j5vEpC8=; b=YFxbZWn6UE+zKQy4hRwPzyFPl2+36bPevPbPbG2/fXQKi9CKwMdAEavXtMojXikRA+ sXeaGCGEitOLFOm+s5ZIab4mllKVepQysW6+UpybGL3nGpVSbuCxwpd7oRsfePzUdWhN dTuXUxR3JBIhhRsP+v4sVxDuWfEnoyOfkECiw2zpkyX8I5pavWqIrKTxoy90XDaKIcxV tCEgFWaODzxVnApOX5uo+X135J6dH/gx6XgBrn1SprZQSSvCD9ryn2czyCDJ8TfCDw3v O98qFFfnqaOy2aYcy74USD03jlBwYKT0jwOp/88VkHRyt3b3LHf9Sa0O23lRE+DOcVby Lezw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=oDGFC/gI72lfoGZZOki5rfawZOBfJCe88/m6j5vEpC8=; b=je9SrRdlHHHYSEwv+wZUle5ey5YwqZo5Vz+FzE1JSdsAA7jbfIz5nT9PwOpF+DpfXo eOMCJ792Ita/VmVFmYx8Y8Rgq+chLKv76hyX2LRX5goCBgiihL+ZYm687v/KOSA++w4J VRPvPpO6YP9LHWCO4ZUr27HQbTftd/snMkTRdhLCJgqB+DGD6LSjZtH6FL3pN3wRlfa1 HutKsI5hldF9OWevrcmykJ0RLCOWW0QUSrb2cnMM1VQVFWUAuqZVS1FvL6kdH1NRbNor daKMH8/J+2h9UhI89jhA7oyPS/qBE/Lz+XCIbaWGWhYLT4sE47KFTcQwEesfz/C9QYha QGsA== X-Gm-Message-State: APjAAAUoYdSbrQF3eqrRiPZTpnndGDjyn1udwAk9h7mwXxyxuXrGvKVF kHOgtjVf9nA8bPtacqWiYeaUrw== X-Google-Smtp-Source: APXvYqxw5BkhrUk8FZJ5+0zyaPgtNMth3wVUKw7rMhCasAV2Q0pfg8VFk2GBHNw3RX1JYnggtYyYQA== X-Received: by 2002:a5d:62d1:: with SMTP id o17mr5030508wrv.9.1579200685599; Thu, 16 Jan 2020 10:51:25 -0800 (PST) Received: from localhost.localdomain (pd95690bc.dip0.t-ipconnect.de. [217.86.144.188]) by smtp.gmail.com with ESMTPSA id c2sm30542016wrp.46.2020.01.16.10.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 10:51:25 -0800 (PST) Message-ID: Subject: Re: Inexplicable duplicate rows with unique constraint From: Laurenz Albe To: Richard van der Hoff , pgsql-general@lists.postgresql.org Date: Thu, 16 Jan 2020 19:51:24 +0100 In-Reply-To: <288488b7-d3b6-905b-3706-43f7a3c7bc52@matrix.org> References: <288488b7-d3b6-905b-3706-43f7a3c7bc52@matrix.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, 2020-01-16 at 16:50 +0000, Richard van der Hoff wrote: > I'm trying to track down the cause of some duplicate rows in a table > which I would expect to be impossible due to a unique constraint. I'm > hoping that somebody here will be able to suggest something I might have > missed. > > The problem relates to a bug filed against our application > (https://github.com/matrix-org/synapse/issues/6696). At first I put this > down to random data corruption on a single user's postgres instance, but > I've now seen three separate reports in as many days and am wondering if > there is more to it. [...] > So, question: what could we be doing wrong to get ourselves into this > situation? > > Some other datapoints which may be relevant: > * this has been reported by one user on postgres 9.6.15 and one on > 10.10, though it's hard to be certain of the version that was running > when the duplication occurred > * the constraint is added when the table is first created (before any > data is added) > * At least one user reports that he has recently migrated his database > from one server to another via a `pg_dump -C` and later piping into psql. I see no hint that this may be the problem, but I have seen corruption like this because of changes in the collations of the C library (which PostgreSQL uses). This only happens with collations other than C, and it cannot be caused by dump/restore. It may, however, be caused by the following: - Upgrading the operating system where PostgreSQL is running to a different glibc. - Streaming replication between machines with different glibc version, and failing over to the standby. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com