Section 12.4. Reporting on Database Changes

   

12.4 Reporting on Database Changes

The remaining sections in this chapter describe the various kinds of reports you can produce once you have collected the necessary baseline database data. This section focuses on database changes resulting from changes to database objects and parameters. The next section focuses on changes to the SQL execution plan.

After collecting our first set of baseline data, we made some changes to the database, collected additional baseline data, made some more changes, and then collected even more baseline data. We did this for several weeks.

12.4.1 Database Changes

The details and times of the changes made to the database are summarized in Table 12-4.

Table 12-4. Baseline changes made to the test database

Date

Changes made since previous baseline

5 Oct

Initial baseline data collected for database ts99

13 Oct

Added a few hundred rows to SCOTT.EMP

Analyzed tables for SCOTT

Changed values for database initialization parameters: SHARED_POOL_SIZE, DB_BLOCK_BUFFERS, and JOB_QUEUE_PROCESSES

19 Oct

Added a few hundred rows to SCOTT.EMP

Added an EMAIL column to SCOTT.EMP

Updated the value in the EMP table

Dropped the column LOSAL from SALGRADE

Analyzed tables for SCOTT

Created a new user , PDBAREP, and granted it several privileges

Granted SELECT on V_$INSTANCE, to SCOTT

28 Oct

Added a few hundred rows to SCOTT.EMP

Created an index on SCOTT.EMP

Analyzed tables for SCOTT

Gave SCOTT UNLIMITED quota on USERS tablespace

Dropped index IDXTEST_3_1_IDX

8 Nov

Added a few hundred rows to SCOTT.EMP

Analyzed tables for SCOTT

Revoked SELECT privileges on JKSTILL.LCL_1 from SCOTT

Granted SELECT, INSERT on JKSTILL.PRIMES table to SCOTT

12.4.2 Reporting on Parameter Changes with spdrvr.pl

Now let's see how we can use the repository to engage in a form of time travel. Although less exciting than as H.G. Wells envisioned it, you'll effectively be able to go back in time to find elusive missing columns and corner privilege revocations. Pretend for a moment that the date is October 15. We've just become aware that the initialization file for one of our databases was recently modified and that, coincidentally, the server is now a little low on memory. We know that everything was correct a week ago, on October 8, but how do we determine what the settings were back then?

Without our repository, there would be no easy way to determine the correct values, except by restoring a tape backup of the file as it appeared last week. This would probably be neither practical nor desirable.

Of course, if you are using a version control system, you'll be able to detect every authorized database change to your database and therefore be able to track official changes. However, experience teaches us, in vivid Technicolor, that such a system is of little use if people bypass it, ignore it, and then deny they've done anything when things go awry. "What? Me? That index? I was fishing . Honest."

But with the repository, you can find these values as they appeared prior to the change. Because you know that the values from October 8 are correct, let's see which parameters have been changed since then. Let's produce a report detailing the difference. We can do that with the -rep_report parameter_diff_rpt command:

 $ spdrvr.pl -machine sherlock -database ts01 -username pdbarep \  -rep_report parameter_diff_rpt  -rep_instance ts99.jks.com \  -rep_start_date  '10/08/2001'  -rep_end_date  '10/15/2001' 

Even though the first baseline was actually run on October 5, the spdrvr.pl script determines which baseline to use by searching for the most recent baseline date that is less than or equal to the date specified. The same type of operation takes place with the end date specified in the example by the following switch:

 -rep_end_date 

When using this switch, and its complement -rep_start_date , be sure to use a date format matching the setting in the pdbarepq.conf configuration file. If the parameter_diff_report were run with the International date format, the command line would look like this:

 $ spdrvr.pl -machine sherlock -database ts01 -username pdbarep \   -rep_report parameter_diff_rpt -rep_instance ts99.jks.com \       -rep_start_date  '2001/10/08'  -rep_end_date  '2001/10/15'  

