Postgres Setup
This documents tells you how to setup Postgres and PgAdmin for 2nd + 3rd semester on you local machine. The two applications, Postgres and PgAdmin both run in isolated Docker Containers. Postgres as a Database Server and PgAdmin as a Database Client. You will launch PgAdmin through a browser.
Docker Desktop. If you are installing on Windows, you might need to update WSL. A message with instructions will show if necessary during installation. If so, open the PowerShell as Administrator and type:
wsl --install
Find a suitable spot on your harddisk. Could be:
C:\Users\<YourUsername>\Documents\Postgres
Open a blank file named docker-compose.yml
in this folder and paste this into it - and save:
# Localhost Docker Compose fil for 2+3. semester på datamatiker uddannelsen
# Opretter to containere:
# db: Postgresql data base server som kører på port 5432
# pgadmin: Webbaseret interface til brug af Postgres. Den tilgås på port 8080
services:
db:
image: postgres:16.2
container_name: db
restart: unless-stopped
mem_limit: 1536MB
mem_reservation: 1024MB
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: appdb # optional: default DB
TZ: Europe/Copenhagen
volumes:
- ./data:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
pgadmin:
image: dpage/pgadmin4:latest
container_name: pgadmin
restart: unless-stopped
mem_reservation: 512MB
mem_limit: 1024MB
depends_on:
db:
condition: service_healthy
environment:
PGADMIN_DEFAULT_EMAIL: admin@cphbusiness.dk
PGADMIN_DEFAULT_PASSWORD: 1234
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False' # skip extra prompt (dev only)
PGADMIN_CONFIG_MAX_LOGIN_ATTEMPTS: 0 # disable lockout on failed logins
TZ: Europe/Copenhagen
volumes:
- ./pgadmin-data:/var/lib/pgadmin # named volume, persists pgAdmin config
ports:
- "8080:80"
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://localhost:80/misc/ping || exit 1"]
interval: 10s
timeout: 5s
retries: 10
volumes:
pgadmin-data:
Open a terminal / gitBash and navigate to the folder where you created the docker-compose.yml
file. Run the following command to start the containers:
docker-compose up -d
This command will download the necessary Docker images and start the Postgres and PgAdmin containers in detached mode. You can check the status of the containers with:
docker-compose ps
Also, you should be able to see the two running containers in Docker Desktop.
localhost:8080
- login: admin@cphbusiness.dk (see docker-compose.yml)
- password: 1234 (see docker-compose.yml)
- Choose: Server -> Register -> Server
On Register - Server dialogue:
On General tab:
- Name: localhost
On Connection tab:
- Host name/address: db
- Port: 5432
- username: postgres
- password: postgres
To simplify the UI, you can hide unused menus here:
- File -> Preferences -> Nodes
You can easily hide these guys:
docker compose down
(-v) // remove volumes
docker compose down -v
sudo rm -rf ./data
- Check if all containers are running with
docker ps -a
- Check if all env variables are set in .env file and are correct
- Check if docker compose has read all environment variables with
docker-compose config
- Check the logs of the individual container with
docker logs <container_name>
ordocker logs --follow <container_name>
On a few laptops, Docker Desktop will not work. The problems can be hard to find - but these two areas are usually the case:
A. Problems with hyper-V - need to be activated in your BIOS
B. Problems with WSL. In the WSL case - it might help to do this:
- Uninstall the current Docker Desktop.
- Remove any .docker folder from your user directory.
- Clean the %temp% folder.
- Unregister docker-desktop using WSL.
- Run wsl –update.
- Reinstall Docker Desktop.
- Restart Windows.
- Make sure WSL Ubuntu is running (check in powershell)
- Start Docker Desktop
- PostgreSQL for database
- pgAdmin for database management
- Docker for containerization
- Docker Compose for container orchestration.