CREATE PLUGGABLE DATABASE
Description
Creates a PDB. This concept refers to tenants in the multi-tenancy feature of kernel. It is a special database and can also be regarded as a logical instance divided from a database instance.
Precautions
- DDL statements for creating PDBs, including CREATE, ALTER, and DROP, cannot be executed in transaction blocks.
- This command can be used only when the GUC parameter enable_mtd is set to on.
- This operation can be performed only in the non-PDB. This command cannot be executed in M-compatible databases.
- The operation user must be assigned as gs_role_create_pdb role or have the SYSADMIN permission.
- A maximum of 128 user PDBs can be created.
- During the database creation, an error message indicating that permission denied is displayed, possibly because the permission on the data directory in the file system is insufficient. If an error message, indicating no space left on device is displayed, the possible cause is that the disk space is used up.
- An A-compatible PDB is created when the compatibility option is defaulted.
- If the initial account password is not specified during database instance installation, the initial account name is case-sensitive, and the created PDB is an M-compatible database, run the following statements in the CLI before enabling and using the PDB. In this way, the database considers content in double quotation marks ("") as an object reference. After the statement is executed, enable and use the PDB and reset the initial account password as prompted.
gs_guc set --pdbname my_pdb -Z datanode -N all -I all -c "sql_mode = 'ansi_quotes'" # my_pdb indicates the new PDB name.
(This operation is performed to ensure that the account password can be properly set for the new PDB. You can reset the sql_mode parameter as required in subsequent operations.)
Syntax
CREATE PLUGGABLE DATABASE pdb_name [ [ WITH ] { [ ENCODING [=] 'encoding' ] | [ LC_COLLATE [=] 'lc_collate' ] | [ LC_CTYPE [=] 'lc_ctype' ] | [ DBCOMPATIBILITY [=] 'compatibility_type' ] | [ DBTIMEZONE [=] 'time_zone' ] }];
Parameters
- pdb_name
Specifies the PDB name.
Value range: a string that complies with the Identifier Naming Conventions. In addition, the PDB name cannot contain a dollar sign ($).
- ENCODING [ = ] 'encoding'
(Optional) Specifies the character encoding used by the database. The value can be a string (for example, SQL_ASCII) or an integer.
If this parameter is not specified, the UTF-8 encoding format is used for the M-compatible database by default, and the encoding format of the template database is used for other databases by default. By default, the codes of the template databases template0, template1, and templatea are related to the OS environment. The character encoding of template1 cannot be changed. To change the encoding, use templatea to create an A-compatible database and use template0 to create a non-A-compatible database.
Common values: GBK, UTF8, Latin1, and GB18030.
- LC_COLLATE [ = ] 'lc_collate'
(Optional) Specifies the character set used by the new database. For example, set this parameter by using lc_collate = 'zh_CN.gbk'.
The use of this parameter affects the sort order of strings (for example, the order of using ORDER BY for execution and the order of using indexes on text columns). By default, the character set of the template database is used. This parameter does not take effect for the M-compatible database.
Value range: character sets supported by the OS.
- LC_CTYPE [ = ] 'lc_ctype'
(Optional) Specifies the character class used by the new database. For example, set this parameter by using lc_ctype = 'zh_CN.gbk'. The use of this parameter affects the classification of characters, such as uppercase letters, lowercase letters, and digits. By default, the character classification of the template database is used. This parameter does not take effect for the M-compatible database.
Value range: character classes supported by the OS.
- DBCOMPATIBILITY [ = ] compatibility_type
(Optional) Specifies the compatible database type. The default database is an O-compatible database.
Value range: A, C, PG, and M. They indicate compatibility with O, TD, POSTGRES, and M-compatible databases respectively.
- DBTIMEZONE [ = ] time_zone
Specifies the time zone of the new database. For example, you can set this parameter by setting DBTIMEZONE to '+00:00'. This parameter affects the time zone of the new database. The PRC is used by default.
Prerequisites: The current database is compatible with database A, a_format_version is set to '10c', and a_format_dev_version is set to 's2'.
Value range: name and abbreviation of the time zone supported by the OS, or the timestamp ranges from –15:59 to +15:00.
Examples
- Prerequisites
Install the multi-tenant database instance by referring to "Multi-tenant Databases > Installing Multi-tenant Database Instances" in Feature Guide.
- Create a PDB.
-- Connect to the postgres database as a system administrator and create a resource plan instruction. gaussdb=# call resource_manager.create_pending_area(); create_pending_area --------------------- (1 row) -- This API is used to create resources. The resource specifications of the current instance determine whether the resources can be successfully created. If the API reports an error, adjust the parameters based on the error description and try again. gaussdb=# CALL resource_manager.create_resource_plan_directive(pdb_name =>'my_pdb', min_cpu => 4, max_dynamic_memory => '18022MB', max_shared_memory => '14745MB', io_limits=> 300, io_priority => 'High', max_connections => 880); create_resource_plan_directive -------------------------------- (1 row) gaussdb=# CALL resource_manager.submit_pending_area(); submit_pending_area --------------------- (1 row) -- Connect to the postgres database as a system administrator and create a PDB. gaussdb=# CREATE PLUGGABLE DATABASE my_pdb; CREATE PLUGGABLE DATABASE
Helpful Links
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.
Chatbot