Quante volte vi capita di avere un database in UTF-8 magari, ma dentro ci sono finiti dei caratteri con codifiche strampalate?
ecco una serie di passaggi che ci permettono di aggiustare questi database:
PGCLIENTENCODING='UTF-8' PGDATABASE=database pg_dump -Fp -O -x -U postgres -h localhost > tempfile1
grep -v "COMMENT ON SCHEMA" < tempfile1 > tempfile2
iconv -f UTF-8 -t CP1252 -c < tempfile2 > tempfile3
iconv -f CP1252 -t UTF-8 -c < tempfile3 > tempfile4
PGDATABASE=nuovodatabase psql -q -U postgres -h localhost -v ON_ERROR_STOP=1 < tempfile4
In questo caso avevo un database in UTF-8 con caratteri CP1252, quindi è stato sufficiente prendere il dump del database, convertirlo in cp1252 e poi riportare il dump in utf8.
Spero possa aiutarvi
Riferimenti:

