DEV Community

mmllllzcn
mmllllzcn

Posted on

GBase Database: A Repeatable Single-Table Migration with UNLOAD and LOAD

Moving a table between database environments should be more than a successful export followed by a successful import. A reliable GBase Database(GBase 8s) single-table migration needs a repeatable process, consistent data formats, and verifiable results.

This tutorial walks through a practical six-step workflow using UNLOAD and LOAD. Each step includes a checkpoint so that anyone on the team can repeat the migration and verify its outcome.

Step 1: Count Source Rows Before Export

Start by recording the number of rows in the source table:

select count(*) from t_order;
Enter fullscreen mode Exit fullscreen mode

Write down the result.

This number becomes the baseline for validating the target table after migration. It is much more reliable than assuming the export file looks complete.

Step 2: Define the Data Format Contract

Before exporting data from GBase Database(GBase 8s), explicitly define the date format and client locale.

Do not rely on individual users' login profiles or environment settings.

export GL_DATE="%iY-%m-%d"
export CLIENT_LOCALE="zh_CN.utf8"
Enter fullscreen mode Exit fullscreen mode

These two environment variables serve different purposes:

  • GL_DATE controls the input and output format of date values.
  • CLIENT_LOCALE defines the client locale used for character and locale-related processing.

For this example, %iY represents a four-digit year, %m the month, and %d the day.

The expected date representation is:

2026-01-08
Enter fullscreen mode Exit fullscreen mode

If the export and import environments use incompatible format or locale settings, date conversion and character handling may produce unexpected results.

Defining these settings explicitly makes the GBase Database data migration process more predictable.

Step 3: Export Data with a Compound Delimiter

Use UNLOAD to export the required columns:

unload to '/data/order.unl' delimiter '|#'
  select order_id, cust_name, addr, created_at from t_order;
Enter fullscreen mode Exit fullscreen mode

Why use |# instead of a comma?

Business data frequently contains commas, especially in addresses, descriptions, and free-text fields. A compound delimiter reduces the chance of accidental conflicts with field content.

GBase Database(GBase 8s) supports delimiters of up to four characters. Longer delimiters are rejected.

The important rule is simple: choose a delimiter that is unlikely to appear in your actual data, and use exactly the same delimiter during import.

Step 4: Inspect the UNLOAD File Before Import

Do not immediately load the entire export file. Inspect a sample first:

head -n 5 /data/order.unl
wc -l /data/order.unl
Enter fullscreen mode Exit fullscreen mode

Check three things:

1. Field structure

Confirm that fields appear to be separated consistently by the selected delimiter.

2. Date format

Verify that date values follow the expected format, such as 2026-01-08.

3. Backslash continuation markers

Look for unexpected trailing backslashes.

In GBase Database UNLOAD output, a trailing backslash can indicate that a field contains a newline and the logical record continues on the next physical line. It is not necessarily an export error.

One important distinction: wc -l counts physical lines, not logical database records.

If the line count differs from the source row count recorded in Step 1, investigate before proceeding. Multiline fields may explain the difference, but an interrupted export or incomplete file must also be ruled out.

Step 5: Create the Target Table and Run LOAD

Create the target table before importing the exported data:

create table t_order_bak (
  order_id    int,
  cust_name   varchar(64),
  addr        varchar(200),
  created_at  date
);
Enter fullscreen mode Exit fullscreen mode

Pay attention to column definitions, especially character lengths.

The target column widths should be sufficient for the source data. Do not assume that matching column names automatically guarantee that all values will fit.

Next, import the file:

load from '/data/order.unl' delimiter '|#'
  insert into t_order_bak;
Enter fullscreen mode Exit fullscreen mode

The delimiter must match the one used in the UNLOAD statement.

GBase Database does not automatically infer your intended delimiter. A mismatch can cause fields to be interpreted incorrectly and may lead to import errors.

Step 6: Validate the Migration with Row Counts

After the import completes, count the target rows:

select count(*) from t_order_bak;
Enter fullscreen mode Exit fullscreen mode

Compare this result with the source row count recorded in Step 1.

However, row counts alone are not sufficient for complete data validation. Also spot-check several important records:

  • The record containing the longest address.
  • The record with the latest date.
  • A name containing non-ASCII characters.
  • Any records with unusual punctuation or embedded newlines.

If the source and target counts differ, investigate these three areas first:

  1. Target column definitions that are too narrow.
  2. Records rejected because of malformed data or format mismatches.
  3. Export files modified by someone or something after the original export.

A successful LOAD command does not automatically mean the migration is complete. Verification is part of the process.

Turn the Six Steps into a Repeatable Migration Script

The six steps can be organized into a reusable migration script.

Keep the main parameters together at the beginning:

Parameter Example
Delimiter `\
{% raw %}GL_DATE %iY-%m-%d
CLIENT_LOCALE zh_CN.utf8
Source table t_order
Target table t_order_bak
Export file /data/order.unl

This makes it easier to reuse the same GBase Database migration procedure across environments and reduces dependence on individual operators remembering every precondition.

The objective is not simply to make the migration work once. It is to make the process repeatable, reviewable, and verifiable by the entire team.

Final Reminder: UNLOAD and LOAD Are Not a Backup Strategy

The UNLOAD and LOAD workflow is useful for single-table data movement, testing, and controlled data transfers.

But it should not be confused with database backup and recovery.

A table export does not replace a backup strategy, and it does not provide point-in-time recovery. Those requirements belong to the database backup and recovery system.

The key takeaway: A reliable GBase Database single-table migration is not just UNLOAD followed by LOAD. It is a six-step process: count, define formats, export, inspect, import, and validate.

Top comments (0)