Saturday, June 29, 2013

Deploy Oracle Enterprise Manager 12c Agent and Add Targets

In this demo I show how to deploy Oracle Agent 12c manually to a new server. Then I show you how to add the database, asm and listener targets to Enterprise Manager 12c.

1. Log into OEM

2.Click setup>add target>add target manually


3. Select add host targets click add host


4. Click add type in the name of the host. Then use the platform drop down to select the host platform. Then click next.


5.  Type in the installation base directory note the installation directory will be auto populated. Select the host named credentials or add new credentials. You can use host credentials that host sudo to root privileges to automate the execute of the root.sh. Click next


6. Review the add host target information and click deploy agent.


7.  Installation progress will begin


8.  If you receive a warning review and resolve issue if needed. If you you need to make changes to your selections you can use the retry drop down to make new selections. If the warning message is ok to continue click the continue drop down and select continue all hosts.

In my case it is a warning about the account I am using does not have sudo privileges so I will continue on all hosts.


9.  Installation will continue


10.  Once the installation is complete you will have a green check mark for installation and agent deployment. Click done

In my case you can see that status for root.sh is showing that I need to manually execute root.sh.


11.  Log into OS as root and CD to the new agent home and execute root.sh.




12.  Select the second choose then use the target type drop down to select "Oracle Database, Listener and Automatic Storage Management". Now click add using guided discovery


13.  Type in the host target name or use the icon to select the host.


14.  Select the host and click select


15.  Now click continue


16.  You will see all the targets discovery on the host to be added to OEM. Use the configure icon to configure each target.


17.  Type in the dbsnmp account password and click test connection. If the dbsnmp account is locked a message will appear and a button to change the password and unlock the account.


18. If the test connection is successful then click next.


19.  Review configuration and click OK


20.  You will now see the configure icon color change to a shade of blue this means the target is configured. Repeat the same configuration steps for all targets.


21.  Once you have configured all targets click next.


22.  Fill in target properties if needed this is information that will be added to target properties but is only an option click next.


23.  Review the discovery summary and click save.


24.  Configuration will begin


25.  Target configuration has been save click OK.


26.  If you search for the targets you will see they have been added but are still in status pending.


27. If you wait few minutes then refresh the screen you will now see all targets are online and up.






My webpages
http://db12c.blogspot.com/
http://cloudcontrol12c.blogspot.com/

http://www.youtube.com/user/jfruiz11375

Follow me on Twitter


How to Update Agent12c Software "Unable to proceed because you have selected a platform for which Management Agent Software is not available on the OMS."

Have you ever received the message "Unable to proceed because you have selected a platform for which Management Agent Software is not available on the OMS." when trying to deploy a new agent?

See my demo on my YouTube channel where I show you how to update your Enterprise Management Agent12c software to be able to deploy agents to other platforms other then the one that your Enterprise Manager is running on.

Demo:
http://www.youtube.com/watch?v=sr58lf55pRI



My webpages
http://db12c.blogspot.com/
http://cloudcontrol12c.blogspot.com/

http://www.youtube.com/user/jfruiz11375

Follow me on Twitter

Friday, June 28, 2013

Use EM12c to Get Database Storage Information

Have you ever been asked by your SAN admin "Can you give me a 6 to 12 month database future growth report"? What about your manager asking can you "Give me database storage trends over the last 6 months"? Well in my case many times to the point I got tried so I built some tables, procedures and views based on the data in Enterprise Manager. I have been using the data since EM10g and now in EM12c.

Follow me on Twitter

The tables contain data for three different types of trends and the data is populated using three different procedures. The data is selected by using the 3 different views.

Tables:
DBA_DATABASE_STORAGE_USAGE- This tables contains the current storage as of the last run of the proc.

DBA_HISTORICAL_STORAGE_USAGE- This table contains the historical data the all months since the target database instance as been in EM.

DBA_FUTURE_STORAGE_USAGE- This table contains all the database storage since the database target has been in EM. The way you get the future storage is based on a view that you can modify based on your storage requirements.

Procedures:
DBA_DB_STORAGE- This proc populates the DBA_DATABASE_STORAGE_USAGE tables with all the current storage.

DBA_HISTORICAL_STORAGE- This proc populates the DBA_HISTORICAL_STORAGE_USAGE table with all the storage since the database instance target was add into Enterprise Manager.

DBA_FUTURE_STORAGE- This proc populates the DBA_HISTORICAL_STORAGE_USAGE table with all the storage since the database instance target was add into Enterprise Manager.

Views:
DBA_CURRENT_DB_STORAGE_USAGE- This views shows the current storage usage allocated space, used space and allocated free space. Also shows the usage in percent. The last two columns show the DATAPUMP and RMAN space usages. The RMAN column is allocated_space * 0.30 and the export is based on allocated space * 0.15. You can change this as need base on your requirements.

Below is an explain output from my vbox setup


DBA_HISTORICAL_DB_STORAGE_USAGE- This view shows historical database storage it shows allocated space, used space and allocated free space. You will also see the percent used and each row is the first of the month for each database instance target in Enterprise Manager.

Below is an explain output from my vbox setup


DBA_FUTURE_STORAGE_USAGE- This view shows future database growth based on the max allocated_space -min allocated_space *12 which you can change as needed. The back 12 month is based on max allocated space -min allocated space *12*0.30. You may ask why 0.30 well I compress my RMAN backups and RMAN has almost a 70% compression rate if you database is not full of lobs. The export 12 month backup is based on on max allocated space -min allocated space *12*0.15. The used space is base on max used space -min used space *12 this is useful if the SAN admin starts ask about white space.

Below is an explain output from my vbox setup note my vbox setup is to small and does not have the numbers to show 12 month growth.


Below is all the scripts to create the tables, procedures and views. I have the schema set to DBA_REPOSITORY so you need to edit the below with your own schema. You can easily do a find and replace.

TABLES
--------------------------------------------------------
--  File created - Friday-June-28-2013
--------------------------------------------------------
--------------------------------------------------------
--  DDL for Table DBA_DATABASE_STORAGE_USAGE
--------------------------------------------------------

  CREATE TABLE "DBA_REPOSITORY"."DBA_DATABASE_STORAGE_USAGE"
   ( "TARGET_GUID" VARCHAR2(40 BYTE),
"ALLOCATED_SPACE_GB" VARCHAR2(10 BYTE),
"USED_SPACE_GB" VARCHAR2(10 BYTE),
"ALLOCATED_FREE_SPACE_GB" VARCHAR2(10 BYTE)
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "DBA_REPOSITORY_DATA" ;

   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_DATABASE_STORAGE_USAGE"."ALLOCATED_SPACE_GB" IS 'Total physical space used in GB';
   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_DATABASE_STORAGE_USAGE"."USED_SPACE_GB" IS 'Total logical space used in GB';
   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_DATABASE_STORAGE_USAGE"."ALLOCATED_FREE_SPACE_GB" IS 'Total free physical space in GB';
--------------------------------------------------------
--  DDL for Table DBA_FUTURE_STORAGE_USAGE
--------------------------------------------------------

  CREATE TABLE "DBA_REPOSITORY"."DBA_FUTURE_STORAGE_USAGE"
   ( "TARGET_GUID" VARCHAR2(40 BYTE),
"ALLOCATED_SPACE_GB" NUMBER,
"USED_SPACE_GB" NUMBER,
"ALLOCATED_FREE_SPACE_GB" NUMBER,
"CALENDAR_MONTH" DATE,
"USED_PCT" NUMBER
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "DBA_REPOSITORY_DATA" ;

   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_FUTURE_STORAGE_USAGE"."ALLOCATED_SPACE_GB" IS 'Total physical space used in GB';
   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_FUTURE_STORAGE_USAGE"."USED_SPACE_GB" IS 'Total logical space used in GB';
   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_FUTURE_STORAGE_USAGE"."ALLOCATED_FREE_SPACE_GB" IS 'Total free physical space in GB';
--------------------------------------------------------
--  DDL for Table DBA_HISTORICAL_STORAGE_USAGE
--------------------------------------------------------

  CREATE TABLE "DBA_REPOSITORY"."DBA_HISTORICAL_STORAGE_USAGE"
   ( "TARGET_GUID" VARCHAR2(40 BYTE),
"ALLOCATED_SPACE_GB" NUMBER,
"USED_SPACE_GB" NUMBER,
"ALLOCATED_FREE_SPACE_GB" NUMBER,
"CALENDAR_MONTH" DATE,
"USED_PCT" NUMBER
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "DBA_REPOSITORY_DATA" ;

   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_HISTORICAL_STORAGE_USAGE"."ALLOCATED_SPACE_GB" IS 'Total physical space used in GB';
   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_HISTORICAL_STORAGE_USAGE"."USED_SPACE_GB" IS 'Total logical space used in GB';
   COMMENT ON COLUMN "DBA_REPOSITORY"."DBA_HISTORICAL_STORAGE_USAGE"."ALLOCATED_FREE_SPACE_GB" IS 'Total free physical space in GB';
--------------------------------------------------------
--  DDL for Index TARGET_GUID_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "DBA_REPOSITORY"."TARGET_GUID_PK" ON "DBA_REPOSITORY"."DBA_DATABASE_STORAGE_USAGE" ("TARGET_GUID")
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "DBA_REPOSITORY_DATA" ;
--------------------------------------------------------
--  Constraints for Table DBA_DATABASE_STORAGE_USAGE
--------------------------------------------------------

  ALTER TABLE "DBA_REPOSITORY"."DBA_DATABASE_STORAGE_USAGE" ADD CONSTRAINT "TARGET_GUID_PK" PRIMARY KEY ("TARGET_GUID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "DBA_REPOSITORY_DATA"  ENABLE;

PROCS
--------------------------------------------------------
--  DDL for Procedure DBA_DB_STORAGE
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "DBA_REPOSITORY"."DBA_DB_STORAGE" IS
tmpVar NUMBER;
/******************************************************************************
   NAME:       DBA_DB_STORAGE
   PURPOSE:    To populate the DBA_database_storage_usage table with storage data info

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        4/19/2013   javier ruiz      1. Created this procedure.

******************************************************************************/
-- gets target_guid
   CURSOR get_target_guid
   IS
      select target_guid
  from mgmt_targets
 where target_type = 'oracle_database';

-- get storage info
CURSOR get_storage (v_target_guid VARCHAR2)
IS
select round (sum (t.tablespace_size / 1024 / 1024 / 1024), 2)
          as allocated_gb,
       round (sum (t.tablespace_used_size / 1024 / 1024 / 1024), 2)
          as used_gb,
       round (
          sum (
             (t.tablespace_size - tablespace_used_size) / 1024 / 1024 / 1024),
          2)
          as allocated_free_gb
  from mgmt$db_tablespaces t,
       (select target_guid
  from mgmt_targets
 where target_guid = v_target_guid
         and (target_type = 'oracle_database')) tg
 where t.target_guid = tg.target_guid;


   v_target_guid                  VARCHAR2 (50);
   v_allocated_space           VARCHAR2 (20);
   v_used_gb                      VARCHAR2 (20);
   v_allocate_free_gb        VARCHAR2 (20);


BEGIN
   tmpVar := 0;

 -- truncating dba_database_storage_usage table
execute immediate 'truncate table DBA_database_storage_usage';

-- we go get the target_guid
FOR c1 IN get_target_guid
   LOOP
      v_target_guid := c1.target_guid;
      --DBMS_OUTPUT.put_line ('THE TARGET_GUID IS: ' || v_target_guid);

-- we go get the storage data
      FOR c2 IN get_storage (v_target_guid)
            LOOP
            v_allocated_space:=c2.allocated_gb;
            v_used_gb:=c2.used_gb;
            v_allocate_free_gb:=c2.allocated_free_gb;

            --DBMS_OUTPUT.put_line ('GUID is ' || v_target_guid);
            --DBMS_OUTPUT.put_line ('Allocated Space ' || v_allocated_space);
            --DBMS_OUTPUT.put_line ('Used Space ' || v_used_gb);
            --DBMS_OUTPUT.put_line ('Allocate Free Space  ' || v_allocate_free_gb);

-- we insert the storage data
            insert into DBA_database_storage_usage
            values (v_target_guid,v_allocated_space,v_used_gb,v_allocate_free_gb);
            commit;

            END LOOP;
   END LOOP;

   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       NULL;
     WHEN OTHERS THEN
       -- Consider logging the error and then re-raise
       RAISE;
END DBA_DB_STORAGE;

/
--------------------------------------------------------
--  DDL for Procedure DBA_FUTURE_STORAGE
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "DBA_REPOSITORY"."DBA_FUTURE_STORAGE" IS
tmpVar NUMBER;
/******************************************************************************
   NAME:       DBA_FUTURE_STORAGE
   PURPOSE:    To populate the DBA_FUTURE_STORAGE_USAGE table with storage data info

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        5/23/2013   javier ruiz       1. Created this procedure.

******************************************************************************/
-- gets target_guid
   CURSOR get_target_guid
   IS
      select target_guid
  from mgmt_targets
 where target_type = 'oracle_database';

-- get storage info
CURSOR get_storage (v_target_guid VARCHAR2)
IS
SELECT
       TO_DATE(TO_CHAR(a_size.month_timestamp,'MON RR'),'MON RR') AS CALENDAR_MONTH,
       round(avg(a_size.size_gb),2) AS allocated_gb,
       round(avg(used.used_gb),2) AS USED_GB,
       round(avg(a_size.size_gb - used.used_gb),2) AS allocated_FREE_GB,
       round(avg((used.used_gb*100)/
                decode(a_size.size_gb,0,1,a_size.size_gb))
                ,2) AS USED_PCT
     FROM
      (SELECT
           m.rollup_timestamp AS month_timestamp,
           sum(m.average/1024) AS size_gb
         FROM
           mgmt$metric_daily m,
           mgmt$target_type t
         WHERE
           t.target_guid=HEXTORAW(v_target_guid) AND
           (t.target_type='rac_database' OR
           (t.target_type='oracle_database' AND t.TYPE_QUALIFIER3 != 'RACINST')) AND
           m.target_guid=t.target_guid AND
           m.metric_guid=t.metric_guid AND
           t.metric_name='tbspAllocation' AND
           (t.metric_column='spaceAllocated') AND
           m.rollup_timestamp >= sysdate-365 and
           m.rollup_timestamp <= sysdate
         GROUP BY m.metric_column, m.rollup_timestamp) a_size,
       (SELECT
           m.rollup_timestamp AS month_timestamp,
           sum(m.average/1024) AS used_gb
         FROM
           mgmt$metric_daily m,
           mgmt$target_type t
         WHERE
           t.target_guid=HEXTORAW(v_target_guid) AND
           (t.target_type='rac_database' OR
           (t.target_type='oracle_database' AND t.TYPE_QUALIFIER3 != 'RACINST')) AND
           m.target_guid=t.target_guid AND
           m.metric_guid=t.metric_guid AND
           t.metric_name='tbspAllocation' AND
           (t.metric_column='spaceUsed') AND
           m.rollup_timestamp >= sysdate-365 and
           m.rollup_timestamp <= sysdate
         GROUP BY m.metric_column, m.rollup_timestamp) used
     WHERE
       a_size.month_timestamp =used.month_timestamp
     GROUP BY TO_CHAR(a_size.month_timestamp,'MON RR');


   v_target_guid                  VARCHAR2 (50);
   v_sid                        VARCHAR2(50);
   v_allocated_space           VARCHAR2 (20);
   v_used_gb                      VARCHAR2 (20);
   v_allocate_free_gb        VARCHAR2 (20);
   v_calendar_month             VARCHAR2 (20);
   v_used_pct                   VARCHAR2 (20);


BEGIN
   tmpVar := 0;

 -- truncating DBA_FUTURE_STORAGE_USAGE table
execute immediate 'truncate table DBA_FUTURE_STORAGE_USAGE';

-- we go get the target_guid
FOR c1 IN get_target_guid
   LOOP
      v_target_guid := c1.target_guid;
      --DBMS_OUTPUT.put_line ('THE TARGET_GUID IS: ' || v_target_guid);

-- we go get the storage data
      FOR c2 IN get_storage (v_target_guid)
            LOOP
            v_allocated_space:=c2.allocated_gb;
            v_used_gb:=c2.used_gb;
            v_allocate_free_gb:=c2.allocated_free_gb;
            v_calendar_month := c2.calendar_month;
            v_used_pct := c2.used_pct;

            --DBMS_OUTPUT.put_line ('GUID is ' || v_target_guid);
            --DBMS_OUTPUT.put_line ('Allocated Space ' || v_allocated_space);
            --DBMS_OUTPUT.put_line ('Used Space ' || v_used_gb);
            --DBMS_OUTPUT.put_line ('Allocate Free Space  ' || v_allocate_free_gb);

-- we insert the storage data
            insert into DBA_FUTURE_STORAGE_USAGE
            values (v_target_guid,v_allocated_space,v_used_gb,v_allocate_free_gb,v_calendar_month,v_used_pct);
            commit;

            END LOOP;
   END LOOP;

   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       NULL;
     WHEN OTHERS THEN
       -- Consider logging the error and then re-raise
       RAISE;
END DBA_FUTURE_STORAGE;

/
--------------------------------------------------------
--  DDL for Procedure DBA_HISTORICAL_STORAGE
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "DBA_REPOSITORY"."DBA_HISTORICAL_STORAGE" IS
tmpVar NUMBER;
/******************************************************************************
   NAME:       DBA_HISTORICAL_STORAGE
   PURPOSE:    To populate the DBA_historical_storage_usage table with storage data info

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        2/20/2011   javier ruiz       1. Created this procedure.

******************************************************************************/
-- gets target_guid
   CURSOR get_target_guid
   IS
      select target_guid
  from mgmt_targets
 where target_type = 'oracle_database';

-- get storage info
CURSOR get_storage (v_target_guid VARCHAR2)
IS
SELECT
       TO_DATE(TO_CHAR(a_size.month_timestamp,'MON RR'),'MON RR') AS CALENDAR_MONTH,
       round(avg(a_size.size_gb),2) AS allocated_gb,
       round(avg(used.used_gb),2) AS USED_GB,
       round(avg(a_size.size_gb - used.used_gb),2) AS allocated_FREE_GB,
       round(avg((used.used_gb*100)/
                decode(a_size.size_gb,0,1,a_size.size_gb))
                ,2) AS USED_PCT
     FROM
      (SELECT
           m.rollup_timestamp AS month_timestamp,
           sum(m.average/1024) AS size_gb
         FROM
           mgmt$metric_daily m,
           mgmt$target_type t
         WHERE
           t.target_guid=HEXTORAW(v_target_guid) AND
           (t.target_type='rac_database' OR
           (t.target_type='oracle_database' AND t.TYPE_QUALIFIER3 != 'RACINST')) AND
           m.target_guid=t.target_guid AND
           m.metric_guid=t.metric_guid AND
           t.metric_name='tbspAllocation' AND
           (t.metric_column='spaceAllocated') AND
           m.rollup_timestamp >= sysdate-365 and
           m.rollup_timestamp <= sysdate
         GROUP BY m.metric_column, m.rollup_timestamp) a_size,
       (SELECT
           m.rollup_timestamp AS month_timestamp,
           sum(m.average/1024) AS used_gb
         FROM
           mgmt$metric_daily m,
           mgmt$target_type t
         WHERE
           t.target_guid=HEXTORAW(v_target_guid) AND
           (t.target_type='rac_database' OR
           (t.target_type='oracle_database' AND t.TYPE_QUALIFIER3 != 'RACINST')) AND
           m.target_guid=t.target_guid AND
           m.metric_guid=t.metric_guid AND
           t.metric_name='tbspAllocation' AND
           (t.metric_column='spaceUsed') AND
           m.rollup_timestamp >= sysdate-365 and
           m.rollup_timestamp <= sysdate
         GROUP BY m.metric_column, m.rollup_timestamp) used
     WHERE
       a_size.month_timestamp =used.month_timestamp
     GROUP BY TO_CHAR(a_size.month_timestamp,'MON RR');


   v_target_guid                  VARCHAR2 (50);
   v_sid                        VARCHAR2(50);
   v_allocated_space           VARCHAR2 (20);
   v_used_gb                      VARCHAR2 (20);
   v_allocate_free_gb        VARCHAR2 (20);
   v_calendar_month             VARCHAR2 (20);
   v_used_pct                   VARCHAR2 (20);


BEGIN
   tmpVar := 0;

 -- truncating DBA_historical_storage_usage table
execute immediate 'truncate table DBA_historical_storage_usage';

-- we go get the target_guid
FOR c1 IN get_target_guid
   LOOP
      v_target_guid := c1.target_guid;
      --DBMS_OUTPUT.put_line ('THE TARGET_GUID IS: ' || v_target_guid);

-- we go get the storage data
      FOR c2 IN get_storage (v_target_guid)
            LOOP
            v_allocated_space:=c2.allocated_gb;
            v_used_gb:=c2.used_gb;
            v_allocate_free_gb:=c2.allocated_free_gb;
            v_calendar_month := c2.calendar_month;
            v_used_pct := c2.used_pct;

            --DBMS_OUTPUT.put_line ('GUID is ' || v_target_guid);
            --DBMS_OUTPUT.put_line ('Allocated Space ' || v_allocated_space);
            --DBMS_OUTPUT.put_line ('Used Space ' || v_used_gb);
            --DBMS_OUTPUT.put_line ('Allocate Free Space  ' || v_allocate_free_gb);

-- we insert the storage data
            insert into DBA_historical_storage_usage
            values (v_target_guid,v_allocated_space,v_used_gb,v_allocate_free_gb,v_calendar_month,v_used_pct);
            commit;

            END LOOP;
   END LOOP;

   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       NULL;
     WHEN OTHERS THEN
       -- Consider logging the error and then re-raise
       RAISE;
END DBA_HISTORICAL_STORAGE;


/

VIEWS
--------------------------------------------------------
--  DDL for View DBA_CURRENT_DB_STORAGE
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "DBA_REPOSITORY"."DBA_CURRENT_DB_STORAGE" ("DB_NAME", "CALENDAR_MONTH", "ALLOCATED_SPACE_GB", "USED_SPACE_GB", "ALLOCATED_FREE_SPACE_GB", "USED_PCT", "backup_space_used_rman", "backup_space_used_export") AS 
  select c.VALUE AS DB_NAME ,to_char(calendar_month,'yyyy-mm-dd') as calendar_month,
ceil(allocated_space_gb) as allocated_space_gb,
ceil(used_space_gb) as used_space_gb,
ceil(allocated_free_space_gb) as allocated_free_space_gb,
used_pct,
ceil(allocated_space_gb*0.30) as "backup_space_used_rman",ceil(used_space_gb*0.15) as"backup_space_used_export" from DBA_HISTORICAL_STORAGE_USAGE a,
(SELECT value,target_guid
            FROM MGMT$DB_INIT_PARAMS
           WHERE name = 'db_name') c
where a.target_guid = c.target_guid
order by 1 asc,2 asc;
--------------------------------------------------------
--  DDL for View DBA_FUTURE_DB_STORAGE
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "DBA_REPOSITORY"."DBA_FUTURE_DB_STORAGE" ("DB_NAME", "12_month_growth_gb", "12_month_backup_gb", "export_12_month_backup_gb", "used_12_month_growth_gb") AS 
  select c.VALUE AS DB_NAME ,
ceil(max(allocated_space_gb)-min(allocated_space_gb))*12as "12_month_growth_gb",
ceil(max(allocated_space_gb)-min(allocated_space_gb))*12*0.30 as "12_month_backup_gb",
ceil(max(used_space_gb)-min(used_space_gb))*12*0.15 as "export_12_month_backup_gb",
ceil(max(used_space_gb)-min(used_space_gb))*12as "used_12_month_growth_gb" from 
DBA_FUTURE_STORAGE_USAGE a,
(SELECT value,target_guid
            FROM MGMT$DB_INIT_PARAMS
           WHERE name = 'db_name') c
where a.target_guid = c.target_guid
and calendar_month between trunc(to_date(sysdate), 'MONTH')-31 and trunc(to_date(sysdate), 'MONTH')
group by c.VALUE
ORDER BY 1 ASC;
--------------------------------------------------------
--  DDL for View DBA_HISTORICAL_DB_STORAGE
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "DBA_REPOSITORY"."DBA_HISTORICAL_DB_STORAGE" ("DB_NAME", "ALLOCATED_SPACE_GB", "USED_SPACE_GB", "ALLOCATED_FREE_SPACE_GB", "CALENDAR_MONTH", "USED_PCT") AS 
  select c.VALUE AS DB_NAME,
allocated_space_gb,
used_space_gb,
allocated_free_space_gb,
calendar_month,used_pct
 from DBA_HISTORICAL_STORAGE_USAGE a,
 (SELECT VALUE, target_guid
            FROM MGMT$DB_INIT_PARAMS
           WHERE name = 'db_name') c
where a.target_guid = c.target_guid
order by 1,4 asc;

PRIVILEGES:
The following privileges need to be granted to the user account that will own the tables, views and procedures.
GRANT SELECT ON SYSMAN.MGMT$DB_INIT_PARAMS TO DBA_REPOSITORY;
GRANT SELECT ON SYSMAN.MGMT$DB_TABLESPACES TO DBA_REPOSITORY;
GRANT SELECT ON SYSMAN.MGMT$METRIC_DAILY TO DBA_REPOSITORY;
GRANT SELECT ON SYSMAN.MGMT$TARGET_TYPE TO DBA_REPOSITORY;
GRANT SELECT ON SYSMAN.MGMT_TARGETS TO DBA_REPOSITORY;
GRANT SELECT ON SYSMAN.MGMT_TARGET_PROPERTIES TO DBA_REPOSITORY;

Wednesday, June 19, 2013

Update Agent 12c Time Zone on Linux and UNIX

9:58 AM
  1. On the server set the TZ to the correct time zone.
    • $export TZ=US/Central
    • $echo $TZ
  1. Create blackout
    • $agent_home/bin/emctl start blackout `hostname` -nodeLevel
  1. Shutdown agent
    • $agent_home/bin/emctl stop agent
  1. Reset agentTZ
    • $agent_home/bin/emctl resetTZ agent
  1. Update agent target time zone in em repository
    • Login to em repository database with sysman
    • SQL>exec mgmt_target.set_agent_tzrgn('<AGENT_TARGET_NAME>','US/Central');
    • SQL>commit;
  1. Start agent
    • $agent_home/bin/emctl start agent
    • $agent_home/bin/emctl upload agent

  1. Stop Blackout
    • $agent_home/bin/emctl stop blackout `hostname`

Friday, June 14, 2013

EM12c Dynamically Generate TNS Entry

Follow me on Twitter

Do you want to dynamically create TNS entries for all your databases in your EM12c? Well using the SQL statement below you can.

-----------------SQL-----------------------

SELECT DISTINCT
            lower(tbl_sid.sid) as db_name,LOWER (tbl_sid.sid)
         || ' = '
         || '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST='
         || tbl_tar.host_name
         || ')(PORT='
         || tbl_port.port
         || '))(CONNECT_DATA=(sid='
         || tbl_sid.sid
         || ')))'
            AS TNS_ENTRY
       FROM (SELECT p.target_guid, p.property_value AS port
               FROM mgmt_target_properties p
              WHERE p.property_name = 'Port') tbl_port,
            (SELECT s.target_guid, UPPER (s.property_value) AS sid
               FROM mgmt_target_properties s
              WHERE s.property_name = 'SID') tbl_sid,
            (SELECT s.target_guid, s.property_value AS version
               FROM mgmt_target_properties s
              WHERE s.property_name IN ('Version')) tbl_ver,
            (SELECT s.target_guid, s.property_value AS PATH
               FROM mgmt_target_properties s
              WHERE s.property_name IN ('OracleHome')) tbl_home,
            (SELECT s.target_guid, s.property_value AS data_guard_status
               FROM mgmt_target_properties s
              WHERE s.property_name IN ('DataGuardStatus')) tbl_dg,
            (SELECT s.target_guid, s.VALUE AS PGA
               FROM mgmt$db_init_params s
              WHERE s.name = 'pga_aggregate_target') tbl_pga,
            (SELECT s.target_guid, s.VALUE AS SGA
               FROM mgmt$db_init_params s
              WHERE s.name = 'sga_max_size') tbl_sga,
            (SELECT s.target_guid, s.VALUE AS mem_max
               FROM mgmt$db_init_params s
              WHERE s.name = 'memory_target') tbl_mem,
            mgmt_target_properties tbl_main,
            mgmt_targets tbl_tar
      WHERE     tbl_main.target_guid = tbl_port.target_guid(+)
            AND tbl_main.target_guid = tbl_sid.target_guid(+)
            AND tbl_main.target_guid = tbl_tar.target_guid(+)
            AND tbl_main.target_guid = tbl_ver.target_guid(+)
            AND tbl_main.target_guid = tbl_home.target_guid(+)
            AND tbl_main.target_guid = tbl_dg.target_guid(+)
            AND tbl_main.target_guid = tbl_pga.target_guid(+)
            AND tbl_main.target_guid = tbl_sga.target_guid(+)
            AND tbl_main.target_guid = tbl_mem.target_guid(+)
            AND tbl_tar.target_type = 'oracle_database'
   GROUP BY tbl_port.port,
            tbl_sid.sid,
            tbl_tar.host_name
            ORDER BY 1

Note: If you are going to use another account other than SYSMAN to select you will need to have the following privilege.

grant select on mgmt$storage_report_data to <username>;
grant select on mgmt_target_properties to <username>;
grant select on mgmt_targets to <username>;
grant exempt access policy to <username>;

Thursday, June 13, 2013

EM12c ASM Storage Report

Below the SQL statement will get you a nice ASM report from EM12c data.

Follow me on Twitter

Below is a sample report I have in my apex application op top of my EM12c repository.








Columns:
target_name- ASM target
dsikgroup- diskgroup name
percent_used- percent of diskgroup space used
total_gb- total size of disk group in gb
usable_total_gb- total space used for diskgroup in gb
free_gb- free space for diskgroup in gb
usable_free_gb- usable free space for diskgroup
no_of_disk- number of disk in disk group
lun_size- lun size
rebal_pending- pending rebalance operations
imbalance- will show imbalance in diskgroup

-----------SQL Statement-----------------------

SELECT target_name,
         diskgroup,
         MAX (DECODE (seq, 7, VALUE)) REDUNDANCY,
         MAX (DECODE (seq, 4, VALUE)) PERCENT_USED,
         MAX (DECODE (seq, 6, ceil(VALUE/1024))) TOTAL_GB,
         MAX (DECODE (seq, 9, ceil(VALUE/1024))) USABLE_TOTAL_GB,
         MAX (DECODE (seq, 3, ceil(VALUE/1024))) FREE_GB,
         MAX (DECODE (seq, 8, ceil(VALUE/1024))) USABLE_FREE_GB,
         MAX (DECODE (seq, 2, VALUE)) NO_OF_DISK,
         ceil(( MAX (DECODE (seq, 6, ceil(VALUE/1024)))) /(MAX (DECODE (seq, 2, VALUE)))) LUN_SIZE,
         MAX (DECODE (seq, 5, decode(VALUE,'No','',value))) REBAL_PENDING,
         MAX (DECODE (seq, 1, VALUE)) IMBALANCE
    FROM (SELECT target_name,
                 key_value diskgroup,
                 VALUE,
                 metric_column,
                 ROW_NUMBER ()
                 OVER (PARTITION BY target_name, key_value
                       ORDER BY metric_column)
                    AS seq
            FROM MGMT$METRIC_CURRENT
          WHERE        target_type in ('osm_instance','osm_cluster')
                   AND metric_column IN
                          ('rebalInProgress',
                           'free_mb',
                           'usable_file_mb',
                           'type',
                           'computedImbalance',
                           'usable_total_mb',
                           'percent_used','diskCnt')
                OR (    metric_column = 'total_mb'
                    AND metric_name = 'DiskGroup_Usage'))
GROUP BY target_name, diskgroup
order by 1,2

Note: If you are going to use another account other than SYSMAN to select you will need to have the following privilege.

grant select on MGMT$METRIC_CURRENT to <username>;
grant exempt access policy to <username>;

 ORA-01722 Invalid Number
If you are seeing the error above this means that one of you columns in you environment has varchar data and not a number. You will need to troubleshoot to find the column with the issue by commenting out one column at a time like the below. I find that seq6 or seq5 sometime have varchar data and numbers.

SELECT target_name,
         diskgroup,
         MAX (DECODE (seq, 7, VALUE)) REDUNDANCY,
         MAX (DECODE (seq, 4, VALUE)) PERCENT_USED,
         --MAX (DECODE (seq, 6, ceil(VALUE/1024))) TOTAL_GB,
         MAX (DECODE (seq, 9, ceil(VALUE/1024))) USABLE_TOTAL_GB,
         MAX (DECODE (seq, 3, ceil(VALUE/1024))) FREE_GB,
         MAX (DECODE (seq, 8, ceil(VALUE/1024))) USABLE_FREE_GB,
         MAX (DECODE (seq, 2, VALUE)) NO_OF_DISK,
         ceil(( MAX (DECODE (seq, 6, ceil(VALUE/1024)))) /(MAX (DECODE (seq, 2, VALUE)))) LUN_SIZE,
         MAX (DECODE (seq, 5, decode(VALUE,'No','',value))) REBAL_PENDING,
         MAX (DECODE (seq, 1, VALUE)) IMBALANCE
    FROM (SELECT target_name,
                 key_value diskgroup,
                 VALUE,
                 metric_column,
                 ROW_NUMBER ()
                 OVER (PARTITION BY target_name, key_value
                       ORDER BY metric_column)
                    AS seq
            FROM MGMT$METRIC_CURRENT
          WHERE        target_type in ('osm_instance','osm_cluster')
                   AND metric_column IN
                          ('rebalInProgress',
                           'free_mb',
                           'usable_file_mb',
                           'type',
                           'computedImbalance',
                           'usable_total_mb',
                           'percent_used','diskCnt')
                OR (    metric_column = 'total_mb'
                    AND metric_name = 'DiskGroup_Usage'))
GROUP BY target_name, diskgroup
order by 1,2

EM12c Database Inventory Report

With the select statement below you can have a database inventory report.

Below is a sample report I have in my apex application op top of my EM12c repository.








Instance name- SID
Host name- Host name where database lives
Version- database version
Total memory- This is the total memory SGA*PGA or if 11g total memory_target
Data Guard Status- Primary or Standby
Port- Listener port
Path- Oracle Home path

-----------SQL Statement-----------------------

     SELECT DISTINCT
            tbl_tar.target_guid,
            tbl_sid.sid AS instance_name,
            CASE
               WHEN tbl_tar.host_name LIKE '%.%'
               THEN
                  LOWER (SUBSTR (tbl_tar.host_name,
                                 1,
                                   INSTR (tbl_tar.host_name,
                                          '.',
                                          2,
                                          1)
                                 - 1))
               ELSE
                  tbl_tar.host_name
            END
               host_name,
            tbl_ver.version,
            CASE
               WHEN tbl_mem.mem_max > 0
               THEN
                  CEIL (tbl_mem.mem_max / 1024 / 1024)
               ELSE
                  CEIL (tbl_sga.sga / 1024 / 1024 + tbl_pga.pga / 1024 / 1024)
            END
               total_memory,
            tbl_dg.data_guard_status,
            tbl_port.port,
            tbl_home.PATH
       FROM (SELECT p.target_guid, p.property_value AS port
               FROM mgmt_target_properties p
              WHERE p.property_name = 'Port') tbl_port,
            (SELECT s.target_guid, UPPER (s.property_value) AS sid
               FROM mgmt_target_properties s
              WHERE s.property_name = 'SID') tbl_sid,
            (SELECT s.target_guid, s.property_value AS version
               FROM mgmt_target_properties s
              WHERE s.property_name IN ('Version')) tbl_ver,
            (SELECT s.target_guid, s.property_value AS PATH
               FROM mgmt_target_properties s
              WHERE s.property_name IN ('OracleHome')) tbl_home,
            (SELECT s.target_guid, s.property_value AS data_guard_status
               FROM mgmt_target_properties s
              WHERE s.property_name IN ('DataGuardStatus')) tbl_dg,
            (SELECT s.target_guid, s.VALUE AS PGA
               FROM mgmt$db_init_params s
              WHERE s.name = 'pga_aggregate_target') tbl_pga,
            (SELECT s.target_guid, s.VALUE AS SGA
               FROM mgmt$db_init_params s
              WHERE s.name = 'sga_max_size') tbl_sga,
            (SELECT s.target_guid, s.VALUE AS mem_max
               FROM mgmt$db_init_params s
              WHERE s.name = 'memory_target') tbl_mem,
            mgmt_target_properties tbl_main,
            mgmt_targets tbl_tar
      WHERE     tbl_main.target_guid = tbl_port.target_guid(+)
            AND tbl_main.target_guid = tbl_sid.target_guid(+)
            AND tbl_main.target_guid = tbl_tar.target_guid(+)
            AND tbl_main.target_guid = tbl_ver.target_guid(+)
            AND tbl_main.target_guid = tbl_home.target_guid(+)
            AND tbl_main.target_guid = tbl_dg.target_guid(+)
            AND tbl_main.target_guid = tbl_pga.target_guid(+)
            AND tbl_main.target_guid = tbl_sga.target_guid(+)
            AND tbl_main.target_guid = tbl_mem.target_guid(+)
            AND tbl_tar.target_type = 'oracle_database'
   GROUP BY tbl_tar.target_guid,
            tbl_port.port,
            tbl_sid.sid,
            tbl_tar.host_name,
            tbl_ver.version,
            tbl_home.PATH,
            tbl_dg.data_guard_status,
            tbl_pga.pga,
            tbl_sga.sga,
            tbl_mem.mem_max
   ORDER BY 2;

Note: If you are going to use another account other than SYSMAN to select you will need to have the following privilege.

grant select on mgmt$storage_report_data to <username>;
grant select on mgmt_target_properties to <username>;
grant select on mgmt_targets to <username>;
grant exempt access policy to <username>;

EM12c Server Report

Ever wanted to see the following type of information you see on the host target homepage in EM12c? Now you can using the select statement I created below.



Below is a sample report I have in my apex application op top of my EM12c repository.







This SQL statement will give you server information from the EM repository tables.

HOST_NAME- server name
HARDWARE- hardware type
OS- os version
FREQ_IN_MHZ- speed of CPU
IMPL- implementation
CPU_CORES- number of cores
CPU_THREADS- number of threads
TOTAL_MEMORY_SIZE_GB- total physical RAM
TOTAL_SWAP_SPACE_IN_GB- total swap space
ROOT_FILESYSTEM_TYPE- type of root file system

-----------SQL Statement-----------------------

SELECT DISTINCT
            a.target_guid,
            CASE
               WHEN host_name LIKE '%.%'
               THEN
                  LOWER (SUBSTR (host_name,
                                 1,
                                   INSTR (host_name,
                                          '.',
                                          2,
                                          1)
                                 - 1))
               ELSE
                  host_name
            END
               host_name,
            system_config hardware,
            OS_summary OS,
            c.freq_in_mhz,
            c.impl,
            cpu_count cpu_cores,
            logical_cpu_count cpu_threads,
            CEIL (mem / 1024) AS total_memory_size_in_gb,
            CEIL (max_swap_space_in_mb / 1024) AS total_swap_space_in_gb,
            d.TYPE AS root_filesystem_type
       FROM MGMT$OS_HW_SUMMARY a,
            MGMT$OS_SUMMARY b,
            (SELECT target_guid, freq_in_mhz, impl
               FROM (SELECT t1.target_guid,
                            T1.FREQ_IN_MHZ,
                            t1.impl,
                            ROW_NUMBER ()
                            OVER (PARTITION BY t1.target_guid ORDER BY t1.impl)
                               rn
                       FROM MGMT$HW_CPU_DETAILS T1)
              WHERE rn = 1) c,
            (SELECT cm_target_guid, TYPE
               FROM CM$MGMT_ECM_OS_FILESYSTEM
              WHERE mount_location IN ('c:\', '/', 'C:\')) d
      WHERE     a.target_guid = b.target_guid
            AND a.target_guid = c.target_guid
            AND a.target_guid = d.cm_target_guid
   ORDER BY 2 ASC;

Note: If you are going to use another account other than SYSMAN to select you will need to have the following privilege.

grant select on MGMT$OS_HW_SUMMARY to <username>;
grant select on MGMT$OS_SUMMARY to <username>;
grant select on MGMT$HW_CPU_DETAILS to <username>;
grant select on CM$MGMT_ECM_OS_FILESYSTEM to <username>;
grant exempt access policy to <username>;

EM12c Storage Report

Want a report with all your storage mounts as well as the total space allocated and used?

Below is a select statement you can use to select the data from the SYSMAN views.

select
target_name,
name,
ceil(sizeb/1024/1024/1024) as allocated_gb,
ceil(usedb/1024/1024/1024) as used_gb,
ceil(freeb/1024/1024/1024) as free_gb
from sysman.mgmt$storage_report_data
where entity_type='Mountpoint'
order by 1 asc

Note: If you are going to use another account other than SYSMAN to select you will need to have the following privilege.

grant select on mgmt$storage_report_data to <username>;
grant exempt access policy to <username>;

Monday, June 10, 2013

Oracle Home Property Missing for 12c Agent

1. Check that the Oracle home exist in the $AGENT_INST/sysman/emd/targets.xml
2. Check that the Oracle home exist in the oraInventory

Here is the resolution:

Missing home in oraInventory

1. Attach home to oraInventory
$cd $AGENT_HOME
$AGENT_HOME/oui/bin/runInstaller -silent -attachHome -invPtrLoc $AGENT_HOME/oraInst.loc ORACLE_HOME_NAME="agent1_home" oracle_home="$AGENT_HOME" "cluster_nodes={}"

2. Run emctl collection
$cd $AGENT_HOME
 $./emctl control agent runCollection <TARGET_ORACLE_HOME_NAME>:oracle_home oracle_home_config

Missing Home in Targets.xml

1. Run emctl collection
 $cd $AGENT_HOME

$./emctl control agent runCollection <TARGET_ORACLE_HOME_NAME>:oracle_home oracle_home_config

12c Agents not showing up on list for upgrade

If you are trying to find your agent to upgrade but it is not in the list you need to check the "Not Upgradable Agents".


  1. Go to Setup>Manage Cloud Control>Upgrade Agents
  2. Click "Not Upgradable Agents"
  3. Following the recommendation to fix the issue
  4. Once resolved try to upgrade the agent again.


Another way to check "Not Upgradable Agents"


  1. Go to Setup>Manage Cloud Control>Agents
  2. Click the link "Not Upgradable"
  3. Review the reason 



Thursday, June 6, 2013

Solaris EM12c Agent Unreachable with Error "peer not authenticated"

If you come across a Solaris EM12c agent with status unreachable with error "peer not authenticated" here is a solution.

Verify the Error:
1.$cd $AGENT_HOME/bin
2.$./emctl status agent
Example of error
Agent is Unreachable (REASON = unable to connect to http server at https://dbtest:3872/emd/main/. [peer not authenticated]) but the host is reachable.

Stop the Agent:
1.$./emctl stop agent
2.Verfiy the java process has stopped
$ps -ef |grep java
If the java process is still running you would see like the following still running
$AGENT_HOME/core/12.1.0.2.0/jdk/bin/sparcv9/java
3.$kill -9 <pid>

Update Config File:
1.$cd $AGENT_HOME/agent_inst/sysman/config
2.$cp s_jvm_options.opt s_jvm_options.opt.orig
3.Add the following line to s_jvm_options.opt
-Dsun.security.pkcs11.enable-solaris=false

Restart Agent and Test Upload:
1.$cd $AGENT_HOME/bin
2. $./emctl start agent
3. $./emctl upload agent

Reference:
EM12c Agent status Fails With "Peer Not Authenticated" Error. [ID 1510706.1]

My webpages
http://db12c.blogspot.com/
http://cloudcontrol12c.blogspot.com/

http://www.youtube.com/user/jfruiz11375

Follow me on Twitter

Resolving Agent12c Unreachable

In OEM if you see the your targets have a status of unreachable here are a few steps you can take to try and resolve the issue.

  
$cd $AGENT_HOME/bin/
$./emctl clearstate agent
$./emctl stop agent
$./emctl clearstate agent

If the agent will not stop you can search for the OS process and issue a kill -9
$ps -ef |grep agent12c/core/12.1.0.1.0/jdk
$kill -9 <pid>

$./emctl clearstate agent
$./emctl start agent
$./emctl upload agent

If the upload fails issue the upload command again
$./emctl upload agent

In OEM you should now see that all targets are back online

If the above steps do not work you can doing the following
$cd $AGENT_HOME/bin/
$./emctl clearstate agent
$./emctl stop agent
$./emctl clearstate agent

$cd AGENT_INST/sysman/log
$rm -rf *.*
$cd $AGENT_INST/sysman/emd
$rm -rf state upload
$cd $AGENT_HOME/bin/
$./emctl clearstate agent
$./emctl start agent
$./emctl clearstate agent
$./emctl status agent
$./emctl upload agent

In OEM you should now see that all targets are back online