---
title: "Unload and load: unloaddb, loaddb"
description: "Export CoraDB schemas and data with coradb unloaddb and load them with coradb loaddb: options, file format, errors and moving databases."
url: "https://www.coradb.ai/manual/admin/admin_unload.html"
markdown_url: "https://www.coradb.ai/manual/markdown/admin/admin_unload.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb unloaddb, coradb loaddb, export database, import data, coradb migration, loaddb file format"
---

# Unload and load: unloaddb, loaddb

## 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

``` bash
coradb unloaddb [options] database_name
```

**coradb 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**.

**-u, --user=ID**

Specify a user account of a database to be unloaded. If this is not specified, the default is **DBA**.

``` bash
coradb unloaddb -u dba -i table_list.txt testdb
```

**-p, --password=PASS**

Specify a user's password of a database to be unloaded. If this is not specified, it is regarded as the empty string is entered.

``` bash
coradb unloaddb -u dba -p dba_pwd -i table_list.txt testdb
```

**-i, --input-class-file FILE**

Unload all schema and index of all tables; however, only the data of specified tables in this file are unloaded.

``` bash
coradb unloaddb -i table_list.txt testdb
```

The following example shows an input file (table_list.txt).

``` text
table_1
table_2
..
table_n
```

If 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.

``` bash
coradb unloaddb --input-class-only -i table_list.txt testdb
```

If this option is used together with the **--include-reference** option, it unloads the referenced tables as well.

``` bash
coradb unloaddb --include-reference -i table_list.txt testdb
```

**--include-reference**

This option is used together with the **-i** option, and also unloads the referenced tables.

**--input-class-only**

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.

**--estimated-size=NUMBER**

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.

``` bash
coradb unloaddb --estimated-size=1000 testdb
```

**--cached-pages=NUMBER**

The **--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.

``` bash
coradb unloaddb --cached-pages 500 testdb
```

**-O, --output-path=PATH**

This option specifies the directory in which to create schema and object files. If this is not specified, files are created in the current directory.

``` bash
coradb unloaddb -O ./CoraDB/Databases/testdb testdb
```

If the specified directory does not exist, the following error message will be displayed.

``` text
unloaddb: No such file or directory.
```

**-s, --schema-only**

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.

``` bash
coradb unloaddb -s testdb
```

**-d, --data-only**

This 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.

``` bash
coradb unloaddb -d testdb
```

**--output-prefix=PREFIX**

This 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.

``` bash
coradb unloaddb --output-prefix abcd testdb
```

**--hash-file=FILE**

This option specifies the name of the hash file.

**-v, --verbose**

This option displays detailed information on the database tables and records being unloaded while the unload operation is under way.

``` bash
coradb unloaddb -v testdb
```

**--use-delimiter**

This option writes the double quote(") on the beginning and end of an identifier. The default is not to write the double quote(").

**-S, --SA-mode**

The **-S** option performs the unload operation by accessing the database in standalone mode.

``` bash
coradb unloaddb -S testdb
```

**-C, --CS-mode**

The **-C** option performs the unload operation by accessing the database in client/server mode.

``` bash
coradb unloaddb -C testdb
```

**--datafile-per-class**

