EDB*Plus의 client_인코딩 문제

17411 단어 encoding
기술을 연마하여 데이터의 길을 실천하고 탁월한 가치를 추구하다
이전 페이지로 돌아가기:PostgreSQL 내부 구조와 소스 코드 연구 인덱스 페이지 최상위 페이지로 돌아가기:PostgreSQL 인덱스 페이지
[작가 고건@ 블로그 동산[email protected]
 
내 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 = 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); 

클라이언트 준비 중_인코딩을 할 때 데이터베이스의 인코딩 이름을 되돌려주는 GetDatabaseEncodingName () 함수를 사용합니다.
사실postgresql.conf의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);  } 

 
 
[작가 고건@ 블로그 동산[email protected]]  
이전 페이지로 돌아가기:PostgreSQL 내부 구조와 소스 코드 연구 인덱스 페이지 최상위 페이지로 돌아가기:PostgreSQL 인덱스 페이지
기술을 연마하여 데이터의 길을 실천하고 탁월한 가치를 추구하다

좋은 웹페이지 즐겨찾기