磨砺技术珠矶,践行数据之道,追求卓越价值

回到上一级页面:PostgreSQL内部结构与源代码研究索引页    回到顶级页面:PostgreSQL索引页

[作者 高健@博客园  luckyjackgao@gmail.com]

我的PPAS下,edb数据库的Encoding是 UTF8:

edb=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access
privileges
-----------+--------------+----------+-------------+-------------+--------------
-----------------
edb | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/enterprisedb +
| | | | | enterprisedb=CTc/enterprisedb
template1 | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/enterprisedb +
| | | | | enterprisedb=CTc/enterprisedb
(4 rows) edb=# 。

而我在postgresql.conf里面去设置 client_encoding,无论如何也无法生效。

client_encoding = sql_ascii             # actually, defaults to database
# encoding

重新启动后也不行:

edb=# show client_encoding;
client_encoding
-----------------
UTF8
(1 row) edb=#

也就是说,client_encoding的值,就算是设置了,也未必起作用。

查看社区版PostgreSQL的源代码作参考,看看是为何:

当我用psql连接到数据库时,CheckMyDatabase函数就会被执行。

我注意到其中的这一段:

    /* If we have no other source of client_encoding, use server encoding */
SetConfigOption("client_encoding", GetDatabaseEncodingName(),
PGC_BACKEND, PGC_S_DYNAMIC_DEFAULT);

在准备client_encoding的时候,它用了 GetDatabaseEncodingName()函数,来返回数据库的Encoding名称。

可以认为,其实postgresql.conf里的 client_encoding的设定是没有用处的,因为内部运算的时候直接拿来了所连接的数据库的Encoding。也可以说,client_encoding是一个历史遗留问题,是PostgreSQL的开发者的失误造成的!

/*
* CheckMyDatabase -- fetch information from the pg_database entry for our DB
*/
static void
CheckMyDatabase(const char *name, bool am_superuser)
{ HeapTuple tup;
Form_pg_database dbform;
char *collate;
char *ctype; /* Fetch our pg_database row normally, via syscache */
tup = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(MyDatabaseId));
if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
dbform = (Form_pg_database) GETSTRUCT(tup); /* This recheck is strictly paranoia */
if (strcmp(name, NameStr(dbform->datname)) != )
ereport(FATAL,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" has disappeared from pg_database",
name),
errdetail("Database OID %u now seems to belong to \"%s\".",
MyDatabaseId, NameStr(dbform->datname)))); /*
* Check permissions to connect to the database.
* These checks are not enforced when in standalone mode, so that there is
* a way to recover from disabling all access to all databases, for
* example "UPDATE pg_database SET datallowconn = false;".
*
* We do not enforce them for autovacuum worker processes either.
*/
if (IsUnderPostmaster && !IsAutoVacuumWorkerProcess())
{
/*
* Check that the database is currently allowing connections.
*/
if (!dbform->datallowconn)
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("database \"%s\" is not currently accepting connections",
name))); /*
* Check privilege to connect to the database. (The am_superuser test
* is redundant, but since we have the flag, might as well check it
* and save a few cycles.)
*/
if (!am_superuser &&
pg_database_aclcheck(MyDatabaseId, GetUserId(),
ACL_CONNECT) != ACLCHECK_OK)
ereport(FATAL,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied for database \"%s\"", name),
errdetail("User does not have CONNECT privilege."))); /*
* Check connection limit for this database.
*
* There is a race condition here --- we create our PGPROC before
* checking for other PGPROCs. If two backends did this at about the
* same time, they might both think they were over the limit, while
* ideally one should succeed and one fail. Getting that to work
* exactly seems more trouble than it is worth, however; instead we
* just document that the connection limit is approximate.
*/
if (dbform->datconnlimit >= &&
!am_superuser &&
CountDBBackends(MyDatabaseId) > dbform->datconnlimit)
ereport(FATAL,
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
errmsg("too many connections for database \"%s\"",
name)));
} /*
* OK, we're golden. Next to-do item is to save the encoding info out of
* the pg_database tuple.
*/
SetDatabaseEncoding(dbform->encoding);
/* Record it as a GUC internal option, too */
SetConfigOption("server_encoding", GetDatabaseEncodingName(),
PGC_INTERNAL, PGC_S_OVERRIDE); /* If we have no other source of client_encoding, use server encoding */
SetConfigOption("client_encoding"
, GetDatabaseEncodingName(),
PGC_BACKEND, PGC_S_DYNAMIC_DEFAULT);
/* assign locale variables */
collate = NameStr(dbform->datcollate);
ctype = NameStr(dbform->datctype); if (pg_perm_setlocale(LC_COLLATE, collate) == NULL)
ereport(FATAL,
(errmsg("database locale is incompatible with operating system"),
errdetail("The database was initialized with LC_COLLATE \"%s\", "
" which is not recognized by setlocale().", collate),
errhint("Recreate the database with another locale or install the missing locale."))); if (pg_perm_setlocale(LC_CTYPE, ctype) == NULL)
ereport(FATAL,
(errmsg("database locale is incompatible with operating system"),
errdetail("The database was initialized with LC_CTYPE \"%s\", "
" which is not recognized by setlocale().", ctype),
errhint("Recreate the database with another locale or install the missing locale."))); /* Make the locale settings visible as GUC variables, too */
SetConfigOption("lc_collate", collate, PGC_INTERNAL, PGC_S_OVERRIDE);
SetConfigOption("lc_ctype", ctype, PGC_INTERNAL, PGC_S_OVERRIDE); /* Use the right encoding in translated messages */
#ifdef ENABLE_NLS
pg_bind_textdomain_codeset(textdomain(NULL));
#endif ReleaseSysCache(tup); }

