Avatar
Fernando Vásquez is an electronics engineer and software developer currently based in the world. He occasionally blogs about Python and Android programming.

PostgreSQL Cheat Sheet

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