🚀 Setting Up PostgreSQL for Fast TDD with Docker

🚀 Setting Up PostgreSQL for Fast TDD with Docker

If you're practicing Test-Driven Development (TDD), a fast, isolated, and disposable database is essential. Here's a quick guide to running PostgreSQL in Docker, optimized for testing ⚡️

🐳 Docker Setup

services:
  postgres-test:
    image: postgres:16.8-alpine
    container_name: postgres-test
    ports:
      - '5432:5432'
    environment:
      POSTGRES_USER: testuser
      POSTGRES_PASSWORD: testpassword
      POSTGRES_DB: minicrm
    tmpfs:
      - /var/lib/postgresql/data:rw
    command:
      [
        'postgres',
        '-c', 'fsync=off',
        '-c', 'full_page_writes=off',
        '-c', 'synchronous_commit=off',
      ]
    restart: 'no'        

⚙️ Why This Works for TDD

  • Ephemeral & fast: tmpfs keeps data in memory – super fast and wiped after each run.
  • Performance-tuned:
  • fsync=off – Skips disk flush.
  • synchronous_commit=off – instant commits.
  • full_page_writes=off – less I/O.
  • Safe for testing: Not production-safe, but perfect for tests where speed > durability.

🧪 Use it in CI/CD or local testing to ensure fast feedback loops and clean environments.

#TDD #Docker #PostgreSQL #Testing #SoftwareEngineering #DevOps #Backend #NodeJS #FullStack #CI #CleanCode #DeveloperTools #JavaScript

To view or add a comment, sign in

More articles by Ashik Sarkar

Explore content categories