Login to PostgreSQL Shell
sudo -iu postgres psql
Useful commands:
l: List all databasesc DB_NAME: Connect to a specific databasedt: List all tables in the current databased TABLE_NAME: Show structure of a tabledu: List all database roles/userspassword USERNAME: Change password for a roleq: Quit psql shell
Example Session
sudo -iu postgres
psql
l # List databases
c mydatabase # Connect to your DB
dt # List tables
d mytable # Describe table structure
q # Quit
Connect to a Specific Database as a User
psql -h <host> -p <port> -U <username> -d <database>
-h <host>→ Hostname of the PostgreSQL server (e.g.,localhost)-p <port>→ Port (default:5432)-U <username>→ Database user-d <database>→ Database name to connect to
Key Locations
- Credentials:
/root/.cloudzy-creds - Config:
/etc/postgresql/*/main - Data:
/var/lib/postgresql - Logs:
/var/log/postgresql