1)切换到 sdbadmin 用户;
2)创建 company_domain 数据域,包含 group1、group2、group3 三个复制组;
sdb
var db = new sdb("localhost", 11810);
db.createdomain("company_domain", [ "group1", "group2", "group3" ], { autosplit: true } );
3)创建 company 集合空间,所属 company_domain 数据域;
db.createcs("company", { domain: "company_domain" } );
4)创建 employee 集合;
db.company.createcl("employee_bak", { "shardingkey": { "empno": 1 }, "shardingtype": "hash", "replsize": -1, "compressed": true, "compressiontype": "lzw", "autosplit": true, "ensureshardingindex": false } );
5)创建实例 pginst,端口使用 5432;
cd /opt/sequoiasql/postgresql/
/opt/sequoiasql/postgresql/bin/sdb_sql_ctl addinst pginst -d database/5432
/opt/sequoiasql/postgresql/bin/sdb_sql_ctl start pginst
6)配置连接 postgresql 实例与 sequoiadb 巨杉数据库存储引擎(transaction 设置为 on ,默认开启事务);
/opt/sequoiasql/postgresql/bin/sdb_sql_ctl createdb company pginst
/opt/sequoiasql/postgresql/bin/psql -p 5432 company
create extension sdb_fdw;
create server sdb_server foreign data wrapper sdb_fdw
options
(
address '127.0.0.1',
service '11810',
user '',
password '',
preferedinstance 'a',
transaction 'on'
);
7)在 postgresql 创建 company 数据库和 employee 外部表 ( id int, name text, age int ) 映射到 sequoiadb 数据库的 company.employee 集合;
create foreign table employee
(
id integer,
name text,
age integer
)
server sdb_server
options ( collectionspace 'company', collection 'employee', decimal 'on' );
8)向 employee 表插入数据 ( id: 10001, name: 'jerry', age: 18 );
insert into employee values (10001, 'jerry', 18);
9)开始事务,向 employee 表插入数据 ( id: 10002, name: 'tom', age: 20 ),回滚事务,然后查询 employee 表;
begin;
insert into employee values (10002, 'tom', 20);
rollback;
10)将 employee 表数据导出到 “/opt/sequoiasql/postgresql/employee.csv”,使用 “\! more /opt/sequoiasql/postgresql/employee.csv” 命令查看数据内容;
copy (select * from employee) to '/opt/sequoiasql/postgresql/employee.csv' with delimiter ',' csv;
\! more /opt/sequoiasql/postgresql/employee.csv
11)在 company 集合空间创建集合 employee_bak, 并将上一步导出的数据文件导入到 employee_bak 中;
sdb
var db=new sdb('localhost',11810);
db.company.createcl("employee_bak", { "shardingkey": { "id": 1 }, "shardingtype": "hash", "replsize": -1, "compressed": true, "compressiontype": "lzw", "autosplit": true, "ensureshardingindex": false } );
create foreign table employee_bak
(
id integer,
name text,
age integer
)
server sdb_server
options ( collectionspace 'company', collection 'employee_bak', decimal 'on' );
sdbimprt --hosts=localhost:11810 --type=csv --file=/opt/sequoiasql/postgresql/employee.csv --fields="id int, name string, age int" -c company -l employee_bak
阅读(1238) | 评论(0) | 转发(0) |