2019独角兽企业重金招聘Python工程师标准>>>
安装说明 配置环境变量PATH, 使得系统可以找到pg_config,命令行执行该命令成功。
export PATH=/opt/pgsql/pg96/bin/:$PATH
切换到 pg_bulkload 的目录
cd pg_bulkload
make
make install
我这样的人喜欢静态编译可执行文件,适合稍稍高一点的晚间
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 pg_bulkload.o recovery.o pgut/pgut.o pgut/pgut-fe.o /opt/pgsql/pg96/lib/libpq.a /opt/pgsql/pg96/lib/libpgcommon.a /opt/pgsql/pg96/lib/libpgport.a /opt/pgsql/pg96/lib/libpq.a pgut/pgut-list.o -L/opt/pgsql/pg96/lib/ -Wl,--as-needed -lpgcommon -lpgport -lz -lreadline -lrt -lcrypt -ldl -lpthread -lm -o pg_bulkload
ok
到你的postgres 数据库,创建 pg_bulkload 拓展
psql
create extension pg_bulkload;
CREATE TABLE hello(name text); INSERT INTO hello(name) values('hello'),('world');
COPY hello to '/tmp/hello_copy';
./pg_bulkload -i /tmp/hello_copy -O hello -h 127.0.0.1 -U postgres -d postgres
[root@laptop pg_bulkload]# cd bin/
[root@laptop bin]# ./pg_bulkload -i /tmp/hello_copy -O hello -h 127.0.0.1 -U postgres -d postgres
NOTICE: BULK LOAD START
NOTICE: BULK LOAD END
0 Rows skipped.
2 Rows successfully loaded.
0 Rows not loaded due to parse errors.
0 Rows not loaded due to duplicate errors.
0 Rows replaced with new rows.