[作者 高健@博客园  luckyjackgao@gmail.com]

回到上一级页面:PostgreSQL内部结构与源代码研究索引页    回到顶级页面:PostgreSQL索引页

磨砺技术珠矶,践行数据之道,追求卓越价值

EDB*Plus的client_encoding问题的更多相关文章

  1. pg 资料大全1

    https://github.com/ty4z2008/Qix/blob/master/pg.md?from=timeline&isappinstalled=0 PostgreSQL(数据库) ...

  2. PostgreSQL内部结构与源代码研究索引页

    磨砺技术珠矶,践行数据之道,追求卓越价值 luckyjackgao@gmail.com 返回顶级页:PostgreSQL索引页 本页记录所有本人所写的PostgreSQL的内部结构和源代码研究相关文摘 ...

  3. 调试器带参数调试(OD,EDB)

    小东西,不要在意这些细节-- OD带参数比较简单: 文件-- 打开 --  在最下面有一个参数 KALI LINUX下的EDB 命令格式为  edb –run  "对应程序路径"  ...

  4. 反汇编动态追踪工具Ollydbg. ALD,ddd,dbg,edb...

    Ollydbg 通常称作OD,是反汇编工作的常用工具,吾爱破解OD附带了118脱壳脚本和各种插件,功能非常强大,基本上不需要再附加安装其它插件了. 对OD的窗口签名进行了更改,从而避免被针对性检测 修 ...

  5. 通过MTK迁移Mysql到EDB实战指南

    1.1 迁移准备 下图是Migration toolkit(MTK)可使用的迁移功能 1 查看一下迁移源数据库testdb信息.共三张表 watermark/2/text/aHR0cDovL2Jsb2 ...

  6. 通过Navicat Premium迁移Oracle到EDB迁移实战

    1.1 DB migration analysis   在从Oracle向EDB迁移数据之前,须要做非常多准备工作.比方须要分析源数据库数据量大小.数据是否稳定.异构数据库兼容.编码方式.业务逻辑(存 ...

  7. EDB*Plus的当前路径问题

    磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL基础知识与基本操作索引页     回到顶级页面:PostgreSQL索引页 [作者 高健@博客园  luckyjackg ...

  8. 清理Windows.edb

    解决Windows.edb文件巨大的windows 10问题的另一个快速解决方法是删除Windows.edb文件. 步骤1:在任务管理器中终止SearchIndexer.exe --按Ctrl + A ...

  9. EDB日志配置-慢sql记录分析

    1.打开:/postgresql的安装目录/data/postgresql.conf 2.找到并更改以下属性,其他的是方便观察设置的,注意要将属性前面的注释符'#'去掉才能生效 ★★★log_dest ...

随机推荐

  1. MySQL->>innodb_autoinc_lock_mode参数控制auto_increment 插入数据时相关锁的模式

    转自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2141640/ ---------------------------------- ...

  2. Linux 软硬链接详解

    软链接 软链接: 类似于windows的快捷方式,—>文本文件,但是包含了真实文件的地址               源文件删除,则软连接也删除               软链接可以放在任何文 ...

  3. 利用Linode面板Clone克隆搬家迁移不同VPS数据及利用IP Swap迁移IP地址

    在众多海外VPS服务商中,老蒋个人认为Linode提供的VPS方案和性价比还是比较高的,尤其目前基础1GB方案仅需10美元每月且全部是SSD固态硬盘,无论是流量还是硬盘大小,基本上可以满足我们大部分用 ...

  4. idea指定SpringBoot启动.properties文件

    比如我的项目下有2个.properties文件,一个是application.properties,一个是application-local.properties,在本地的时候想指定用applicat ...

  5. Hadoop HBase概念学习系列之行、行键(十一)

    行是由列簇中的列组成.行根据行键依照字典顺序排序. HBase的行使用行键标识,可以使用行键查询整行的数据. 对同一个行键的访问都会落在同样的物理节点上.如果表包含2个列簇,属于两个列簇的文件还是保存 ...

  6. 快速搭建一个Express工程骨架

    下载express-generator 通过应用生成器,可以帮我们快速搭建项目需要的骨架.这就需要npm在全局下载express-generator(-g就是在全局安装) npm install ex ...

  7. [DAViCHi/SeeYa/T-ARA][원더우먼][Wonder Woman]

    歌词来源:http://music.163.com/#/song?id=5371229 作曲 : 赵英秀 [作曲 : 赵英秀] [作曲 : 赵英秀] 作词 : K-Smith [作词 : KSmith ...

  8. 转 oracle的热备份和冷备份

    一.冷备份介绍:    冷备份数据库是将数据库关闭之后备份所有的关键性文件包括数据文件.控制文件.联机REDO LOG文件,将其拷贝到另外的位置.此外冷备份也可以包含对参数文件和口令文件的备份,但是这 ...

  9. 洛谷 P2764 最小路径覆盖问题【最大流+拆点+路径输出】

    题目链接:https://www.luogu.org/problemnew/show/P2764 题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V ...

  10. ARC与Toll-Free Bridging

    arc模块与mrc模块的沟通. 相当于程序的混编处理. Toll-Free Briding保证了在程序中,可以方便和谐的使用Core Foundation类型的对象和Objective-C类型的对象. ...