How can i change database encoding for a PostgreSQL database using sql or phpPgAdmin?
相关问题
- Django distinct is not working
- PostgreSQL: left outer join syntax
- Connecting Python to a Heroku PostgreSQL DB?
- PostgreSQL - Deleting data that are older than an
- Does PLV8 support making http calls to other serve
相关文章
- postgresql 关于使用between and 中是字符串的问题
- postgresql 月份差计算问题
- Using boolean expression in order by clause
- Table valued Parameter Equivalent in Postgresql
- in redshift postgresql can I skip columns with the
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- PostgreSQL field data type for IPv4 addresses
- Using prepared statement in stored function
To expand on the answers given, you can use these commands to accomplish your task.
Dumping database: http://www.postgresql.org/docs/9.4/static/backup-dump.html
Creating database: http://www.postgresql.org/docs/9.4/static/sql-createdatabase.html
This is a list of all encodings available for version 9.4: http://www.postgresql.org/docs/9.4/static/multibyte.html#MULTIBYTE-CHARSET-SUPPORTED
In short, you cannot do this with only phpPgAdmin or SQL without risking existing data corruption. You have to export all data, create database with correct encoding and restore exported data.
This is how you should proceed:
create database dump:
pg_dump your_database > your_database.sql
this will save your database in sql format, in encoding you currently have.
delete database (or rename it):
DROP DATABASE your_database
if you have enough storage to do it I recommend leaving old database until you make sure everything is OK with new one, rename it:
ALTER DATABASE your_database RENAME TO your_database_backup;
create database with new encoding:
CREATE DATABASE your_database WITH ENCODING 'UNICODE' TEMPLATE=template0;
import data from dump created before:
PGCLIENTENCODING=YOUR_OLD_ENCODING psql -f your_database.sql your_database
you need to set psql client encoding to one you had in old database.
Changing encoding on-the-fly isn't possible as it would require rewriting most of internal database data which is almost equal to recreating db way I described.
It is possible to just alter internal postgres informations about database and any new data after this alteration will be saved correctly, however your existing data might get corrupted.
You can change encoding on the fly without dump/restore: