Monday, April 11, 2016

Daily Activity--Oracle dba

Shift handover report, it contains pending request.


    1)    Oracle Database instance is running or not
    2)    Database Listener is running or not.
    3)    Check any session blocking the other session
    4)    Check the alert log for an error
    5)    Check is there any dbms jobs running & check the status of the same
    6)    Check the Top session using more Physical I/O
    7)    Check the number of log switch per hour
    8)    How_much_redo_generated_per_hour
    9)    Run the statpack report
   10)    Detect lock objects
   11)  Check the SQL query consuming lot of resources.
   12)  Check the usage of SGA
   13)  Display database sessions using rollback segments
   14)  State of all the DB Block Buffer
   15)  Check for the invalid objects and recompile.
   16)  Verify the success of archive log backups, based on the backup interval.
   17)  Monitoring space Availability
   18)  Check tablespaces should not be used more that 75%.
   19)  Viewing the Alert log file to analyze the ORA errors if any.
   20)  Check all last night backups were successful.
   21)  Most Important - Check your oracle license and do not run/execute/create     anything beyond the oracle license policy.

To Find out the total size of the DB and Database growth weekly/monthly for future
necessary space arrangements

select( select sum(bytes)/1024/1024/1024 data_size from dba_data_files ) +( select nvl(sum(bytes),0)/1024/1024/1024 temp_size from dba_temp_files ) +( select sum(bytes)/1024/1024/1024 redo_size from sys.v_$log ) +( select sum(BLOCK_SIZE*FILE_SIZE_BLKS)/1024/1024/1024 controlfile_size from v$controlfile) "Size in GB" from dual;

Query to find the 10 Largest Objects in DB:
============================================


 select * from (select    SEGMENT_NAME,SEGMENT_TYPE,BYTES/1024/1024/1024 GB,TABLESPACE_NAME from  dba_segments order by 3 desc ) where rownum<= 10;

Sunday, April 10, 2016

DBMS_COMPARISON: Oracle 11g new features

It can use this package for several reason: if  checking or replicatiion  between production and test databases data etc.

For all scan modes to be supported by the DBMS_COMPARISON package, the database objects must have one of the following types of indexes:

    *  single-column index on a number, timestamp, interval, or DATE datatype column
    *  A composite index that only includes number, timestamp, interval, or DATE datatype columns. Each column in the composite index            must either have a NOT NULL constraint or be part of the primary key.

 The DBMS_COMPARISON package supports all Oracle Data Types (VARCHAR2, NVARCHAR2, NUMBER, FLOAT, DATE, TIMESTAMP etc) except the following:

LONG
LONG RAW
ROWID
UROWID
CLOB
NCLOB
BLOB
BFILE

There are some useful data dictionary views

    *    DBA/USER_COMPARISON_SCAN
    *    DBA/USER_COMPARISON_SCAN_SUMMARY
    *    DBA/USER_COMPARISON_SCAN_VALUES
    *    DBA/USER_COMPARISON_ROW_DIF

Now,Let us proceed

DECLARE
        scan_info  dbms_comparison.comparison_type;
        scan_id    INTEGER;
        consistent BOOLEAN;
BEGIN
--  dbms_comparison.drop_comparison(comparison_name => 'empcompare');
dbms_comparison.create_comparison(comparison_name    => 'empcompare',
schema_name        => 'TEST',
object_name        => 'compareclone',
dblink_name        => null,
remote_schema_name => 'TEST_REMOTE',
remote_object_name => 'EMP'
);

consistent := dbms_comparison.compare(comparison_name => 'empcompare', scan_info       => scan_info);

IF consistent = TRUE THEN
        dbms_output.put_line('No differences were found.');
ELSE
        dbms_output.put_line('Differences were found.');
END IF;

dbms_comparison.converge(comparison_name  => 'empcompare',
scan_id          => scan_info.scan_id,
scan_info        => scan_info,
converge_options => dbms_comparison.CMP_CONVERGE_REMOTE_WINS);

dbms_output.put_line('Scan ID: ' || scan_info.scan_id);
dbms_output.put_line('Local Rows Merged:' || scan_info.loc_rows_merged);
dbms_output.put_line('Remote Rows Merged:' || scan_info.rmt_rows_merged);
dbms_output.put_line('Local Rows Deleted:' || scan_info.loc_rows_deleted);
dbms_output.put_line('Remote Rows Deleted:' ||scan_info.rmt_rows_deleted);
END;

Now ,create a new table  with structure only

17:00:47 TEST_REMOTE> create table emp1 as select  *  from TEST.emp where 1=2;

after delete run the below procedure
====================================


DECLARE
        scan_info  dbms_comparison.comparison_type;
        scan_id    INTEGER;
        consistent BOOLEAN;
BEGIN
--  dbms_comparison.drop_comparison(comparison_name => 'empcompare_new');
dbms_comparison.create_comparison(comparison_name    => 'empcompare_new',
schema_name        => 'TEST',
object_name        => 'compareclone',
dblink_name        => null,
remote_schema_name => 'TEST_REMOTE',
remote_object_name => 'EMP'
);

consistent := dbms_comparison.compare(comparison_name => 'empcompare_new', scan_info       => scan_info);

IF consistent = TRUE THEN
        dbms_output.put_line('No differences were found.');
ELSE
        dbms_output.put_line('Differences were found.');
END IF;

dbms_comparison.converge(comparison_name  => 'empcompare_new',
scan_id          => scan_info.scan_id,
scan_info        => scan_info,
converge_options => dbms_comparison.CMP_CONVERGE_REMOTE_WINS);

dbms_output.put_line('Scan ID: ' || scan_info.scan_id);
dbms_output.put_line('Local Rows Merged:' || scan_info.loc_rows_merged);
dbms_output.put_line('Remote Rows Merged:' || scan_info.rmt_rows_merged);
dbms_output.put_line('Local Rows Deleted:' || scan_info.loc_rows_deleted);
dbms_output.put_line('Remote Rows Deleted:' ||scan_info.rmt_rows_deleted);
END;
/

DECLARE
*
ERROR at line 1:
ORA-23626: No eligible index on table TEST.compareclone
ORA-06512: at "SYS.DBMS_COMPARISON", line 4793
ORA-06512: at "SYS.DBMS_COMPARISON", line 448
ORA-06512: at line 7

17:04:47 TEST_REMOTE>alter table emp1 add CONSTRAINT "emp_ID_PK" PRIMARY KEY (EMP_CODE);

Table altered.

Elapsed: 00:00:00.03

17:05:46 TEST_REMOTE>DECLARE
        scan_info  dbms_comparison.comparison_type;
        scan_id    INTEGER;
        consistent BOOLEAN;
BEGIN
--  dbms_comparison.drop_comparison(comparison_name => 'empcompare');
dbms_comparison.create_comparison(comparison_name    => 'empcompare',
schema_name        => 'TEST',
object_name        => 'compareclone',
dblink_name        => null,
remote_schema_name => 'TEST_REMOTE',
remote_object_name => 'EMP'
);

consistent := dbms_comparison.compare(comparison_name => 'empcompare', scan_info       => scan_info);

IF consistent = TRUE THEN
        dbms_output.put_line('No differences were found.');
ELSE
        dbms_output.put_line('Differences were found.');
END IF;

dbms_comparison.converge(comparison_name  => 'empcompare',
scan_id          => scan_info.scan_id,
scan_info        => scan_info,
converge_options => dbms_comparison.CMP_CONVERGE_REMOTE_WINS);

dbms_output.put_line('Scan ID: ' || scan_info.scan_id);
dbms_output.put_line('Local Rows Merged:' || scan_info.loc_rows_merged);
dbms_output.put_line('Remote Rows Merged:' || scan_info.rmt_rows_merged);
dbms_output.put_line('Local Rows Deleted:' || scan_info.loc_rows_deleted);
dbms_output.put_line('Remote Rows Deleted:' ||scan_info.rmt_rows_deleted);
END;17:05:47   2  17:05:47   3  17:05:47   4  17:05:47   5  17:05:47   6  17:05:47   7  17:05:47   8  17:05:47   9  17:05:47  10  17:05:47  11  17:05:47  12  17:05:47  13  17:05:47  14  17:05:47  15  17:05:47  16  17:05:47  17  17:05:47  18  17:05:47  19  17:05:47  20  17:05:47  21  17:05:47  22  17:05:47  23  17:05:47  24  17:05:47  25  17:05:47  26  17:05:47  27  17:05:47  28  17:05:47  29  17:05:47  30  17:05:47  31  17:05:47  32  17:05:47  33 
17:05:48  34  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.99
17:05:50 TEST_REMOTE>select count(1) from emp1;

  COUNT(1)