The output from the parameter_diff_report report appears in Example 12-6. Note that data appears only when there are differences within values associated with the database parameters, as stored in PDBA_PARAMETERS. If, for example, there have been no changes to the Oracle initialization parameters between October 5 and October 13, there will be nothing to report. A parameter comparison on these two dates will reveal that nothing has changed.

Example 12-6. Output from the parameter_diff_rpt report
 PDBAREP Parameter Differences report Page: 1 as of 2001/10/13 03:09:37 compared to 2001/10/05 18:29:05                     TS99.JKS.COM  2002/05/19 21:55:40                                                        S S                                                        E Y                                                        S S                                                      D M M M A                                                      E O O O D PARAMETER            DESCRIPTION          VALUE      F D D D J -------------------- -------------------- ---------- - - - - - db_block_buffers     Number of database b 1000       N N N N N                      locks cached in memo                      ry job_queue_processes  number of job queue  2          Y N I N N                      processes to start shared_pool_size     size in bytes of sha 3145728    N N N N N                      red pool    3 rows selected.    PDBAREP Parameter Differences report                      Page:          1 as of 2001/10/05 18:29:05 compared to 2001/10/13 03:09:37                     TS99.JKS.COM  2002/05/19 21:55:40                                                        S S                                                        E Y                                                        S S                                                      D M M M A                                                      E O O O D PARAMETER            DESCRIPTION          VALUE      F D D D J -------------------- -------------------- ---------- - - - - - db_block_buffers     Number of database b 500        N N N N N                      locks cached in memo                      ry job_queue_processes  number of job queue  0          Y N I N N                      processes to start shared_pool_size     size in bytes of sha 2097152    N N N N N                      red pool    3 rows selected. 

On the other hand, suppose that sometime between October 5 and October 13 you changed the database initialization parameters DB_BLOCK_BUFFERS, JOB_QUEUE_PROCESSES, and SHARED_POOL_SIZE. When you run the parameter_diff_rpt report, it would show the values of these parameters as they appeared on October 13, followed by the values as they appeared on October 5. Looking again at Example 12-6, you'll see that the report appears in two parts :

  • The first part shows the parameters on October 13.

  • The second part shows that the parameters were indeed different on October 5 and October 13. The values of the parameters were all increased after October 5.

We now know what the correct settings were eight days ago, and we can change them back to the former values if necessary.

The pdbarepq.conf configuration file contains templates of the SQL for each of the available repository reports. The command-line options of spdrvr.pl are used with these templates to generate the actual SQL used. Typical PDBA-generated SQL used to create this kind of report is shown in Example 12-7.

Example 12-7. Sample query for spdrvr.pl
 select    s.global_name cinstance    , p.name parm_name    , p.description parm_description    , p.value parm_value    , decode(       nvl(p.isdefault,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.isdefault,'F'),1,1)    ) isdefault    , decode(       nvl(p.isses_modifiable,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.isses_modifiable,'F'),1,1)    ) isses_modifiable    , decode(       nvl(p.issys_modifiable,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.issys_modifiable,'F'),1,1)    ) issys_modifiable    , decode(       nvl(p.ismodified,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.ismodified,'F'),1,1)    ) ismodified    , decode(       nvl(p.isadjusted,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.isadjusted,'F'),1,1)    ) isadjusted from pdba_parameters p, pdba_snap_dates s where s.global_name like 'TS99.JKS.COM' and s.pk = 1000000 and s.pk = p.snap_date_pk minus select    s.global_name cinstance    , p.name parm_name    , p.description parm_description    , p.value parm_value    , decode(       nvl(p.isdefault,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.isdefault,'F'),1,1)    ) isdefault    , decode(       nvl(p.isses_modifiable,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.isses_modifiable,'F'),1,1)    ) isses_modifiable    , decode(       nvl(p.issys_modifiable,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.issys_modifiable,'F'),1,1)    ) issys_modifiable    , decode(       nvl(p.ismodified,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.ismodified,'F'),1,1)    ) ismodified    , decode(       nvl(p.isadjusted,'FALSE'),       'FALSE','N',       'TRUE','Y',        substr(nvl(p.isadjusted,'F'),1,1)    ) isadjusted from pdba_parameters p, pdba_snap_dates s where s.global_name like 'TS99.JKS.COM' and s.pk = 1001570 and s.pk = p.snap_date_pk order by 1,2; 

