amakarudze / django-playground

Try our tips to optimize Django queries by yourself

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gitguardian Engineering Blog Playground

Welcome to this playground. You can test all tips of 10 tips to optimize PostgreSQL queries in your Django project using this repo.

Quickstart

Requirements

To run this playground, you'll need

Usage

  1. Install virtualenv

You may need to install graphviz before

pipenv install -d
  1. Setup your environment

Copy the example env file

cp .env.example .env

Edit .env by setting a PostgreSQL password and a Django Secret Key.

  1. Activate your environment
pipenv shell
  1. Start your PostgreSQL container
docker compose up -d
  1. Open a notebook
./manage.py shell_plus --notebook

You are now ready to start ;)

Create DB dump

mkdir -p db_dump
pg_dump -h localhost -p $DATABASE_PORT -Fd $DATABASE_NAME -U $DATABASE_USER -Z0 -j 10 -f dumpdir
tar -cf - dumpdir | pigz > db_dump/dumpdir.tar.gz
cd db_dump
split -n 4 dumpdir.tar.gz dbdump --additional-suffix=.db.part

Load DB dump

cat db_dump/dbdump*.db.part > db_dump/dumpdir.tar.gz
mkdir -p dumpdir
pigz -dc db_dump/dumpdir.tar.gz | tar -C dumpdir --strip-components 1 -xf -
pg_restore -j 10 -Fd -O -h localhost -p $DATABASE_PORT -U $DATABASE_USER -d $DATABASE_NAME dumpdir

About

Try our tips to optimize Django queries by yourself

License:GNU General Public License v3.0


Languages

Language:Jupyter Notebook 92.0%Language:Python 7.9%Language:CSS 0.0%