Importing a Windows database (in en_GB.CP1252) to linux - Mailing list pgsql-admin

From Jean-Christophe BOGGIO
Subject Importing a Windows database (in en_GB.CP1252) to linux
Date
Msg-id 5d7b5d51-a7c7-4cf2-943c-49b93441b8fa@thefreecat.org
Whole thread Raw
Responses Re: Importing a Windows database (in en_GB.CP1252) to linux
List pgsql-admin

Hello,

I have a (custom) backup created on a Windows machine in en_GB.CP1252 encoding. And of course, some characters can't be imported because they don't exist in UTF-8.

So I created a new cluster on PG18 port 5433 initialized in WIN1252 encoding:

$ \l imlocal
                                           List of databases
 Name   | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges  
---------+-------+----------+-----------------+---------+-------+--------+-----------+-------------------
imlocal | cat   | WIN1252  | libc            | C       | C     | ∅    | ∅       | ∅
(1 row)

I am now trying to import the data in that database but I keep getting this error:

$ pg_restore -p 5433 -t csakafl -d imlocal imlocal20251127.backup
pg_restore: error: COPY failed for table "csakafl": ERROR:  invalid byte sequence for encoding "UTF8": 0x92
CONTEXT:  COPY csakafl, line 298

So pg_restore still thinks I want to use UTF8.

So I created an en_GB.CP1252 locales definitions folder like this:

mkdir ~/locales
cd ~/locales
cp cp /usr/share/i18n/charmaps/CP1252.gz .
gunzip CP1252.gz
localedef -cv -i en_GB -f CP1252 ./en_GB.CP1252

Then I now want to use this to restore my database so I tried setting:

setenv LOCPATH ~/locales
setenv LC_ALL en_GB.CP1252
setenv LANG en_GB.CP1252

And even forcing LC_ALL when launching pg_restore:

$ LC_ALL=en_GB.CP1252 pg_restore -p 5433 -t csakafl -d imlocal imlocal20251127.backup
pg_restore: error: COPY failed for table "csakafl": ERROR:  invalid byte sequence for encoding "UTF8": 0x92
CONTEXT:  COPY csakafl, line 298

What am I doing wrong?

Thanks for your help,

JC


pgsql-admin by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Migration from MSSQL to POSTGRESQL
Next
From: Ron Johnson
Date:
Subject: Re: Migration from MSSQL to POSTGRESQL