Connection toolkitPostgreSQL
psql
Connect to PostgreSQL databases using the interactive terminal.
psql -U <user> -d <database>
psql workflows, schema changes, analytical queries, and admin tasks.
Connect to PostgreSQL databases using the interactive terminal.
psql -U <user> -d <database>
\l
View current connection details or list available databases.
\conninfo
CREATE SCHEMA
Provision databases and namespaces for isolation.
CREATE DATABASE <db_name>;
Enable extensions such as UUID generation or citext.
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
Add columns, constraints, or indexes to existing tables.
ALTER TABLE <table> ADD COLUMN <column> TEXT;
Retrieve rows with advanced filtering and window functions.
SELECT * FROM <table> WHERE status = 'active' ORDER BY created_at DESC LIMIT 50;
Bulk import or export table data using CSV or text formats.
\copy <table> FROM '<path>.csv' CSV HEADER;
UPDATE
DELETE
Modify rows within transactional blocks.
INSERT INTO <table> (<column1>,<column2>) VALUES ('<value1>','<value2>') RETURNING id;
pg_restore
Create logical backups and restore them to target instances.
pg_dump -Fc -f backup.dump -d <database>
ANALYZE
Maintain table statistics and reclaim storage.
VACUUM (VERBOSE, ANALYZE) <table>;
GRANT
Manage access control for users and roles.
ALTER ROLE <role> WITH LOGIN PASSWORD '<password>';