Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eSLtI-0002ED-8o for pgsql-general@arkaria.postgresql.org; Fri, 22 Dec 2017 11:53:28 +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 1eSLtH-00051g-56 for pgsql-general@arkaria.postgresql.org; Fri, 22 Dec 2017 11:53:27 +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 1eSLtG-00051W-PF for pgsql-general@lists.postgresql.org; Fri, 22 Dec 2017 11:53:26 +0000 Received: from smtp57.i.mail.ru ([217.69.128.37]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eSLt8-0003Dn-Fm for pgsql-general@postgresql.org; Fri, 22 Dec 2017 11:53:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Date:Message-ID:Subject:From:To; bh=i8BVRpoO6PbAZvppUKW2OEgnsLxfvQMn0dd8BGhbylA=; b=tPzX39cKLvkYnZCHksQKZnFfLLE3WVbLMkTpV+K4Dx/0qudu0CvejjbKPG4zfEWBDLwSPpgp9OV/wA4GoHmNrWknfW9CJgKAYH2c1RtT6Zofca2xdlusb9z52+zE0HSbKDHuXTo7/Wy97aS4WGe/1aCWjR1mpFiE8bc6cfi/sbE=; Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1eSLt6-0002gX-8h for pgsql-general@postgresql.org; Fri, 22 Dec 2017 14:53:16 +0300 To: pgsql-general General From: rihad Subject: pg_upgrading to 10.1 corrupts (varchar,varchar) UNIQUE indices Message-ID: Date: Fri, 22 Dec 2017 15:53:12 +0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: smtp57.i.mail.ru; auth=pass smtp.auth=rihad@mail.ru smtp.mailfrom=rihad@mail.ru X-7FA49CB5: 0D63561A33F958A50A6462647ADDEFF68D925B309E9CFAD36E1AA5ECB797E82E725E5C173C3A84C37CE9EF00282E02DFFF76BD37191C621CA91E23F1B6B78B78B5C8C57E37DE458B4C7702A67D5C3316FA3894348FB808DBEB6346B700B4D54FE5BFE6E7EFDEDCD789D4C264860C145E X-Mailru-Sender: B19AB4DAF1EA2FB58A8BBB454389F7B439C3FCCEDE6662C1CBDBCE1251EF3AFDC87DFF528253291DABBFE0CF075BC50BFB559BB5D741EB96004FA9CEFBA991DA3A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: OK List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi there, this is a reproducible error. We recently pg_upgraded our production database to 10.1 from 9.6.6. The upgrade runs fine with the suggestion to analyze all data. [rihad@postgres-10-test]$ cat analyze_new_cluster.sh #!/bin/sh echo 'This script will generate minimal optimizer statistics rapidly' echo 'so your system is usable, and then gather statistics twice more' echo 'with increasing accuracy.  When it is done, your system will' echo 'have the default level of optimizer statistics.' echo echo 'If you have used ALTER TABLE to modify the statistics target for' echo 'any tables, you might want to remove them and restore them after' echo 'running this script because they will delay fast statistics generation.' echo echo 'If you would like default statistics as quickly as possible, cancel' echo 'this script and run:' echo '    "/10.1/bin/vacuumdb" --all --analyze-only' echo "/10.1/bin/vacuumdb" --all --analyze-in-stages echo echo 'Done' which we run after the upgrade. It doesn't matter if we do the analyze so in a test environment with no activity or run it concurrently with the already started production queries. The problem: Some of our tables have indices of the form:     "index_translations_on_locale_and_key" UNIQUE, btree (locale, key)  locale     | character varying(255)      |           | |  key        | character varying(255)      |           |          | or     "index_users_on_email_and_type" UNIQUE, btree (email, type)  email           | character varying(255)      |           | not null | ''::character varying  type            | character varying           |           | not null | (these are different tables) Trying to find data using the specified indices fails to find matching rows: foo=# select * from translations where locale='de' and key='extranet.options.places.age_brackets_hints.a';  id | locale | key | value | created_at | updated_at | resolved ----+--------+-----+-------+------------+------------+---------- (0 rows) foo=# explain select * from translations where locale='de' and key='extranet.options.places.age_brackets_hints.a';                                                        QUERY PLAN ------------------------------------------------------------------------------------------------------------------------  Index Scan using index_translations_on_locale_and_key on translations  (cost=0.41..2.63 rows=1 width=234)    Index Cond: (((locale)::text = 'de'::text) AND ((key)::text = 'extranet.options.places.age_brackets_hints.a'::text)) (2 rows) reindexing the table fixes the issue: foo=# reindex index index_translations_on_locale_and_key ; REINDEX foo=# select * from translations where locale='de' and key='extranet.options.places.age_brackets_hints.a';    id   | locale |                     key |                        value                        | created_at         |         updated_at         | resolved --------+--------+----------------------------------------------+-----------------------------------------------------+----------------------------+----------------------------+----------  136373 | de     | extranet.options.places.age_brackets_hints.a | Alter für einen vollen Gast-Tarif, z.B ab 12 Jahre  | 2017-08-22 11:27:27.774259 | 2017-09-02 09:05:45.244927 | f (1 row) foo=# explain select * from translations where locale='de' and key='extranet.options.places.age_brackets_hints.a';                                                        QUERY PLAN ------------------------------------------------------------------------------------------------------------------------  Index Scan using index_translations_on_locale_and_key on translations  (cost=0.41..2.63 rows=1 width=234)    Index Cond: (((locale)::text = 'de'::text) AND ((key)::text = 'extranet.options.places.age_brackets_hints.a'::text)) (2 rows) The upgrade guide states that only hash indices should be rebuilt after the upgrade, not btree ones.