replication 可以确保系统的ha 以及lb 数据的查询,timesacledb 使用pg 内置的stream replication 进行复制的支持

docker 运行参考 https://github.com/rongfengliang/streaming-replication-docker ( 修改基础镜像添加gis 支持)

运行复制集群

  • clone 复制集群docker 代码
git clone https://github.com/timescale/streaming-replication-docker.git
  • 运行复制集群
  ./start_containers.sh

测试复制集群

注意此时账户postgres 密码是postgres repuser 是repuser 可以查看配置
测试数据下载地址 https://timescaledata.blob.core.windows.net/datasets/nyc_data.tar.gz

  • 状态查看
  • 导入schema
psql -U postgres -d nyc_data -h localhost < nyc_data.sql
  • 导入数据
psql -U postgres -d nyc_data -h localhost -c "\COPY rides FROM nyc_data_rides.csv CSV"

数据查询

  • 时序查询
SELECT time_bucket('5 minute', pickup_datetime) AS five_min, count(*) FROM rides WHERE pickup_datetime < '2016-01-01 02:00' GROUP BY five_min ORDER BY five_min;

结果

2016-01-01 00:00:00 703
2016-01-01 00:05:00 1482
2016-01-01 00:10:00 1959
2016-01-01 00:15:00 2200
2016-01-01 00:20:00 2285
2016-01-01 00:25:00 2291
2016-01-01 00:30:00 2349
2016-01-01 00:35:00 2328
2016-01-01 00:40:00 2440
2016-01-01 00:45:00 2372
2016-01-01 00:50:00 2388
2016-01-01 00:55:00 2473
2016-01-01 01:00:00 2395
2016-01-01 01:05:00 2510
2016-01-01 01:10:00 2412
2016-01-01 01:15:00 2482
2016-01-01 01:20:00 2428
2016-01-01 01:25:00 2433
2016-01-01 01:30:00 2337
2016-01-01 01:35:00 2366
2016-01-01 01:40:00 2325

gis 查询

  • 让nyc_data 支持gis
CREATE EXTENSION postgis;
ALTER TABLE rides ADD COLUMN pickup_geom geometry(POINT,2163);
ALTER TABLE rides ADD COLUMN dropoff_geom geometry(POINT,2163);
  • 生成geo 数据(有点慢,需要花点时间)
UPDATE rides SET pickup_geom = ST_Transform(ST_SetSRID(ST_MakePoint(pickup_longitude,pickup_latitude),4326),2163);
UPDATE rides SET dropoff_geom = ST_Transform(ST_SetSRID(ST_MakePoint(dropoff_longitude,dropoff_latitude),4326),2163);
  • gis 查询
SELECT time_bucket('30 minutes', pickup_datetime) AS thirty_min, COUNT(*) AS near_times_sq
FROM rides
WHERE ST_Distance(pickup_geom, ST_Transform(ST_SetSRID(ST_MakePoint(-73.9851,40.7589),4326),2163)) < 400
AND pickup_datetime < '2016-01-01 14:00'
GROUP BY thirty_min ORDER BY thirty_min;

说明

详细配置说明,参考 https://docs.timescale.com/v0.9/tutorials/replication,里面有详细的说明

参考资料

https://docs.timescale.com/v0.9/tutorials/tutorial-hello-nyc
https://docs.timescale.com/v0.9/tutorials/replication
https://docs.timescale.com/v0.9/getting-started/installation/mac/installation-homebrew
https://github.com/timescale/streaming-replication-docker
https://github.com/rongfengliang/streaming-replication-docker

 
 
 
 

