windows下postgresql安装timescaledb

    timescaledb是一个时序数据库,可以创建超表hypertable。它并不是一个独立的数据库,它依赖于postgresql,目前相当于postgresql的一个插件或者扩展。

    要安装timescaledb,需要先安装postgresql。

    这里安装的postgresql是12.14版本,下载地址:https://get.enterprisedb.com/postgresql/postgresql-12.14-1-windows-x64-binaries.zip

    timescaledb是2.10.1版本,下载地址:https://github.com/timescale/timescaledb/releases/tag/2.10.1 

    这里为了配合postgresql版本,我们选择第一个下载项:

    前面下载的postgresql是免安装版本,直接解压到系统中的d:/tools目录下,目录结构如下:

    这里本来没有data目录的,我们需要手动创建。 

    初始化postgresql,进入postgresql安装目录,打开命令行:

bin\initdb -D data

    这一步会把数据文件生成在data目录,并且生成配置文件postgresql.conf 。

   . 

    到这里,postgresql基本就可以使用了, 免安装版本很省事。

    ==========

    接着就是timescaledb的安装,简单的安装,就是执行timescaledb目录下的setup.exe。这种方式需要设置postgresql环境变量,主要如下4个:

    PGHOME: D:\tools\pgsql

    PGDATA:   D:\tools\pgsql\data

    PGLIB:       D:\tools\pgsql\lib

    Path:          D:\tools\pgsql\bin;%Path%

    这种安装方式,本质上还是替换一些文件,如下所示timescaledb解压之后的目录结构:

    在执行timescaledb-tune.exe的时候,把其中三个动态库文件加入到了postgresql安装目录下的lib目录,把其余control和sql文件加入到了share/extension目录,最后对postgresql.conf进行了简单配置。

    还有一种安装方式就是上面提到的手动移动文件的办法:

    1、把标红的三个动态库文件timescaledb.dll,timescaledb-2.10.1.dll,timescaledb-tsl-2.10.1.dll文件拷贝到lib目录。

     2、移动标绿的文件到share/extension目录。

     3、修改postgresql.conf文件,把shared_preload_libraries="timescaledb"加上。这个配置shared_preload_libraries=""默认是注释的,并且为空,我们要安装timescaledb就把他配置上。

     替换完成,就启动postgresql。

D:\tools\pgsql>bin\pg_ctl.exe -D data -l pgsql.log start
等待服务器进程启动 .... 完成
服务器进程已经启动

    我们使用命令行进入postgresql,默认用户是系统用户名,我们进入postgres数据库。

D:\tools\pgsql>bin\psql postgres
psql (12.14)
输入 "help" 来获取帮助信息.

postgres=# create database test;
CREATE DATABASE
postgres=# \l
                                                                数据库列表
   名称    |    拥有者     | 字元编码 |            校对规则            |             Ctype              |            存 取权限
-----------+---------------+----------+--------------------------------+--------------------------------+---------------------------------
 postgres  | Administrator | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
 template0 | Administrator | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | =c/Administrator               +
           |               |          |                                |                                | Administrator=CTc/Administrator
 template1 | Administrator | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | =c/Administrator               +
           |               |          |                                |                                | Administrator=CTc/Administrator
 test      | Administrator | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
(4 行记录)


postgres=# \c test
您现在已经连接到数据库 "test",用户 "Administrator".
test=# \dx
                       已安装扩展列表
  名称   | 版本 |  架构模式  |             描述
---------+------+------------+------------------------------
 plpgsql | 1.0  | pg_catalog | PL/pgSQL procedural language
(1 行记录)

    创建了test数据库,我们看了扩展只有plpgsql。

    接着,我们创建timescaledb扩展。

test=# create extension timescaledb;
警告:
WELCOME TO
 _____ _                               _     ____________
|_   _(_)                             | |    |  _  \ ___ \
  | |  _ _ __ ___   ___  ___  ___ __ _| | ___| | | | |_/ /
  | | | |  _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \
  | | | | | | | | |  __/\__ \ (_| (_| | |  __/ |/ /| |_/ /
  |_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/
               Running version 2.10.1
For more information on TimescaleDB, please visit the following links:

 1. Getting started: https://docs.timescale.com/timescaledb/latest/getting-started
 2. API reference documentation: https://docs.timescale.com/api/latest
 3. How TimescaleDB is designed: https://docs.timescale.com/timescaledb/latest/overview/core-concepts

Note: TimescaleDB collects anonymous reports to better understand and assist our users.
For more information and how to disable, please see our docs https://docs.timescale.com/timescaledb/latest/how-to-guides/configuration/telemetry.

CREATE EXTENSION
test=# \dx
                                            已安装扩展列表
    名称     |  版本  |  架构模式  |                               描述
-------------+--------+------------+-------------------------------------------------------------------
 plpgsql     | 1.0    | pg_catalog | PL/pgSQL procedural language
 timescaledb | 2.10.1 | public     | Enables scalable inserts and complex queries for time-series data
(2 行记录)

   到这里,我们基本就可以认为timescaledb安装成功。 

    这种免安装版本,基本没有什么配置,就是执行几个简单的命令,初始化数据库,启动数据库,创建扩展。在安装timescaledb的时候,手动添加文件到postgresql安装目录中,也从安装的角度感受到了timescaledb确实依赖postgresql,而且它相当于一个插件,有没有,对postgresql本身影响不大,如果timescaledb安装失败,最多就是创建timescaledb扩展的时候可能会报错。

    最后,我们通过pgAdmin可以看到有了timescaledb扩展的test数据库中的函数:

   create_hypertable就在其中。时序数据库最主要就是利用这个函数来创建超表。 

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

luffy5459

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值