User Tools

Site Tools


psql_ascii_2_utf8

This is an old revision of the document!


Software packages

Login to your server as “root” and install the Recode tool. In Linux Debian you do this by typing:

   apt-get install recode

Then switch to the “postgres” account:

   su postgres

Now create a dump of your SQL_ASCII database:

   pg_dump SQL_ASCII_database_name > SQL_ASCII_database_dump.sql

Next check content of your file by typing:

  file SQL_ASCII_database_dump.sql

You should get the following output:

  
  SQL_ASCII_database_dump.sql: ISO-8859 text

Then you convert your ISO-8859 file to UTF8 by typing:

  cat SQL_ASCII_database_dump.sql | recode iso-8859-1..u8 > UTF8_database_dump.sql

Check the result by typing:

  file UTF8_database_dump.sql

You should now get the following output:

  UTF8_database_dump.sql: UTF-8 Unicode text

Now open the new UTF8_database_dump.sql file with your favourite editor and change the line:

  SET client_encoding = 'SQL_ASCII';

to:

  SET client_encoding = 'UTF8';

Create a new database:

  createdb UTF8_database_name

And import the UTF8_database_dump.sql

  psql UTF8_database_name < UTF8_database_dump.sql

That's it!

psql_ascii_2_utf8.1413816106.txt.gz · Last modified: 2014/12/30 16:45 (external edit)