This 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](https://www.coradb.ai/manual/admin/admin_unload.html#how-to-write-files-to-load-database)).

``` bash
coradb unloaddb --datafile-per-class testdb
```

## 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.

``` bash
coradb loaddb [options] database_name
```

**Input 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](https://www.coradb.ai/manual/admin/admin_unload.html#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:

1.  Load schema file (including primary keys)
2.  Load object file
3.  Load index file (secondary keys and foreign keys)
4.  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.

**-u, --user=ID**

This option specifies the user account of a database where records are loaded. If the option is not specified, the default value is **PUBLIC**.

``` bash
coradb loaddb -u admin -d testdb_objects newdb
```

**-p, --password=PASS**

This 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.

``` bash
coradb loaddb -u dba -p pass -d testdb_objects newdb
```

**-S, --SA-mode**

This 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.

``` bash
coradb loaddb -S -u dba -d testdb_objects newdb
```

**-C, --CS-mode**

This 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.

``` bash
coradb loaddb -C -u dba -d testdb_objects newdb
```

**--data-file-check-only**

This option checks only the syntax of the data contained in testdb_objects, and does not load the data to the database.

``` bash
coradb loaddb --data-file-check-only -d testdb_objects newdb
```

**-l, --load-only**

**Stand-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.

``` bash
coradb loaddb -l -d testdb_objects newdb
```

**--estimated-size=NUMBER**

This 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.

``` bash
coradb loaddb --estimated-size 8000 -d testdb_objects newdb
```

**-v, --verbose**

This 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.

``` bash
coradb loaddb -v -d testdb_objects newdb
```

**-c, --periodic-commit=COUNT**

This 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.

``` bash
coradb loaddb -c 100 -d testdb_objects newdb
```

**--no-oid**

The following is a command that loads records into newdb ignoring the OIDs in testdb_objects.

``` bash
coradb loaddb --no-oid -d testdb_objects newdb
```

**--no-statistics**

The 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.

``` bash
coradb loaddb --no-statistics -d testdb_objects newdb
```

**-s, --schema-file=FILE\[:LINE\]**

This 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.

``` bash
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.

``` bash
coradb loaddb -u dba -s testdb_trigger newdb
```

**-i, --index-file=FILE\[:LINE\]**

The 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.

``` bash
coradb loaddb -c 100 -d testdb_objects newdb
coradb loaddb -u dba -i testdb_indexes newdb
```

**-d, --data-file=FILE**

This 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.

``` bash
coradb loaddb -u dba -d testdb_objects newdb
```

**-t, --table=TABLE**

This option specifies the table name if a table name header is omitted in the data file to be loaded.

``` bash
coradb loaded -u dba -d testdb_objects -t tbl_name newdb
```

**--error-control-file=FILE**

This option specifies the file that describes how to handle specific errors occurring during database loading.

``` bash
coradb loaddb --error-control-file=error_test -d testdb_objects newdb
```

For 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.

``` text
vi $CORADB/msg/en_US/coradb.msg

$set 5 MSGCAT_SET_ERROR
1 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.

  ``` text
  vi error_file

  +DEFAULT
  -2
  -670
  #-115 --> comment
  +2
  ```

**--ignore-class-file=FILE**

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.

``` bash
coradb loaddb --ignore-class-file=skip_class_list -d testdb_objects newdb
```

**--trigger-file=FILE**

You can specify a file that contains triggers that need to be loaded into a database.

``` bash
coradb loaddb --trigger-file=testdb_triggers -d testdb_objects newdb
```

> **Warning:**
> The **--no-logging** option enables to load data file quickly when **loaddb** is executed by not storing transaction logs; however, it has risk, which data cannot be recovered in case of errors occurred such as incorrect file format or system failure. In this case, you must rebuild database to solve the problem. Thus, in general, it is not recommended to use this option exception of building a new database which does not require data recovery. If you use this option, **loaddb** does not check the errors like unique violation. To use this option, you should consider these issues.


### 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

In CoraDB, a comment is represented by two hyphens (--).

``` sql
-- This is a comment!
```

#### 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.

  ``` text
  %id class_name class_id
  class_name:
      identifier
  class_id:
      integer
  ```

  The *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.

  ``` text
  %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.

  ``` text
  %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](https://www.coradb.ai/manual/admin/admin_unload.html#conf-reference-relation).

  ``` text
  %class employee (name age department)
  ```

#### 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.

  ``` text
  %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.

  ``` text
  %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 (\|)."

  ``` text
  @class_ref | instance_no
  class_ref:
       class_name
       class_id
  ```

  Specify 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.

  ``` text
  %class paycheck(name department salary)
  @employee|1   'planning'   8000000   
  @employee|2   'planning'   6000000  
  @employee|3   'sales'   5000000  
  @employee|4   'development'   4000000
  @employee|5   'development'   5000000
  ```

  Since the id 21 was assigned to the *employee* class by using the **%id** command in the [Assigning an identifier to a class](https://www.coradb.ai/manual/admin/admin_unload.html#assign-id-to-class) section, the above example can be written as follows:

  ``` text
  %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

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](https://www.coradb.ai/manual/admin/admin_unload.html#unloaddb) and [loaddb](https://www.coradb.ai/manual/admin/admin_unload.html#loaddb).

1.  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\].

2.  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](https://www.coradb.ai/manual/admin/admin_backup.html#backupdb).

3.  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](https://www.coradb.ai/manual/admin/admin_unload.html#unloaddb) .

4.  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.

5.  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](https://www.coradb.ai/manual/start.html).

6.  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](https://www.coradb.ai/manual/install.html) in "Getting Started."

7.  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](https://www.coradb.ai/manual/admin/admin_utils.html#createdb) for creating a database and [loaddb](https://www.coradb.ai/manual/admin/admin_unload.html#loaddb) for loading a database.

8.  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](https://www.coradb.ai/manual/admin/admin_backup.html#backupdb) .

> **Warning:**
> Even if the version is identical, the 32-bit database volume and the 64-bit database volume are not compatible for backup and recovery. Therefore, it is not recommended to recover a 32-bit database backup on the 64-bit CoraDB or vice versa.


> **Warning:**
> When using the TDE feature in CoraDB 11, it does not provide backward compatibility. So, the unloaded file in CoraDB 11 cannot be loaded into a lower version if more the one TDE table exists.
