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
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
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"
Run a 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;
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
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);
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;
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