PostgreSQL编码问题

栏目: 数据库 · PostgreSQL · 发布时间: 8年前

内容简介:PostgreSQL编码问题

唔,其实算是不务正业的项目,最近看的小说站一直被人攻击,所以打算自己跑个自己看……(有够闲的),因为是 Linux 环境,所以打算用易读的程序,这个用的是PostgreSQL,也是第一次接触,本来以为全是默认配置,也不用我去管啥,结果还真碰到了点问题,所以在这Record一下了。

这个是在安装页面配置网站的时候点击确认后会出现的,基本上就是导入数据库的时候出错了,错误代码如下

"ERROR: newencoding (UTF8) is incompatible with theencoding of the template database (SQL_ASCII) Hint: Use the sameencoding as in the template database, or use template0 as template."

网上搜了下还算是PostgreSQL的经典错误……也是醉了,还有一个经典错误我在之后也碰到了_(:з」∠)_,就是默认只允许一个用户访问,所以如果已登录的用户不退出去,其它程序(用户)就不能访问了……所以请记得在操作后正常退出

解决方法的话不急,我们先来看下原因,简单从错误上看,就是编码问题,新编码 (UTF8) 与模板数据库的 (SQL_ASCII)不相同,所以无法成功导入。我稍微了解了下,这可能与系统在安装PostgreSQL时设置的Locale不是UTF-8有关,毕竟Centos系统默认的Locale好像挺蛋疼,更改Locale的方法在我以前的文章应该能找到来着,所以这边不提了。

su - postgres  //切换到postgres用户
psql -U postgres  //连接数据库
 
update pg_database set datallowconn = TRUE where datname = 'template0';
\c template0
update pg_database set datistemplate = FALSE where datname = 'template1';
drop database template1;
create database template1 with template = template0 encoding = 'UTF8';
update pg_database set datistemplate = TRUE where datname = 'template1';
\c template1
update pg_database set datallowconn = FALSE where datname = 'template0';

一行行跑完,然后退出PostgreSQL(请务必退出,不要留着连接进程……),然后重新点击安装向导的确认就没问题了。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Game Engine Architecture, Second Edition

Game Engine Architecture, Second Edition

Jason Gregory / A K Peters/CRC Press / 2014-8-15 / USD 69.95

A 2010 CHOICE outstanding academic title, this updated book covers the theory and practice of game engine software development. It explains practical concepts and techniques used by real game studios,......一起来看看 《Game Engine Architecture, Second Edition》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具