Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 | 



Creating Database

Description

The cubrid createdb utility creates databases and initializes them with the built-in CUBRID system tables. It can also define initial users to be authorized in the database and specify the locations of the logs and databases. In general, the cubrid createdb utility is used only by DBA.

Syntax

cubrid createdb options database_name

options :

[--db-volume-size=size] [--db-page-size=size] [--log-volume-size=size] [--log-page-size=size] [--comment=comment] [{-F |--file-path=}path] [{-L |--log-path=}path] [{-B |--lob-base-path=}path] [--server-name=host] [-r|--replace] [--more-volume-file=file] [--user-definition-file=file] [--csql-initialization-file=file] [{-o |--output-file=}file] [-v|--verbose]

  • cubrid : An integrated utility for the CUBRID service and database management.
  • createdb : A command used to create a new database.
  • options : A short option starts with a single dash (-) while a full name option starts with a double dash (--).
  • database_name : Specifies a unique name for the database to be created, without including the path name to the directory where the database will be created. If the specified database name is the same as that of an existing database name, CUBRID halts creation of the database to protect existing files.
Options

The following table shows options available with the cubrid createdb utility (options are case sensitive).

Option

Description

--db-volume-size

Specifies the size of the database volume that will be created first in bytes.
Default value : A value of db_volume_size, the system parameter

--db-page-size

Specifies the database page size in bytes.
Default value : 16K

--log-volume-size

Specifies the log volume size in bytes.

--log-page-size

Specifies the page size of log volume in bytes.
Default value : Database page size

--comment

Adds information on the database to be created in the form of a comment.

-F
--file-path

Specifies the directory path where the database will be created.
Default value : Current working directory

-L
--log-path

Specifies the directory path where log files will be stored.
Default value : A directory path specified with the -F option

-B
--lob-base-path

Specifies the directory path where LOB data files will be stored.
Default value : <location of database volumns created>/lob directory

--server-name

Specifies the name of the server host to connect to.
Default value : localhost

-r
--replace

Allows overwriting if the name of the database to be created is the same as that of an existing database.
Default value : Deactivated

--more-volume-file

Specifies the file that includes the specifications for creating an additional volume of the database.

--user-definition-file

Specifies the file that includes user definitions.

--csql-initialization-file

Specifies the file for csql initialization.

-o
--output-file

Specifies the file where output messages concerning database creation are stored.

-v
--verbose

Displays detailed messages to the screen concerning database creation.
Default value : Deactivated

Size of the first database volume (--db-volume-size)

The --db-volume-size option specifies the size of the database volume that will be created first. The default value is  the value of the system parameter db_volume_size, and the minimum value is 20M. You can set units as K, M, G and T, which stand for kilobytes (KB), megabytes (MB), gigabytes (GB), and terabytes (TB) respectively. If you omit the unit, bytes will be applied. 

The following example shows how to create a database named testdb and assign 512 MB to its first volume.

cubrid createdb --db-volume-size=512M testdb

Database page size (--db-page-size)

The --db-page-size option specifies the size of the database page; the minimum value is 4K and the maximum value is 16K (default). K stands for kilobytes (KB).

The value of page size is one of the followings: 4K, 8K, or 16K. If a value between 4K and 16K is specified, system rounds up the number. If a value greater than 16K or less than 4K, the specified number is used.

The following example shows how to create a database named testdb and configure its page size 16K.

cubrid createdb --db-page-size=16K testdb

Log volume size (--log-volume-size)

The --log-volume-size option specifies the size of the database log volume. The default value is the same as database volume size, and the minimum value is 20M. You can set units as K, M, G and T, which stand for kilobytes (KB), megabytes (MB), gigabytes (GB), and terabytes (TB) respectively. If you omit the unit, bytes will be applied. 

The following example shows how to create a database named testdb and assign 256 MB to its log volume.

cubrid createdb --log-volume-size=256M testdb

Log page size (--log-page-size)

The --log-page-size option specifies the size of the log volume page. The default value is the same as data page size. The minimum value is 4K and the maximum value is 16K. K stands for kilobytes (KB).

The value of page size is one of the followings: 4K, 8K, or 16K. If a value between 4K and 16K is specified, system rounds up the number. If a value greater than 16K or less than 4K, the specified number is used.

