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. Python 非递归遍历图

    class Queue: def __init__(self,max_size): self.max_size = int(max_size) self.queue = [] def put(self ...

  2. SQL学习笔记之项目中常用的19条MySQL优化

    在写文章之前,首先感谢 飞友科技 陆老师提供的文档.. 声明一下:下面的优化方案都是基于 “ Mysql-索引-BTree类型 ” 的 0x00 EXPLAIN 做MySQL优化,我们要善用 EXPL ...

  3. Python3.x的BeautifulSoup解析html常用函数

    Python3.x的BeautifulSoup解析html常用函数 1,初始化: soup = BeautifulSoup(html) # html为html源代码字符串,type(html) == ...

  4. MSF基础攻击实践报告

    MSF基础攻击实践 MSF的六个模块:exploit,encoder,payload,aux,post,nops exploit——渗透攻击模块 测试者利用它来攻击一个系统,程序,或服务,以获得开发者 ...

  5. CUDA、tensorflow与cuDNN的版本匹配问题【转】

    本文转载自:https://blog.csdn.net/MahoneSun/article/details/80809042 一.问题现象 CUDA.tensorflow 与 cuDNN有版本匹配的问 ...

  6. Object.defineProperty和Object.defineProperties

    添加属性到对象,或修改现有属性的特性   用法:     Object.defineProperty(object, propertyName, descriptor); 参数:     object ...

  7. codeforces 200 div2 C. Rational Resistance 思路题

    C. Rational Resistance time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. iOS线程之——NSCondition

    多线程在各种编程语言中都是难点,很多语言中实现起来很麻烦,objective-c虽然源于c,但其多线程编程却相当简单,可以与java相媲美.这篇文章主要从线程创建与启动.线程的同步与锁.线程的交互.线 ...

  9. jspf、jsp小记

    jsp页面:

  10. java并发编程:线程安全管理类--原子操作类--AtomicInteger

    在java并发编程中,会出现++,--等操作,但是这些不是原子性操作,这在线程安全上面就会出现相应的问题.因此java提供了相应类的原子性操作类. 1.AtomicInteger