一、數據庫安裝
根據自身環境需要選擇安裝
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 數據庫安裝擴展
https://blog.csdn.net/llwy1428/article/details/105167524
7、Centos7 PostgreSql 數據庫使用FDW擴展
https://blog.csdn.net/llwy1428/article/details/106291669
二、TimescaleDB 安裝配置
1、安裝數據庫:
https://blog.csdn.net/llwy1428/article/details/102486414
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
至此, Centos7 postgresql v11 安裝時序數據庫 TimescaleDB 操作完畢!