Task-first Postgres and psql tasks.

Database & SQL

This page favors everyday Postgres tasks developers reach for repeatedly in local work, migrations, and troubleshooting.

psql
\l

Example: Run this after connecting with `psql` to see available databases on the current server.

Gotcha: This is a `psql` meta-command, not SQL. It works inside the `psql` client only.

\dt

Example: A quick inventory command when you need to see what tables are available in the connected database.

Gotcha: Like other backslash commands, this is for `psql`, not for application SQL execution.

Inspection
SELECT pg_size_pretty(pg_total_relation_size('users'));

Example: Useful for spotting unexpectedly large tables in local or staging environments.

Gotcha: Total relation size includes indexes and toast storage, not just raw table rows.

Queries
SELECT * FROM users LIMIT 10;

Example: Useful for quickly checking table contents without dumping the whole dataset.

Gotcha: Without `ORDER BY`, the first rows returned are not guaranteed to be meaningful or stable.

Commenting your code is like cleaning your bathroom you never want to do it, but it really does create a more pleasant experience for you and your guests.

Ryan Campbell

CodersTool Categories