PostgreSQL error: database does not exist

FATAL:  database "gianluca" does not exist

You connected to the cluster successfully, but asked for a database that isn't there. When the "missing database" in the message is your own username, nothing is broken: psql simply defaults the database name to the user name when you don't specify one.

What this error means

A PostgreSQL server (cluster) hosts multiple databases; every connection targets exactly one. If the requested name doesn't exist on the cluster you actually reached, you get this FATAL. Both halves of that sentence cause confusion:

Common causes

How to diagnose it

# Cosa c'è davvero su questo cluster:
psql -h HOST -p 5432 -U USER -d postgres -c '\l'

Connecting to the always-present postgres maintenance database and listing what exists answers both questions at once: whether you're on the right cluster, and what the database is actually called.

How to fix it

🔍 The twin error: role does not exist — same defaulting mechanism, on the user name side.