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.92) (envelope-from ) id 1jF3Op-0004mQ-Ib for pgsql-general@arkaria.postgresql.org; Thu, 19 Mar 2020 22:12:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jF3Oo-0003fW-EB for pgsql-general@arkaria.postgresql.org; Thu, 19 Mar 2020 22:12:22 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1jF3Oo-0003bf-4c for pgsql-general@lists.postgresql.org; Thu, 19 Mar 2020 22:12:22 +0000 Received: from [162.222.244.8] (helo=net153.net) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jF3Ok-0004CQ-Vv for pgsql-general@lists.postgresql.org; Thu, 19 Mar 2020 22:12:21 +0000 Received: from [IPv6:2001:470:b965:1:71f1:f7a:be02:1fb9] (unknown [IPv6:2001:470:b965:1:71f1:f7a:be02:1fb9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by net153.net (Postfix) with ESMTPSA id CB6A31A2 for ; Thu, 19 Mar 2020 17:12:13 -0500 (CDT) Subject: Re: Invalid byte sequence errors on DB restore To: pgsql-general@lists.postgresql.org References: <2c81203a-01ef-ca84-1294-91420f71dd1f@net153.net> From: Samuel Smith Message-ID: <7813515f-0872-9cfa-7cbb-b6675610744e@net153.net> Date: Thu, 19 Mar 2020 17:12:13 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <2c81203a-01ef-ca84-1294-91420f71dd1f@net153.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 162.222.244.8 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/15/20 11:18 PM, Samuel Smith wrote: > My current DB backup routine is just to call pg_dump and pipe to gzip. > We recently started to get a failure to restore (which is basically just > using psql -f on the pg_dump file) with the following errors: > > invalid byte sequence for encoding "UTF8": 0xa0 >  and > invalid byte sequence for encoding "UTF8": 0xd7 0x20 > > > This is on a pg 9.2.24 instance. Any tips to troubleshoot? > > Regards, > Samuel Smith > > Our issue actually turned out to be that a couple of our production database had the encoding set to SQL_ASCII while all of our development servers had UTF-8. This meant in some cases where we would restore a production database into development (for testing or bug hunting), there would be a failure to parse the backup file. A similar issue to this blog post: https://www.endpoint.com/blog/2017/07/21/postgres-migrating-sqlascii-to-utf-8 So our fix was to dump the affected production databases using the LATIN1 encoding for pg_dump followed by destroying and recreating the database and setting its new encoding to UTF-8. Then we could restore the data using the pg_dump file with LATIN1 encoding. Regards, Samuel Smith