timescaledb replication 使用的更多相关文章

  1. 列属性:RowGUIDCol、Identity 和 not for replication

    Table Column有两个特殊的属性RowGUIDCol 和 Identity,用于标记数据列: $ROWGUID 用于引用被属性 RowGUIDCol 标识的UniqueIdentifier 类 ...

  2. MySQL 5.7 Replication 相关新功能说明

    背景: MySQL5.7在主从复制上面相对之前版本多了一些新特性,包括多源复制.基于组提交的并行复制.在线修改Replication Filter.GTID增强.半同步复制增强等.因为都是和复制相关, ...

  3. Kafka replication

    Kafka replication kafka_replication_detailed_design_v2.pdf kafka Detailed Replication Design V3 Apac ...

  4. Replication的犄角旮旯(三)--聊聊@bitmap

    <Replication的犄角旮旯>系列导读 Replication的犄角旮旯(一)--变更订阅端表名的应用场景 Replication的犄角旮旯(二)--寻找订阅端丢失的记录 Repli ...

  5. 一个哥们看到数据库日志不断增大 [log_reuse_wait_desc]为replication 之后的做法

    一哥们看到数据库日志不断增大 [log_reuse_wait_desc]为replication 之后的做法 一天那个哥们看到数据库日志暴涨,用sys.databases 视图看一下[log_reus ...

  6. 由于Replication,DBCC Shrink不能收缩Log File

    使用Backup创建测试环境之后,发现testdb的Log File过大,达到400GB,由于测试环境实际上不需要这么大的Log Space,占用400GB的Disk Space实在浪费Disk Re ...

  7. 对Big Table进行全表更新,导致 Replication 同步数据的过程十分缓慢

    在Publisher database中更新一个big table,数据行数是3.4亿多.由于没有更新 clustered Index key,因此,只产生了3.4亿多个Update Commands ...

  8. The replication agent has not logged a progress message in 10 minutes.

    打开Replication Monitor,在Subscription Watch List Tab中,发现有大量的status= “Performance critical” 的黄色Warning, ...

  9. SQL SERVER Transactional Replication中添加新表如何不初始化整个快照

    在SQL SERVER的复制(Replication)中,有可能出现由于业务需求变更,需要新增一张表或一些表到已有的复制(发布订阅)当中,这种需求应该是很正常,也很常见的.但是在已有的复制(发布订阅) ...

随机推荐

  1. opencv-ios开发笔记9 使用透视变换矫正扭曲的图片

    http://blog.csdn.net/baixiaozhe/article/details/51762086 摄像头观察一个矩形的图片时往往只能得到一个扭曲的图片: 原图: 实际情况是摄像头经常从 ...

  2. git仓库迁移的两种解决方案

    Git仓库迁移而不丢失log的方法 要求能保留原先的commit记录,应该如何迁移呢? 同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢? 注意:如果使用了代码审核工具Gerrit ...

  3. POJ 3436 ACM Computer Factory(最大流+路径输出)

    http://poj.org/problem?id=3436 题意: 每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了.计算机的生产过程通过N台不同的机器来完成,每台机器用它的性 ...

  4. Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)

    http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...

  5. POJ 3613 Cow Relays(floyd+快速幂)

    http://poj.org/problem?id=3613 题意: 求经过k条路径的最短路径. 思路: 如果看过<矩阵乘法在信息学的应用>这篇论文就会知道 现在我们在邻接矩阵中保存距离, ...

  6. APP AutoTestCaseID

    public class AutoTestCaseID { ElementExist el = new ElementExist(); static AutoTestExcelFile ft = ne ...

  7. 发起图片请求的几种可能性(webkit内核)

    网页测试源代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> &l ...

  8. VNC Viewer连接Cent OS 时的 复制粘帖 功能

    虽然 VNC Viewer 比起 vsphere Client 来, 感觉性能差一点. 但毕竟也是个选择. 找了一下 它的这个 功能. 运行一下 vncconfig & 就可以了. 实测好用. ...

  9. python 数字的四舍五入的问题

    由于 python3 包括python2.7 以后的round策略使用的是decimal.ROUND_HALF_EVEN 即Round to nearest with ties going to ne ...

  10. @ResponseBody和@ResponseEntity注解

    如果需要返回json格式的数据,那么添加该注解就行了@ResponseBody对于ResponseEntity确切的说是ResponseEntity ,如果你即需要返回数据,又需要确定数据的状态,就用 ...