Files
laboratori-cloud/labs/lab-05-database/how-to-guides/connect-to-postgresql.md
Luca Sacchi Ricciardi f8544afe35 docs(06-02): create Diátaxis documentation for Lab 05 Database & RDS
Documentation (6 files, 1500+ lines):
Tutorials (3):
- 01-deploy-rds-database.md: Deploy PostgreSQL in private network
- 02-data-persistence.md: Data persistence with named volumes
- 03-security-compliance.md: INF-01/02/03/04 compliance

How-to Guides (1):
- connect-to-postgresql.md: Connection methods

Reference (1):
- postgresql-commands.md: PostgreSQL command reference

Explanation (1):
- database-rds-parallels.md: Docker↔RDS parallels with architecture diagrams

Key concepts:
- PostgreSQL container → RDS Instance
- Private network → VPC Private Subnet
- Named volume → EBS volume
- Resource limits → DB instance class

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 17:41:29 +02:00

1.1 KiB

How-to: Connettersi a PostgreSQL in Docker

Come connettersi al database

Da container nella stessa rete

docker exec lab05-app psql -h db -U lab05_user -d lab05_db

Se devi connetterti dall'host, aggiungi temporaneamente:

# docker-compose.yml
ports:
  - "127.0.0.1:5432:5432"

Poi:

psql -h 127.0.0.1 -U lab05_user -d lab05_db

Con pgAdmin o altri tool

  1. Configura connection string:
host=127.0.0.1 port=5432 user=lab05_user password=lab05_password dbname=lab05_db
  1. Oppure usa PostgreSQL URI:
postgresql://lab05_user:lab05_password@127.0.0.1:5432/lab05_db

Risoluzione problemi

Connection refused

Il database è in rete privata. Devi connetterti da container nella stessa rete:

# Prima entra in un container
docker exec -it lab05-app sh

# Poi connettiti
psql -h db -U lab05_user -d lab05_db

Password authentication failed

Verifica le credenziali in docker-compose.yml:

grep POSTGRES_PASSWORD docker-compose.yml