postgresql 数据库 timescaledb 函数time_bucket_gapfill()报错解决及更换 license
文章目录
前言
最近在工作中使用postgresql 和 timescaledb 的time_bucket_gapfill()函数 报错,让更换license,在网上找了一大圈,没有找到,最后解决了这个问题,这篇文章记录我的解决办法
一 遇到问题:
报错如下
错误: function “time_bucket_gapfill” is not supported under the current “apache” license
HINT: Upgrade your license to ‘timescale’ to use this free community feature.
二 解决办法:
方法一: 直接改 timescaledb.license参数
查看timescaledb.license参数命令:
show timescaledb.license;
修改命令:
alter system set timescaledb.license='timescale';
结果不行,报错如下:
lter system set timescaledb.license=‘timescale’;
错误: 无法访问文件 “$libdir/timescaledb-tsl-2.5.2”: 没有那个文件或目录
那只能换包了
方法二: 更换 timescaledb 版本(自带’timescale’ license)
如果出现上面那种情况,那我们只能
1.下载yum包
先从官网上下载带 'timescale’版本的yum 包
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{
rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2. 更新一下本地包
yum update timescaledb_14
下载rpm包
yumdownloader --resolve --destdir=/u01 timescaledb-2-postgresql-14.x86_64
下载所缺的依赖包
yumdownloader --resolve --destdir=/u01 timescaledb-2-loader-postgresql-14.x86_64
yumdownloader --resolve --destdir=/u01 timescaledb-tools-0.12.0-0.el7.x86_64
3. 备份原有数据
由于timescaledb的版本不一致,不能直接使用pg_dump 命令来备份数据库的数据
在这里我采用单表数据进行备份的方式:
psql --host "0.0.0.0" --port "5432" --dbname "原数据库名" --username "postgres" \
-c "\COPY (SELECT * FROM 超级表名 {后面可以跟where 加限制条件}) TO /u01/data.csv DELIMITER ',' CSV"
4. 备份原有表结构
这里可以使用pg_dump等命令导出表结构的sql。
5. 杀掉连接数据库的进程:
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection
pid <> pg_backend_pid()
-- don't kill the connections to other databases
AND datname = '原库名'
;