How Do I View and Set the Database Character Encoding?

Viewing the Database Character Encoding

Use the server_encoding parameter to check the character set encoding of the current database. For example, the character encoding of database music is UTF8.

1
2
3
4
5
music=> SHOW server_encoding;
 server_encoding
-----------------
 UTF8
(1 row)

Setting the Database Character Encoding

GaussDB(DWS) does not support the modification of the character encoding format of a created database.

If you need to specify the character encoding format of a database, use template0 and the CREATE DATABASE syntax to create a database. To make your database compatible with most characters, you are advised to use the UTF8 encoding when creating a database.

CREATE DATABASE syntax

1
2
3
4
5
6
7
8
CREATE DATABASE database_name
    [ [ WITH ] { [ OWNER [=] user_name ] |
               [ TEMPLATE [=] template ] |
               [ ENCODING [=] encoding ] |
               [ LC_COLLATE [=] lc_collate ] |
               [ LC_CTYPE [=] lc_ctype ] |
               [ DBCOMPATIBILITY [=] compatibility_type ] |
               [ CONNECTION LIMIT [=] connlimit ]}[...] ];

Examples

Create database music using UTF8 (the local encoding type is also UTF8).

1
CREATE DATABASE music ENCODING 'UTF8' template = template0;