Files
laboratori-cloud/labs/lab-05-database/reference/postgresql-commands.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.6 KiB

Reference: PostgreSQL Commands per Lab 05

Comandi Utili

Connessione

# Connessione base
docker exec lab05-db psql -U lab05_user -d lab05_db

# Connessione con host specificato
docker exec lab05-app psql -h db -U lab05_user -d lab05_db

# Esegui comando singolo
docker exec lab05-db psql -U lab05_user -d lab05_db -c "SELECT version();"

Operazioni Database

-- Crea database
CREATE DATABASE test_db;

-- Lista database
\l

-- Cambia database
\c test_db

-- Droppia database
DROP DATABASE test_db;

Operazioni Tabelle

-- Crea tabella
CREATE TABLE test_table (
    id SERIAL PRIMARY KEY,
    name TEXT,
    value INTEGER
);

-- Lista tabelle
\dt

-- Descrivi tabella
\d test_table

-- Droppia tabella
DROP TABLE test_table;

DML

-- Insert
INSERT INTO test_table (name, value) VALUES ('test', 42);

-- Select
SELECT * FROM test_table;

-- Update
UPDATE test_table SET value = 100 WHERE name = 'test';

-- Delete
DELETE FROM test_table WHERE name = 'test';

Utility

# Verifica PostgreSQL pronto
docker exec lab05-db pg_isready -U lab05_user

# Backup database
docker exec lab05-db pg_dump -U lab05_user lab05_db > backup.sql

# Ripristina database
cat backup.sql | docker exec -i lab05-db psql -U lab05_user lab05_db

Variabili Ambiente PostgreSQL

Variabile Descrizione Default
POSTGRES_DB Nome database postgres
POSTGRES_USER Utente creato -
POSTGRES_PASSWORD Password utente -
POSTGRES_INITDB_ARGS Argomenti initdb -
PGDATA Data directory /var/lib/postgresql/data