TimescaleDB 安装

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm

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

yum update

yum install timescaledb-2-postgresql-14

/usr/pgsql-14/bin/postgresql-14-setup initdb

#使用timescaledb-tune脚本配置数据库完成安装后,您需要配置数据库以便可以使用它。
#最简单的方法是运行timescaledb-tune 脚本,它包含在timescaledb-tools软件包中
timescaledb-tune --pg-config=/usr/pgsql-14/bin/pg_config --quiet --yes


vim /var/lib/pgsql/14/data/postgresql.conf
将#port=5432前面的#删除
将#listen_addresses = 'localhost'改成listen_addresses = '*'

vim /var/lib/pgsql/14/data/pg_hba.conf
在最后面添加一行如下代码,然后保存
host    all             all             0.0.0.0/0               trust


systemctl enable postgresql-14
systemctl start postgresql-14

## 查看状态
systemctl status postgresql-14

# 切换到postgres用户
su - postgres

# 登录数据库
psql

# 修改密码
alter user postgres password '新的密码';

sudo systemctl restart postgresql-14.service

su - postgres
# 创建库或直接使用postgres库
createdb mydatabase

# 连接到该数据库
psql mydatabase

# 在数据库中加载 TimescaleDB 扩展
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;


-- 链接数据库
psql -U postgres -h localhost -d mydatabase

-- 创建超级表
CREATE TABLE conditions (
    time        TIMESTAMPTZ       NOT NULL,
    location    TEXT              NOT NULL,
    temperature DOUBLE PRECISION  NULL,
    humidity    DOUBLE PRECISION  NULL
);

-- 对超级表进行分区
SELECT create_hypertable('conditions', 'time');

SELECT create_hypertable('需要使用时序数据库的表名', '时间索引字段');

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值