The following example shows how to create  a database named testdb and configure its log volume page size 8K.

cubrid createdb --log-page-size=8K testdb

Comment (--comment)

The --comment option specifies a comment to be included in the database volume header. If the character string contains spaces, the comment must be enclosed in double quotes.

The following example shows how to create a database named testdb and add a comment to the database volume.

cubrid createdb --comment "a new database for study" testdb

Database directory path (-F)

The -F option specifies an absolute path to a directory where the new database will be created. If the -F option is not specified, the new database is created in the current working directory.

The following example shows how to create a database named testdb in the directory /dbtemp/new_db.

cubrid createdb -F "/dbtemp/new_db/" testdb

Log file directory path (-L)

The -L option specifies an absolute path to the directory where database log files are created. If the -L option is not specified, log files are created in the directory specified by the -F option. If neither -F nor -L option is specified, database log files are created in the current working directory.

The following example shows how to create a database named testdb in the directory /dbtemp/newdb and log files in the directory /dbtemp/db_log.

cubrid createdb -F "/dbtemp/new_db/" -L "/dbtemp/db_log/" testdb

LOB data file directory path (-B)

The --lob-base-path option specifies a directory where LOB data files are stored when BLOB/CLOB data is used. If the --lob-base-path option is not specified, LOB data files are store in <location of database volumns created>/lob directory.

The following example shows how to create a database named testdb in the working directory and specify /home/data1 of local file system as a location of LOB data files.

cubrid createdb --lob-base-path "file:/home1/data1" testdb

Server host name (--server-name)

The --server-name option enables the server of a specific database to run in the specified host when CUBRID client/server is used. The information of a host specified is stored in the databases.txt file. If this option is not specified, the current localhost is specified by default.

The following example shows how to create a database named testdb and register it on the host aa_host.

cubrid createdb --server-name aa_host testdb

Overwriting (-r)

The -r option creates a new database and overwrites an existing database if one with the same name exists. If the -r option is not specified, database creation is halted.

The following example shows how to create a new database named testdb and overwrite the existing database with the same name.

cubrid createdb -r testdb

Adding a database volume (--more-volume-file)

The --more-volume-file option creates an additional volume based on the specification contained in the file specified by the option. The volume is created in the same directory where the database is created. Instead of using this option, you can add a volume by using the cubrid addvoldb utility.

The following example shows how to create a database named testdb as well as an additional volume based on the specification stored in the vol_info.txt file.

cubrid createdb --more-volume-file vol_info.txt testdb

The following is a specification of the additional volume contained in the vol_info.txt file. The specification of each volume must be written on a single line.

#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# NAME volname COMMENTS volcmnts PURPOSE volpurp NPAGES volnpgs

NAME data_v1 COMMENTS "data information volume" PURPOSE data NPAGES 1000

NAME data_v2 COMMENTS "data information volume" PURPOSE data NPAGES 1000

NAME data_v3 PURPOSE data NPAGES 1000

NAME index_v1 COMMENTS "index information volume" PURPOSE index NPAGES 500

NAME temp_v1 COMMENTS "temporary information volume" PURPOSE temp NPAGES 500

NAME generic_v1 COMMENTS "generic information volume" PURPOSE generic NPAGES 500

#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

As shown in the example, the specification of each volume consists followings.

NAME volname COMMENTS volcmnts PURPOSE volpurp NPAGES volnpgs

  • volname : The name of the volume to be created. It must follow the UNIX file name conventions and be a simple name not including the directory path. The specification of a volume name can be omitted. If it is, the "database name to be created by the system_volume identifier" becomes the volume name.
  • volcmnts : Comment to be written in the volume header. It contains information on the additional volume to be created. The specification of the comment on a volume can also be omitted.
  • volpurp : It must be one of the following types: data, index, temp, or generic based on the purpose of storing volumes. The specification of the purpose of a volume can be omitted in which case the default value is generic.
  • volnpgs : The number of pages of the additional volume to be created. The specification of the number of pages of the volume cannot be omitted; it must be specified.

User information file (--user-definition-file)

The --user-definition-file option adds users who have access to the database to be created. It adds a user based on the specification contained in the user information file specified by the parameter. Instead of using the --user-definition-file option, you can add a user by using the CREATE USER statement (for details, see Managing USER).

The following example shows how to create a database named testdb and add users to testdb based on the user information defined in the user_info.txt file.

