概述

TimescaleDB是由PostgreSQL支持 的开源时间序列数据库,昨晚PG插件的形式存在,如果要使用到相关时序的功能,需要安装上此插件。安装方法有以下两种

YUM安装

如果你的PG是使用YUM网络安装,则可以同样使用该方法安装TimescaleDB插件
就根据官网上给出的方法,方便简洁

创建yum源

TimescaleDB官方给出了一个yum源,添加这个repo文件之后即可使用

  1. # Add our repo
  2. sudo cat > /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
  3. [timescale_timescaledb]
  4. name=timescale_timescaledb
  5. baseurl=https://packagecloud.io/timescale/timescaledb/el/7/\$basearch
  6. repo_gpgcheck=1
  7. gpgcheck=0
  8. enabled=1
  9. gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey
  10. sslverify=1
  11. sslcacert=/etc/pki/tls/certs/ca-bundle.crt
  12. metadata_expire=300
  13. EOL

选择版本安装

更新yum源之后,安装插件,注意相关版本

  1. sudo yum update -y
  2. # Now install appropriate package for PG version
  3. sudo yum install -y timescaledb-postgresql-10

安装完成之后直接创建拓展使用即可

编译安装

有时数据库不是使用yum源,而是自己编译安装的,这时配置的环境和yum源上的都不一致。就推荐使用源码安装就可以,不是很麻烦

使用yum方法失败

有时会失败,如下。就只能只用源码安装了

  1. [root@jh_test build]# yum install -y timescaledb-postgresql-10
  2. Error: Package: timescaledb-postgresql-10-1.2.2-0.el7.x86_64 (timescale_timescaledb)
  3. Requires: postgresql10-devel >= 10.2
  4. Error: Package: timescaledb-postgresql-10-1.2.2-0.el7.x86_64 (timescale_timescaledb)
  5. Requires: postgresql10-server >= 10.2
  6. Error: Package: timescaledb-postgresql-10-1.2.2-0.el7.x86_64 (timescale_timescaledb)
  7. Requires: postgresql10 >= 10.2
  8. You could try using --skip-broken to work around the problem
  9. You could try running: rpm -Va --nofiles --nodigest

安装好cmake 3.4+

TimescaleDB的编译是基于 cmake 3.4以上的版本

安装好依赖:

  1. yum install gcc-c++

安装cmake:
选择合适的版本安装 https://cmake.org/download/

解压后进入解压包内,执行如下

  1. ./bootstrap
  2. gmake
  3. gmake install

完成之后查看一下版本

  1. [root@jh_test build]# cmake --version
  2. cmake version 3.14.0
  3. CMake suite maintained and supported by Kitware (kitware.com/cmake).

下载源码

  1. [root@jh_test ~]# git clone https://github.com/timescale/timescaledb.git
  2. Cloning into 'timescaledb'...
  3. remote: Enumerating objects: 1, done.
  4. remote: Counting objects: 100% (1/1), done.
  5. remote: Total 14983 (delta 0), reused 1 (delta 0), pack-reused 14982
  6. Receiving objects: 100% (14983/14983), 5.26 MiB | 959.00 KiB/s, done.
  7. Resolving deltas: 100% (11724/11724), done.
  8. [root@jh_test ~]# cd timescaledb/
  9. [root@jh_test timescaledb]#
  10. [root@jh_test timescaledb]# ls
  11. appveyor.yml bootstrap.bat CMakeLists.txt docs LICENSE-APACHE README.md sql test tsl
  12. bootstrap CHANGELOG.md CONTRIBUTING.md LICENSE NOTICE scripts src timescaledb.control.in version.config

将源码的版本改为自己的PG适配的版本

  1. [root@jh_test timescaledb]# git checkout 1.2.1
  2. Note: checking out '1.2.1'.
  3. You are in 'detached HEAD' state. You can look around, make experimental
  4. changes and commit them, and you can discard any commits you make in this
  5. state without impacting any branches by performing another checkout.
  6. If you want to create a new branch to retain commits you create, you may
  7. do so (now or later) by using -b with the checkout command again. Example:
  8. git checkout -b new_branch_name
  9. HEAD is now at b334e10... Release 1.2.1

