initdb -D /var/lib/postgresql/dataRun once when creating a new cluster.
Server lifecycle, utility commands, grants, monitoring, and cluster maintenance tasks.
Start, stop, and inspect PostgreSQL server processes.
initdb -D /var/lib/postgresql/dataRun once when creating a new cluster.
pg_ctl -D /var/lib/postgresql/data -l logfile startSee summary for usage details.
pg_ctl -D /var/lib/postgresql/data stop -m fastSee summary for usage details.
pg_ctl -D /var/lib/postgresql/data restartSee summary for usage details.
pg_isready -h localhost -p 5432 -d appdbSee summary for usage details.
SHOW data_directory;See summary for usage details.
SHOW config_file;See summary for usage details.
SELECT pg_reload_conf();See summary for usage details.
Cluster-level utilities for common admin tasks.
createdb -h localhost -U postgres appdbSee summary for usage details.
dropdb -h localhost -U postgres appdbSee summary for usage details.
createuser -h localhost -U postgres --interactiveSee summary for usage details.
dropuser -h localhost -U postgres olduserSee summary for usage details.
reindexdb -h localhost -U postgres -d appdb --concurrentlySee summary for usage details.
vacuumdb -h localhost -U postgres -d appdb --analyze-in-stagesSee summary for usage details.
CLUSTER orders USING idx_orders_created_at;Can improve locality for certain access patterns.
ANALYZE public.users;See summary for usage details.
Catalog views and functions used in ops and debugging.
SELECT pid, usename, application_name, state, query
FROM pg_stat_activity
ORDER BY backend_start;See summary for usage details.
SELECT pg_cancel_backend(pid)
FROM pg_stat_activity
WHERE pid = 12345;See summary for usage details.
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE pid = 12345;See summary for usage details.
SELECT pid, relation::regclass, mode, granted
FROM pg_locks
ORDER BY relation, mode;See summary for usage details.
SELECT pg_size_pretty(pg_database_size('appdb'));See summary for usage details.
SELECT pg_size_pretty(pg_total_relation_size('public.users'));See summary for usage details.
SELECT * FROM pg_stat_bgwriter;See summary for usage details.
SELECT schemaname, relname, indexrelname, idx_scan
FROM pg_stat_user_indexes
ORDER BY idx_scan ASC, relname;See summary for usage details.
Ownership, grants, and privilege management.
GRANT SELECT ON TABLE public.users TO readonly;See summary for usage details.
GRANT USAGE ON SCHEMA public TO readonly;See summary for usage details.
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO appuser;See summary for usage details.
REVOKE UPDATE ON TABLE public.users FROM readonly;See summary for usage details.
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO appuser;See summary for usage details.
ALTER TABLE public.users OWNER TO appuser;See summary for usage details.
SET ROLE readonly;See summary for usage details.
RESET ROLE;See summary for usage details.