Skip to content

Commit

Permalink
Fix misclassification of partitioned tables/indexes.
Browse files Browse the repository at this point in the history
Partitioned tables and indexes were being classified as UNKNOWN but they should be classified as TABLE/INDEX.
  • Loading branch information
gaoxueyu committed Jul 21, 2020
1 parent 2fcf4f5 commit c07aa82
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
30 changes: 30 additions & 0 deletions expected/pgaudit.out
Expand Up @@ -1168,6 +1168,36 @@ DROP TABLE public.t;
NOTICE: AUDIT: SESSION,86,1,DDL,DROP TABLE,,,DROP TABLE public.t;,<none>
DROP ROLE alice;
NOTICE: AUDIT: SESSION,87,1,ROLE,DROP ROLE,,,DROP ROLE alice;,<none>
--
-- Test PARTITIONED table
CREATE TABLE h(x int ,y int) PARTITION BY HASH(x);
NOTICE: AUDIT: SESSION,88,1,DDL,CREATE TABLE,,,"CREATE TABLE h(x int ,y int) PARTITION BY HASH(x);",<none>
CREATE TABLE h_0 partition OF h FOR VALUES WITH ( MODULUS 2, REMAINDER 0);
NOTICE: AUDIT: SESSION,89,1,DDL,CREATE TABLE,,,"CREATE TABLE h_0 partition OF h FOR VALUES WITH ( MODULUS 2, REMAINDER 0);",<none>
CREATE TABLE h_1 partition OF h FOR VALUES WITH ( MODULUS 2, REMAINDER 1);
NOTICE: AUDIT: SESSION,90,1,DDL,CREATE TABLE,,,"CREATE TABLE h_1 partition OF h FOR VALUES WITH ( MODULUS 2, REMAINDER 1);",<none>
INSERT INTO h VALUES(1,1);
NOTICE: AUDIT: SESSION,91,1,WRITE,INSERT,TABLE,public.h,"INSERT INTO h VALUES(1,1);",<none>
SELECT * FROM h;
NOTICE: AUDIT: SESSION,92,1,READ,SELECT,TABLE,public.h,SELECT * FROM h;,<none>
x | y
---+---
1 | 1
(1 row)

SELECT * FROM h_0;
NOTICE: AUDIT: SESSION,93,1,READ,SELECT,TABLE,public.h_0,SELECT * FROM h_0;,<none>
x | y
---+---
1 | 1
(1 row)

CREATE INDEX h_idx ON h (x);
NOTICE: AUDIT: SESSION,94,1,DDL,CREATE INDEX,,,CREATE INDEX h_idx ON h (x);,<none>
DROP INDEX h_idx;
NOTICE: AUDIT: SESSION,95,1,DDL,DROP INDEX,,,DROP INDEX h_idx;,<none>
DROP TABLE h;
NOTICE: AUDIT: SESSION,96,1,DDL,DROP TABLE,,,DROP TABLE h;,<none>
-- Cleanup
-- Set client_min_messages up to warning to avoid noise
SET client_min_messages = 'warning';
Expand Down
2 changes: 2 additions & 0 deletions pgaudit.c
Expand Up @@ -1038,10 +1038,12 @@ log_select_dml(Oid auditOid, List *rangeTabls)
switch (rte->relkind)
{
case RELKIND_RELATION:
case RELKIND_PARTITIONED_TABLE:
auditEventStack->auditEvent.objectType = OBJECT_TYPE_TABLE;
break;

case RELKIND_INDEX:
case RELKIND_PARTITIONED_INDEX:
auditEventStack->auditEvent.objectType = OBJECT_TYPE_INDEX;
break;

Expand Down
12 changes: 12 additions & 0 deletions sql/pgaudit.sql
Expand Up @@ -818,6 +818,18 @@ RESET ROLE;
DROP TABLE public.t;
DROP ROLE alice;

--
-- Test PARTITIONED table
CREATE TABLE h(x int ,y int) PARTITION BY HASH(x);
CREATE TABLE h_0 partition OF h FOR VALUES WITH ( MODULUS 2, REMAINDER 0);
CREATE TABLE h_1 partition OF h FOR VALUES WITH ( MODULUS 2, REMAINDER 1);
INSERT INTO h VALUES(1,1);
SELECT * FROM h;
SELECT * FROM h_0;
CREATE INDEX h_idx ON h (x);
DROP INDEX h_idx;
DROP TABLE h;

-- Cleanup
-- Set client_min_messages up to warning to avoid noise
SET client_min_messages = 'warning';
Expand Down

0 comments on commit c07aa82

Please sign in to comment.