
Cheatsheet containing Postgres Commands you need, Missing Anything? Kindly add a response or comment will add that 😄.
The following command connects to a database under a specific user. After pressing Enter PostgreSQL will ask for the password of the user.
psql -d database -U user -W
Once you are connected to a database, you can switch the connection to a new database under a user-specified by user. The previous connection will be closed. If you omit the user parameter, the current user is assumed.
\c dbname username
Lists available databases in the current PostgreSQL database server,
\l
Show table definition including indexes, constraints & triggers (psql)
\d TABLE_NAME
More detailed table definition including description and physical disk size (psql)
\d+
List tables from the current schema (psql)
\dt
To list all schemas of the currently connected database, you use the \dn command.
\dn
To list available functions in the current database, you use the \df command.
\df
To list available views in the current database, you use the \dv command.
\dv
To list all users and their assigned roles, you use \du command:
\du
List tables from all schemas
\dt *.*
List the tables in a specific schema
\dt <name-of-schema>.*
If you want to save time, type the previous command again. You can use \g Command to execute the previous command:
\g
To display command history, you use the \s command.
\s
If you want to save the command history to a file, you need to specify the file name followed the \s command as follows:
\s filename
In case you want to execute psql commands from a file, you use \i Command as follows:
\i filename
Export a table as CSV
\copy (SELECT * FROM __table_name__) TO 'file_path_and_name.csv' WITH CSV
Show table indexes (SQL)
SELECT * FROM pg_indexes WHERE tablename='__table_name__' AND
schemaname='__schema_name__';
Analyze a table and store the results in the pg_statistic system catalog (SQL)
ANALYZE [__table__]
Comment on table (SQL)
Comment on table employee is 'Stores employee records';
Comment on column (SQL)
Comment on column employee.ssn is 'Employee Social Security Number';
SELECT reltuples AS card FROM pg_class WHERE relname = '<table_name>';
SHOW max_connections;
SELECT sum(numbackends) FROM pg_stat_database;
EXPLAIN SELECT * FROM post LIMIT 50;
SELECT count(*) AS exact_count FROM myschema.mytable;
\l+
\l+ <database_name>
To know all available psql commands, you use the \? command.
\?
To get help on specific PostgreSQL statements, you use the \h command.
For example, if you want to know detailed information on ALTER TABLE statement, you use the following command:
\h ALTER TABLE
psql supports some types of output format and allows you to customize how the output is formatted on the fly.
\a Command switches from aligned to non-aligned column output.
\H Command formats the output to HTML format.
To quit psql, you use \q the command and press enter to exit psql.
\q

A comprehensive guide to essential SQL commands, joins, set operations, and best practices for efficient database querying and management.
Engineering![Setting Up Mac for Development [May 2026]](/_next/image?url=%2Fcontent%2Fblogs%2Fmac-setup-2026.png&w=3840&q=75)
The current toolkit and the AI coding stack I'd put on a fresh Mac today. A year after my 2025 setup.
Engineering
A deep, structured, research-anchored dive into UI/UX onboarding that synthesizes current best practices, psychology insights, expert research, and real product examples.
Engineering