微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

记一次 Centos7 postgresql v11 安装时序数据库 TimescaleDB

转自:http://www.luyixian.cn/news_show_395768.aspx

记一次 Centos7 postgresql v11 安装时序数据库 TimescaleDB

2020/5/26 16:27:32 0 人评论 83 次浏览 分类学习教程

一、数据库安装

根据自身环境需要选择安装

1、yum 指定目录安装

https://blog.csdn.net/llwy1428/article/details/105143053

2、yum 直接安装

https://blog.csdn.net/llwy1428/article/details/102486414

3、编译安装

https://blog.csdn.net/llwy1428/article/details/95444151

4、Postgresql 基本操作

https://blog.csdn.net/llwy1428/article/details/102598732

5、Centos7 yum 安装、配置 PgAdmin4

https://blog.csdn.net/llwy1428/article/details/102486511

6、Centos7 Postgresql 数据库使用FDW扩展

https://blog.csdn.net/llwy1428/article/details/106291669

 

二、TimescaleDB  安装配置

1、安装数据库

https://blog.csdn.net/llwy1428/article/details/105143053

2、制作 timescaledb.repo 文件

[root@localhost ~]# sudo vi /etc/yum.repos.d/timescaledb.repo
[timescale_timescaledb]
name=timescale_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/7/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
Metadata_expire=300

3、安装 timescaledb-postgresql-11 

[root@localhost ~]# sudo yum install -y timescaledb-postgresql-11

4、配置数据库

[root@localhost ~]# sudo timescaledb-tune --pg-config=/usr/pgsql-11/bin/pg_config 

注:如果使用认配置,可直接使用如下命令

[root@localhost ~]# sudo timescaledb-tune --pg-config=/usr/pgsql-11/bin/pg_config --quiet --yes

5、重启数据库服务

[root@localhost ~]# sudo systemctl restart postgresql-11.service

6、测试:

切换用户

[root@localhost ~]# su - postgres

进入命令窗口:

-bash-4.2$ psql

创建数据库 timeseries

postgres=# CREATE DATABASE timeseries;
postgres=# \l

进入创建的数据库 timeseries

postgres=# \c timeseries
timeseries=# CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

创建表:

timeseries=# CREATE TABLE conditions (time TIMESTAMP WITH TIME ZONE NOT NULL,device_id TEXT,temperature NUMERIC,humidity NUMERIC);
timeseries=# SELECT create_hypertable('conditions', 'time');

插入数据:

timeseries=# INSERT INTO conditions(time, device_id, temperature, humidity) VALUES (Now(), 'weather-pro-000000', 84.1, 84.1);
timeseries=# INSERT INTO conditions VALUES (Now(), 'weather-pro-000002', 71.0, 51.0),(Now(), 'weather-pro-000003', 70.5, 50.5),(Now(), 'weather-pro-000004', 70.0, 50.2);


查询数据

timeseries=# SELECT * FROM conditions LIMIT 10;

查询数据

timeseries=# SELECT * FROM conditions ORDER BY time DESC LIMIT 3;

 

参考地址(官网):

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-timescaledb-on-centos-7

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