关于 SequoiaDB
快速入门
安装
基本操作
数据模型
SQL引擎
S3引擎
系统架构
数据库管理
连接器
驱动
参考手册
故障排除
SAC 管控中心
Web服务
版本信息
用户安装好 PostgreSQL 实例组件后,可直接通过 PostgreSQL Shell 使用标准的 SQL 语言访问 SequoiaDB 巨杉数据库。
加载 SequoiaDB 连接驱动
sample=# create extension sdb_fdw;
配置 SequoiaDB 连接参数
sample=# 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:
详细参数说明可参考 关联 SequoiaDB 连接参数说明。
关联 SequoiaDB 集合空间与集合
sample=# create foreign table test (name text, id numeric) server sdb_server options ( collectionspace 'sample', collection 'employee', decimal 'on' );
Note:
- 在 PostgreSQL 中建立相应的映射表关联 SequoiaDB 集合时,需要确保映射表的字段名与集合的字段名大小写一致,且映射表的字段类型与集合的字段类型一致;否则,将查询不到相关数据。
- 详细参数说明可参考 关联 SequoiaDB 集合空间与集合参数说明。
更新表的统计信息
sample=# analyze test;
查询
sample=# select * from test;
写入数据
sample=# insert into test values( 'one', 3 );
更改数据
sample=# update test set id = 9 where name = 'one';
查看所有的表( show tables; )
sample=# \d
查看表的描述信息
sample=# \d test
删除表的映射关系
sample=# drop foreign table test;
退出 PostgreSQL Shell 环境
sample=# \q
PostgreSQL | API | 注意事项 |
---|---|---|
smallint | int32 | 当 API 中的值超过smallint范围时会发生截断 |
integer | int32 | |
bigint | int64 | |
serial | int32 | |
bigserial | int64 | |
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 |
参数名 | 类型 | 描述 | 是否必填 |
---|---|---|---|
user | string | 数据库用户名 | 否 |
password | string | 数据库密码 | 否 |
address | string | 协调节点地址,需要填写多个协调节点地址时,格式为:'ip1:port1,ip2:port2,ip3:port3',service 字段可填写任意一个非空字符串 | 是 |
service | string | 协调节点 serviceName | 是 |
preferedinstance | string | 设置 SequoiaDB 的连接属性,多个属性以逗号分隔,如:preferedinstance '1,2,A',详细配置可参考 preferedinstance 取值 | 否 |
preferedinstancemode | string | 设置 SequoiaDB 的连接属性 preferedinstance 的选择模式 | 否 |
sessiontimeout | string | 设置 SequoiaDB 的连接属性会话超时时间,如:sessiontimeout '100' | 否 |
transaction | string | 设置 SequoiaDB 是否开启事务,默认为 off,开启为 on | 否 |
cipher | string | 设置是否使用加密文件输入密码,默认为 off,开启为 on;密文模式的介绍可参考密码管理 | 否 |
token | string | 设置加密令牌 | 否 |
cipherfile | string | 设置加密文件,默认为 ~/sequoiadb/passwd |
否 |
Note:
如果用户没有配置数据库密码验证,可以忽略 user 与 password 字段。
参数名 | 类型 | 描述 | 是否必填 |
---|---|---|---|
collectionspace | string | SequoiaDB 中已存在的集合空间 | 是 |
collection | string | SequoiaDB 中已存在的集合 | 是 |
decimal | string | 是否对接 SequoiaDB 的 decimal 字段,默认为 off | 否 |
pushdownsort | string | 是否下压排序条件到 SequoiaDB,默认为 on,关闭为 off | 否 |
pushdownlimit | string | 是否下压 limit 和 offset 条件到 SequoiaDB,默认为 on。开启 pushdownlimit 时,必须同时开启 pushdownsort ,否则可能会造成结果非预期的问题 | 否 |
Note:
用户所指定的集合空间与集合必须已经存在于 SequoiaDB,否则查询出错。
查看 PostgreSQL Shell 中默认的配置
sample=#\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 = 'sample' USER = 'sdbadmin' PORT = '5432' ENCODING = 'UTF8'
调整 PostgreSQL Shell 查询时每次获取记录数
sample=#\set FETCH_COUNT 100
Note:
调整配置后,每次获取记录数达到 100 时立即返回记录,然后再继续获取。
用户直接在 PostgreSQL Shell 中修改配置,只能在当前 PostgreSQL Shell 中生效。如果希望配置永久生效,则需要通过配置文件修改相关配置。修改步骤如下:
获取配置文件路径
$ /opt/postgresql/bin/pg_config --sysconfdir
输出结果如下:
$ /opt/postgresql/etc
如果显示目录不存在,则需要手动创建
$ mkdir -p /opt/postgresql/etc
将需要修改的参数写入配置文件中
$ echo "\\set FETCH_COUNT 100" >> /opt/postgresql/etc
Note:
用户修改配置后需要重启 psql 使配置生效。
编辑 /opt/postgresql/data/postgresql.conf
文件,将如下 PostgreSQL Shell 的日志级别:
client_min_messages = notice
改为:
client_min_messages = debug1
编辑 /opt/postgresql/data/postgresql.conf
文件,将如下 pg 引擎的日志级别:
log_min_messages = warning
改为:
log_min_messages = debug1
如果 PostgreSQL 连接的 SequoiaDB 协调节点重启,在查询时报错
ERROR: Unable to get collection "sample.employee", rc = -15 HINT: Make sure the collectionspace and collection exist on the remote database
解决方法:
重新进入 PostgreSQL Shell
sample=# \q $ bin/psql -p 5432 sample