-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
40 lines (27 loc) · 1.3 KB
/
schema.sql
File metadata and controls
40 lines (27 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- sudo -u postgres psql -d metricsdb
-- CREATE EXTENSION postgis;
CREATE TABLE IF NOT EXISTS metrics (
time timestamptz NOT NULL,
device_id varchar(12) NOT NULL,
location geography(pointz,4326), -- longitude, latitude, altitude
registry boolean, -- location source == SOURCE_REGISTRY
gateway_id varchar(28),
sf smallint, -- spreading factor
bw integer, -- bandwidth (Hz)
rssi real, -- Received Signal Strength Indication (dBm)
snr real, -- Signal to Noise Ratio (dB)
c_rate char(3), -- coding rate
airtime_us integer, -- airtime in microseconds
freq integer, -- frequency (Hz)
chan_idx smallint, -- channel index
chan_rssi real, -- channel rssi (dBm)
f_cnt integer,
f_port smallint,
frm_payload bytea,
pl jsonb
) PARTITION BY RANGE (time);
CREATE INDEX IF NOT EXISTS metrics_time_idx ON metrics(time);
CREATE INDEX IF NOT EXISTS metrics_pl_idx ON metrics USING GIN(pl);
-- Weekly partioning example:
-- CREATE TABLE metrics_2021_11_29 PARTITION OF metrics FOR VALUES FROM ('2021-11-29') TO ('2021-12-06');
-- CREATE TABLE metrics_2021_12_06 PARTITION OF metrics FOR VALUES FROM ('2021-12-06') TO ('2021-12-13');