@ -12,11 +12,11 @@ create extension pg_audit;
-- STATEMENT - The statement being logged
-- PARAMETER - If parameter logging is requested, they will follow the
-- statement
select current_user \gset
--
-- Create a superuser role that we know the name of for testing
CREATE USER super SUPERUSER;
ALTER ROLE super SET pg_audit.log = 'Role';
ALTER ROLE super SET pg_audit.log_level = 'notice';
-- Set pg_audit parameters for the current (super)user.
ALTER ROLE :current_user SET pg_audit.log = 'Role';
ALTER ROLE :current_user SET pg_audit.log_level = 'notice';
CREATE FUNCTION load_pg_audit( )
RETURNS VOID
LANGUAGE plpgsql
@ -31,7 +31,7 @@ $function$;
-- being loaded from shared_preload_libraries. Otherwise, the hooks
-- won't be set up and called correctly, leading to lots of ugly
-- errors.
\connect - sup er;
\connect - :current_us er;
select load_pg_audit();
load_pg_audit
---------------
@ -70,7 +70,7 @@ DROP TABLE test;
NOTICE: AUDIT: SESSION,2,1,DDL,DROP TABLE,TABLE,public.test,DROP TABLE test;,<not logged>
--
-- Create second test user
\connect - sup er
\connect - :current_us er
select load_pg_audit();
load_pg_audit
---------------
@ -241,7 +241,7 @@ UPDATE test3
WARNING: AUDIT: OBJECT,6,1,WRITE,INSERT,TABLE,public.test2,<previously logged>,<previously logged>
--
-- Change permissions of user 2 so that only object logging will be done
\connect - sup er
\connect - :current_us er
select load_pg_audit();
load_pg_audit
---------------
@ -328,7 +328,7 @@ DROP TABLE test3;
DROP TABLE test4;
--
-- Change permissions of user 1 so that session logging will be done
\connect - sup er
\connect - :current_us er
select load_pg_audit();
load_pg_audit
---------------
@ -376,7 +376,7 @@ INSERT INTO account (id, name, password, description)
VALUES (1, 'user1', 'HASH1', 'blah, blah');
--
-- Change permissions of user 1 so that only object logging will be done
\connect - sup er
\connect - :current_us er
select load_pg_audit();
load_pg_audit
---------------
@ -435,7 +435,7 @@ NOTICE: AUDIT: OBJECT,2,1,WRITE,UPDATE,TABLE,public.account,"UPDATE account
SET password = 'HASH2';",<not logged>
--
-- Change permissions of user 1 so that session relation logging will be done
\connect - sup er
\connect - :current_us er
select load_pg_audit();
load_pg_audit
---------------
@ -546,7 +546,7 @@ NOTICE: AUDIT: SESSION,5,1,WRITE,UPDATE,TABLE,public.account,"UPDATE account
SET password = 'HASH2';",<not logged>
--
-- Change back to superuser to do exhaustive tests
\connect - sup er
\connect - :current_us er
select load_pg_audit();
load_pg_audit
---------------
@ -751,12 +751,12 @@ NOTICE: AUDIT: SESSION,26,1,READ,SELECT,TABLE,public.test,"SELECT
(0 rows)
SELECT 1,
current_user ;
substring('Thomas' from 2 for 3) ;
NOTICE: AUDIT: SESSION,27,1,READ,SELECT,,,"SELECT 1,
current_user ;",<none>
?column? | current_user
----------+--------------
1 | super
substring('Thomas' from 2 for 3) ;",<none>
?column? | substring
----------+-----------
1 | hom
(1 row)
DO $$
@ -1054,3 +1054,18 @@ GRANT user1 TO user2;
NOTICE: AUDIT: SESSION,59,1,ROLE,GRANT ROLE,,,GRANT user1 TO user2;,<none>
REVOKE user1 FROM user2;
NOTICE: AUDIT: SESSION,60,1,ROLE,REVOKE ROLE,,,REVOKE user1 FROM user2;,<none>
DROP TABLE test.account_copy;
DROP TABLE test.test_insert;
DROP SCHEMA test;
DROP TABLE foo.bar;
DROP TABLE foo.baz;
DROP SCHEMA foo;
DROP TABLE hoge;
DROP TABLE account;
DROP TABLE account_role_map;
DROP USER user2;
NOTICE: AUDIT: SESSION,61,1,ROLE,DROP ROLE,,,DROP USER user2;,<none>
DROP USER user1;
NOTICE: AUDIT: SESSION,62,1,ROLE,DROP ROLE,,,DROP USER user1;,<none>
DROP ROLE auditor;
NOTICE: AUDIT: SESSION,63,1,ROLE,DROP ROLE,,,DROP ROLE auditor;,<none>