Re: Weird behavior with unique constraint not respected, and random results on same queries

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Thomas SIMON <tsimon(at)neteven(dot)com>
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Weird behavior with unique constraint not respected, and random results on same queries
Date: 2020-10-12 15:53:47
Message-ID: CABUevEwX+YrJ42LQJJM6R40Fh+e4zOsGrkEceoCyHiuJf9oz=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mon, Oct 12, 2020 at 5:43 PM Thomas SIMON <tsimon(at)neteven(dot)com> wrote:

> Hi all,
>
> I encounter strange behavior since a few days, and the promote of a
> recently installed server as master in my infrastructure (debian 10, was
> added as slave a few days ago)
> I use postgresql 12.4 on master an slave.
>

Is the previous master also Debian 10?

Specifically, when upgrading to Debian 10 you need to reindex all indexes
on text fields (see https://wiki.postgresql.org/wiki/Locale_data_changes)
This can in particular cause problems in replication, whereby your primary
and standby nodes have to run the same version of Debian since you cannot
do a separate reindex on the standby.

E.g. if your master is Debian 9, then you can expect some lookups to be
incorrect on the standby, and after you do a failover you may see entries
with invalid values in a unique index go in because of the lack of reindex.

Since the promote, I find on database some duplicated entries , despite
> the fact that the constraint should not allow this.
> It seems to only happens with entries having "special" characters
> (understand " ", "-", "+", ...)
>

As you can see from the locale page above, the changes are specifically
around special characters, so this is an indication that it might be this
problem.

If this is the problem, the fix is a REINDEX and to make sure that all
nodes in the replication cluster use the same version of the collections in
the future. If the reindex fails because of existing duplicate entries, you
will have to find a way to clean those up before reindexing. You may have
to drop the indexes, then clean up, and then recreate them.

--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/>
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/>

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Thomas SIMON 2020-10-12 17:47:19 Re: Weird behavior with unique constraint not respected, and random results on same queries
Previous Message Thomas SIMON 2020-10-12 15:43:29 Weird behavior with unique constraint not respected, and random results on same queries