Skip to content

Commit

Permalink
Added grafana and metabase to docker demo postgres seed.
Browse files Browse the repository at this point in the history
  • Loading branch information
riclolsen committed Sep 15, 2024
1 parent 8641865 commit c8b3da7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions demo-docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:

# Postgresql/TimescaleDB historian. Without auth!
timescaledb:
image: timescale/timescaledb:latest-pg14
image: timescale/timescaledb:latest-pg16
container_name: jsdemo_timescaledb
restart: unless-stopped
command: postgres -c shared_preload_libraries=timescaledb
Expand All @@ -59,7 +59,7 @@ services:

# Postgresql/TimescaleDB Process SQL hist files
process_pg_hist:
image: timescale/timescaledb:latest-pg14
image: timescale/timescaledb:latest-pg16
container_name: jsdemo_process_pg_hist
command: /sql/process_pg_hist.sh
restart: unless-stopped
Expand Down
32 changes: 29 additions & 3 deletions demo-docker/postgres_seed/create_tables.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@

-- psql -h 127.0.0.1 -U postgres -w -f create_tables.sql

CREATE DATABASE "grafanaappdb"
WITH OWNER "postgres"
ENCODING 'UTF8'
-- LC_COLLATE = 'en-US.UTF8' -- can cause errors sometimes
-- LC_CTYPE = 'en-US.UTF8'
TEMPLATE template0;

CREATE DATABASE "metabaseappdb"
WITH OWNER "postgres"
ENCODING 'UTF8'
-- LC_COLLATE = 'en-US.UTF8' -- can cause errors sometimes
-- LC_CTYPE = 'en-US.UTF8'
TEMPLATE template0;

CREATE DATABASE "json_scada"
WITH OWNER "postgres"
ENCODING 'UTF8'
LC_COLLATE = 'en_US.UTF-8'
LC_CTYPE = 'en_US.UTF-8'
-- LC_COLLATE = 'en-US.UTF8' -- can cause errors sometimes
-- LC_CTYPE = 'en-US.UTF8'
TEMPLATE template0;

\c json_scada

CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
-- CREATE EXTENSION IF NOT EXISTS timescaledb_toolkit CASCADE;

-- after timescaledb updates
-- ALTER EXTENSION timescaledb UPDATE;
-- ALTER EXTENSION timescaledb_toolkit UPDATE;

-- disable timescaledb telemetry
ALTER SYSTEM SET timescaledb.telemetry_level=off;

-- create tables

Expand All @@ -36,6 +58,10 @@ comment on column hist.flags is 'Bit mask 0x80=value invalid, 0x40=Time tag at s

-- timescaledb hypertable, partitioned by day
SELECT create_hypertable('hist', 'time_tag', chunk_time_interval=>86400000000);
-- data retention policy (older data will be deleted)

-- SELECT add_drop_chunks_policy('hist', INTERVAL '45 days'); -- this is for timescaledb < 2.0
SELECT add_retention_policy('hist', INTERVAL '45 days');

-- DROP TABLE realtime_data;
CREATE TABLE IF NOT EXISTS realtime_data (
Expand Down Expand Up @@ -87,4 +113,4 @@ GRANT SELECT ON grafana_realtime TO grafana;

CREATE USER json_scada WITH PASSWORD 'json_scada';
GRANT CONNECT ON DATABASE json_scada TO json_scada;
GRANT all ON realtime_data, hist TO json_scada;
GRANT all ON realtime_data, hist, grafana_hist TO json_scada;
5 changes: 4 additions & 1 deletion demo-docker/postgres_seed/init-user-db.sh
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
psql -h 127.0.0.1 -U postgres -w -f create_tables.sql
psql -h 127.0.0.1 -U postgres -w -f create_tables.sql template1
psql -h 127.0.0.1 -U postgres -w -f metabaseappdb.sql metabaseappdb
psql -h 127.0.0.1 -U postgres -w -f grafanaappdb.sql grafanaappdb

0 comments on commit c8b3da7

Please sign in to comment.