DEV Community

mmllllzcn
mmllllzcn

Posted on

How to Load Multiple Tables with dbload in GBase Database(GBase 8s)

Loading five tables with five separate load commands works, but it means manually managing file order, delimiters, column mappings, and error handling. For multi-table imports, dbload provides a more manageable approach: define the loading rules in one control file and execute them with a single command.

In GBase Database(GBase 8s), dbload supports multiple source files and target tables through a control file. This tutorial explains how to configure the control file, map source columns, choose command-line parameters, test data before a full import, and prepare a recovery strategy for failed batch loads.

1. Define Multiple Tables in One dbload Control File

A typical dbload control file looks like this:

file '/data/dept.unl' delimiter ',' 2;
insert into t_dept;

file '/data/emp.unl' delimiter '|' 5;
insert into t_emp(f_id, f_name, f_dept, f_birth) values(f01, f02, f03, f05);
Enter fullscreen mode Exit fullscreen mode

Each file definition contains two statements:

  • file: Specifies the source file path, field delimiter, and number of source columns.
  • insert: Specifies the target table and optional source-to-target column mapping.

In the second example, the target table receives source fields 1, 2, 3, and 5. Source field 4 is intentionally skipped.

This is particularly useful when importing files whose column order differs from the target table structure.

A single GBase Database dbload control file can contain multiple file and insert definitions, allowing several tables to be loaded in sequence.

2. Count Source Columns Correctly

One important detail: the column count in the file statement refers to the source file, not the target table.

An incorrect count can cause unexpected import results:

  • Too few columns: Later source fields are not read.
  • Too many columns: Short records may fail with format errors.

Instead of guessing, inspect the source file:

awk -F'|' '{print NF; exit}' /data/emp.unl
Enter fullscreen mode Exit fullscreen mode

If the output is 5, declare five source columns in the control file.

This simple check helps prevent avoidable GBase Database data import errors, especially when processing files generated by different applications.

3. Configure dbload Parameters for Batch Loading

After preparing the control file, execute the import:

dbload -d db1 -c load.ctl -e 10 -n 1 -i 1 -k
Enter fullscreen mode Exit fullscreen mode

Several parameters directly affect the loading process:

Parameter Purpose
-e 10 Sets the tolerated bad-record threshold to 10
-n 1 Commits every row
-i 1 Skips the first source line
-k Requests an exclusive lock during loading

Pay particular attention to -i.

When a source CSV contains a header, the header must be skipped explicitly. GBase Database(GBase 8s) does not automatically identify header rows. Without the appropriate setting, column names may be treated as data and cause type-conversion errors.

Also consider the trade-off between commit frequency and performance. A smaller -n value reduces the amount of uncommitted work but increases commit overhead.

Locking behavior should be evaluated against the application's concurrent access requirements before running the import.

4. Test a Sample Before Importing the Full Dataset

Before running a large batch import, create a small sample:

head -n 101 /data/emp.unl > /data/emp_sample.unl
Enter fullscreen mode Exit fullscreen mode

For a file with one header line, this produces 100 data rows plus the header.

Temporarily point the control file to the sample file and execute the same dbload workflow.

Verify the following:

  • Exactly 100 data rows are loaded.
  • Date values are converted correctly.
  • Non-ASCII characters display correctly.
  • Source and target column mappings are correct.
  • No unexpected format or conversion errors appear.

Only after these checks pass should you switch the control file back to the full source file.

Remember that -e controls the tolerated number of bad records. It does not replace error-log inspection or identify the root cause automatically.

This sample-first approach makes GBase Database bulk data loading easier to validate before committing to a full production import.

5. Design a Recovery Strategy for Failed Batch Loads

A batch import can fail after processing a substantial amount of data. The difficult part is often determining what has already been committed.

Before starting a production import, record:

  1. The source file's total row count.
  2. The current maximum primary key in the target table.
  3. The import start time.

If the import fails, use the recorded information and the actual loading results to identify the affected data range.

Where appropriate, clean up the imported range using primary keys or a defined time interval before rerunning the task.

Do not assume that restarting the same command will automatically resume from the failed record.

The -n parameter also affects recovery planning:

  • Smaller commit intervals mean less uncommitted work.
  • Larger commit intervals may improve throughput but increase the amount of work associated with an interrupted batch.

For reliable GBase Database batch import, the recovery procedure should be documented in the same operational script as the loading command.

6. Verify the Imported Data

A successful command execution is not enough. Always verify the target table after loading.

Start with a row-count check:

SELECT COUNT(*) FROM t_emp;
Enter fullscreen mode Exit fullscreen mode

Compare the result with the expected source row count, accounting for skipped header lines and any records intentionally rejected.

Then inspect representative records:

  • A record containing non-ASCII characters.
  • A record with a boundary date value.
  • Records near the beginning and end of the source file.

Check for truncation, incorrect date conversion, and unexpected column mapping.

These acceptance checks help ensure that GBase Database(GBase 8s) data loading has produced the expected results rather than simply completing the import process.

Conclusion

Reliable multi-table loading requires more than a working dbload command.

The control file defines the source-to-target mapping. Command-line parameters determine error tolerance, commit frequency, header handling, and locking behavior. Sample testing validates the import, while a documented recovery strategy makes failed batches manageable.

With a structured workflow, GBase Database dbload can make multi-table data imports more consistent, verifiable, and easier to maintain.

The key principle is simple: define the loading contract, validate a sample, control the failure scope, and verify the results before accepting the batch.

Top comments (0)