Skip to content

Instantly share code, notes, and snippets.

@yshurik
Forked from anandology/pg-encoding.txt
Created April 25, 2018 20:01
Show Gist options
  • Save yshurik/aeb2b96bff41c05a6c3234d264e7cd01 to your computer and use it in GitHub Desktop.
Save yshurik/aeb2b96bff41c05a6c3234d264e7cd01 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