PostgreSQL Cheat Sheet
Published on 29 Apr 2021
PostgreSQL Cheat Sheet
Basic commands
\l -- list databases
\dg -- list roles/groups
\dt -- list of tables
\c __DB__ -- usr or connect to a database
\du+ -- list user accounts (roles)
User and permissions management
ALTER USER "postgres" WITH PASSWORD '__PASS__';
CREATE USER __USER__ WITH PASSWORD '__PASS__'
CREATE ROLE __USER__ WITH SUPERUSER LOGIN PASSWORD '__PASS__';
CREATE DATABASE __DATABASE__ WITH OWNER __USER__ ENCODING 'utf-8';
GRANT ALL PRIVILEGES ON DATABASE __DATABASE__ to __USER__;
GRANT ALL PRIVILEGES ON TABLE __TABLE__ TO __USER__; -- pg8
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO __USER__; -- pg9
CREATE USER stusr WITH SUPERUSER LOGIN PASSWORD 'phdy.lt_2'; --phdy.lt!2
CREATE ROLE stuser WITH SUPERUSER LOGIN PASSWORD 'phdy.lt_2';
CREATE DATABASE searchtelligence WITH OWNER stuser ENCODING 'utf-8';
GRANT ALL PRIVILEGES ON DATABASE searchtelligence to stuser;
all tags
IDE architecture" cli crontab crypto csv database docker editor error exceptions fastapi ffmpeg filename git go history http iteration javascript linux logging me mysql numpy orm pdo pentaho php postgres python random rename rsync rust selenium server solana sql sqlite ssh typescript user w3m wordpress