Loading deploy/.env +3 −1 Original line number Diff line number Diff line PGDATA=/var/lib/postgresql/data/db-files/ INTERVAL=half-hour INTERVAL=hourly MAINTENANCE_INTERVAL=half-hour RETENTION_TIME=7 days POSTGRES_DB=ais deploy/docker-compose.postgresql.tmpl.yml +2 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ services: - POSTGRES_USER - PGDATA - INTERVAL - MAINTENANCE_INTERVAL - RETENTION_TIME networks: postgres-vessel-net: aliases: Loading rootfs/docker-entrypoint-initdb.d/vessel.sh +15 −9 Original line number Diff line number Diff line Loading @@ -54,8 +54,14 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E ON ais.location USING gist (shape); CREATE INDEX IF NOT EXISTS sidx_location_tstamp ON ais.location (tstamp); CREATE INDEX IF NOT EXISTS sidx_location_tstamp_desc ON ais.location (tstamp DESC); CREATE INDEX IF NOT EXISTS sidx_location_mmsi ON ais.location (mmsi); CREATE INDEX IF NOT EXISTS sidx_location_tstamp_mmsi ON ais.location (tstamp, mmsi); CREATE OR REPLACE FUNCTION ais.initialize_geom_and_dates() RETURNS TRIGGER Loading Loading @@ -116,12 +122,12 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E WHEN TAG IN ('CREATE TABLE') EXECUTE PROCEDURE on_create_table_create_trigger(); SELECT partman.create_parent('ais.location', 'tstamp', 'native', '${INTERVAL}', p_premake := 8); UPDATE partman.part_config SET infinite_time_partitions = true; SELECT cron.schedule('@${INTERVAL}', \$\$CALL partman.run_maintenance_proc(p_analyze := false)\$\$); SELECT partman.create_parent('ais.location', 'tstamp', 'native', '${INTERVAL}', p_premake := 3); UPDATE partman.part_config SET infinite_time_partitions = true, retention = '${RETENTION_TIME}', retention_keep_table = false; CREATE VIEW ais.last_20m AS SELECT DISTINCT ON (mmsi) * FROM ais.location WHERE tstamp > current_timestamp - interval '20 minutes' ORDER BY mmsi, tstamp DESC; SELECT cron.schedule('@${MAINTENANCE_INTERVAL}', \$\$CALL partman.run_maintenance_proc(p_analyze := false)\$\$); EOSQL No newline at end of file Loading
deploy/.env +3 −1 Original line number Diff line number Diff line PGDATA=/var/lib/postgresql/data/db-files/ INTERVAL=half-hour INTERVAL=hourly MAINTENANCE_INTERVAL=half-hour RETENTION_TIME=7 days POSTGRES_DB=ais
deploy/docker-compose.postgresql.tmpl.yml +2 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ services: - POSTGRES_USER - PGDATA - INTERVAL - MAINTENANCE_INTERVAL - RETENTION_TIME networks: postgres-vessel-net: aliases: Loading
rootfs/docker-entrypoint-initdb.d/vessel.sh +15 −9 Original line number Diff line number Diff line Loading @@ -54,8 +54,14 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E ON ais.location USING gist (shape); CREATE INDEX IF NOT EXISTS sidx_location_tstamp ON ais.location (tstamp); CREATE INDEX IF NOT EXISTS sidx_location_tstamp_desc ON ais.location (tstamp DESC); CREATE INDEX IF NOT EXISTS sidx_location_mmsi ON ais.location (mmsi); CREATE INDEX IF NOT EXISTS sidx_location_tstamp_mmsi ON ais.location (tstamp, mmsi); CREATE OR REPLACE FUNCTION ais.initialize_geom_and_dates() RETURNS TRIGGER Loading Loading @@ -116,12 +122,12 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E WHEN TAG IN ('CREATE TABLE') EXECUTE PROCEDURE on_create_table_create_trigger(); SELECT partman.create_parent('ais.location', 'tstamp', 'native', '${INTERVAL}', p_premake := 8); UPDATE partman.part_config SET infinite_time_partitions = true; SELECT cron.schedule('@${INTERVAL}', \$\$CALL partman.run_maintenance_proc(p_analyze := false)\$\$); SELECT partman.create_parent('ais.location', 'tstamp', 'native', '${INTERVAL}', p_premake := 3); UPDATE partman.part_config SET infinite_time_partitions = true, retention = '${RETENTION_TIME}', retention_keep_table = false; CREATE VIEW ais.last_20m AS SELECT DISTINCT ON (mmsi) * FROM ais.location WHERE tstamp > current_timestamp - interval '20 minutes' ORDER BY mmsi, tstamp DESC; SELECT cron.schedule('@${MAINTENANCE_INTERVAL}', \$\$CALL partman.run_maintenance_proc(p_analyze := false)\$\$); EOSQL No newline at end of file