|
| 1 | + |
| 2 | +:sectnums: |
| 3 | +:sectnumlevels: 5 |
| 4 | + |
| 5 | += pg_bulkload |
| 6 | + |
| 7 | +== Overview |
| 8 | +pg_bulkload is a high-performance bulk data loading extension for PostgreSQL. It bypasses conventional read/write mechanisms to significantly improve the efficiency of importing text data into the database. It supports data filtering, error tolerance, parallel loading, and checkpoint recovery, making it suitable for scenarios such as large-scale historical data migration, data warehouse batch synchronization, and offline log ingestion. Compared to the native COPY command, pg_bulkload delivers a notable improvement in import speed. |
| 9 | + |
| 10 | +== Installation |
| 11 | +The IvorySQL installation package already includes the pg_bulkload extension. If you installed IvorySQL using the installation package, you typically do not need to manually install pg_bulkload. For other installation methods, refer to the source code installation steps below. |
| 12 | + |
| 13 | +[TIP] |
| 14 | +The source code installation environment is Ubuntu 24.04 (x86_64), with IvorySQL 5 or later already installed at `/usr/ivory-5`. |
| 15 | + |
| 16 | +=== Source Code Installation |
| 17 | +Download the pg_bulkload v3.1.23 source code from https://github.com/ossc-db/pg_bulkload/releases/tag/VERSION3_1_23. |
| 18 | + |
| 19 | +** Install Dependencies |
| 20 | +[literal] |
| 21 | +---- |
| 22 | +sudo apt install gawk |
| 23 | +---- |
| 24 | + |
| 25 | +** Install pg_bulkload |
| 26 | +[literal] |
| 27 | +---- |
| 28 | +# Extract the source code and enter its directory |
| 29 | +cd pg_bulkload-VERSION3_1_23 |
| 30 | +
|
| 31 | +# Modify the Makefile to accommodate IvorySQL's non-PIE static libraries |
| 32 | +
|
| 33 | + LDFLAGS+=-Wl,--build-id |
| 34 | ++ |
| 35 | ++# Workaround for non-PIE static libraries (e.g., IvorySQL's libpgcommon.a) |
| 36 | ++# Some distributions build libpgcommon.a without -fPIE, causing link failures |
| 37 | ++# when the system defaults to PIE executables. |
| 38 | ++ifdef DISABLE_PIE |
| 39 | ++CFLAGS+=-no-pie |
| 40 | ++LDFLAGS+=-no-pie |
| 41 | ++endif |
| 42 | +
|
| 43 | +# Build the code, setting the PG_CONFIG environment variable to the path of pg_config, e.g., /usr/ivory-5/bin/pg_config |
| 44 | +make PG_CONFIG=/usr/ivory-5/bin/pg_config clean |
| 45 | +make PG_CONFIG=/usr/ivory-5/bin/pg_config DISABLE_PIE=1 |
| 46 | +sudo make PG_CONFIG=/usr/ivory-5/bin/pg_config |
| 47 | +---- |
| 48 | + |
| 49 | +== Create Extension |
| 50 | +Connect to the database via psql and execute the following commands: |
| 51 | +[literal] |
| 52 | +---- |
| 53 | +ivorysql=# CREATE extension pg_bulkload; |
| 54 | +CREATE EXTENSION |
| 55 | +
|
| 56 | +ivorysql=# SELECT * FROM pg_available_extensions WHERE name = 'pg_bulkload'; |
| 57 | + name | default_version | installed_version | comment |
| 58 | +-------------+-----------------+-------------------+----------------------------------------------------------------- |
| 59 | + pg_bulkload | 3.1.23 | 3.1.23 | pg_bulkload is a high speed data loading utility for PostgreSQL |
| 60 | +(1 row) |
| 61 | +---- |
| 62 | + |
| 63 | +== Usage |
| 64 | +[literal] |
| 65 | +---- |
| 66 | +ivorysql=# create database testdb; |
| 67 | +CREATE DATABASE |
| 68 | +
|
| 69 | +ivorysql=# \c testdb |
| 70 | +You are now connected to database "testdb" as user "highgo". |
| 71 | +
|
| 72 | +testdb=# create table tb_asher (id int,name text); |
| 73 | +CREATE TABLE |
| 74 | +testdb=# \q |
| 75 | +
|
| 76 | +# Generate a sample CSV file |
| 77 | +seq 100000| awk '{print $0"|asher"}' > bulk_asher.txt |
| 78 | +
|
| 79 | +# Load the data from bulk_asher.txt into the tb_asher table in the testdb database |
| 80 | +/usr/ivory-5/bin/pg_bulkload -i ./bulk_asher.txt -O tb_asher -l ./tb_asher_output.log -P ./tb_asher_bad.txt -o "TYPE=CSV" -o "DELIMITER=|" -d testdb -U highgo -h 127.0.0.1 |
| 81 | +---- |
0 commit comments