{"id":287,"date":"2008-06-18T09:55:00","date_gmt":"2008-06-18T09:55:00","guid":{"rendered":"http:\/\/new.cottee.org\/2008\/06\/postgres-converting-encodings\/"},"modified":"2008-06-18T09:55:00","modified_gmt":"2008-06-18T09:55:00","slug":"postgres-converting-encodings","status":"publish","type":"post","link":"https:\/\/cottee.org\/?p=287","title":{"rendered":">Postgres &#8211; Converting Encodings"},"content":{"rendered":"<p>>I&#8217;ve run into a number of problems recently with dealing with old databases of ours which are encoded with LATIN1. Now, with postgres 8.3 (maybe before) you&#8217;ll get a message if you try to create LATIN1 saying something like <\/p>\n<pre>createdb: database creation failed: ERROR:  encoding LATIN1 does not match server's locale en_US.UTF-8<br \/>DETAIL:  The server's LC_CTYPE setting requires encoding UTF8.<br \/><\/pre>\n<p>I got bored trying to work out why &#8211; it seems to be that postgres now prevents what it shouldn&#8217;t have allowed in the past but did. But if you do want to convert from the old to the new locale &#8211; how do you do it? Remarkably simple it turns out. <\/p>\n<p>Do a pg_dump of your existing database. Then take the dump file and run it through iconv &#8211; something like this. <\/p>\n<pre> <br \/>\ticonv -f latin1 -t utf8 original.sql > converted.sql<br \/><\/pre>\n<p>It&#8217;s pretty obvious what the options mean (-f = from, -t = to). iconv comes as standard on Mac and should be available for most linux distos (seems to be installed on ubuntu server by default). <\/p>\n<p>However, before you get too excited &#8211; you should ensure that whatever apps are using that database will cope with the new encoding for input and output. That may be &#8216;non-trivial&#8217; \ud83d\ude09 <\/p>\n<div class=\"blogger-post-footer\"><img width='1' height='1' src='https:\/\/blogger.googleusercontent.com\/tracker\/9210244490645736884-5494820046338398737?l=blog.cottee.org' alt='' \/><\/div>\n","protected":false},"excerpt":{"rendered":"<p>>I&#8217;ve run into a number of problems recently with dealing with old databases of ours which are encoded with LATIN1. Now, with postgres 8.3 (maybe before) you&#8217;ll get a message if you try to create LATIN1 saying something like createdb: database creation failed: ERROR: encoding LATIN1 does not match server&#8217;s locale en_US.UTF-8DETAIL: The server&#8217;s LC_CTYPE setting requires encoding UTF8. I got bored trying to work out why &#8211; it seems to be that postgres now prevents what it shouldn&#8217;t have&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/cottee.org\/?p=287\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[40],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-oldsite","tag-postgres"],"_links":{"self":[{"href":"https:\/\/cottee.org\/index.php?rest_route=\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cottee.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cottee.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cottee.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cottee.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=287"}],"version-history":[{"count":0,"href":"https:\/\/cottee.org\/index.php?rest_route=\/wp\/v2\/posts\/287\/revisions"}],"wp:attachment":[{"href":"https:\/\/cottee.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cottee.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cottee.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}