Skip to content

Commit 02c7dad

Browse files
authored
Merge pull request #1018 from CodeForPhilly/main
reconcile main w staging
2 parents 5306464 + a7aa7b7 commit 02c7dad

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

data/Dockerfile-timescale

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM postgres:16-bullseye
2+
3+
ENV POSTGIS_MAJOR=3
4+
ENV POSTGIS_VERSION=3.5.0+dfsg-1.pgdg110+1
5+
ENV TIMESCALE_MAJOR=2
6+
ENV TIMESCALE_MINOR=17
7+
8+
RUN apt-get update \
9+
&& apt-get install -y --no-install-recommends lsb-release curl gnupg apt-transport-https wget \
10+
# ca-certificates: for accessing remote raster files;
11+
# fix: https://github.com/postgis/docker-postgis/issues/307
12+
ca-certificates \
13+
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \
14+
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts \
15+
# Add timescale repository and key
16+
&& echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $(lsb_release -c -s) main" \
17+
| tee /etc/apt/sources.list.d/timescaledb.list \
18+
&& wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey \
19+
| gpg --dearmor -o /etc/apt/trusted.gpg.d/timescaledb.gpg \
20+
# Install timescaledb
21+
&& apt-get update \
22+
&& apt-get install -y --no-install-recommends timescaledb-$TIMESCALE_MAJOR-postgresql-$PG_MAJOR="$TIMESCALE_MAJOR.$TIMESCALE_MINOR*" postgresql-client-$PG_MAJOR \
23+
# Remove temporary files
24+
&& rm -rf /var/lib/apt/lists/* \
25+
&& rm -f /etc/apt/trusted.gpg.d/timescaledb.gpg
26+
27+
28+
RUN mkdir -p /docker-entrypoint-initdb.d
29+
30+
# Set up TimescaleDB extension during database initialization
31+
RUN echo "shared_preload_libraries='timescaledb'" >> /usr/share/postgresql/postgresql.conf.sample

data/docker-compose.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ services:
6161
context: .
6262
dockerfile: Dockerfile-pg
6363
environment:
64-
- PGPORT=5433
65-
- POSTGRES_PASSWORD
64+
PGPORT: 5433
65+
POSTGRES_PASSWORD:
6666
restart: always
6767
ports:
6868
- '5433:5433'
@@ -74,5 +74,24 @@ services:
7474
extra_hosts:
7575
- host.docker.internal:host-gateway
7676

77+
postgres-timescale:
78+
container_name: cagp-postgres-timescale
79+
build:
80+
context: .
81+
dockerfile: Dockerfile-timescale
82+
environment:
83+
PGPORT: 5434
84+
POSTGRES_PASSWORD:
85+
restart: always
86+
ports:
87+
- '5434:5434'
88+
volumes:
89+
- timescale_database_volume:/var/lib/postgresql/data
90+
- ./init_pg_timescale.sql:/docker-entrypoint-initdb.d/init_pg.sql
91+
- /etc/timezone:/etc/timezone:ro
92+
- /etc/localtime:/etc/localtime:ro
93+
extra_hosts:
94+
- host.docker.internal:host-gateway
7795
volumes:
7896
database_volume:
97+
timescale_database_volume:

data/init_pg_timescale.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE DATABASE vacantlotdb;
2+
\c vacantlotdb;
3+
CREATE EXTENSION postgis;
4+
CREATE EXTENSION pg_stat_statements;
5+
CREATE EXTENSION timescaledb;

docs/SETUP/BACK_END.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ To stop the postgres container run:
118118
docker compose down postgres
119119
```
120120

121+
### PostgreSQL Extensions
122+
123+
We use Postgres extensions for GIS and time series functionality not included in base Postgres.
124+
125+
#### PostGIS
126+
[PostGIS](https://postgis.net/) is an open-source extension for PostgreSQL that adds support for spatial and geographic data types and functions. It enables the storage, querying, and analysis of location-based data directly within the database, replacing the need for many external tools and libraries.
127+
128+
#### Timescale DB
129+
[TimescaleDB](https://docs.timescale.com/) is an open-source relational database built on PostgreSQL, optimized for handling time-series data efficiently.
130+
131+
At the core of TimescaleDB are hypertables, which partition data across time for efficient querying. Hypertables behave like normal Postgres tables, but are optimized for querying data based on timestamps. For our use case, hypertables simplify data management by automatically creating monthly partitions, replacing our previous method of manually creating a separate schema for each month.
132+
133+
#### pg_stat_statements
134+
135+
The [pg_stat_statements](https://www.postgresql.org/docs/current/pgstatstatements.html) extension provides detailed statistics on query performance, helping to identify slow or resource-intensive queries. It tracks execution counts, execution times, and rows returned, making it a useful tool for analyzing slow or problematic queries.
136+
121137
## Python Development
122138

123139
You can set up your local Python environment so you can develop and run the backend `script.py` and create and run unit tests outside of Docker. Build your local environment to match what is defined in the `Dockerfile`. Install the same python version as is in the Dockerfile, using `pyenv` to manage multiple distributions if needed. Use `pipenv` to create a virtual environment. Install the pip dependencies that are defined in the `Pipfile` into your virtual environment. Install the executables with `apt-get`. Now you can develop in Python in your terminal and IDE and run unit tests with `pytest`.

0 commit comments

Comments
 (0)