12.4.3 More Report Examples

On October 25, we decided to run some additional reports to see what might have changed in the ts99 database since the time that we started capturing repository metadata. [2] Example 12-8 shows different variants on the commands you can specify in order to view the data in different ways.

[2] Metadata is data about data. An example of metadata is the statistics stored in the Oracle data dictionary when the ANALYZE TABLE command is use. It is data about the data in the specified table.

Example 12-8. Reports on database changes as of October 19
 $ spdrvr.pl -machine sherlock -database ts01 -username pdbarep \  -rep_report table_rpt  -rep_instance ts99% -rep_schema scott \     -rep_end_date '10/25/2001'    $ spdrvr.pl -machine sherlock -database ts01 -username pdbarep \  -rep_report column_diff_rpt  -rep_instance ts99% -rep_schema scott \     -rep_end_date '10/25/2001'    $ spdrvr.pl -machine sherlock -database ts01 -username pdbarep \  -rep_report table_privs_diff_rpt  -rep_instance ts99% \     -rep_grantee scott -rep_end_date '10/25/2001'    $ spdrvr.pl -machine sherlock -database ts01 -username pdbarep \  -rep_report user_rpt  -rep_instance ts99% 

The reports table_rpt , column_diff_rpt , and table_privs_diff_rpt produce the outputs summarized here:

Tables and indexes need to be periodically analyzed via the ANALYZE command to provide statistics for Oracle's cost-based optimizer (CBO). The CBO is the part of the database engine that determines how best to join indexes and tables when querying the database.

table_rpt

In Example 12-9 we see that the number of employees in the EMP table has dramatically increased since the time when the repository was first populated . By implication , we can also tell that EMP was unanalyzed (not processed with the ANALYZE command) when its first baseline was taken, because BLOCKS and NUMBER OF ROWS have no values for October 5.

Example 12-9. The table_rpt report, as of October 19
 %oramon> spdrvr.pl  -machine sherlock -database ts01 -username pdbarep \   -rep_report table_rpt -rep_database ts99% -rep_schema scott PDBAREP Table report for                                 Page:          1 TS99.JKS.COM                                                NUMBER OWNER  TABLE NAME SNAPSHOT DATE        BLOCKS OF ROWS ------ ---------- -------------------- ------ -------  SCOTT  BONUS      2001/10/05 18:29:05                   2001/10/19 04:11:23       1       4           DUMMY      2001/10/05 18:29:05                   2001/10/13 03:09:37       1       1                   2001/10/19 04:11:23       1       1  EMP        2001/10/05 18:29:05   2001/10/13 03:09:37       3     224   2001/10/19 04:11:23      29   1,792    SALGRADE   2001/10/05 18:29:05                   2001/10/13 03:09:37        1      5                   2001/10/19 04:11:23        1      5    15 rows selected. 
column_diff_rpt

In Example 12-10, the Column Differences report, we find that two column changes have been made between October 5 and October 19. The EMAIL column has been added to the EMP table during this time, and the column LOSAL no longer appears in SALGRADE.

Example 12-10. The column_diff_rpt report as of October 19
 %oramon> spdrvr.pl  -machine sherlock -database ts01 -username pdbarep \   -rep_report column_diff_rpt -rep_database ts99% -rep_schema scott \   -rep_end_date '2001/10/19'    PDBAREP Table Column Differences report                Page:          1 as of 2001/10/19 04:11:23 compared to 2001/10/05 18:29:05                               TS99.JKS.COM  2002/05/19 22:19:51                              COL              DATA      DATA   DATA OWNER  TABLE NAME  COLUMN     ID DATA_TYPE  LENGTH PRECISION  SCALE NULL ------ ----------- -------- ---- ---------- ------ --------- ------ ---- SCOTT  EMP         EMAIL       9 VARCHAR2       40                  Y    1 row selected.    PDBAREP Table Column Differences report                Page:          1 as of 2001/10/05 18:29:05 compared to 2001/10/19 04:11:23                               TS99.JKS.COM  2002/05/19 22:19:51                                 COL              DATA      DATA   DATA OWNER  TABLE NAME  COLUMN     ID DATA_TYPE  LENGTH PRECISION  SCALE NULL ------ ----------- -------- ---- ---------- ------ --------- ------ ---- SCOTT  SALGRADE    LOSAL       2 NUMBER         22                  Y    1 row selected. 
