Timesacledb Test Demo Data Run

Source: Internet
Author: User
Tags psql postgis docker run

Timesacledb installation or use of Docker, for test data need to be downloaded in advance

Start Timesacledb

Using a GIS-enabled mirror, you need to use

docker run -d --name timescaledb -p 5432:5432 timescale/timescaledb-postgis
Preparation environment
    • Download test data
https://timescaledata.blob.core.windows.net/datasets/nyc_data.tar.gz
    • Create DATABASE && Extended load Timesacledb
CREATE DATABASE nyc_data;\c nyc_dataCREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
Loading data
    • Import schema
psql -U postgres -d nyc_data -h localhost < nyc_data.sql
    • Import data
psql -U postgres -d nyc_data -h localhost -c "\COPY rides FROM nyc_data_rides.csv CSV"
Run a query
    • Basic Query
SELECT date_trunc(‘day‘, pickup_datetime) as day, avg(fare_amount) FROM rides WHERE passenger_count > 1 AND pickup_datetime < ‘2016-01-08‘ GROUP BY day ORDER BY day;SELECT date_trunc(‘day‘, pickup_datetime) as day, COUNT(*) FROM rides GROUP BY day ORDER BY day LIMIT 5;
    • Time series Query
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;
System data


Query details
    • View Timesacledb's work through explain
EXPLAIN SELECT * FROM rides;

GIS Query
    • Let Nyc_data support GIS
CREATE EXTENSION postgis;ALTER TABLE rides ADD COLUMN pickup_geom geometry(POINT,2163);ALTER TABLE rides ADD COLUMN dropoff_geom geometry(POINT,2163);
    • Generate GEO data (a bit slow, take some time)
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 Query
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;
    • System-generated data
Description
总的来说简单,同时具有时序数据库的特点,对于我们来说不需要关注数据多的时候性能的问题,还是很不错的,对于ha 以及集群功能还有待研究
Resources

Https://docs.timescale.com/v0.9/tutorials/tutorial-hello-nyc
Https://docs.timescale.com/v0.9/getting-started/installation/mac/installation-homebrew

Timesacledb Test Demo Data Run

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.