执行bootstrap

  1. [root@jh_test timescaledb]# ./bootstrap
  2. -- The C compiler identification is GNU 4.8.5
  3. -- Check for working C compiler: /usr/bin/cc
  4. -- Check for working C compiler: /usr/bin/cc -- works
  5. -- Detecting C compiler ABI info
  6. -- Detecting C compiler ABI info - done
  7. -- Detecting C compile features
  8. -- Detecting C compile features - done
  9. -- TimescaleDB version 1.2.1. Can be updated from version 1.2.0
  10. -- Build type is Release
  11. -- Install method is 'source'
  12. -- Performing Test CC_SUPPORTS_VISIBILITY_HIDDEN
  13. -- Performing Test CC_SUPPORTS_VISIBILITY_HIDDEN - Success
  14. -- Using compiler GNU
  15. -- Found Git: /usr/bin/git (found version "1.8.3.1")
  16. -- Using pg_config /usr/pgsql/bin/pg_config
  17. -- Compiling against PostgreSQL version 10.6
  18. -- Using docker based clang-format
  19. -- Found OpenSSL: /usr/lib64/libcrypto.so (found version "1.0.2k")
  20. -- Using OpenSSL version 1.0.2k
  21. -- Using nm /usr/bin/nm
  22. -- Using pg_regress /usr/pgsql-10/lib/pgxs/src/test/regress/pg_regress
  23. -- Using pg_isolation_regress PG_ISOLATION_REGRESS-NOTFOUND
  24. -- Configuring done
  25. -- Generating done
  26. -- Build files have been written to: /root/timescaledb/build
  27. TimescaleDB build system initialized in ./build. To compile, do:
  28. cd ./build && make
  1. [root@jh_test timescaledb]# cd build/
  2. [root@jh_test build]# ls
  3. CMakeCache.txt CMakeFiles cmake_install.cmake Makefile scripts sql src test timescaledb.control tsl version.config
  4. [root@jh_test build]#
  5. [root@jh_test build]# make
  6. Scanning dependencies of target sqlupdatescripts
  7. [ 1%] Generating /root/timescaledb/build/sql/timescaledb--1.2.0--1.2.1.sql
  8. [ 2%] Generating /root/timescaledb/build/sql/timescaledb--1.1.1--1.2.1.sql
  9. [ 3%] Generating /root/timescaledb/build/sql/timescaledb--1.1.0--1.2.1.sql
  10. [ 4%] Generating /root/timescaledb/build/sql/timescaledb--1.0.1--1.2.1.sql
  11. [ 5%] Generating /root/timescaledb/build/sql/timescaledb--1.0.0--1.2.1.sql
  12. [ 5%] Generating /root/timescaledb/build/sql/timescaledb--1.0.0-rc3--1.2.1.sql
  13. [ 6%] Generating /root/timescaledb/build/sql/timescaledb--1.0.0-rc2--1.2.1.sql
  14. [ 7%] Generating /root/timescaledb/build/sql/timescaledb--1.0.0-rc1--1.2.1.sql
  15. [ 8%] Generating /root/timescaledb/build/sql/timescaledb--0.12.1--1.2.1.sql
  16. [ 9%] Generating /root/timescaledb/build/sql/timescaledb--0.12.0--1.2.1.sql
  17. [ 10%] Generating /root/timescaledb/build/sql/timescaledb--0.11.0--1.2.1.sql
  18. .....(省略)
  19. [ 92%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/planner.c.o
  20. [ 93%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/bgw_policy/reorder_api.c.o
  21. [ 94%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/bgw_policy/drop_chunks_api.c.o
  22. [ 94%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/bgw_policy/job.c.o
  23. [ 95%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/gapfill/gapfill.c.o
  24. [ 96%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/gapfill/planner.c.o
  25. [ 97%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/gapfill/exec.c.o
  26. [ 98%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/gapfill/locf.c.o
  27. [ 99%] Building C object tsl/src/CMakeFiles/timescaledb-tsl.dir/gapfill/interpolate.c.o
  28. [100%] Linking C shared module timescaledb-tsl-1.2.1.so
  29. [100%] Built target timescaledb-tsl

检查当前当前安装用户下的PG环境是否是自己想要的,无误后执行make install

  1. [root@jh_test build]# pg_config
  2. [root@jh_test build]# make install
  3. [ 24%] Built target sqlupdatescripts
  4. [ 24%] Built target sqlfile
  5. [ 83%] Built target timescaledb
  6. [ 88%] Built target timescaledb-loader
  7. [100%] Built target timescaledb-tsl
  8. Install the project...
  9. -- Install configuration: "Release"
  10. -- Installing: /usr/pgsql-10/share/extension/timescaledb.control
  11. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.2.1.sql
  12. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.2.0--1.2.1.sql
  13. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.1.1--1.2.1.sql
  14. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.1.0--1.2.1.sql
  15. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.0.1--1.2.1.sql
  16. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.0.0--1.2.1.sql
  17. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.0.0-rc3--1.2.1.sql
  18. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.0.0-rc2--1.2.1.sql
  19. -- Installing: /usr/pgsql-10/share/extension/timescaledb--1.0.0-rc1--1.2.1.sql
  20. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.12.1--1.2.1.sql
  21. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.12.0--1.2.1.sql
  22. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.11.0--1.2.1.sql
  23. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.10.1--1.2.1.sql
  24. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.10.0--1.2.1.sql
  25. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.9.2--1.2.1.sql
  26. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.9.1--1.2.1.sql
  27. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.9.0--1.2.1.sql
  28. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.8.0--1.2.1.sql
  29. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.7.1--1.2.1.sql
  30. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.7.0--1.2.1.sql
  31. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.6.1--1.2.1.sql
  32. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.6.0--1.2.1.sql
  33. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.5.0--1.2.1.sql
  34. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.4.2--1.2.1.sql
  35. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.4.1--1.2.1.sql
  36. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.4.0--1.2.1.sql
  37. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.3.0--1.2.1.sql
  38. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.2.0--1.2.1.sql
  39. -- Installing: /usr/pgsql-10/share/extension/timescaledb--0.1.0--1.2.1.sql
  40. -- Installing: /usr/pgsql-10/lib/timescaledb-1.2.1.so
  41. -- Installing: /usr/pgsql-10/lib/timescaledb.so
  42. -- Installing: /usr/pgsql-10/lib/timescaledb-tsl-1.2.1.so
  43. [root@jh_test build]#

添加动态库参数

打开postgresql.conf 文件添加一行参数 shared_preload_libraries = ‘timescaledb’
完成后重启

  1. [postgres@jh_test pgdata]$ vi postgresql.conf
  2. [postgres@jh_test pgdata]$ pg_ctl restart
  3. waiting for server to shut down.... done
  4. server stopped
  5. waiting for server to start....2019-03-15 19:10:16.796 CST [15613] LOG: listening on IPv4 address "0.0.0.0", port 5432
  6. 2019-03-15 19:10:16.796 CST [15613] LOG: listening on IPv6 address "::", port 5432
  7. 2019-03-15 19:10:16.803 CST [15613] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
  8. 2019-03-15 19:10:16.956 CST [15613] LOG: redirecting log output to logging collector process
  9. 2019-03-15 19:10:16.956 CST [15613] HINT: Future log output will appear in directory "pg_log".
  10. done
  11. server started

创建拓展

  1. [postgres@jh_test pgdata]$ psql
  2. psql (10.6)
  3. Type "help" for help.
  4. postgres=# CREATE EXTENSION timescaledb;
  5. WARNING:
  6. WELCOME TO
  7. _____ _ _ ____________
  8. |_ _(_) | | | _ \ ___ \
  9. | | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ /
  10. | | | | _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \
  11. | | | | | | | | | __/\__ \ (_| (_| | | __/ |/ /| |_/ /
  12. |_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/
  13. Running version 1.2.1
  14. For more information on TimescaleDB, please visit the following links:
  15. 1. Getting started: https://docs.timescale.com/getting-started
  16. 2. API reference documentation: https://docs.timescale.com/api
  17. 3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture
  18. Note: TimescaleDB collects anonymous reports to better understand and assist our users.
  19. For more information and how to disable, please see our docs https://docs.timescaledb.com/using-timescaledb/telemetry.
  20. CREATE EXTENSION
0 评论  
添加一条新评论