----------
      2339

Elapsed: 00:00:00.00
17:06:09 TEST_REMOTE>delete from emp1 where rownum <13;

12 rows deleted.

Elapsed: 00:00:00.00
17:06:59 TEST_REMOTE>commit;

Commit complete.

Elapsed: 00:00:00.00
17:07:02 TEST_REMOTE>select count(1) from emp1;

  COUNT(1)
----------
      2327


17:08:13 TEST_REMOTE>DECLARE
        scan_info  dbms_comparison.comparison_type;
        scan_id    INTEGER;
        consistent BOOLEAN;
BEGIN
--  dbms_comparison.drop_comparison(comparison_name => 'empcompare_new');
dbms_comparison.create_comparison(comparison_name    => 'empcompare_new',
schema_name        => 'TEST',
object_name        => 'compareclone',
dblink_name        => null,
remote_schema_name => 'TEST_REMOTE',
remote_object_name => 'EMP'
);

consistent := dbms_comparison.compare(comparison_name => 'empcompare_new', scan_info       => scan_info);

IF consistent = TRUE THEN
        dbms_output.put_line('No differences were found.');
ELSE
        dbms_output.put_line('Differences were found.');
END IF;

dbms_comparison.converge(comparison_name  => 'empcompare_new',
scan_id          => scan_info.scan_id,
scan_info        => scan_info,
converge_options => dbms_comparison.CMP_CONVERGE_REMOTE_WINS);

dbms_output.put_line('Scan ID: ' || scan_info.scan_id);
dbms_output.put_line('Local Rows Merged:' || scan_info.loc_rows_merged);
dbms_output.put_line('Remote Rows Merged:' || scan_info.rmt_rows_merged);
dbms_output.put_line('Local Rows Deleted:' || scan_info.loc_rows_deleted);
dbms_output.put_line('Remote Rows Deleted:' ||scan_info.rmt_rows_deleted);
END;17:11:54   2  17:11:54   3  17:11:54   4  17:11:54   5  17:11:54   6  17:11:54   7  17:11:54   8  17:11:54   9  17:11:54  10  17:11:54  11  17:11:54  12  17:11:54  13  17:11:54  14  17:11:54  15  17:11:54  16  17:11:54  17  17:11:54  18  17:11:54  19  17:11:54  20  17:11:54  21  17:11:54  22  17:11:54  23  17:11:54  24  17:11:54  25  17:11:54  26  17:11:54  27  17:11:54  28  17:11:54  29  17:11:54  30  17:11:54  31  17:11:54  32  17:11:54  33 
17:11:55  34  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.48
17:11:57 TEST_REMOTE>select count(*) from emp1;

  COUNT(*)
----------
      2339


Thursday, April 7, 2016

ORA-24248 XMLDB extensible security not installed

A few days ago I ran into this problem. We upgraded one of our development database from oracle 10gR2 to 11gR1 recently.
 After the upgrade the application was broken very badly. Any user trying to login to the application was getting the error below:


ORA-24248: XML DB extensible security not installed
ORA-06512: at "SYS.UTL_INADDR", line 19
ORA-06512: at "SYS.UTL_INADDR", line 40
ORA-06512: at line 1


 I found that that in one of Java classes in the application, where a connection was being established to the databases, a query was being executed like this.


SELECT global_name,utl_inaddr.get_host_address FROM global_name;

The error above is quite self explanatory. I went ahead and verified the existence of Oracle XML Database and found the following:


11:49:41 sql>select comp_name from dba_registry;

COMP_NAME
----------------------------------------------------------------

Oracle Database Catalog Views
Oracle Database Packages and Types
Oracle Enterprise Manager

As can be seen from the output of the above query, we were missing Oracle XML Database. I was able to reproduce the problem in sqlplus.


