我試圖改變我運行的PostgreSQL數據庫的client_encoding
配置變量的默認值。我希望它是UTF8
,但目前它設置爲LATIN1
。如何更改Postgres中的默認client_encoding?
數據庫已被設置爲使用UTF-8編碼:
application_database=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------------+----------+----------+-------------+-------------+--------------------------------------
postgres | postgres | LATIN1 | en_US | en_US |
application_database | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres=CTc/postgres +
| | | | | application_database=Tc/postgres
template0 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
哪個according to the docs應該已經結果,用UTF8作爲默認client_encoding
(重點煤礦)的客戶端:
client_encoding (string)
設置客戶端編碼(字符集)。 默認是使用數據庫編碼。
但事實並非如此:
$ sudo psql --dbname=application_database
psql (9.1.19)
Type "help" for help.
application_database=# SHOW client_encoding;
client_encoding
-----------------
LATIN1
(1 row)
我甚至用ALTER USER <user> SET ...
更改我登錄的用戶的默認配置嘗試:
application_database=# ALTER USER root SET client_encoding='UTF8';
ALTER ROLE
application_database=# SELECT usename, useconfig FROM pg_shadow;
usename | useconfig
----------------------+------------------------
postgres |
root | {client_encoding=UTF8}
application_database |
(3 rows)
但也沒有效果:
$ sudo psql --dbname=application_database
psql (9.1.19)
Type "help" for help.
application_database=# SELECT current_user;
current_user
--------------
root
(1 row)
application_database=# SHOW client_encoding;
client_encoding
-----------------
LATIN1
(1 row)
沒有什麼任何在我的系統PSQL文件:
[email protected]:~$ cat ~/.psqlrc
cat: /home/vagrant/.psqlrc: No such file or directory
[email protected]:~$ cat /etc/psqlrc
cat: /etc/psqlrc: No such file or directory
[email protected]:~$ sudo su
[email protected]:/home/vagrant# cat ~/.psqlrc
cat: /root/.psqlrc: No such file or directory
我運行PosgreSQL 9.1:
application_database=# SELECT version();
version
-------------------------------------------------------------------------------------------------------------
PostgreSQL 9.1.19 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 64-bit
(1 row)
「cat〜/ .psqlrc和cat/etc/psqlrc的結果是什麼?」添加到問題 – Ajedi32
將'client_encoding ='UTF8''附加到'/ etc/postgresql/9.1/main/postgresql.conf'並使用'/etc/init.d/postgresql restart'重新啓動Postgres不起作用。新連接的客戶端編碼仍然是'LATIN1'。設置環境變量確實有效,但就像你說的那樣是客戶特定的。雖然我的情況可能會「足夠好」...... – Ajedi32