开发者社区> 嗯哼9925> 正文

EDB*Plus的client_encoding问题

简介:
+关注继续查看

我的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)) != 0)                                
        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 >= 0 &&                            
            !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);           
                            
}                                    
复制代码




版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
【已解决】Client does not support authentication protocol requested by server; consider upgrading MySQL client
Client does not support authentication protocol requested by server; consider upgrading MySQL client
63 0
成功解决 SyntaxError: Non-UTF-8 code starting with \xc0 in file but no encoding declared; see http://p
成功解决 SyntaxError: Non-UTF-8 code starting with \xc0 in file but no encoding declared; see http://p
95 0
Fetch failed: unable to access': E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Fetch failed: unable to access': E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
129 0
Unable to read additional data from server sessionid
jenkins构建项目报错: Caused by: com.weibo.api.motan.exception.MotanFrameworkException: error_message: ClusterSupport No service urls for the refer:motan://192.
9769 0
Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
错误信息: Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING 环境现象 chrome chrome浏览器下,之前访问的界面是什么样子,访问出错的这个网址后,界面依然还是什么样子,只是不响应鼠标...
2979 0
navicat连接oracle报错ORA-12737: Instant Client Light: unsupported server character set CHS16GBK”
原文如下http://blog.163.com/cp7618@yeah/blog/static/7023477720142154449893/?COLLCC=1318255100&   这个工具可以用于任何版本 8i 或以上的 Oracle 数据库服务器,并支持大部份 Oracle 最新版本的功能,包括目录、表空间、同义词、实体化视图、触发器、序列、类型等。
1354 0
Error 200 fault:SOAP-ENV:Client [no subcode]
Error 200 fault:SOAP-ENV:Client [no subcode] 使用gsoap生成的webservice客户端调用其它程序发布的webservice的时候,一直未找到原因,困扰好久,最好,查到原因是因为 对方采用的是RPC方式发布的webservice,将url的路径修改为全路径后问题解决,调用成功。
1313 0
+关注
文章
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载