table_privs_diff_rpt

In Example 12-11 we're surprised to see that scott has been granted SELECT privilege on V_$INSTANCE. Although this view contains non-sensitive information, we believe in granting direct privileges on dictionary objects only for DBAs . Maybe in another life we'll reconsider our conservative views! Based on this report, you decide to chat with scott, to find out how he stumbled upon this privilege.

Example 12-11. The table_privs_diff_rpt as of October19
 %oramon> spdrvr.pl   -machine sherlock -database ts01 -username pdbarep \   -rep_report table_privs_diff_rpt -rep_database ts99% \   -rep_grantee scott -rep_end_date '2001/10/19'    PDBAREP Table Privileges Differences report          Page:          1 as of 2001/10/13 03:09:37 compared to 2001/10/05 18:29:05 TS99.JKS.COM  2002/05/19 22:46:27 GRANTEE      TABLE NAME        PRIVILEGE  OWNER     GRANTOR  GRANTABLE    1 row selected.    no rows selected 

12.4.4 spdrvr.pl Implementation

Before we look further at the kinds of reports you can produce with the spdrvr.pl script, let's dig down and take a quick look at its implementation and see why, despite our abiding love for Perl, we've also used SQL*Plus in our implementation.

Have you ever had a household tool you love so much that you find yourself exploring the house from attic to basement , looking for ways to make use of it? That's the way we feel about Perl. However, as Clint Eastwood said once of a man's belief in himself, we've got to recognize its limitations. A screwdriver may sometimes get called up for reserve duty as a chisel, but that usage will impact its longevity as a screwdriver. And if you trim the hedges around your home with a circular power-saw, people are going to talk.

We've come to realize, somewhat sadly, that Perl does indeed have its limits. The most glaring one we've noticed emerges when we're writing ad hoc SQL reports. Perl is a good choice when writing reports that demand lots of computation, but it fails to do things easily that long-time users of SQL*Plus take for granted. Here are a few examples:

Column breaks and report breaks

The SQL*Plus BREAK command formats reports to make them easier to interpret:

 break on username skip 1 page on table name skip 1 
Column and report totals

SQL*Plus calculates totals with simplicity:

 break on custid skip 1 on invoice_id skip 1 on report compute sum of invoice_amt on custid compute sum of invoice_item_amt on invoice_id compute sum of invoice_amt on custid 
Report headers and footers

The SQL*Plus ttitle and btitle commands can create report headers and footers:

 ttitle 'PDBAREP Parameter Differences report ' RIGHT 'Page: ' SQL.PNO -    skip 'as of <<END_DATE>> compared to <<START_DATE>>' -    right uinstance '  ' usysdate skip 2 

All of the above features can be duplicated in Perl, but it takes a while. And being the virtuously lazy programmers we are, we can't really justify writing all the necessary code when SQL*Plus already handles these features so well. [3] What we've done, therefore, is to create a Perl/SQL*Plus hybrid that uses the best features from each tool to accomplish our goal. In this case, the goal is to produce nice reports with a minimum amount of effort. Before we begin, let's take a look at some of the pros and cons of both tools:

[3] You might want to take a look at the Senora tool described in Chapter 3; this tool, which is based on DDL::Oracle (also described in Chapter 3), provides a SQL*Plus clone written entirely in Perl, along with several other interactive Perl DBI tools such as dbish .

  • With SQL*Plus we get nicely formatted reports that are easy to produce.

  • With Perl we can make up for some of the serious cross-platform liabilities of SQL*Plus, take advantage of Perl's strong command-line processing, use Perl's many modules, and easily redirect output. Perl also possesses a command-line interface that is infinitely flexible.

12.4.5 Predefined spdrvr.pl Reports

The spdrvr.pl repository script allows you to invoke a number of predefined database reports simply by specifying the appropriate command-line options. Several reports are predefined for you.

column_diff_rpt

Report on differences in table columns in the repository. This report may be delimited by a date range. If dates are not supplied, the oldest and newest dates from the repository will be used.

column_rpt

Report on table columns in repository.

index_column_diff_rpt

Report on differences in index columns in the repository. This report may be delimited by a date range. If dates are not supplied, the oldest and newest dates from the repository will be used.

index_column_rpt

Report on indexed columns in the repository.

index_rpt

Report on indexes in the repository.

master_priv_rpt

Report on database privilege grants in the repository.

parameter_diff_rpt

Report on database initialization parameter differences in the repository. This report may be delimited by a date range. If dates are not supplied, the oldest and newest dates from the repository will be used.

parameter_rpt

Report on database initialization parameters in the repository.

profile_rpt

Report on profiles in the repository.

role_privs_diff_rpt

Report on differences in role privileges in the repository.

role_privs_rpt

Report on role privileges in the repository.

role_rpt

Report on database roles in the repository.

sequence_rpt

Report on sequences in the repository.

sys_privs_diff_rpt

Report on differences in system privileges in the repository.

sys_privs_rpt

Report on system privileges in the repository.

table_privs_diff_rpt

Report on differences in table privileges in the repository.

table_privs_rpt

Report on table privileges in the repository.

table_rpt

Report on tables in the repository.

tablespace_rpt

Report on tablespaces in the repository.

user_rpt

Report on users in the repository.

12.4.6 Command-line Options for spdrvr.pl

You can request the reports listed in the previous section by including the appropriate command-line options when you invoke the spdrvr.pl repository script. Table 12-5 and Table 12-6 summarize these options.

12.4.6.1 Common command-line options

You will need to include most of the options in Table 12-5 regardless of what report you want to produce. You can obtain a list of available reports and their required command-line options by typing:

 $ spdrvr.pl -report_list 

We'll show the output from this command a little later in this section.

Table 12-5. Common command-line options ” spdrvr.pl

Option

Description

-machine

Server where the repository database resides.

-database

Database where the PDBAREP user is installed.

-username

Repository schema owner.

-file

Optional parameter that specifies output to a file.

-verbose

Optional parameter that prints the SQL as it is executed.

-report_list

Outputs a list of available reports to the console

-rep_report

Specifies which report to run.

-rep_database

Specifies which database ( global_name ) to report on.

The arguments for -machine , -database , -username , and -rep_report are always required. The argument for -rep_database is optional but recommended. The use of -rep_database really depends on the nature of the report. If you want to find out what changes have been made to a table on a specific database between two dates, you'll need to specify which database the report should be querying on. If you omit this option, any tables from other databases with the same name will be included in the output. (This is probably not what you want.)

Let's suppose you want to run the report table_rpt for the database ts99.jks.com and that the repository owned by pdbarep is in database ts01 on server sherlock . The minimal command line needed to run this report would be:

 $ spdrvr.pl -machine  sherlock  -database  ts01  -username  pdbarep  \     -rep_instance  'ts99%'  -rep_report table_rpt 

To include only tables with "PSAP" as the first four characters of their name, within accounts that begin with "SAP," the command line would look like this:

 $ spdrvr.pl -machine sherlock -database ts01 -username pdbarep \      -rep_instance 'ts99%' -rep_report table_rpt \      -rep_schema  'sap%'  -rep_table_name  'psap%'  
12.4.6.2 Report-specific command-line options

Table 12-6 lists the report-specific command-line options. For example, you might use the -rep_privilege option if you are requesting the table_privs_rpt report, but that option would have no effect on the parameter_rpt that lists database initialization parameters.

Table 12-6. Report-specific command-line options ” spdrvr.pl

Report

Specific parameters

-rep_end_date

End date for report (unnecessary for some reports).

-rep_grantee

Grantee of privileges. Use this option to report on the privileges granted to a particular user or role.

-rep_grantor

Grantor of privileges. This will limit the report to privileges granted by this user.

-rep_granted_role

Roles granted. This will limit the report to a role or roles that have been granted.

-rep_index_name

Index to report on.

-rep_object_owner

Owner of database object to report on.

-rep_object_name

Name of database object to report on.

-rep_pagesize

Controls the SQL*Plus pagesize.

-rep_parm_name

Name of database parameter to report on.

-rep_parm_value

Value of database parameter value to report on.

-rep_privilege

Database privileges granted.

-rep_profile

Database profile name to report on.

-rep_resource_type

Profile resource type to report on.

-rep_resource_name

Profile resource name to report on.

-rep_role

Role to report on.

-rep_schema

Schema to report on.

-rep_sequence_name

Name of sequence to report on.

-rep_start_date

Start date for report (unnecessary for some reports).

-rep_table_name

Table to report on.

-rep_table_owner

Table owner to report on.

-rep_tablespace_name

Tablespace to report on.

-rep_username

Username to report on.

No single report makes use of all of these switches, although some are used in several reports.

12.4.6.3 Using the -report_list option

The first time you run the spdrvr.pl script, you should use the -report_list option, which prints out a list of currently configured reports along with the report-specific command-line options that may be used with it:

 $ sprdrvr.pl -report_list 

