返回首页

gbase数据、南大通用产品文档:GBase8a预测函数

更新日期:2024年09月11日

语法
Linear 回归的预测函数的语法如下:
linregr_predict(coefficients,
independent_varname
)
参数说明

coefficients:模型结果表中保存的相关系数。

independent_varname:自变量的列名,数组类型。

透明存储加密机制
GBase
8s 目前的存储加密由数据库内核在后端安全存储引擎中实现,对于
合法用户来说完全透明,不影响合法数据库用户的前端操作,不存在功能损
失;采用按数据页加密的方式,不仅易于实现且加解密效率高;物理存储密文
态,内存缓存明文态的机制保证了数据检索的高效性,使加密对GBase
8s 原有
的高效检索机制几乎没有造成任何实质性影响,由于存储加密造成的性能下降


GBase 8s 技术白皮书
南大通用数据技术股份有限公司
第29 页
不超过15%。
6 GBase 8s 图形化管理工具
GBase 8s 提供功能强大的、类型丰富的、易于使用的图形化管理工具帮助
数据库管理员管理数据库。

使用gsql 操作密态数据库
步骤1 以操作系统用户gbase 登录数据库主节点。
步骤2 执行以下命令打开密态开关,连接密态数据库。
gsql -p PORT postgres -r -C
步骤3 创建客户端主密钥CMK 和列加密密钥CEK。具体涉及到的新增创建CMK 的语法
参考《GBase 8c V5_3.0.0_SQL 手册》CREATE CLIENT MASTER KEY 章节,创建的CEK
的语法参考《GBase 8c V5_3.0.0_SQL 手册》CREATE COLUMN ENCRYPTION KEY
--创建客户端加密主密钥(CMK)
postgres=# CREATE CLIENT MASTER KEY ImgCMK1 WITH (KEY_STORE = localkms,
KEY_PATH ="key_path_value1", ALGORITHM = RSA_2048);
postgres=# CREATE CLIENT MASTER KEY ImgCMK WITH (KEY_STORE = localkms,
KEY_PATH ="key_path_value2", ALGORITHM = RSA_2048);
postgres=# CREATE COLUMN ENCRYPTION KEY ImgCEK1 WITH VALUES
(CLIENT_MASTER_KEY = ImgCMK1, ALGORITHM =
AEAD_AES_256_CBC_HMAC_SHA256);
CREATE COLUMN ENCRYPTION KEY
查询存储密钥信息的系统表结果如下。
postgres=# SELECT * FROM gs_client_global_keys;
global_key_name | key_namespace | key_owner |
key_acl |
create_date
-----------------+---------------+-----------+---------+----------------------------
imgcmk1
| 2200
|
10
| 2022-06-06 11:04:00.656617
imgcmk
| 2200
|
10
| 2022-06-06 11:04:05.389746
(2 rows)

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
200
postgres=# SELECT column_key_name,column_key_distributed_id ,global_key_id,key_owner
FROM gs_column_keys;
column_key_name | column_key_distributed_id | global_key_id | key_owner
-----------------+---------------------------+---------------+-----------
imgcmk1
|
|
10
|
2022-06-06 11:04:00.656617
imgcmk
|
|
10
|
2022-06-06 11:04:05.389746
(2 rows)
postgres=# SELECT column_key_name,column_key_distributed_id ,global_key_id,key_owner
FROM gs_column_keys;
column_key_name | column_key_distributed_id | global_key_id | key_owner
-----------------+---------------------------+---------------+-----------
imgcek1
|
760411027
|
16392
|
10
imgcek
|
3618369306 |
16398
|
10
(2 rows)
步骤4 创建加密表。
postgres=# CREATE TABLE creditcard_info (id_number
int, name text encrypted with
(column_encryption_key = ImgCEK, encryption_type = DETERMINISTIC), credit_card
varchar(19) encrypted with (column_encryption_key = ImgCEK1, encryption_type =
DETERMINISTIC));
NOTICE: The 'DISTRIBUTE BY' clause is not specified. Using 'id_number' as the distribution
column by default.
HINT: Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
CREATE TABLE
查询表的详细信息如下,Modifiers 值为encrypted 则表示该列是加密列。
postgres=# \d creditcard_info
Table "public.creditcard_info" Column
|
Type| Modifiers
-------------+-------------------+------------
id_number | integer
name
| text
credit_card | character varying | encrypted
步骤5 向加密表插入数据并进行等值查询。
postgres=# INSERT INTO creditcard_info VALUES (1,'joe','6217986500001288393');
INSERT 0 1
postgres=# INSERT INTO creditcard_info VALUES (2, 'joy','62199856783491543233');
INSERT 0 1
postgres=# select * from creditcard_info where name = 'joe';
id_number | name |
credit_card
-----------+------+---------------------

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
201
1 | joe | 6217986500001288393
(1 row)
注意:使用非密态客户端查看该加密表数据时是密文
postgres=# select id_number,name from creditcard_info;
id_number | name
-----------+--------------------
1 |
\x011aefabd754ded0a536a96664790622487c4d366d313aecd5839e410a46d29cba96a60e48310
00000ee7905 6a114c9a6c041bb552b78052e912a8b730609142074c63791abebd0d38
2 |
\x011aefabd76853108eb406c0f90e7c773b71648fa6e2b8028cf634b49aec65b4fcfb376f3531000
000f7471c868 6682de215d09aa87113f6fb03884be2031ef4dd967afc6f7901646b
(2 rows)
步骤6 (可选)对加密表进行alter 和update 操作。
postgres=# ALTER TABLE creditcard_info ADD COLUMN age int ENCRYPTED WITH
(COLUMN_ENCRYPTION_KEY = ImgCEK, ENCRYPTION_TYPE = DETERMINISTIC);
ALTER TABLE
postgres=# \d creditcard_info
Table "public.creditcard_info" Column
| Type| Modifiers
-------------+-------------------+------------
id_number | integer
name
| text
credit_card | character varying | encrypted
age
| integer
| encrypted
postgres=# ALTER TABLE creditcard_info DROP COLUMN age;
ALTER TABLE
postgres=# update creditcard_info set credit_card = '154320000011111111' where name = 'joy';
UPDATE 1
postgres=# select * from creditcard_info where name = 'joy';
id_number | name | credit_card
-----------+------+-------------------
2 | joy | 154320000011111111
(1 row)
----结束