zoukankan      html  css  js  c++  java
  • PostgreSQL—安装使用timescale时序数据库

    安装 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、

  • 相关阅读:
    必须克服的10种不良阅读习惯
    如何提升你的影响力
    爱情在线:拥抱变化的男女爱情!
    时间与生命
    女子最钟爱的五种男人
    社交常用表达:把人家的名字给忘了怎么办?
    最常用英语口头禅[推荐]
    中秋节的来历
    学会欣赏自己
    转帖]白领:4大行业通往高薪之路
  • 原文地址:https://www.cnblogs.com/liuhaidon/p/14294837.html
Copyright © 2011-2022 走看看