ITPub博客

首页 > 数据库 > > postGreSQL 插件 timescaleDB 安装使用

postGreSQL 插件 timescaleDB 安装使用

作者:u_9ff4c058a0e0 时间:2022-05-12 15:36:00 0 删除 编辑

基本环境

操作系统: centOS 7

postGreSQL : 10

timescaleDB : 1.0 +

postGreSQL安装

Centos7 安装Postgresql10.5和PostGIS


https://blog.csdn.net/u010430471/article/details/81663248

timescaleDB 安装

PostgreSQL 时序数据库插件 timescaleDB 部署实践 - PostGIS + timescaleDB => PG时空数据库 -- 德哥


https://github.com/digoal/blog/blob/master/201801/20180129_01.md


官网安装文档


TimescaleDB Docs - Installing


https://docs.timescale.com/v1.2/getting-started/installation/rhel-centos/installation-yum

timescaleDB 设置

TimescaleDB Docs - Setting up TimescaleDB


https://docs.timescale.com/v1.2/getting-started/setup

实验

 1    -- 下载测试数据
2    wget https://timescaledata.blob.core.windows.net/datasets/weather_small.tar.gz
3
4    wget https://timescaledata.blob.core.windows.net/datasets/weather_big.tar.gz
5
6    -- 创建数据库
7    create database weather;
8
9    -- 解压下载文件
10    tar -zxvf weather_small.tar.gz
11
12    -- 创建表结构
13    psql -U postgres -d weather < weather.sql
14
15    -- 导入数据
16    psql -U postgres -d weather -c "\COPY conditions FROM weather_small_conditions.csv CSV"
17    psql -U postgres -d weather -c "\COPY locations FROM weather_small_locations.csv CSV"
18
19
20    -- 查询测试
21
22    SELECT * FROM conditions c ORDER BY time DESC LIMIT 10;
23
24
25    SELECT time, c.device_id, location,
26    trunc(temperature, 2) temperature, trunc(humidity, 2) humidity
27    FROM conditions c
28    INNER JOIN locations l ON c.device_id = l.device_id
29    WHERE l.environment = 'outside'
30    ORDER BY time DESC LIMIT 10;
31
32
33    SELECT date_trunc('hour', time) "hour",
34    trunc(avg(temperature), 2) avg_temp,
35    trunc(min(temperature), 2) min_temp,
36    trunc(max(temperature), 2) max_temp
37    FROM conditions c
38    WHERE c.device_id IN (
39        SELECT device_id FROM locations
40        WHERE location LIKE 'field-%'
41    ) GROUP BY "hour" ORDER BY "hour" ASC LIMIT 24;

注释

 1-- 数据库启动
2systemctl start postgresql-10
3
4-- 连接数据库
5psql
6
7-- 创建数据库
8CREATE database weather_big;
9
10-- 创建时序关系
11CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
12
13-- 导入数据
14psql -U postgres -d weather_big < weather.sql
15psql -U postgres -d weather_big -c "\COPY conditions FROM weather_big_conditions.csv CSV"
16psql -U postgres -d weather_big -c "\COPY locations FROM weather_big_locations.csv CSV"

来源 https://www.modb.pro/db/242504

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69999831/viewspace-3164110/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2022-02-11

  • 博文量
    1828
  • 访问量
    20599