0%

基于postgres-15安装TimescaleDB

TimescaleDB

TimescaleDB 是基于postgres的时序数据库,安装TimescaleDB需要先安装postgres,然后将postgres转成TimescaleDB.

参考前文安装 postgres-15.

安装TimescaleDB

  1. 安装yum源
sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  1. 安装TimescaleDB资源库
sudo tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
[timescale_timescaledb]
name=timescale_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/$(rpm -E %{rhel})/\$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
  1. 更新
sudo yum update
  1. YUM安装TimescaleDB
sudo yum install timescaledb-2-postgresql-15
# 同时安装postgres15
# sudo yum install timescaledb-2-postgresql-16 postgresql16
  1. 初始化数据库(已经安装过了就跳过)
sudo /usr/pgsql-16/bin/postgresql-15-setup initdb
  1. 将PostgreSQL调成TimescaleDB
# 如果修改过data目录可以通过 -conf-path 指定位置,否在找不到。
sudo timescaledb-tune --pg-config=/usr/pgsql-15/bin/pg_config -conf-path=/home/pgsql/data/postgresql.conf
  1. 重启数据库
systemctl restart postgresql-15
  1. 添加数据库拓展
# 登录
psql -U postgres -h 127.0.0.1 -p 5432
-- Add TimescaleDB to the database
CREATE EXTENSION IF NOT EXISTS timescaledb;

-- Check that TimescaleDB is installed
postgres=# \dx
                                               List of installed extensions
    Name     | Version |   Schema   |                                     Description                                      
-------------+---------+------------+--------------------------------------------------------------------------------------
 plpgsql     | 1.0     | pg_catalog | PL/pgSQL procedural language
 timescaledb | 2.15.2  | public     | Enables scalable inserts and complex queries for time-series data (Apache 2 Edition)
(2 rows)