Search code examples
postgresqluuidtimescaledbpostgres-14

Weird UUID behavior after switching to timescaledb-ha


This is a copy of https://github.com/timescale/timescaledb-docker-ha/issues/417

We have been running a database on the regular timescaledb:latest-pg14 image. We have a table (let's call it entities) where rows are identified by the columns 'TenantId' (uuid) and 'Id' (text).

Now comes the weird part, which we do not understand.

We switched to using timescaledb-ha:pg14-ts2.11 instead, because we want to use postgis. We correctly mounted the old data at /home/postgres... But suddenly, we saw that some queries were not finding entities anymore. When we were listing the entities filtered with WHERE TenantId = 'some_uuid' we were seeing the entities, but when we tried querying single ones with WHERE TenantId = 'some_uuid' AND Id = 'some_id', we were not matching the entities, even though they clearly existed. Interestingly, when we cast the 'TenantId' colum to 'text' like so WHERE TenantId::text = 'some_uuid' it was working again!

The database encoding and collations were exactly the same (utf8 and en_us.utf8)

Do you have any idea what is going on here?


Solution

  • One important difference between the timescaledb and timescaledb-ha docker images is that the timescaledb image is based on Alpine, whereas the timescaledb-ha is based on Ubuntu. One notable difference between Alpine and Ubuntu is that Alpine uses musl libc, which has limited support for collation (see https://github.com/docker-library/postgres/issues/327).

    I suspect that queries which hit the index are the ones which are failing, because the index is corrupted. I would suggest that you rebuild all indexes and try running queries again.