11:52:23 sql>select global_name,utl_inaddr.get_host_address from global_name;
select global_name,utl_inaddr.get_host_address from global_name
                   *
ERROR at line 1:
ORA-24248: XML DB extensible security not installed
ORA-06512: at "SYS.UTL_INADDR", line 19
ORA-06512: at "SYS.UTL_INADDR", line 40
ORA-06512: at line 1


Install XML Database: Oracle 11g Enterprise Edition


$ cd $ORACLE_HOME/rdbms/admin

$ sqlplus / as sysdba

[oracle@Localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Apr 8 11:55:27 2016

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> spool install_xml_db.log
SQL> @catqm xdb sysaux temp YES
-- xdb is the password for XML Database repository schema
-- sysaux is the default tablespace for XML Database repository schema.
-- temp is the default temporary tablespace for XML Database repository schema.
-- YES is for using secure files for xdb$resource
.
.
.

SQL> declare
  2    suf  varchar2(26);
  3    stmt varchar2(2000);
  4  begin
  5    select toksuf into suf from xdb.xdb$ttset where flags = 0;
  6    stmt := 'grant all on XDB.X$PT' || suf || ' to DBA';
  7    execute immediate stmt;
  8    stmt := 'grant all on XDB.X$PT' || suf || ' to SYSTEM WITH GRANT OPTION';
  9    execute immediate stmt;
 10  end;
 11  /

PL/SQL procedure successfully completed.

SQL>spool off
11:58:14 SQL> select comp_name , status from dba_registry;

 COMP_NAME                                STATUS
---------------------------------------- --------------------------------------------
Oracle XML Database                      VALID
Oracle Database Catalog Views          VALID
Oracle Database Packages and Types     VALID
Oracle Enterprise Manager         VALID

The XML Database installation is complete. I opened the install_xml_db.log and didn't find any significant errors in it. Then I verified from dba_registry again to see the status of XML Database installed.


12:04:33 SQL> select global_name,utl_inaddr.get_host_address from global_name;
select global_name,utl_inaddr.get_host_address from global_name
                   *
 ERROR at line 1:
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "SYS.UTL_INADDR", line 19
ORA-06512: at "SYS.UTL_INADDR", line 40
ORA-06512: at line 1

Now the ORA-24248 is gone because we have XML Database installed. Now we are seeing ORA-24247, which means we can't access any network host using UTL_INADDR unless we allow access to this host via ACL.


SQL> conn / as sysdba
Connected.

BEGIN
   DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (
        acl          =>'my_application_acl.xml',
        description  => 'ACL for users of my application.',
        principal    => 'SCOTT',
        is_grant     => TRUE,
        privilege    => 'resolve',
        start_date   => null,
        end_date     => null
    );
END;
/

PL/SQL procedure successfully completed.

/*
 All that UTL_INADDR.get_host_address does is resolve the host and return the IP Address.
 DBMS_NETWORK_ACL_ADMIN.CREATE_ACL creates an ACL and grant privilege to a user or role
 to that ACL.
 For the sake of this article I am using SCOTT as the grantee of the privilege resolve but
 in my application I granted this privilege to a role which was assigned to all the
 application users. So through that role all the users were granted resole privilege to
 this ACL.
*/


BEGIN
   DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL (
     acl         =>'my_application_acl.xml',
     host        => 'localhost',
     lower_port  => null,
     upper_port  => null
     );
END;
/

PL/SQL procedure successfully completed.

/*
 When UTL_INADDR.get_host_address is invoked without a host name specified with it,
 it sends the request to localhost. So we need to assign our ACL to the host "localhost".
*/

commit;


SQL> conn scott/tiger
Connected.
SQL> set lines 10000
SQL> column global_name format a20
SQL> column get_host_address format a15
SQL> select global_name,utl_inaddr.get_host_address from global_name;


TESTDB  10.XXX.XXX.XXX



As you can see above, SCOTT is now able to get server's IP Adress using utl_inaddr.get_host_address. And this solves our problem with the application.

Uninstall XML Database: Oracle 11g Enterprise Edition


$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus / as sysdba

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> @catnoqm.sql
-- This will uninstall the Oracle XML Database.