cubrid createdb --user-definition-file user_info.txt testdb

The syntax of a user information file is as follows:

USER user_name [ groups_clause | members_clause ]|

groups_clause:

 [ GROUPS group_name [ { group_name }... ] ]

members_clause:

 [ MEMBERS member_name [ { member_name... } ] ]

  • The user_name is the name of the user who has access to the database. It must not include spaces.
  • The GROUPS clause is optional. The group_name is the upper level group that contains the user_name. Here, the group_name can be multiply specified and must be defined as USER in advance.
  • The MEMBERS clause is optional. The member_name is the name of the lower level member that belongs to the user_name. Here, the member_name can be multiply specified and must be defined as USER in advance.

Comments can be used in a user information file. A comment line must begin with a consecutive hyphen lines (--). Blank lines are ignored.

The following example shows a user information in which grandeur and sonata are included in sedan group, tuscan is included in suv group, and i30 is included in hatchback group. The name of the user information file is user_info.txt.

--

-- Example 1 of a user information file

--

USER sedan

USER suv

USER hatchback

USER grandeur GROUPS sedan

USER sonata GROUPS sedan

USER tuscan GROUPS suv

USER i30 GROUPS hatchback

The following example shows a file that has the same user relationship information as the file above. The difference is that the MEMBERS statement is used in the file below.

--

-- Example 2 of a user information file

--

USER grandeur

USER sonata

USER tuscan

USER i30

USER sedan MEMBERS sonata grandeur

USER suv MEMBERS tuscan

USER hatchback MEMBERS i30

File where CSQL statements are stored (--csql-initialization-file)

The --csql-initialization-file option executes an SQL statement on the database to be created by using the CSQL Interpreter. A schema can be created based on the SQL statement contained in the file specified by the parameter.

The following example shows how to create a database named testdb and execute the SQL statement defined in table_schema.sql through the CSQL Interpreter.

cubrid createdb --csql-initialization-file table_schema.sql testdb

Storing output messages to a file (-o)

The -o option stores messages related to the database creation to the file given as a parameter. The file is created in the same directory where the database was created. If the -o option is not specified, messages are displayed on the console screen. The -o option allows you to use information on the creation of a certain database by storing messages, generated during the database creation, to a specified file.

The following example shows how to create a database named testdb and store the output of the utility to the db_output file instead of displaying it on the console screen.

cubrid createdb -o db_output testdb

Verbose output (-v)

The -v option displays all information on the database creation operation onto the screen. Like the -o option, this option is useful in checking information related to the creation of a specific database. Therefore, if you specify the -v option together with the -o option, you can store the output messages in the file given as a parameter; the messages contain the operation information about the cubrid createdb utility and database creation process.

The following example shows how to create a database named testdb and display detailed information on the operation onto the screen.

cubrid createdb -v testdb

Remark

temp_file_max_size_in_pages is a parameter that configures the maximum number of pages assigned to store the temporary temp volume - used for complicated queries or storing arrays - on the disk.

While the default value is -1, the temporary temp volume may be increased up to the amount of extra space on the disk specified by the temp_volume_path parameter. If the value is 0, the temporary temp volume cannot be created. In this case, the permanent temp volume should be added by using the cubrid addvoldb utility.

For the efficient management of the volume, it is recommended to add a volume for each usage. By using the cubrid spacedb utility, you can check the reaming space of each volume. By using the cubrid addvoldb utility, you can add more volumes as needed while managing the database. When adding a volume while managing the database, you are advised to do so when there is less system load. Once the assigned volume for a usage is completely in use, a generic volume will be created, so it is suggested to add extra volume for a usage that is expected to require more space.

Next, we will look at how to add volumes for data, index, and temp by creating the database and separating the volume usage.

cubrid createdb --db-volume-size=512M --log-volume-size=256M cubriddb

cubrid addvoldb -p data -n cubriddb_DATA01 --db-volume-size=512M cubriddb

cubrid addvoldb -p data -n cubriddb_DATA02 --db-volume-size=512M cubriddb

cubrid addvoldb -p index -n cubriddb_INDEX01 cubriddb --db-volume-size=512M cubriddb

cubrid addvoldb -p temp -n cubriddb_TEMP01 cubriddb --db-volume-size=512M cubriddb