-
文档
-
关于 SequoiaDB
安装
系统要求
安装部署
基本操作
数据模型
SQL引擎
PostgreSQL实例组件
MySQL实例组件
FileSystem引擎
S3引擎
系统架构
编目节点
分区组
数据库管理
特殊配置项修改
数据库工具
集群启停
集群扩容
备份恢复
日志归档重放
监控
快照
列表
安全
查询访问计划
基于代价的访问计划评估
查看访问计划
统计信息
连接器
驱动
C驱动
C++驱动
CSharp驱动
Java开发驱动
PHP驱动
Python驱动
REST接口
参考手册
SequoiaDB Shell方法
概述
Global
Sdb
SdbCS
SdbCollection
SdbCursor
SdbQuery
SdbReplicaGroup
SdbNode
SdbDomain
Oma
File
FileContent
Cmd
Remote
Hash
IniFile
Sdbtool
Ssh
System
辅助类型对象
特殊类型对象
操作符
匹配符
选择符
函数操作
更新符
聚集符
SQL语法
语句
子句
函数
监控视图
故障排除
常见错误
SAC 管控中心
安装与登录
部署
主机操作
存储集群操作
MySQL 实例操作
PostgreSQL 实例操作
监控
配置
SequoiaDB 数据操作
集合空间
集合
索引
记录
PostgreSQL 实例数据操作
MySQL 实例数据操作
Web服务
连接
以下操作均在PostgreSQL shell 环境下执行。
连接PostgreSQL实例组件与存储引擎
加载SequoiaDB连接驱动
foo=# create extension sdb_fdw;
配置与SequoiaDB连接参数
foo=# create server sdb_server foreign data wrapper sdb_fdw options(address '127.0.0.1', service '11810', user 'sdbUserName', password 'sdbPassword', preferedinstance 'A', transaction 'off');
Note:
- 如果没有配置数据库密码验证,可以忽略user与password字段。
- 如果需要提供多个协调节点地址,options 中的 address 字段可以按格式 'ip1:port1,ip2:port2,ip3:port3'填写。此时,service 字段可填写任意一个非空字符串。
- preferedinstance 设置 SequoiaDB 的连接属性。多个属性以逗号分隔,如:preferedinstance '1,2,A'。详细配置请参考 preferedinstance 取值
- preferedinstancemode 设置 preferedinstance 的选择模式
- sessiontimeout 设置会话超时时间 如:sessiontimeout '100'
- transaction 设置 SequoiaDB 是否开启事务,默认为off。开启为on
- cipher 设置是否使用加密文件输入密码,默认为off。开启为on
- token 设置加密口令
- cipherfile 设置加密文件,默认为 ./passwd
关联SequoiaDB的集合空间与集合
foo=# create foreign table test (name text, id numeric) server sdb_server options ( collectionspace 'foo', collection 'bar', decimal 'on' ) ;
Note:
- 集合空间与集合必须已经存在于SequoiaDB,否则查询出错。
- 如果需要对接SequoiaDB的decimal字段,则需要在options中指定 decimal 'on' 。
- pushdownsort 设置是否下压排序条件到 SequoiaDB,默认为on,关闭为off。
- pushdownlimit 设置是否下压 limit 和 offset 条件到 SequoiaDB,默认为on,关闭为off。
- 开启 pushdownlimit 时,必须同时开启 pushdownsort ,否则可能会造成结果非预期的问题。
- 默认情况下,表的字段映射到SequoiaDB中为小写字符,如果强制指定字段为大写字符,创建方式参考“注意事项1”。
- 映射 SequoiaDB 的数组类型,创建方式参考“注意事项2”。
更新表的统计信息
foo=# analyze test;
查询
foo=# select * from test;
写入数据
foo=# insert into test values('one',3);
更改数据
foo=# update test set id=9 where name='one';
查看所有的表(show tables;)
foo=# \d
查看表的描述信息
foo=# \d test
删除表的映射关系
foo=# drop foreign table test;
退出PostgreSQL shell环境
foo=# \q
使用须知
数据类型的对应关系
PostgreSQL API 注意事项 smallint int 当API中的值超过smallint范围时会发生截断 integer int bigint long serial int bigserial long real double 存在精度问题,SequoiaDB 存储时不是完全一致 double precision double numeric decimal / string 在创建外表时,指定选项 decimal 为 'on', numeric 映射对应 decimal ,否则对应 string decimal decimal / string 在创建外表时,指定选项 decimal 为 'on', decimal 映射对应 decimal ,否则对应 string text string char string varchar string bytea binary(type=0) date date timestamp timestamp TYPE[] array 仅支持一维数组 boolean boolean text null 注意事项
注意字符的大小写
SequoiaDB 中的集合空间、集合和字段名均对字母的大小写敏感。
- 集合空间、集合名大写
假设SequoiaDB 中存在名为 FOO 的集合空间,BAR 的集合,在PostgreSQL中建立相应的映射表:
foo=# create foreign table sdb_upcase_cs_cl (name text) server sdb_server options ( collectionspace 'FOO', collection 'BAR' ) ;
- 字段名大写
假设SequoiaDB 中存在名为foo的集合空间,bar的集合,而且保存的数据为:
{ "_id": { "$oid":"53a2a0e100e75e2c53000006" }, "NAME": "test" }
在PostgreSQL中建立相应的映射表:
foo=# create foreign table sdb_upcase_field ("NAME" text) server sdb_server options ( collectionspace 'foo', collection 'bar' ) ;
执行查询命令:
foo=# select * from sdb_upcase_field; NAME ------ test (1 rows)
映射SequoiaDB中的数据类型
假设SequoiaDB中存在foo集合空间,bar集合,保存记录为:
{ "_id": { "$oid":"53a2de926b4715450a000001" }, "name": [ 1, 2, 3 ], "id": 123 }
在 PostgreSQL 中建立相应的映射表:
foo=# create foreign table bartest (name int[], id int) server sdb_server options ( collectionspace 'foo', collection 'bar' ) ;
执行查询命令:
foo=# select * from bartest; name | id --------+----- {1,2,3} | 123
连接 SequoiaDB 协调节点错误
如果 PostgreSQL 连接的 SequoiaDB 协调节点重启,在查询时报错:
ERROR: Unable to get collection "foo.bar", rc = -15 HINT: Make sure the collectionspace and collection exist on the remote database
解决方法:
退出 PostgreSQL shell
foo=# \q
重新进入 PostgreSQL shell
$ bin/psql -p 5432 foo
调整 PostgreSQL 配置文件
查看 pg_shell 中默认的配置:
foo=#\set AUTOCOMMIT = 'on' PROMPT1 = '%/%R%# ' PROMPT2 = '%/%R%# ' PROMPT3 = '>> ' VERBOSITY = 'default' VERSION = 'PostgreSQL 9.3.4 on x86_64-unknown-linux-gnu, compiled by gcc (SUSE Linux) 4.3.4 [gcc-4_3-branch revision 152973], 64-bit' DBNAME = 'foo' USER = 'sdbadmin' PORT = '5432' ENCODING = 'UTF8'
调整 pg_shell 查询时,每次获取记录数
foo=#\set FETCH_COUNT 100
Note:
- 调整为 pg shell 每次获取100 条记录立即返回记录,然后再继续获取。
- 直接在 pg shell 中修改配置,只能在当前 pg_shell 中生效,重新登录 pg_shell 需要重新设置。
修改配置文件,调整 pg shell 查询时,每次获取记录数
$ /opt/postgresql/bin/pg_config --sysconfdir
结果为:
$ /opt/postgresql/etc
Note:
如果显示目录不存在,自己手动创建即可。
$ mkdir -p /opt/postgresql/etc
将需要修改的参数写入配置文件中(需重启psql使配置生效):
$ echo "\\set FETCH_COUNT 100" >> /opt/postgresql/etc
调整 pg shell 的日志级别
编辑 /opt/postgresql/data/postgresql.conf 文件,将
client_min_messages = notice
改为:
client_min_messages = debug1
调整 pg 引擎的日志级别
编辑 /opt/postgresql/data/postgresql.conf 文件,将
log_min_messages = warning
改为:
log_min_messages = debug1