You can use the CREATE DATABASE syntax to create a database in a Lindorm instance and configure attributes such as TTL for the database to manage data in a unified manner.
Applicable engines and versions
The CREATE DATABASE syntax is applicable to LindormTable and LindormTSDB.
The CREATE DATABASE syntax is supported by LindormTable 2.2.16 and later versions.
The CREATE DATABASE syntax is supported by all versions of LindormTSDB.
Syntax
create_database_statement ::= CREATE DATABASE [ IF NOT EXISTS ] database_identifier [ WITH attribute_statement ]
attribute_statement ::= '(' attribute_definition (',' attribute_definition)* ')'
attribute_definition ::= attr_identifier '=' attr_val
LindormTable whose version is earlier than 2.2.16 supports only the CREATE SCHEMA [ IF NOT EXISTS ] schema_identifier
syntax. LindormTable 2.2.16 and later versions support its equivalent syntax CREATE SCHEMA [ IF NOT EXISTS ] schema_identifier
. SCHEMA
is equivalent to DATABASE
. After you create a database, the database is represented by the DATABASE
keyword.
Supported parameters
The following table describes the parameters of the CREATE DATABASE syntax supported by LindormTable and LindormTSDB.
Parameter | LindormTable | LindormTSDB |
〇 | 〇 | |
✖️ | 〇 |
Parameters
Database name (database_identifier)
The database name must comply with the following rules:
The name can be 4 to 16 characters in length.
The name can contain digits, letters, hyphens (-), and underscores (_).
The following reserved words cannot be used as database names: lindorm, default, and global.
Database attributes (attribute_definition)
This parameter is supported only by LindormTSDB.
You can use the WITH
keyword to configure one or more attributes for the database. Example: WITH (cold_boundary=30, ttl=60)
. The following table describes the attributes that you can configured for a database.
Attribute | Type | Description |
cold_boundary | BIGINT | The hot and cold data boundary. Unit: days. The default value of this attribute is 0, which indicates that cold storage is not enabled for the database. Note To configure this attribute, you must enable the cold storage feature in the Lindorm console. For more information, see Enable cold storage. |
partition_interval | BIGINT | The interval based on which data is partitioned. Data and indexes within the same interval are stored in the same partition. Unit: days. The default value of this attribute varies with the version of LindormTable.
|
ttl | BIGINT | The TTL of data in the database. Unit: days. Data that exceeds the TTL is automatically cleared. Default value: 0. If you leave this attribute unspecified or keep the default value of this attribute, data in the database is permanently stored. Note If you configure the ttl attribute and the cold_boundary attribute, make sure that the value of the ttl attribute is greater than the value of the cold_boundary attribute. |
Examples
Create a database
CREATE DATABASE DB1;
Verify the result
You can execute the SHOW DATABASES;
statement to check whether the database is created.
Configure attributes for a database
Create a database named DB1 and specify that data in DB1 is transferred to cold storage after 30 days and is cleared after 60 days.
CREATE DATABASE DB1 WITH(cold_boundary=30,ttl=60);
Verify the result
You can execute the
SHOW DATABASES;
statement to check whether the database is created.You can execute the
DESCRIBE DATABASE DB1;
statement to view the attributes configured for the database DB1.