SELECT usename, usecreatedb, usesuper, usecatupd FROM pg_user;
List DBA Accounts
SELECT usename FROM pg_user WHERE usesuper IS TRUE;
Check if Current User is Superuser
SELECT current_setting('is_superuser')='on';
Current Database
SELECT current_database();
List Databases
SELECT datname FROM pg_database;
List Tables
SELECT c.relname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid);
List Columns
SELECT relname, A.attname FROM pg_class C, pg_namespace N, pg_attribute A, pg_type T WHERE (C.relkind='r') AND (N.oid=C.relnamespace) AND (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum>0) AND (NOT A.attisdropped) AND (N.nspname ILIKE 'public');
Find Tables from Column Name
#If you want to list all the table names that contain a column LIKE'%password%':SELECT DISTINCT relname FROM pg_class C, pg_namespace N, pg_attribute A, pg_type T WHERE (C.relkind='r') AND (N.oid=C.relnamespace) AND (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum>0) AND (NOT A.attisdropped) AND (N.nspname ILIKE 'public') AND attname LIKE '%password%';
Hostname, IP Address
#Returns db server IP address (ornullifusinglocalconnection) SELECT inet_server_addr();#Returns db server portSELECT inet_server_port();
Create Users (PRIV)
CREATEUSERtest1PASSWORD'pass1';#Grant some privs at the same timeCREATEUSERtest1PASSWORD'pass1' CREATEUSER;