db2-random-data
v1.0.0
Published
这个工具读取一个表名和数据量列表,向指定 schema 下的表插入随机数据。
Readme
Db2 12.1.2 random test-data inserter
这个工具读取一个表名和数据量列表,向指定 schema 下的表插入随机数据。
直接执行
列表文件格式:
CUSTOMER,100
ORDERS,200
PRODUCT,50执行前准备好 Db2 CLP 和数据库连接环境,然后传入 schema 和列表文件:
chmod +x random_insert.sh
./random_insert.sh APP list.txt通过 npm 全局安装后也可以执行:
db2-random-data APP list.txt脚本安装过程一次、设置 schema 一次、逐行插入,最后提交。
不需要在 Docker 容器内执行。只要运行脚本的机器具有 Db2 CLP,它可以连接本机 或远程 DB2。Docker 只是开发阶段可选的测试数据库。
Implemented mapping
| Db2 type | Generated value |
| --- | --- |
| CHAR, CHARACTER, VARCHAR | random ASCII digit string, bounded by SYSCAT.COLUMNS.LENGTH |
| DECIMAL, NUMERIC | random value derived from precision (LENGTH) and SCALE, with an overflow safety margin |
| integer and floating numeric types | random value within a conservative type-safe range |
| DATE | CURRENT DATE |
| TIMESTAMP | CURRENT TIMESTAMP |
| BLOB | fixed X'ABCD1234' bytes |
| any other type | NULL |
Identity and generated columns are omitted from the insert list. Inserts use a
single recursive-CTE INSERT ... SELECT except for the rare table containing
only generated columns.
Expected limitations
This is type-aware rather than business-aware. Foreign keys, unique keys,
check constraints, triggers, row/column access control, and unsupported
NOT NULL columns can still reject the insert. Very large DATACOUNT values
also create a large transaction; commit batching is intentionally not hidden
inside the procedure.
SQL PL 已依据 IBM Db2 12.1 文档检查;当前版本没有在真实 Db2 12.1.2 实例中 执行过,首次在目标环境运行前应先对测试表进行一次 smoke test。
