EDB*Plus的client_encoding问题

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB PostgreSQL 版,企业版 4核16GB
推荐场景:
HTAP混合负载
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
简介:

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




相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
2月前
|
SQL 流计算
"Missing version in readMessageBegin, old client?
"Missing version in readMessageBegin, old client?
28 1
|
8月前
|
XML 编解码 数据格式
python报错 ‘utf-8‘ codec can‘t encode characters in position xxxx-xxxx: surrogates not allowed
python报错 ‘utf-8‘ codec can‘t encode characters in position xxxx-xxxx: surrogates not allowed
239 0
|
SQL 关系型数据库 MySQL
Mysql报错:Illegal mix of collations (utf8mb4_bin,NONE) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation
Mysql报错:Illegal mix of collations (utf8mb4_bin,NONE) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation
446 0
|
Java 关系型数据库 MySQL
tomcat运行报错:unknown character set utf8mb4
tomcat运行报错:unknown character set utf8mb4
87 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
成功解决 SyntaxError: Non-UTF-8 code starting with \xc0 in file but no encoding declared; see http://p
|
Python
SyntaxError: Non-UTF-8 code starting with ‘\xc7‘ in file
学习SyntaxError: Non-UTF-8 code starting with ‘\xc7‘ in file。
357 0
file encode - /UI2/CL_HTTP_FILE_ENCODE
Created by Wang, Jerry, last modified on Mar 24, 2015
108 0
file encode - /UI2/CL_HTTP_FILE_ENCODE
|
SQL 安全 数据库
The server principal "sa" is not able to access the database "xxxx" under the current security context
在SQL Server服务器上一个作业执行时,遇到下面错误信息: Message: Executed as user: dbo. The server principal "sa" is not able to access the database "xxxx" under the current security context. [SQLSTATE 08004] (Error 916). The step failed.   作业本身执行的存储过程非常简单,就是将数据库A中的历史数据处理过后,归档到A_History库中,结果就遇到这么一个问题。
2886 0

热门文章

最新文章