Skip to content

Instantly share code, notes, and snippets.

@anandology
Created July 8, 2013 15:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anandology/5949798 to your computer and use it in GitHub Desktop.
Save anandology/5949798 to your computer and use it in GitHub Desktop.
Fixing PostgreSQL default encoding in Ubuntu
# Option 1 - rebuild the cluster
# This will delete alle existing data
pg_dropcluster --stop 9.2 main
pg_createcluster --start -e UTF-8 9.2 main
# Option 2 - rebuild the template1 database
# All the database created after this will have UTF-8 encoding
psql template1 -c "UPDATE pg_database SET datallowconn = TRUE WHERE datname='template0'"
psql template0 -c "UPDATE pg_database SET datistemplate = FALSE WHERE datname='template1'"
dropdb template1
createdb template1 -T template0 -E utf-8
psql template0 -c "UPDATE pg_database SET datistemplate = TRUE WHERE datname='template1'"
psql template1 -c "UPDATE pg_database SET datallowconn = FALSE WHERE datname='template0'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment