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('需要使用时序数据库的表名', '时间索引字段');
TimescaleDB 安装
最新推荐文章于 2024-03-11 09:49:17 发布