@@ -26,6 +26,8 @@ table db_audit.ddl_start_log limit 100;
2626
2727-- ----------------------------------------------------------------------------------------------------------------------
2828
29+ -- drop view db_audit.objects;
30+ 2931create view db_audit .objects as
3032with t as (
3133 select t .object_identity , t .object_type
@@ -36,11 +38,29 @@ with t as (
3638)
3739select t.* ,
3840 -- created:
39- c .created_at , c .tag as created_tag, c .top_queries as created_top_queries, c .context_stack as created_context_stack,
40- cd .events_total as created_events_total, cd .max_created_at - c .transaction_start_at as created_transaction_duration,
41+ c .created_at ,
42+ c .tag as created_tag,
43+ c .top_queries as created_top_queries,
44+ c .context_stack as created_context_stack,
45+ c .trigger_depth as created_trigger_depth,
46+ c .application_name as created_application_name,
47+ c .client_addr as created_client_addr,
48+ c .client_port as created_client_port,
49+ c .via_pooler as created_via_pooler,
50+ cd .events_total as created_events_total,
51+ cd .max_created_at - c .transaction_start_at as created_transaction_duration,
4152 -- updated:
42- u .created_at as updated_at, u .tag as updated_tag, u .top_queries as updated_top_queries, u .context_stack as updated_context_stack,
43- ud .events_total as updated_events_total, ud .max_created_at - u .transaction_start_at as updated_transaction_duration
53+ u .created_at as updated_at,
54+ u .tag as updated_tag,
55+ u .top_queries as updated_top_queries,
56+ u .context_stack as updated_context_stack,
57+ u .trigger_depth as updated_trigger_depth,
58+ u .application_name as updated_application_name,
59+ u .client_addr as updated_client_addr,
60+ u .client_port as updated_client_port,
61+ u .via_pooler as updated_via_pooler,
62+ ud .events_total as updated_events_total,
63+ ud .max_created_at - u .transaction_start_at as updated_transaction_duration
4464from t
4565left join db_audit .ddl_log as c -- вычисляем дату-время создания
4666 on c .object_identity = t .object_identity
@@ -57,12 +77,17 @@ left join db_audit.ddl_log as c --вычисляем дату-время соз
5777left join db_audit .ddl_log as u -- вычисляем дату-время обновления
5878 on u .object_identity = t .object_identity
5979 and u .object_type = t .object_type
60- and u .tag ~ ' ^(CREATE|ALTER|COMMENT)\M ' -- CREATE OR REPLACE
80+ /*
81+ GRANT and REVOKE does not work as expected, because
82+ "object_type" is 'TABLE' instead 'view', "schema_name" is null, "object_identity" is null.
83+ It's need to report PostgreSQL developers team.
84+ */
85+ and u .tag ~ ' ^(CREATE|ALTER|COMMENT|GRANT|REVOKE)\M '
6186 and (c .created_at is null or u .created_at > c .created_at )
6287 and not exists(
6388 select
6489 from db_audit .ddl_log as e
65- where e .tag ~ ' ^(DROP|CREATE|ALTER|COMMENT)\M '
90+ where e .tag ~ ' ^(DROP|CREATE|ALTER|COMMENT|GRANT|REVOKE )\M '
6691 and e .object_identity = u .object_identity
6792 and e .object_type = u .object_type
6893 and e .created_at > u .created_at
@@ -101,4 +126,3 @@ GRANT SELECT ON db_audit.objects TO alexan;
101126
102127-- TEST
103128table db_audit .objects limit 100 ;
104-
0 commit comments