Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2744105
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: Mysql/postgreSQL

2016-07-12 11:47:56

一、查看模板库编码
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding  |   Collate   |    Ctype    |   Access privileges   
-----------+----------+-----------+-------------+-------------+-----------------------
 postgres  | postgres | SQL_ASCII | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | SQL_ASCII | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |           |             |             | postgres=CTc/postgres
 template1 | postgres | SQL_ASCII | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |           |             |             | postgres=CTc/postgres
(3 rows)


二、新建数据库指定编码为UTF8

postgres=# create database www ENCODING='UTF8';
ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT:  Use the same encoding as in the template database, or use template0 as template.
postgres=# ^C


三、修改template0 属性
postgres=# \c - postgres

postgres=#  update pg_database set datallowconn = TRUE where datname = 'template0';
UPDATE 1
postgres=# \c template0
You are now connected to database "template0" as user "postgres".

template0=# update pg_database set datistemplate = FALSE where datname = 'template1';
UPDATE 1

template0=# drop database template1;
DROP DATABASE

template0=# create database template1 with template = template0 encoding = 'UTF8';
CREATE DATABASE

template0=# update pg_database set datistemplate = TRUE where datname = 'template1';
UPDATE 1
template0=#  \c template1

You are now connected to database "template1" as user "postgres".
template1=#  update pg_database set datallowconn = FALSE where datname = 'template0';
UPDATE 1

四、新建数据库指定编码为UTF8
template1=# create database www ENCODING='UTF8';
CREATE DATABASE
template1=# \l
                                  List of databases
   Name    |  Owner   | Encoding  |   Collate   |    Ctype    |   Access privileges   
-----------+----------+-----------+-------------+-------------+-----------------------
 postgres  | postgres | SQL_ASCII | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | SQL_ASCII | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |           |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8      | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 www       | postgres | UTF8      | zh_CN.UTF-8 | zh_CN.UTF-8 | 
(4 rows)


template1=# 
阅读(5772) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~