Skip to content

Instantly share code, notes, and snippets.

@rponte
Created June 17, 2020 20:11
Show Gist options
  • Select an option

  • Save rponte/c3637d488b38ce0c39df76d2c6b34f79 to your computer and use it in GitHub Desktop.

Select an option

Save rponte/c3637d488b38ce0c39df76d2c6b34f79 to your computer and use it in GitHub Desktop.
Docker-compose: PostgreSQL and PgAdmin
# Use postgres/example user/password credentials
version: '3.1'
services:
db:
image: "postgres:10.6"
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
volumes:
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
- ./bootstrap:/docker-entrypoint-initdb.d
pgadmin:
image: adminer
restart: always
ports:
- 8080:8080
volumes:
database-data: # named volumes can be managed easier using docker-compose
@rponte
Copy link
Author

rponte commented Jun 29, 2021

Running PostgreSQL 13.x container via command line:

docker run --name cdc-postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d postgres:13.3

We can start and stop the container as well:

docker container start cdc-postgres
docker container stop cdc-postgres

@rponte
Copy link
Author

rponte commented Dec 21, 2022

Running pg_activity to monitoring Postgres instance:

image

Just run the commands below to install in the container where the postgres is running:

docker-compose exec <pg_server_name> bash # or docker exec -i -t postgres bash
apt update && apt install pg-activity && pg_activity -U postgres

For more details, see this Reddit comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment