-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall_method5_global_data_dictionary.sql
More file actions
229 lines (202 loc) · 7.87 KB
/
install_method5_global_data_dictionary.sql
File metadata and controls
229 lines (202 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
prompt Creating jobs for global data dictionary...;
--These jobs collect information every day for commonly used data dictionary objects.
--These steps must be run on the central management server, as a DBA.
--Although they are jobs, they must be owned by an active, configured user.
--If that user's account is terminated you will have to recreate the jobs.
--
--Feel free to add your own commonly used tables.
---------------------------------------
--#0: Check the user.
@code/check_user must_be_m5_user
---------------------------------------
--#1: DBA_USERS.
begin
dbms_scheduler.create_job(
job_name => 'M5_DBA_USERS_JOB',
job_type => 'PLSQL_BLOCK',
start_date => systimestamp at time zone 'US/Eastern',
enabled => true,
repeat_interval => 'freq=daily; byhour=3; byminute=0; bysecond=0',
job_action =>
q'<
begin
m5_proc(
p_code => '
--All 11gR2 columns.
select
username, user_id, password, account_status, lock_date, expiry_date,
default_tablespace, temporary_tablespace, created, profile, initial_rsrc_consumer_group,
external_name, cast(password_versions as varchar2(12)) password_versions,
editions_enabled, authentication_type
from dba_users
',
p_table_name => 'method5.m5_dba_users',
p_table_exists_action => 'DELETE',
p_asynchronous => false,
p_targets => '%'
);
end;
>'
);
end;
/
---------------------------------------
--#2: V$PARAMETER.
begin
dbms_scheduler.create_job(
job_name => 'M5_V$PARAMETER_JOB',
job_type => 'PLSQL_BLOCK',
start_date => systimestamp at time zone 'US/Eastern',
enabled => true,
repeat_interval => 'freq=daily; byhour=3; byminute=5; bysecond=0',
job_action =>
q'<
begin
--Gather data in a user schema.
m5_proc(
p_code => '
--All 11gR2 columns.
select
num, name, type, value, display_value, isdefault, isses_modifiable,
issys_modifiable, isinstance_modifiable, ismodified, isadjusted,
isdeprecated, isbasic, description, update_comment, hash
from v$parameter;
',
p_table_name => 'method5.m5_v$parameter',
p_table_exists_action => 'DELETE',
p_asynchronous => false,
p_targets => '%'
);
end;
>'
);
end;
/
---------------------------------------
--#3: Privileges.
begin
dbms_scheduler.create_job(
job_name => 'M5_PRIVILEGES_JOB',
job_type => 'PLSQL_BLOCK',
start_date => systimestamp at time zone 'US/Eastern',
enabled => true,
repeat_interval => 'freq=daily; byhour=3; byminute=10; bysecond=0',
job_action =>
q'<
begin
--These queries include all 11g columns.
m5_proc(
p_code => 'select grantee, owner, table_name, grantor, privilege, grantable, hierarchy from dba_tab_privs',
p_table_name => 'method5.m5_dba_tab_privs',
p_table_exists_action => 'DELETE',
p_asynchronous => false,
p_targets => '%'
);
m5_proc(
p_code => 'select grantee, granted_role, admin_option, default_role from dba_role_privs',
p_table_name => 'method5.m5_dba_role_privs',
p_table_exists_action => 'DELETE',
p_asynchronous => false,
p_targets => '%'
);
m5_proc(
p_code => 'select grantee, privilege, admin_option from dba_sys_privs',
p_table_name => 'method5.m5_dba_sys_privs',
p_table_exists_action => 'DELETE',
p_asynchronous => false,
p_targets => '%'
);
end;
>'
);
end;
/
---------------------------------------
--#4: USER$.
begin
dbms_scheduler.create_job(
job_name => 'M5_USER$_JOB',
job_type => 'PLSQL_BLOCK',
start_date => systimestamp at time zone 'US/Eastern',
enabled => true,
repeat_interval => 'freq=daily; byhour=3; byminute=15; bysecond=0',
job_action =>
q'<
begin
--Gather data in a user schema.
m5_proc(
p_code => '
--All 11g columns.
select
user#, name, type#, password, datats#, tempts#, ctime, ptime, exptime, ltime,
resource$, audit$, defrole, defgrp#, defgrp_seq#, astatus, lcount, defschclass,
ext_username, spare1, spare2, spare3, spare4, spare5, spare6
from sys.user$
',
p_table_name => 'method5.m5_user$',
p_table_exists_action => 'DELETE',
p_asynchronous => false,
p_targets => '%'
);
end;
>'
);
end;
/
---------------------------------------
--#5: Force job to run first time.
prompt Running jobs. This may take a few minutes to gather all the data...;
--No need to see the M5_PROC output.
set serveroutput off;
begin
dbms_scheduler.run_job('M5_DBA_USERS_JOB');
dbms_scheduler.run_job('M5_V$PARAMETER_JOB');
dbms_scheduler.run_job('M5_PRIVILEGES_JOB');
dbms_scheduler.run_job('M5_USER$_JOB');
end;
/
prompt All jobs should say "SUCCEEDED"...
select job_name, status, to_char(log_date, 'YYYY-MM-DD HH24:MI') log_date
from
(
select job_name, status, log_date, row_number() over (partition by job_name order by log_date desc) last_when_1
from dba_scheduler_job_run_details
where job_name like 'M5_%JOB'
order by log_date desc
)
where last_when_1 = 1
order by job_name;
---------------------------------------
--#6: Create public synonyms on the tables.
prompt Registering global data dictionary tables...
insert /*+ ignore_row_on_dupkey_index(m5_global_data_dictionary, m5_global_data_dictionary_uq) */
into method5.m5_global_data_dictionary
select 'METHOD5' owner, 'M5_DBA_USERS' table_name from dual union all
select 'METHOD5' owner, 'M5_V$PARAMETER' table_name from dual union all
select 'METHOD5' owner, 'M5_DBA_TAB_PRIVS' table_name from dual union all
select 'METHOD5' owner, 'M5_DBA_ROLE_PRIVS' table_name from dual union all
select 'METHOD5' owner, 'M5_DBA_SYS_PRIVS' table_name from dual union all
select 'METHOD5' owner, 'M5_USER$' table_name from dual;
commit;
---------------------------------------
--#7: Create public synonyms on the tables.
prompt Creating public synonyms for global data dictionary...
create or replace public synonym m5_dba_users for method5.m5_dba_users;
create or replace public synonym m5_dba_users_meta for method5.m5_dba_users_meta;
create or replace public synonym m5_dba_users_err for method5.m5_dba_users_err;
create or replace public synonym m5_v$parameter for method5.m5_v$parameter;
create or replace public synonym m5_v$parameter_meta for method5.m5_v$parameter_meta;
create or replace public synonym m5_v$parameter_err for method5.m5_v$parameter_err;
create or replace public synonym m5_dba_tab_privs for method5.m5_dba_tab_privs;
create or replace public synonym m5_dba_tab_privs_meta for method5.m5_dba_tab_privs_meta;
create or replace public synonym m5_dba_tab_privs_err for method5.m5_dba_tab_privs_err;
create or replace public synonym m5_dba_role_privs for method5.m5_dba_role_privs;
create or replace public synonym m5_dba_role_privs_meta for method5.m5_dba_role_privs_meta;
create or replace public synonym m5_dba_role_privs_err for method5.m5_dba_role_privs_err;
create or replace public synonym m5_dba_sys_privs for method5.m5_dba_sys_privs;
create or replace public synonym m5_dba_sys_privs_meta for method5.m5_dba_sys_privs_meta;
create or replace public synonym m5_dba_sys_privs_err for method5.m5_dba_sys_privs_err;
create or replace public synonym m5_user$ for method5.m5_user$;
create or replace public synonym m5_user$_meta for method5.m5_user$_meta;
create or replace public synonym m5_user$_err for method5.m5_user$_err;
prompt Done.