pgloader 学习(九) pg 2 pg 使用with 参数控制同步逻辑
作者:互联网
pgloader 支持比较丰富的配置参数,同时默认数据在同步的时候是会进行索、schema
以及数据的同步对于实际我们可能存在需要进行控制,我们可以通过with
参数方便的处理
参考配置
- load 文件
load database
from pgsql://postgres:dalong@postgres:5432/postgres
into pgsql://postgres:dalong@postgres2:5432/postgres
including only table names matching 'users','members' in schema 'public'
ALTER TABLE NAMES MATCHING 'users' IN SCHEMA 'public' RENAME TO 'gitlab2_users'
ALTER TABLE NAMES MATCHING 'members' IN SCHEMA 'public' RENAME TO 'gitlab2_members'
with
create no indexes,
no foreign keys;
- load 文件说明
这个一个简单的同步gitlabusers
,members
数据到pg 数据库的处理(数据聚合处理),同时进行了别名处理
users
->gitlab2_users
members
->gitlab2-members
同时忽略源数据表的索引以及外边的添加处理(我们
只需要数据)
完整docker-compose 运行说明
- docker-compose 文件
version: "3"
services:
pgloader-pg:
image: dimitri/pgloader
volumes:
- "./pgloader-config:/loader"
command: pgloader /loader/pg/pg.load
postgres:
image: postgres:9.6.11
ports:
- "5432:5432"
environment:
- "POSTGRES_PASSWORD:dalong"
postgres2:
image: postgres:9.6.11
ports:
- "5433:5432"
environment:
- "POSTGRES_PASSWORD:dalong"
- 运行说明
先导出gitlab pg 数据(默认是本地unix socket),然后导出数据到docker-compose 定义中的postgres
操作:
导出表数据:
pg_dump -h hostip -p 5432 -U postgres -t members -d postgres > members.sql
pg_dump -h hostip -p 5432 -U postgres -t users -d postgres > users.sql
导入表数据:
psql -h 127.0.0.1 -U postgres -p 5432 -d postgres < users.sql
psql -h 127.0.0.1 -U postgres -p 5432 -d postgres < members.sql
运行数据导入:
docker-compose up pgloader-pg
- 效果
pgloader-pg_1 | WARNING:
pgloader-pg_1 | Couldn't re-execute SBCL with proper personality flags (/proc isn't mounted? setuid?)
pgloader-pg_1 | Trying to continue anyway.
pgloader-pg_1 | 2019-06-27T04:43:52.045000Z LOG pgloader version "3.6.2~devel"
pgloader-pg_1 | 2019-06-27T04:43:52.150000Z LOG Migrating from #<PGSQL-CONNECTION pgsql://postgres@postgres:5432/postgres {10070D34D3}>
pgloader-pg_1 | 2019-06-27T04:43:52.151000Z LOG Migrating into #<PGSQL-CONNECTION pgsql://postgres@postgres2:5432/postgres {10070D4B63}>
pgloader-pg_1 | 2019-06-27T04:43:52.882000Z LOG report summary reset
pgloader-pg_1 | table name errors rows bytes total time
pgloader-pg_1 | ------------------------ --------- --------- --------- --------------
pgloader-pg_1 | fetch meta data 0 2 0.061s
pgloader-pg_1 | Create Schemas 0 0 0.000s
pgloader-pg_1 | Create SQL Types 0 0 0.006s
pgloader-pg_1 | Create tables 0 4 0.035s
pgloader-pg_1 | Set Table OIDs 0 2 0.000s
pgloader-pg_1 | ------------------------ --------- --------- --------- --------------
pgloader-pg_1 | "public".gitlab2_members 0 27629 3.1 MB 0.513s
pgloader-pg_1 | "public".gitlab2_users 0 4153 2.2 MB 0.392s
pgloader-pg_1 | ------------------------ --------- --------- --------- --------------
pgloader-pg_1 | COPY Threads Completion 0 4 0.506s
pgloader-pg_1 | Reset Sequences 0 2 0.022s
pgloader-pg_1 | Create Triggers 0 0 0.001s
pgloader-pg_1 | Install Comments 0 0 0.000s
pgloader-pg_1 | ------------------------ --------- --------- --------- --------------
pgloader-pg_1 | Total import time ? 31782 5.3 MB 0.529s
pgloader-pg2pg_pgloader-pg_1 exited with code 0
说明
同时可以也可以配置一些其他参数,比如schema only
, data only
, 还是很方便的
参考资料
https://github.com/rongfengliang/pgloader-gitlab-pg2pg
https://pgloader.readthedocs.io/en/latest/ref/pgsql.html
标签:5432,同步,users,pgloader,pg,members,postgres 来源: https://www.cnblogs.com/rongfengliang/p/11096359.html