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 ]}[...] ]; |
- TEMPLATE [ = ] template
Indicates the template name, that is, the name of the template to be used to create the database. GaussDB(DWS) creates a database by copying a database template. GaussDB(DWS) has two initial template databases template0 and template1 and a default user database gaussdb.
Value range: an existing database name. If this is not specified, the system copies template1 by default. Its value cannot be gaussdb.
Currently, database templates cannot contain sequences. If sequences exist in the template library, database creation will fail.
- ENCODING [ = ] encoding
Character encoding used by the database. The value can be a character string (for example, SQL_ASCII') or an integer number.
If this parameter is not specified, the encoding of the template database is used by default. The encoding of template databases template0 and template1 depends on the OS by default. The character encoding of template1 cannot be changed. To change the encoding, use template0 to create a database.
Value range: GBK, UTF8, and Latin1
The character set encoding of the new database must be compatible with the local settings (LC_COLLATE and LC_CTYPE).
Examples
Create database music using UTF8 (the local encoding type is also UTF8).
1
|
CREATE DATABASE music ENCODING 'UTF8' template = template0; |
Database Usage FAQs
- How Do I Change Distribution Columns?
- How Do I View and Set the Database Character Encoding?
- What Do I Do If Date Type Is Automatically Converted to the Timestamp Type During Table Creation?
- Do I Need to Run VACUUM FULL and ANALYZE on Common Tables Periodically?
- Do I Need to Set a Distribution Key After Setting a Primary Key?
- Is GaussDB(DWS) Compatible with PostgreSQL Stored Procedures?
- What Are Partitioned Tables, Partitions, and Partition Keys?
- How Can I Export the Table Structure?
- How Do I Delete Table Data Efficiently?
- How Do I View Foreign Table Information?
- If No Distribution Column Is Specified, How Will Data Be Stored?
- How Do I Replace the Null Result with 0?
- How Do I Check Whether a Table Is Row-Stored or Column-Stored?
- How Do I Query the Information About GaussDB(DWS) Column-Store Tables?
- Why Sometimes the GaussDB(DWS) Query Indexes Become Invalid?
- How Do I Use a User-Defined Function to Rewrite the CRC32() Function?
- What Are the Schemas Starting with pg_toast_temp* or pg_temp*?
- Solutions to Inconsistent GaussDB(DWS) Query Results
- Which System Catalogs That the VACUUM FULL Operation Cannot Be Performed on?
- In Which Scenarios Would a Statement Be "idle in transaction"?
- How Does GaussDB(DWS) Implement Row-to-Column and Column-to-Row Conversion?
- What Are the Differences Between Unique Constraints and Unique Indexes?
- What Are the Differences Between Functions and Stored Procedures?
- How Do I Delete Duplicate Table Data?
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbotmore