@@ -12,11 +12,11 @@ create extension pg_audit;
1212-- STATEMENT - The statement being logged
1313-- PARAMETER - If parameter logging is requested, they will follow the
1414-- statement
15+ select current_user \gset
1516--
16- -- Create a superuser role that we know the name of for testing
17- CREATE USER super SUPERUSER;
18- ALTER ROLE super SET pg_audit.log = 'Role';
19- ALTER ROLE super SET pg_audit.log_level = 'notice';
17+ -- Set pg_audit parameters for the current (super)user.
18+ ALTER ROLE :current_user SET pg_audit.log = 'Role';
19+ ALTER ROLE :current_user SET pg_audit.log_level = 'notice';
2020CREATE FUNCTION load_pg_audit( )
2121 RETURNS VOID
2222 LANGUAGE plpgsql
@@ -31,7 +31,7 @@ $function$;
3131-- being loaded from shared_preload_libraries. Otherwise, the hooks
3232-- won't be set up and called correctly, leading to lots of ugly
3333-- errors.
34- \connect -super ;
34+ \connect -:current_user ;
3535select load_pg_audit();
3636 load_pg_audit
3737---------------
@@ -70,7 +70,7 @@ DROP TABLE test;
7070NOTICE: AUDIT: SESSION,2,1,DDL,DROP TABLE,TABLE,public.test,DROP TABLE test;,<not logged>
7171--
7272-- Create second test user
73- \connect -super
73+ \connect -:current_user
7474select load_pg_audit();
7575 load_pg_audit
7676---------------
@@ -241,7 +241,7 @@ UPDATE test3
241241WARNING: AUDIT: OBJECT,6,1,WRITE,INSERT,TABLE,public.test2,<previously logged>,<previously logged>
242242--
243243-- Change permissions of user 2 so that only object logging will be done
244- \connect -super
244+ \connect -:current_user
245245select load_pg_audit();
246246 load_pg_audit
247247---------------
@@ -328,7 +328,7 @@ DROP TABLE test3;
328328DROP TABLE test4;
329329--
330330-- Change permissions of user 1 so that session logging will be done
331- \connect -super
331+ \connect -:current_user
332332select load_pg_audit();
333333 load_pg_audit
334334---------------
@@ -376,7 +376,7 @@ INSERT INTO account (id, name, password, description)
376376 VALUES (1, 'user1', 'HASH1', 'blah, blah');
377377--
378378-- Change permissions of user 1 so that only object logging will be done
379- \connect -super
379+ \connect -:current_user
380380select load_pg_audit();
381381 load_pg_audit
382382---------------
@@ -435,7 +435,7 @@ NOTICE: AUDIT: OBJECT,2,1,WRITE,UPDATE,TABLE,public.account,"UPDATE account
435435 SET password = 'HASH2';",<not logged>
436436--
437437-- Change permissions of user 1 so that session relation logging will be done
438- \connect -super
438+ \connect -:current_user
439439select load_pg_audit();
440440 load_pg_audit
441441---------------
@@ -546,7 +546,7 @@ NOTICE: AUDIT: SESSION,5,1,WRITE,UPDATE,TABLE,public.account,"UPDATE account
546546 SET password = 'HASH2';",<not logged>
547547--
548548-- Change back to superuser to do exhaustive tests
549- \connect -super
549+ \connect -:current_user
550550select load_pg_audit();
551551 load_pg_audit
552552---------------
@@ -751,12 +751,12 @@ NOTICE: AUDIT: SESSION,26,1,READ,SELECT,TABLE,public.test,"SELECT
751751(0 rows)
752752
753753SELECT 1,
754- current_user ;
754+ substring('Thomas' from 2 for 3) ;
755755NOTICE: AUDIT: SESSION,27,1,READ,SELECT,,,"SELECT 1,
756- current_user ;",<none>
757- ?column? |current_user
758- ----------+--------------
759- 1 |super
756+ substring('Thomas' from 2 for 3) ;",<none>
757+ ?column? |substring
758+ ----------+-----------
759+ 1 |hom
760760(1 row)
761761
762762DO $$
@@ -1054,3 +1054,18 @@ GRANT user1 TO user2;
10541054NOTICE: AUDIT: SESSION,59,1,ROLE,GRANT ROLE,,,GRANT user1 TO user2;,<none>
10551055REVOKE user1 FROM user2;
10561056NOTICE: AUDIT: SESSION,60,1,ROLE,REVOKE ROLE,,,REVOKE user1 FROM user2;,<none>
1057+ DROP TABLE test.account_copy;
1058+ DROP TABLE test.test_insert;
1059+ DROP SCHEMA test;
1060+ DROP TABLE foo.bar;
1061+ DROP TABLE foo.baz;
1062+ DROP SCHEMA foo;
1063+ DROP TABLE hoge;
1064+ DROP TABLE account;
1065+ DROP TABLE account_role_map;
1066+ DROP USER user2;
1067+ NOTICE: AUDIT: SESSION,61,1,ROLE,DROP ROLE,,,DROP USER user2;,<none>
1068+ DROP USER user1;
1069+ NOTICE: AUDIT: SESSION,62,1,ROLE,DROP ROLE,,,DROP USER user1;,<none>
1070+ DROP ROLE auditor;
1071+ NOTICE: AUDIT: SESSION,63,1,ROLE,DROP ROLE,,,DROP ROLE auditor;,<none>