getting a full history of all sql queries run on the database sql server code example
Example 1: list all permissions on a table in postgres
SELECT grantee, privilege_type
FROM information_schema.role_table_grants
WHERE table_name='mytable'
Example 2: postgresql print sessions using the database
select pid as process_id,
usename as username,
datname as database_name,
client_addr as client_address,
application_name,
backend_start,
state,
state_change
from pg_stat_activity;