How to convert a db in postgreSQL to utf8?

前端 未结 4 1744
太阳男子
太阳男子 2020-12-31 09:08

I\'ve just got a db in postgreSQL for my project and just realized it\'s in SQL_ASCII encoding, which means \"no encoding\" I think.

So what is the simplest way to c

4条回答
  •  没有蜡笔的小新
    2020-12-31 09:44

    I searched the entire internet looking for a solution to this issue and Koyots solution above worked first time after wasting countless hours trying everything to migrate an old SQL_ASCII database to a new UTF8 database

    To expand upon the solution...

    • I first redirected all websites to a maintenance page
    • Renamed the database by appending "_ascii" to it's name just to be sure nothing could connect to it and also so I know after that this was the original database !!
    • Created a new utf8 database with "_utf8" appended to the name (append TEMPLATE=template0 to the CREATE DATABASE STATEMENT)
    • Backed up the ascii database
    • Restored the backup to the new utf8 database
    • Renamed the utf8 database back to what I had named it before
    • Check database total size is roughly the same size as the original database. Won't match exactly due to dead tuples etc. New database should be smaller based on fill factor etc.
    • Turn off website redirects
    • Test all websites

    I'd suggest keeping both databases for a couple of weeks until you are sure you have not lost any data (provided you can spare the disk space)

提交回复
热议问题