Go ahead and try it. The output should be similar to that displayed in Example 12-12 (although we've cut down the actual output, as it can run to several pages).

Example 12-12. Partial output from "spdrvr.pl -report_list"
  column_diff_rpt  :  report on differences in table columns in repository   may be delimited by a date range  .  if dates not supplied, the oldest and newest dates   from the repository will be used   may be limited by the following tags  :  <<GLOBAL_NAME>>   -rep_instance   <<OWNER>>         -rep_schema   <<TABLE_NAME>>    -rep_table_name   <<START_DATE_PK>> -rep_start_date   <<END_DATE_PK>>   -rep_end_date  master_priv_rpt :     report on privileges granted in repository    may be limited by the following tags:       <<GLOBAL_NAME>>    -rep_instance    <<GRANTEE>>        -rep_grantee    <<PRIVILEGE>>      -rep_privilege    <<OBJECT_OWNER>>   -rep_object_owner    <<OBJECT_NAME>>    -rep_object_name    <<GRANTED_ROLE>>   -rep_granted_role          parameter_diff_rpt :     report on database parameter differences in repository    may be delimited by a date range.      if dates not supplied, the oldest and newest dates    from the repository will be used       may be limited by the following tags:       <<GLOBAL_NAME>>    -rep_instance    <<START_DATE_PK>>  -rep_start_date    <<END_DATE_PK>>    -rep_end_date    sys_privs_diff_rpt :     report on differences in system privileges in repository    may be limited by the following tags:       <<GLOBAL_NAME>>    -rep_instance    <<GRANTEE>>        -rep_grantee    <<PRIVILEGE>>      -rep_privilege    <<START_DATE_PK>>  -rep_start_date    <<END_DATE_PK>>    -rep_end_date    table_rpt :     report on tables in repository    may be limited by the following tags:       <<GLOBAL_NAME>>   -rep_instance    <<OWNER>>         -rep_schema    <<TABLE_NAME>>    -rep_table_name 

12.4.7 Options and Tags

Each command-line option shown in Example 12-12 is associated with a tag enclosed in a double set of angle brackets: <<TAG>> . The column_diff_rpt report has these tags associated with the following command-line options:

 <<GLOBAL_NAME>>   -rep_instance <<OWNER>>         -rep_schema <<TABLE_NAME>>    -rep_table_name  <<START_DATE_PK>> -rep_start_date   <<END_DATE_PK>>   -rep_end_date  

These tags are used internally within spdrvr.pl to replace values in a SQL script, values that will later get sent to SQL*Plus. The tags are divided into two types, date and text, as discussed in the following sections.

12.4.7.1 Date options

The -rep_start_date and -rep_end_date command-line options are the only date-style options. The tags usually associated with these options are <<START_DATE_PK>> and <<END_DATE_PK>> .

-rep_start_date

Used to specify a particular date on the command line; however, this is used internally by spdrvr.pl to look up the primary key of the row in PDBA_SNAP_DATES , the one corresponding to the requested date. The value of that primary key is used to replace the value of <<START_DATE_PK>> in the actual query.

If -rep_start_date date is missing from the repository, the most recent date, up to the date specified, is used. Using the following dates, the first date in PDBA_SNAP_DATES is October 5, the second is October 13, and the third is October 19. If you specified the report to start from October 15, the spdrvrl.pl script would find no data collected for that date, and would then choose the closest date that's less than October 15, which is October 13. (We promise that this will make more sense when you run the actual reports.):

 GLOBAL_NAME     SNAP_DATE --------------- ------------------- TS99.JKS.COM    2001/10/05 18:29:05 TS99.JKS.COM  2001/10/13  03:09:37 TS99.JKS.COM    2001/10/19 04:11:23 TS99.JKS.COM    2001/10/28 23:13:25 TS99.JKS.COM    2001/11/08 12:18:36 

If you specified a date less than any in the repository, the first available date in the repository will be used, which is October 5. This will also be used if -rep_start_date is not specified.

-rep_end_date

Works in similar fashion. If you specify an end date of October 25, the actual end date used will be October 19, as this is the latest one that's less than the date specified. If the specified date is greater than the latest one in the repository, or if the -rep_end_date switch remains unused, the latest repository date will be used in reports; that is, November 8.

This logic may seem rather convoluted, but trust us, it does make reports easier to run. Let's look at an example. Suppose that midway through November you suspect that changes have been made to the HELP_DESK schema. You know that last month everything worked fine ” but now there's a problem. To figure out what's going on, you won't need to check every date in the repository. You can simply enter the approximate range and let spdrvr.pl determine the actual dates. The following reports all changes:

 $ spdrvr.pl -machine sherlock -database ts01 -username pdbarep \  -rep_report column_diff_rpt  -rep_instance ts99% \   -rep_schema help_desk \     -rep_start_date  '2001/10/01'  \     -rep_end_date  '2001/11/12'  

The actual report dates used would be October 5 and November 8.

12.4.7.2 Text options

Most of the command-line options on the spdrvr.pl script are text options. These include all the database objects ” users, tables, tablespaces, indexes, and so on. We can be somewhat inexact in specifying these text strings. Most of the SQL queries found in pdbarepq.conf use the LIKE operator, rather than the = equality operator. This allows the use of the % wildcard for text-based columns, used in WHERE clauses.

The following command requests a report on which roles have been granted to which users, where the grantee's name begins with an S :

 spdrvr.pl -machine sherlock -database ts01 \   -username pdbarep -rep_database ts99% \   -rep_report role_privs_rpt  -rep_grantee s%  

If you wish to see the actual SQL generating the report, add the -verbose option to the command line. In our example, the SQL looks like this:

 select     s.global_name cinstance    , p.grantee    , p.granted_role    , p.admin_option    , p.default_role    , s.snap_date from pdba_role_privs p, pdba_snap_dates s  where s.global_name like 'TS99%  '  and p.grantee like 'S%  ' and s.pk between 1000000 and 1006331 and s.pk = p.snap_date_pk order by global_name, grantee, granted_role, snap_date; 

Notice how the switches -rep_database ts99% and -rep_grantee s% uppercase their corresponding values in the SQL statement. (The % wildcard may be used in any of the non-date command-line arguments.)

   


Perl for Oracle DBAs
Perl for Oracle Dbas
ISBN: 0596002106
EAN: 2147483647
Year: 2002
Pages: 137

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net