0

I was needing to change the encoding of a compressed .dmp file created using the pg_dump command. Currently I only have the dump file and not the whole database. How can I alter the file to be compliant with another encoding? I would like to go from win1252 to latin1. When using iconv on a linux machine, it tells me win1252 is not supported.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
user972276
  • 2,973
  • 9
  • 33
  • 46

1 Answers1

2

A .dmp file from Postgres is a regular plain text file so you should be able to use e.g. iconv. Say you wanted to switch from UTF-8 to LATIN1, you could do:

iconv -f utf-8 -t latin1 <infile >outfile

Please note though that this will only change the encoding of the characters. If you need to change the DDL that is used to create the tables, columns etc, you will need to modify the file manually. Or import it, make the changes and then export again.

  • I would like to go from win1252 to latin1 and its saying win1252 is not supported – user972276 Feb 19 '13 at 19:17
  • The issue I am having is that when I try to import a database from a dmp file encoded in win1252 to a linux nmachine, I get an error saying postgres cannot convert from win1252 to latin1. I would like to be able to import the database into the linux box with no errors – user972276 Feb 19 '13 at 19:23
  • Try cp1252, it's equivalent to win1252. – Rickard Andersson Feb 19 '13 at 19:23
  • cp1252 seems to work. I did not know they were the same thanks! I am getting an error though when running the command: "iconv: illegal input sequence at position 4682" – user972276 Feb 19 '13 at 19:28
  • Well, that means either that the dmp isn't cp1252 or that it is, but that it contains one or more non-cp1252 character sequences. You can use the `-c` option to discard any characters iconv is unable to convert. Have a look at `iconv --help` for additional options. – Rickard Andersson Feb 19 '13 at 19:36