安裝 TimescaleDB
1、制作 timescaledb.repo 文件
[root@localhost ~]# vim /etc/yum.repos.d/timescaledb.repo # 方式一 [root@localhost ~]# tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL # 方式二 [root@localhost ~]# cat > /etc/yum.repos.d/timescale_timescaledb.repo <<EOL # 方式三 [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 EOL
2、更新源,有時可以省略這一步
[root@localhost ~]# yum update -y
3、安裝 timescaledb-postgresql-12
[root@localhost ~]# yum install -y timescaledb-postgresql-12 # 安裝的版本是1.7.4,使用可能有點問題。 [root@localhost ~]# yum install -y timescaledb-2-postgresql-12 # 安裝的版本是2.0.1,推薦這個版本。
4、配置 postgresql.conf 文件,使用 postgres 啟動時加載 'timescaledb'
[root@localhost ~]# vim /var/lib/pgsql/12/data/postgresql.conf # 方式一 shared_preload_libraries = 'timescaledb' # 不區分大小寫,也可以寫timescaleDB。 [root@localhost ~]# echo "shared_preload_libraries='timescaledb'">>/var/lib/pgsql/12/data/postgresql.conf # 方式二 [root@localhost ~]# sudo timescaledb-tune --pg-config=/usr/pgsql-12/bin/pg_config # 方式三 [root@localhost ~]# sudo timescaledb-tune --pg-config=/usr/pgsql-12/bin/pg_config --quiet --yes # 方式三,如果使用默認配置,可直接使用該命令
5、重啟數據庫服務
[root@localhost ~]# service postgresql-12 restart [root@localhost ~]# systemctl restart postgresql-12.service
6、安裝檢驗
[root@localhost ~]# su - postgres # 切換到 postgres 用戶。
-bash-4.2$ psql # 進入到 postgres 的命令行,即命令窗口。
postgres=# CREATE DATABASE timeseries; # 創建數據庫 timeseries
postgres=# \l # 查看數據庫
postgres=# \c timeseries # 進入創建的數據庫 timeseries
timeseries=# create extension timescaledb; # 方式一,添加 TimescaleDB 插件
timeseries=# CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; # 方式二,使用 TimescaleDB 擴展數據庫
7、查看 TimescaleDB 版本
timeseries=# \dx; timeseries=# SELECT default_version, installed_version FROM pg_available_extensions WHERE name = 'timescaledb';
使用 TimescaleDB
1、創建標准表:conditions
2、創建超級表:時序表
3、刪除超級表
timeseries=# drop table conditions;
4、
