Importing a Windows database (in en_GB.CP1252) to linux

From: Jean-Christophe BOGGIO <postgresql(at)thefreecat(dot)org>
To: "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Importing a Windows database (in en_GB.CP1252) to linux
Date: 2025-12-01 13:37:43
Message-ID: 5d7b5d51-a7c7-4cf2-943c-49b93441b8fa@thefreecat.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Ron Johnson 2025-12-01 14:45:02 Re: Migration from MSSQL to POSTGRESQL
Previous Message Kasper Føns 2025-12-01 09:49:42 Fwd: restore_command on high-throughput cluster never switches to streaming replication