SELECT
r.rolname,
r.rolsuper,
r.rolinherit,
r.rolcreaterole,
r.rolcreatedb,
r.rolcanlogin,
r.rolconnlimit, r.rolvaliduntil,
ARRAY(SELECT b.rolname
FROM pg_catalog.pg_auth_members m
JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)
WHERE m.member = r.oid) as memberof
, r.rolreplication
FROM pg_catalog.pg_roles r
ORDER BY 1;
Postgres
Basic commands
-
List all available databases:
\\l oder \\list
-
List all tables in the database:
\\dt
-
Describe specified table:
\\d+ <table>
-
Connect via command line:
psql -U <user> -h <host> <db-instance>
SQL
-
Select element in HSTORE (e.g. for SELECT):
<HSTORE column> → '<key in HSTORE>'
-
Execute a stored procedure with a custom type:
SELECT mySproc(ROW(col1, col2, col3, col4, col5)::my_custom_type)
-
Find current transactions:
SELECT * FROM pg_stat_activity
-
Remove all tables inside a schema:
DROP SCHEMA public CASCADE; CREATE SCHEMA public;
-
Create static table:
SELECT * FROM (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t(num, descr);
Administrative
-
Find out about the current roles and rights: