FEAT : maj doc
This commit is contained in:
parent
4ac415c22f
commit
6f5293d325
56
notes.md
56
notes.md
@ -8,8 +8,7 @@
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
ssh grab-4
|
ssh grab-4
|
||||||
docker exec -t client-demo-postgres-1 pg_dump -Fc -U postgres -d postgres -f /tmp/backup_postgres.dump
|
docker exec client-demo-postgres-1 pg_dump -Fc -U postgres postgres > /tmp/backup_postgres.dump
|
||||||
docker cp client-demo-postgres-1:/tmp/backup_postgres.dump /tmp/backup_postgres.dump
|
|
||||||
exit
|
exit
|
||||||
|
|
||||||
cd /tmp
|
cd /tmp
|
||||||
@ -25,11 +24,11 @@ pg_restore -c -x -I mesure_idx2 -d postgres -h localhost -U postgres -W backup_
|
|||||||
CREATE TABLE mesure_ng (
|
CREATE TABLE mesure_ng (
|
||||||
"date" TIMESTAMPTZ,
|
"date" TIMESTAMPTZ,
|
||||||
id_captation INT NOT NULL,
|
id_captation INT NOT NULL,
|
||||||
valeur float4 NOT NULL,
|
valeur float4 NOT NULL
|
||||||
) WITH (
|
) WITH (
|
||||||
tsdb.hypertable,
|
tsdb.hypertable,
|
||||||
timescaledb.segmentby = 'id_captation',
|
timescaledb.segmentby = 'id_captation',
|
||||||
timescaledb.orderby='time DESC'
|
timescaledb.orderby='date DESC'
|
||||||
)
|
)
|
||||||
|
|
||||||
INSERT INTO mesure_ng ("date", id_captation, valeur)
|
INSERT INTO mesure_ng ("date", id_captation, valeur)
|
||||||
@ -37,6 +36,11 @@ INSERT INTO mesure_ng ("date", id_captation, valeur)
|
|||||||
FROM mesure
|
FROM mesure
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Compression des données (stockage en colonnes)
|
||||||
|
|
||||||
|
`SELECT add_columnstore_policy('mesure_ng', INTERVAL '15 days')`
|
||||||
|
|
||||||
|
|
||||||
### Ex. de requête
|
### Ex. de requête
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
@ -59,10 +63,50 @@ ORDER BY
|
|||||||
heure;
|
heure;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Exploit
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT *
|
||||||
|
FROM timescaledb_information.chunks
|
||||||
|
WHERE hypertable_name = 'mesure_ng'
|
||||||
|
```
|
||||||
|
|
||||||
|
`SELECT * FROM timescaledb_information.jobs`
|
||||||
|
|
||||||
### Continuous aggregates (WIP)
|
### Continuous aggregates (WIP)
|
||||||
|
|
||||||
<https://www.tigerdata.com/docs/use-timescale/latest/continuous-aggregates/create-a-continuous-aggregate>
|
<https://www.tigerdata.com/docs/use-timescale/latest/continuous-aggregates/create-a-continuous-aggregate>
|
||||||
|
|
||||||
* CREATE MATERIALIZED VIEW
|
* CREATE MATERIALIZED VIEW
|
||||||
* SELECT add_continuous_aggregate_policy
|
* CALL add_continuous_aggregate_policy
|
||||||
* supprimer les "vieilles" données de mesure_ng
|
* supprimer les "vieilles" données de mesure_ng (add_retention_policy ?)
|
||||||
|
|
||||||
|
#### Exemples
|
||||||
|
|
||||||
|
##### Gauges
|
||||||
|
|
||||||
|
CREATE MATERIALIZED VIEW sensor_hourly
|
||||||
|
WITH (timescaledb.continuous)
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
time_bucket('1 hour', time) AS bucket,
|
||||||
|
sensor_id,
|
||||||
|
average(
|
||||||
|
time_weight('linear', "date", valeur)
|
||||||
|
) AS moyenne_temporelle,
|
||||||
|
percentile_agg(value) AS pct
|
||||||
|
FROM sensor_data
|
||||||
|
GROUP BY bucket, sensor_id;
|
||||||
|
|
||||||
|
Puis
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
bucket,
|
||||||
|
sensor_id,
|
||||||
|
approx_percentile(0.95, pct) AS p95,
|
||||||
|
approx_percentile(0.99, pct) AS p99
|
||||||
|
FROM sensor_hourly;
|
||||||
|
|
||||||
|
##### Index
|
||||||
|
|
||||||
|
delta(counter_agg(time, value))
|
||||||
Loading…
Reference in New Issue
Block a user