Use PostgreSQL the Right Way!
Best practices and Tips on how to use and configure PostgreSQL in the best way.
4 min readAug 6, 2022
This post summarizes some situations and configurations I’ve had to adapt to work with the PostgreSQL database; let’s get to the tips.
Deploy PostgreSQL using Docker Compose:
How many times have you not had to build a quick test environment and have not had a database installed and configured for use, Docker is easy to do:
Create a docker-compose.yaml file with the content below:
version: '3'services:
postgres:
image: postgres:13.1
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "postgres", "-U", "root" ]
timeout: 45s
interval: 10s
retries: 10
restart: always
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=password
- APP_DB_USER=docker
- APP_DB_PASS=docker
- APP_DB_NAME=docker
volumes:
- ./db:/docker-entrypoint-initdb.d/
ports:
- 5432:5432
With docker-compose installed, run the command below:
docker-compose up
Your database can now be used!