Skip to content

Commit

Permalink
Use a socket connection to the database in dev
Browse files Browse the repository at this point in the history
TCP has a measurable overhead for each DB query compared to the unix
socket.
https://momjian.us/main/blogs/pgblog/2012.html#June_6_2012
  • Loading branch information
francoisfreitag committed Jan 30, 2025
1 parent 01c75e5 commit 7e8268b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jobs:
image: postgis/postgis:15-master
env:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
volumes:
- /var/run/postgresql:/var/run/postgresql
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
Expand All @@ -46,6 +46,10 @@ jobs:
--health-retries 5
steps:
- name: Setup PostgreSQL environment
run: |
echo PGHOST=/var/run/postgresql >> $GITHUB_ENV
echo PGUSER=postgres >> $GITHUB_ENV
- name: 🐘 Non-durable PostgreSQL
run: |
psql <<SQL
Expand All @@ -54,10 +58,6 @@ jobs:
ALTER SYSTEM SET full_page_writes=off;
SQL
docker kill --signal=SIGHUP ${{ job.services.postgres.id }}
env:
PGPASSWORD: password
PGHOST: localhost
PGUSER: postgres
- uses: actions/checkout@v4.2.2
- name: 🌍 Install spatial libraries
run: sudo apt-get update && sudo apt-get install binutils build-essential libproj-dev gdal-bin
Expand All @@ -66,10 +66,6 @@ jobs:
psql <<SQL
CREATE DATABASE itou;
SQL
env:
PGPASSWORD: password
PGHOST: localhost
PGUSER: postgres
- name: 💂 Install Python
uses: actions/setup-python@v5
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ envs/secrets.env

# Config
docker-compose-prod.yml
docker/dev/postgres/
docker/prod/

# Project specific
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ services:
shm_size: 1g
volumes:
- postgres_data:/var/lib/postgresql/data
- type: bind
source: ${PWD}/docker/dev/postgres
target: /var/run/postgresql/
restart: unless-stopped
ports:
- "127.0.0.1:${POSTGRES_PORT_ON_DOCKER_HOST:-5432}:5432"
Expand Down
16 changes: 16 additions & 0 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ arguments pour se connecter à la base de données.
Les variables suivantes permet d’accéder à la base de données définie dans le
[docker-compose.yml](../docker-compose.yml) simplement avec la commande `psql`.

Deux options:

#### Socket UNIX

La plus performante, et devrait bien fonctionner sur les systèmes
[*nix](https://fr.wikipedia.org/wiki/Type_Unix).

```bash
export PGDATABASE=itou
export PGHOST="${PWD}/docker/dev/postgres"
export PGUSER=postgres
# La connexion par la socket est autorisée par défaut.
```

#### TCP

```bash
export PGDATABASE=itou
export PGHOST=localhost
Expand Down

0 comments on commit 7e8268b

Please sign in to comment.