This example uses ...
-
Djangoas the “glue” between web browsers and a database1 -
Postgreswith extensionTimescaleDBas the web application database2 -
Celeryas a task queue powered byRedis
Tip
If you have any trouble getting setup, feel free to ask a question at django-timescaledb-example/discussions
-
Install
Postgres8 and thusTimescaleDB8
Important
For Windows try tporadowski/redis or zkteco-home/redis-windows. Celery is used alongside Redis as a task queue & may not run in which case you'll have to adapt **/tasks.py for Bogdanp/dramatiq
-
Install this project's
Pythondependencies via ...poetry install
-
Create a
.envfile from.env.distto store credentials ...cp .env.dist .env
Warning
Create a complex secret key10 if you intend to deploy this web application
-
Create a
TimescaleDBdatabase with userdjangovia thePostgresCLI ...sh shell/createdb.sh
Important
For Windows adapt shell/createdb.sh for Command Prompt or PowerShell
Warning
Create a new role with a password if you go on to do something with this database
-
Create a superuser to access the
adminsite ...poetry run python manage.py createsuperuser
-
Launch
Django,Redis&Celery...honcho start
Tip
Go to http://localhost:8000 & you should see a running web application
- Re-launch the database server ...
pg_ctl start -D .db/- Launch a shell within your virtual environment so you don't need
poetry run** to runDjangocommands likepoetry run python manage.py ......
poetry shellFootnotes
Footnotes
-
To display a web page it asks a database for the data it needs to render files that the browser interprets (HTML, CSS & JavaScript) so it can display a user interface ↩
-
TimescaleDBis an extension to thePostgresdatabase which grants it timeseries capabilities.Postgreswasn't designed to handle timeseries workloads in which data is infrequently inserted and frequently queried in bulk.TimescaleDBadaptsPostgresvia "hypertables" which enable compression of many rows into "chunks" which are indexed by timestamps. Consequently, queries on ranges of timestamps are faster sincePostgrescan search "chunks" instead of rows & storage is cheaper. By compressing,TimescaleDBtrades insert performance for query performance. ↩ -
I use
git clone...git clone git@github.com:rdmolony/rdmolony.github.io.git... since I prefer to authenticate with
GitHubviaSSH↩ -
I use
nix...
↩nix profile install nixpkgs#python3 -
I use
nix...nix profile install nixpkgs#pipxWhy not use
pip?Pythonships withpipwhich installs dependencies "globally" which means that you can't easily install the same 3rd party library twice ↩ -
I use
pipx...
↩pipx install poetry -
I use
pipx...
↩pipx install honcho -
I use
nix...
↩ ↩2nix profile install --impure --expr 'with import <nixpkgs> {}; pkgs.postgresql.withPackages (p: [ p.timescaledb ])' -
I use
nix...
↩nix profile install nixpkgs#redis -
Generate a
SECRET_KEY...poetry run python -c " from django.core.management.utils import get_random_secret_key print(get_random_secret_key()) "... & copy it into
.env↩