Unload and load: unloaddb, loaddb
unloaddb
Section titled “unloaddb”The purposes of loading/unloading databases are as follows:
- To rebuild databases by volume reconfiguration
- To migrate database in different system environments
- To migrate database in different versions
coradb unloaddb [options] database_namecoradb unloaddb utility creates the following files:
- Schema file(database-name**_schema**): A file that contains information on the schema defined in the database.
- Object file(database-name**_objects**): A file that contains information on the records in the database.
- Index file(database-name**_indexes**): A file that contains information on the indexes defined in the database.
- Trigger file(database-name**_trigger**): A file that contains information on the triggers defined in the database. If you don't want triggers to be running while loading the data, load the trigger definitions after the data loading has completed.
The schema, object, index, and trigger files are created in the same directory.
The following is [options] used in coradb unloaddb.
Specify a user account of a database to be unloaded. If this is not specified, the default is DBA.
coradb unloaddb -u dba -i table_list.txt testdbSpecify a user's password of a database to be unloaded. If this is not specified, it is regarded as the empty string is entered.
coradb unloaddb -u dba -p dba_pwd -i table_list.txt testdbUnload all schema and index of all tables; however, only the data of specified tables in this file are unloaded.
coradb unloaddb -i table_list.txt testdbThe following example shows an input file (table_list.txt).
table_1table_2..table_nIf this option is used together with the --input-class-only option, it creates schema, index, and data files of tables only specified in the input file of -i option.
coradb unloaddb --input-class-only -i table_list.txt testdbIf this option is used together with the --include-reference option, it unloads the referenced tables as well.
coradb unloaddb --include-reference -i table_list.txt testdbThis option is used together with the -i option, and also unloads the referenced tables.
This option is used together with the -i option, and creates only a schema file of tables specified in the input file of -i option.
This option allows you to assign hash memory to store records of the database to be unloaded. If the --estimated-size option is not specified, the number of records of the database is determined based on recent statistics information. This option can be used if the recent statistics information has not been updated or if a large amount of hash memory needs to be assigned. Therefore, if the number given as the argument for the option is too small, the unload performance deteriorates due to hash conflicts.
coradb unloaddb --estimated-size=1000 testdbThe --cached-pages option specifies the number of pages of tables to be cached in the memory. Each page is 4,096 bytes. The administrator can configure the number of pages taking into account the memory size and speed. If this option is not specified, the default value is 100 pages.
coradb unloaddb --cached-pages 500 testdbThis option specifies the directory in which to create schema and object files. If this is not specified, files are created in the current directory.
coradb unloaddb -O ./CoraDB/Databases/testdb testdbIf the specified directory does not exist, the following error message will be displayed.
unloaddb: No such file or directory.This option specifies that only the schema file will be created from amongst all the output files which can be created by the unload operation.
coradb unloaddb -s testdbThis option specifies that only the data file will be created from amongst all of the output files which can be created by the unload operation.
coradb unloaddb -d testdbThis option specifies the prefix for the names of schema and object files created by the unload operation. Once the example is executed, the schema file name becomes abcd_schema and the object file name becomes abcd_objects. If the --output-prefix option is not specified, the name of the database to be unloaded is used as the prefix.
coradb unloaddb --output-prefix abcd testdbThis option specifies the name of the hash file.
This option displays detailed information on the database tables and records being unloaded while the unload operation is under way.
coradb unloaddb -v testdbThis option writes the double quote(") on the beginning and end of an identifier. The default is not to write the double quote(").
The -S option performs the unload operation by accessing the database in standalone mode.
coradb unloaddb -S testdbThe -C option performs the unload operation by accessing the database in client/server mode.
coradb unloaddb -C testdbThis option specifies that the output file generated through unload operation creates a data file per each table. The file name is generated as <Database Name>_<Table Name>_ objects for each table. However, all column values in object types are unloaded as NULL and %id class_name class_id part is not written in the unloaded file (see How to write files to load database).
coradb unloaddb --datafile-per-class testdbloaddb
Section titled “loaddb”You can load a database by using the coradb loaddb utility in the following situations:
- Migrating previous version of CoraDB database to new version of CoraDB database
- Migrating a third-party DBMS database to a CoraDB database
- Inserting massive amount of data faster than using the INSERT statement
In general, the coradb loaddb utility uses files (schema definition, object input, and index definition files) created by the coradb unloaddb utility.
coradb loaddb [options] database_nameInput files
- Schema file(database-name**_schema**): A file generated by the unload operation; it contains schema information defined in the database.
- Object file(database-name**_objects**): A file created by an unload operation. It contains information on the records in the database.
- Index file(database-name**_indexes**): A file created by an unload operation. It contains information on the indexes defined in the database.
- Trigger file(database-name**_trigger**): A file created by an unload operation. It contains information on the triggers defined in the database.
- User-defined object file(user_defined_object_file): A file in table format written by the user to enter mass data. (For details, see How to write files to load database .)
Execution order of input files
The coradb loaddb utility follows a specific order of parsing and executing input files, ensuring both correctness and optimized performance. The order is as follows:
- Load schema file (including primary keys)
- Load object file
- Load index file (secondary keys and foreign keys)
- Load trigger file
Loading modes
The coradb loaddb utility provides two modes of loading the data into a database.
- Stand-alone mode loads the data offline, within a single thread environment.
- Client-server mode connects to a server and loads the data online and in parallel. Client-server mode can be much faster, but object references and class/shared attributes are not supported in this mode and they can only be loaded in stand-alone mode
The following table shows [options] available with the coradb loaddb utility.
This option specifies the user account of a database where records are loaded. If the option is not specified, the default value is PUBLIC.
coradb loaddb -u admin -d testdb_objects newdbThis option specifies the password of a database user who will load records. If the option is not specified, you will be prompted to enter the password.
coradb loaddb -u dba -p pass -d testdb_objects newdbThis option loads data into a database in stand-alone mode. This is the default loading mode of loaddb and it is fully compatible with CoraDB 10.1 and older database versions.
coradb loaddb -S -u dba -d testdb_objects newdbThis option connects to a running server process. Unlike the stand-alone mode, the client-server mode loads the data using multiple threads, leading to greater performance for large amounts of data. Multiple loaddb sessions may run at the same time. Object references and class/shared attributes are not supported in this mode.
coradb loaddb -C -u dba -d testdb_objects newdbThis option checks only the syntax of the data contained in testdb_objects, and does not load the data to the database.
coradb loaddb --data-file-check-only -d testdb_objects newdbStand-alone mode does, by default, one prior syntax check on the whole data file before actually loading the data into the database. If a syntax error occurs, no data is loaded and the error is reported.
Using the -l option, the prior syntax check is skipped, thus increasing the loading speed. Syntax is still checked before loading each row into the database. Loading is stopped if a syntax error occurs, but data may be partially loaded.
Client-server mode doesn't do the prior syntax check, so this option has no effect.
coradb loaddb -l -d testdb_objects newdbThis option can be used to improve loading performance when the number of records to be unloaded exceeds the default value of 5,000. You can improve the load performance by assigning large hash memory for record storage with this option.
coradb loaddb --estimated-size 8000 -d testdb_objects newdbThis option shows how to display detailed information on the tables and records of the database being loaded while the database loading operation is performed. You can check the detailed information such as the progress, the class being loaded and the number of records to be entered.
coradb loaddb -v -d testdb_objects newdbThis option commits periodically every time COUNT records are entered into the database. If this option is not specified, all records included in testdb_objects are loaded to the database before the transaction is committed. If this option is used together with the -s or -i option, commit is performed periodically every time 100 DDL statements are loaded.
The recommended commit interval varies depending on the data to be loaded. It is recommended that the parameter of the -c option be configured to 50 for schema loading and 1 for index loading. For record loading, the recommended and default value is 10240.
To commit only once, after all the data is loaded, set --periodic-commit to a very high value.
coradb loaddb -c 100 -d testdb_objects newdbThe following is a command that loads records into newdb ignoring the OIDs in testdb_objects.
coradb loaddb --no-oid -d testdb_objects newdbThe following is a command that does not update the statistics information of newdb after loading testdb_objects. It is useful especially when small data is loaded to a relatively big database; you can improve the load performance by using this command.
coradb loaddb --no-statistics -d testdb_objects newdbThis option loads the schema information or the trigger information defined in the schema file or the trigger file, from the LINE-th. You can load the actual records after loading the schema information first by using the -s option.
On the following example, testdb_schema is a file created by the unload operation and contains the schema information of the unloaded database.
coradb loaddb -u dba -s testdb_schema newdb
Start schema loading.Total 86 statements executed.Schema loading from testdb_schema finished.Statistics for Catalog classes have been updated.The following loads the triggers defined in testdb into the newly created newdb database. testdb_trigger is a file created by the unload operation and contains the trigger information of the unloaded database. It is recommended to load the schema information after loading the records.
coradb loaddb -u dba -s testdb_trigger newdbThe following loads the index information defined in the index file, from the LINE-th. On the following example, demo_indexes is a file created by the unload operation and contains the index information of the unloaded database. You can create indexes with the -i option, after loading records with the -d option.
coradb loaddb -c 100 -d testdb_objects newdbcoradb loaddb -u dba -i testdb_indexes newdbThis option loads the record information into newdb by specifying the data file or the user-defined object file. testdb_objects is either an object file created by the unload operation or a user-defined object file written by the user for mass data loading.
coradb loaddb -u dba -d testdb_objects newdbThis option specifies the table name if a table name header is omitted in the data file to be loaded.
coradb loaded -u dba -d testdb_objects -t tbl_name newdbThis option specifies the file that describes how to handle specific errors occurring during database loading.
coradb loaddb --error-control-file=error_test -d testdb_objects newdbFor the server error code name, see the $CORADB/include/dbi.h file.
For error messages by error code (error number), see the number under $set 5 MSGCAT_SET_ERROR in the $CORADB/msg/<character set name>/coradb.msg file.
vi $CORADB/msg/en_US/coradb.msg
$set 5 MSGCAT_SET_ERROR1 Missing message for error code %1$d.2 Internal system failure: no more specific information is available.3 Out of virtual memory: unable to allocate %1$ld memory bytes.4 Has been interrupted....670 Operation would have caused one or more unique constraint violations....The format of a file that details specific errors is as follows:
- -<error code>: Configures to ignore the error that corresponds to the <error code> (loaddb is continuously executed even when an error occurs while it is being executed).
- +<error code>: Configures not to ignore the error that corresponds to the <error code> (loaddb is stopped when an error occurs while it is being executed).
- +DEFAULT: Configures not to ignore errors from 24 to 33.
If the file that details errors is not specified by using the --error-control-file option, the loaddb utility is configured to ignore errors from 24 to 33 by default. As a warning error, it indicates that there is no enough space in the database volume. If there is no space in the assigned database volume, a generic volume is automatically created.
The following example shows a file that details errors.
-
The warning errors from 24 to 33 indicating DB volume space is insufficient are not ignored by configuring +DEFAULT.
-
The error code 2 is not ignored because +2 has been specified later, even when -2 has been specified first.
-
-670 has been specified to ignore the error code 670, which is a unique violation error.
-
#-115 has been processed as a comment since # is added.
vi error_file+DEFAULT-2-670#-115 --> comment+2
You can specify a file that lists classes to be ignored during loading records. All records of classes except ones specified in the file will be loaded.
coradb loaddb --ignore-class-file=skip_class_list -d testdb_objects newdbYou can specify a file that contains triggers that need to be loaded into a database.
coradb loaddb --trigger-file=testdb_triggers -d testdb_objects newdbHow to write files to load database
Section titled “How to write files to load database”You can add mass data to the database more rapidly by writing the object input file used in the coradb loaddb utility. An object input file is a text file in simple table form that consists of comments and command/data lines.
Comment
Section titled “Comment”In CoraDB, a comment is represented by two hyphens (--).
-- This is a comment!Command line
Section titled “Command line”A command line begins with a percent character (%) and consists of %class and %id commands; the former defines classes, and the latter defines aliases and identifiers used for class identification.
-
Assigning an Identifier to a Class
You can assign an identifier to class reference relations by using the %id command.
%id class_name class_idclass_name:identifierclass_id:integerThe class_name specified by the %id command is the class name defined in the database, and class_id is the numeric identifier which is assigned for object reference.
%id employee 2%id office 22%id project 23%id phone 24 -
Specifying the Class and Attribute
You can specify the classes (tables) and attributes (columns) upon loading data by using the %class command. The data line should be written based on the order of attributes specified. When a class name is provided by using the -t option while executing the coradb loaddb utility, you don't have to specify the class and attribute in the data file. However, the order of writing data must comply with the order of the attribute defined when creating a class.
%class class_name ( attr_name [attr_name... ] )The schema must be pre-defined in the database to be loaded.
The class_name specified by the %class command is the class name defined in the database and the attr_name is the name of the attribute defined.
The following example shows how to specify a class and three attributes by using the %class command to enter data into a class named employee. Three pieces of data should be entered on the data lines after the %class command. For this, see Configuring reference relation.
%class employee (name age department)
Data line
Section titled “Data line”A data line comes after the %class command line. Data loaded must have the same type as the class attributes specified by the %class command. The data loading operation stops if these two types are different.
Data for each attribute must be separated by at least one space and be basically written as a single line. However, if the data to be loaded takes more than one line, you should specify the plus sign (+) at the end of the first data line to enter data continuously on the following line. Note that no space is allowed between the last character of the data and the plus sign.
-
Loading an Instance
As shown below, you can load an instance that has the same type as the specified class attribute. Each piece of data is separated by at least one space.
%class employee (name)'jordan''james''garnett''malone' -
Assigning an Instance Number
You can assign a number to a given instance at the beginning of the data line. An instance number is a unique positive number in the specified class. Spaces are not allowed between the number and the colon (:). Assigning an instance number is used to configure the reference relation for later.
%class employee (name)1: 'jordan'2: 'james'3: 'garnett'4: 'malone'
-
Configuring Reference Relation
You can configure the object reference relation by specifying the reference class after an "at sign (@)" and the instance number after the "vertical line (|)."
@class_ref | instance_noclass_ref:class_nameclass_idSpecify a class name or a class id after the @ sign, and an instance number after a vertical line ().
The following example shows how to load class instances into the paycheck class. The name attribute references an instance of the employee class. As in the last line, data is loaded as NULL if you configure the reference relation by using an instance number not specified earlier.
%class paycheck(name department salary)@employee|1 'planning' 8000000@employee|2 'planning' 6000000@employee|3 'sales' 5000000@employee|4 'development' 4000000@employee|5 'development' 5000000Since the id 21 was assigned to the employee class by using the %id command in the Assigning an identifier to a class section, the above example can be written as follows:
%class paycheck(name department salary)@21|1 'planning' 8000000@21|2 'planning' 6000000@21|3 'sales' 5000000@21|4 'development' 4000000@21|5 'development' 5000000
Migrating database
Section titled “Migrating database”To use a new version of CoraDB database, you may need to migrate an existing data to a new one. For this purpose, you can use the "Export to an ASCII text file" and "Import from an ASCII text file" features provided by CoraDB.
The following section explains migration steps using the coradb unloaddb and coradb loaddb utilities.
Recommended scenario and procedures
The following steps describes migration scenario that can be applied while the existing version of CoraDB is running. For database migration, you should use the coradb unloaddb and coradb loaddb utilities. For details, see unloaddb and loaddb.
-
Stop the existing CoraDB service
Execute coradb service stop to stop all service processes running on the existing CoraDB and then check whether all CoraDB-related processes have been successfully stopped.
To verify whether all CoraDB-related processes have been successfully stopped, execute ps -ef | grep cora_ in Linux. If there is no process starting with cora_, all CoraDB-related processes have been successfully stopped. In Windows, press the <Ctrl+Alt+Delete> key and select [Start Task Manager]. If there is no process starting with cora_ in the [Processes] tab, all CoraDB-related processes have been successfully stopped. In Linux, when the related processes remain even after the CoraDB service has been terminated, use kill command to forcibly terminate them, and use ipcs -m command to check and release the shared memory used by the CoraDB broker. To forcibly terminate related processes in Windows, go to the [Processes] tab of Task Manager, right-click the image name, and then select [End Process].
-
Back up the existing database
Perform backup of the existing version of the database by using the coradb backupdb utility. The purpose of this step is to safeguard against failures that might occur during the database unload/load operations. For details on the database backup, see backupdb.
-
Unload the existing database
Unload the database created for the existing version of CoraDB by using the coradb unloaddb utility. For details on unloading a database, see unloaddb .
-
Store the existing CoraDB configuration files
Store the configuration files such as coradb.conf, coradb_broker.conf and cm.conf in the $CORADB/conf directory. The purpose of this step is to conveniently apply parameter values for the existing CoraDB database environment to the new one.
-
Install a new version of CoraDB
Once backing up and unloading of the data created by the existing version of CoraDB have been completed, delete the existing version of CoraDB and its databases and then install the new version of CoraDB. For details on installing CoraDB, see Getting started.
-
Configure the new CoraDB environment
Configure the new version of CoraDB by referring to configuration files of the existing database stored in the step 3, " Store the existing CoraDB configuration files ." For details on configuring new environment, see Installing and running CoraDB in "Getting Started."
-
Load the new database
Create a database by using the coradb createdb utility and then load the data which had previously been unloaded into the new database by using the coradb loaddb utility. Please see createdb for creating a database and loaddb for loading a database.
-
Back up the new database
Once the data has been successfully loaded into the new database, back up the database created for the new version of CoraDB by using the coradb backupdb utility. The reason for this step is because you cannot restore the data backed up in the existing version of CoraDB when using the new version. For details on backing up the database, see backupdb .