【最佳实践】瀚高数据库安全版v4.5.7安装timescale插件

假如要在瀚高数据库安全版v4.5.7上使用timescale,需要从瀚高公司拿到扩展包timescaledb-v2.5.0_hgdbv457.tar

1. 先解压到安装目录:

关闭数据库:

pg_ctl stop

解压缩:

tar -xvf timescaledb-v2.5.0_hgdbv457.tar -C /opt/HighGo4.5.7-see/

启动数据库:

pg_ctl start

2. 创建指定用户和数据库:

假如我们想用使用用户test把扩展对象创建到数据库testdb上,后面由该用户来操作。命令脚本:

psql highgo sysdba <<-"EOF"
create user test password 'Hello@123' valid until 'infinity';
create database testdb with owner=test encoding=utf8 connection limit=-1;
EOF

cat >> /root/.pgpass <<-"EOF"
localhost:5866:testdb:sysdba:Hello@123
localhost:5866:testdb:test:Hello@123
EOF
chmod 0600 ~/.pgpass

说明:如果已经有数据库和用户,则不需要创建。

3. 创建扩展对象:

  1. 设置系统参数启动加载对应库文件:
psql highgo sysdba <<EOF
alter system set shared_preload_libraries = 'timescaledb';
EOF
pg_ctl restart
  1. 关闭三权:
psql highgo syssso <<EOF
select set_secure_param('hg_sepofpowers','off');
EOF
pg_ctl restart
  1. 创建扩展对象:
psql testdb sysdba <<EOF
create extension if not exists timescaledb cascade;  
EOF
  1. 恢复三权:
psql highgo syssso <<EOF
select set_secure_param('hg_sepofpowers','on');
EOF
pg_ctl restart

4. 总结

我们测试一下

psql testdb test <<-"EOF"
CREATE TABLE "acl_monitor_historydata" (
    ctime bigint NOT NULL,
    res_id character varying(128) NOT NULL,
    res_type character varying(64) NOT NULL,
    metrics jsonb
);
---基于postgres的表创建TimescaleDB超表
SELECT create_hypertable('acl_monitor_historydata', 'ctime', chunk_time_interval => 31536000000 );
INSERT INTO acl_monitor_historydata ( res_id, ctime, metrics, res_type )
VALUES
 ( 'b3afbffdfc664f26bc73866f985712f3.6ce0af4748724308bcdb87587bd0d18d', 1666777860001, '{"b3afbffdfc664f26bc73866f985712f3.f38907be649e389c106a057a03593c55":{"1":"5.36870912E8","12":"0.0","20":"5.36870912E8","21":"0.0"},"b3afbffdfc664f26bc73866f985712f3.6ce0af4748724308bcdb87587bd0d18d":{"44":"0.00","33":"1.0","34":"9.27731712E9","24":"3.83604457472E11","35":"1.6637763584E10","14":"0.06125","36":"0.44239","25":"0.34309","37":"7.360446464E9","1":"1","2":"0.27","3":"0.23","4":"0.2","50":"8.589930496E9","61":"0.04","51":"8.589930496E9","40":"1","52":"0.0","41":"0.022","53":"0.0","42":"0.028","43":"0.014","54":"0.0"},"persistInterval":{"persistInterval":"60000"},"b3afbffdfc664f26bc73866f985712f3.db0fa15ab96130742865783aa0e03d61":{"11":"2483606.0","22":"0.0","13":"165.0","25":"1.0","16":"0.0","19":"0.0","9":"1405108.0"},"b3afbffdfc664f26bc73866f985712f3.36b1282d60724fb13a77e7b16ddec422":{"1":"2.2577061888E11","12":"1.29613287424E11","20":"3.55383906304E11","21":"0.36471"}}' :: jsonb, 'HOST_LINUX' );
EOF

你可能感兴趣的:(数据库,瀚高数据库,timescale)