Howto rename managed target on Oracle EM 12c

This post is also available in: Português

During many months the only way that I found to rename a Managed Target on OEM Cloud Control was deleting and adding it again. However, there is another way as I will show you. This procedure was tested and validated on EMc 12.1.0.2. So, if you choose to try at another version, make it at your own risk!

All managed targets in Enteprise Manager Cloud Control 12c have a "Display Name" and a "Target Name".

Moreover, there are two types of targets:

  • Repository Side targets
  • Agent Side targets

To query the Repository Side targets, use the following SQL inside your EM repository:

SELECT ENTITY_TYPE,
       TYPE_DISPLAY_NAME,
       ENTITY_NAME,
       DISPLAY_NAME
FROM   SYSMAN.EM_MANAGEABLE_ENTITIES
WHERE  MANAGE_STATUS = 2
AND    REP_SIDE_AVAIL = 1
ORDER  BY 1,2;

To query the Agent Side targets, use the following SQL inside your EM repository:

SELECT ENTITY_TYPE,
       TYPE_DISPLAY_NAME,
       ENTITY_NAME,
       DISPLAY_NAME,
       EMD_URL
FROM   SYSMAN.EM_MANAGEABLE_ENTITIES
WHERE  MANAGE_STATUS = 2
AND    REP_SIDE_AVAIL = 0
AND    EMD_URL IS NOT NULL
ORDER  BY 1,2,3;

The agent side targets are stored also inside your target host. You can list them executing the following script (as the EM Agent user):

[root@evabddrjs001 ~]# su - emc12
[emc12@evabddrjs001 ~]$ $AGENT_HOME/bin/emctl config agent listtargets
Oracle Enterprise Manager Cloud Control 12c Release 2
Copyright (c) 1996, 2012 Oracle Corporation.  All rights reserved.
[10.221.63.104, host]
[10.221.63.104:3872, oracle_emd]
[agent12c1_2_evabddrjs001, oracle_home]
[COLISEU_104, oracle_database]
[OraDb10g_home1_1_evabddrjs001, oracle_home]
[COLISEU_10.221.63.104, oracle_listener]
[emc12@evabddrjs001 ~]$

First, let's see an example of how to rename Repository side targets:

Rename Repository Side Targets

What you need to know:

  • These targets are not monitored by the Cloud Control Agent.
  • These targets are not present in the Cloud Control Agent files "$AGENT_BASE/sysman/emd/targets.xml"
  • These targets are only present in the Cloud Control repository and they are mainly known as "System" targets or aggregate targets (like groups).

The "Display Name" and the "Target Name" are usually the same on Repository Side targets.

It is possible to rename Repository Side targets. First, execute the following emcli command as oracle user inside your EMc server:

[root@ec12mntrjr001 ~]# su - oracle
[oracle@ec12mntrjr001 ~]$ emcli login -username=sysman
Enter password :

Login successful
[oracle@ec12mntrjr001 ~]$ emcli sync
Synchronized successfully

Target Name

To rename the "Target Name" of the target, use the following query:

-target_name=<the actual target name>
-new_target_name=<the new target name>

Eg: Renaming a target name from "oracbddrjs_cluster" to "oracbddrjs-cluster".

[oracle@ec12mntrjr001 ~]$ emcli rename_target -target_type="cluster" -target_name="oracbddrjs_cluster" -new_target_name="oracbddrjs-cluster"

Now check with the "Repository Side Targets" SQL above if the Target name and Display name were modified.

If only the target name was changed, proceed to the next step.

Display Name

To rename the "Display Name" of the target, use the query:

-name=<the target name> # Note that I use the new name because I renamed it in the step before.
-display_name=<new display name>

Eg: Renaming a display name to "oracbddrjs-cluster".

[oracle@ec12mntrjr001 ~]$ emcli modify_target -name="oracbddrjs-cluster" -type="cluster" -display_name="oracbddrjs-cluster"
Target "oracbddrjs-cluster:cluster" modified successfully
[oracle@ec12mntrjr001 ~]$

Now, let's see an example of how to rename Agent side targets:

Rename Agent Side Targets

What you need to know:

  • These targets are monitored by the Cloud Control Agent.
  • These targets are present in the Cloud Control Agent files "$AGENT_BASE/sysman/emd/targets.xml"

The "Display Name" and the "Target Name" may be different for Agent Side targets.
The "Target Name" for an Agent Side target is the name of the target in the EM Cloud Control Agent file "$AGENT_BASE/sysman/emd/targets.xml".
(Which can be retrieved with the EM Cloud Control Agent command "emctl config agent listtargets").

Display Name

To change the "Display Name" of an Agent Side target, you can use the following command:

Eg: Renaming the listener display name from "COLISEU_10.221.63.104" to "LISTENER_10.221.63.104".

[root@ec12mntrjr001 ~]# su - oracle
[oracle@ec12mntrjr001 ~]$ emcli login -username=sysman
Enter password :

Login successful
[oracle@ec12mntrjr001 ~]$ emcli modify_target -name="COLISEU_10.221.63.104" -type="oracle_listener" -display_name="LISTENER_10.221.63.104" -on_agent
Target "COLISEU_10.221.63.104:oracle_listener" modified successfully

Checking on target side:

[emc12@evabddrjs001 ~]$ emctl config agent listtargets
Oracle Enterprise Manager Cloud Control 12c Release 2
Copyright (c) 1996, 2012 Oracle Corporation.  All rights reserved.
[10.221.63.104, host]
[10.221.63.104:3872, oracle_emd]
[agent12c1_2_evabddrjs001, oracle_home]
[COLISEU_104, oracle_database]
[OraDb10g_home1_1_evabddrjs001, oracle_home]
[COLISEU_10.221.63.104, oracle_listener]
[emc12@evabddrjs001 ~]$

The target name didn't change, but the Display name on EM is now modified as the picture below:

Target Name

Attention: Do this at your own risk. Oracle does not support it yet and it will be necessary to do manual changes on SYSMAN packages.

In this example, we will rename the listener target name from "COLISEU_10.221.63.104" to "LISTENER_10.221.63.104". Note that the display name was already changed in the step before.

First of all, stop the agent on the target host, edit the "$AGENT_BASE/sysman/emd/targets.xml" with the desired target name and start the agent again:

[emc12@evabddrjs001 ~]$ emctl stop agent
Oracle Enterprise Manager Cloud Control 12c Release 2
Copyright (c) 1996, 2012 Oracle Corporation.  All rights reserved.
Stopping agent ..... stopped.
[emc12@evabddrjs001 ~]$ vim $AGENT_BASE/sysman/emd/targets.xml

Before:

[emc12@evabddrjs001 ~]$ cat $AGENT_BASE/sysman/emd/targets.xml
...
<Target TYPE="oracle_listener" NAME="COLISEU_10.221.63.104" DISPLAY_NAME="LISTENER_10.221.63.104" ON_HOST="" EMD_URL="https://10.221.63.104:3872/emd/main/" TIMEZONE_REGION="" IDENTIFIER="TARGET_GUID=0AD03AC01B183A0E9762470BD2A4799E">
<Property NAME="Machine" VALUE="10.221.63.104"/>
<Property NAME="Port" VALUE="1521"/>
<Property NAME="ListenerOraDir" VALUE="/software/app/oracle/product/network/admin"/>
<Property NAME="OracleHome" VALUE="/software/app/oracle/product"/>
<Property NAME="LsnrName" VALUE="LISTENER"/>
</Target>
...

After:

[emc12@evabddrjs001 ~]$ cat $AGENT_BASE/sysman/emd/targets.xml
 ...
<Target TYPE="oracle_listener" NAME="LISTENER_10.221.63.104" DISPLAY_NAME="LISTENER_10.221.63.104" ON_HOST="" EMD_URL="https://10.221.63.104:3872/emd/main/" TIMEZONE_REGION="" IDENTIFIER="TARGET_GUID=0AD03AC01B183A0E9762470BD2A4799E">
<Property NAME="Machine" VALUE="10.221.63.104"/>
<Property NAME="Port" VALUE="1521"/>
<Property NAME="ListenerOraDir" VALUE="/software/app/oracle/product/network/admin"/>
<Property NAME="OracleHome" VALUE="/software/app/oracle/product"/>
<Property NAME="LsnrName" VALUE="LISTENER"/>
</Target>
...
[emc12@evabddrjs001 ~]$ emctl start agent
Oracle Enterprise Manager Cloud Control 12c Release 2
Copyright (c) 1996, 2012 Oracle Corporation.  All rights reserved.
Starting agent .................. started.
[emc12@evabddrjs001 ~]$ vim $AGENT_BASE/sysman/emd/targets.xml
[emc12@evabddrjs001 ~]$ emctl config agent listtargets
Oracle Enterprise Manager Cloud Control 12c Release 2
Copyright (c) 1996, 2012 Oracle Corporation.  All rights reserved.
[10.221.63.104, host]
[10.221.63.104:3872, oracle_emd]
[agent12c1_2_evabddrjs001, oracle_home]
[COLISEU_104, oracle_database]
[OraDb10g_home1_1_evabddrjs001, oracle_home]
[LISTENER_10.221.63.104, oracle_listener]
[emc12@evabddrjs001 ~]$

The target name on the client changed. However, only those changes are not enough. If we check on EM, we will see that the target name is still unchanged.

Now, we have 2 different methods with same results to finish our target rename:

Method 1:

If you try to change the target name as we did on "Repository Managed Targets", you will get the following error:

[oracle@ec12mntrjr001 ~]$ emcli rename_target -target_type="oracle_listener" -target_name="COLISEU_10.221.63.104" -new_target_name="LISTENER_10.221.63.104"
Rename not supported for given Target Type.

This command line implicit calls the procedure SYSMAN.EM_TARGET.RENAME_TARGET.

Unfortanelly, if we check the procedure code inside the package body, there is a comment:

-- we will implement rename of agent side targets when it is fully
-- supported by agent

However, we have already done this manual agent name change.

To accomplish this, you will need to edit the PACKAGE BODY SYSMAN.EM_TARGET. Make a backup of the code and apply the changes:

From:

     -- we will implement rename of agent side targets when it is fully
     -- supported by agent
    IF ( l_trec.manage_status = MANAGE_STATUS_MANAGED AND
         l_trec.emd_url IS NOT NULL) 
    THEN
      raise_application_error(MGMT_GLOBAL.INVALID_PARAMS_ERR,
          MGMT_GLOBAL.INVALID_PARAMS_ERR||' Not allowed') ;
    END IF ;

To:

     -- we will implement rename of agent side targets when it is fully
     -- supported by agent
    IF ( l_trec.manage_status = MANAGE_STATUS_MANAGED AND
         l_trec.emd_url IS NOT NULL) 
    THEN
      --raise_application_error(MGMT_GLOBAL.INVALID_PARAMS_ERR,
      --    MGMT_GLOBAL.INVALID_PARAMS_ERR||' Not allowed') ;
	  null;
    END IF ;

Now recompile the package and any dependent invalid object:

SQL> EXEC sys.UTL_RECOMP.recomp_serial('SYSMAN');

PL/SQL procedure successfully completed.

Let's try again.

[oracle@ec12mntrjr001 ~]$ emcli rename_target -target_type="oracle_listener" -target_name="COLISEU_10.221.63.107" -new_target_name="LISTENER_10.221.63.107"
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "SYSMAN.EM_TARGET" has been invalidated
ORA-04065: not executed, altered or dropped package body "SYSMAN.EM_TARGET"
ORA-06508: PL/SQL: could not find program unit being called: "SYSMAN.EM_TARGET"
ORA-06512: at "SYSMAN.MGMT_TARGET", line 3373
ORA-06512: at line 1

If you get this error, just reconnect or resync the session that was opened before you made the package change, and try again:

[oracle@ec12mntrjr001 ~]$ emcli sync
Synchronized successfully
[oracle@ec12mntrjr001 ~]$ emcli rename_target -target_type="oracle_listener" -target_name="COLISEU_10.221.63.107" -new_target_name="LISTENER_10.221.63.107"
Target COLISEU_10.221.63.107 successfully renamed to LISTENER_10.221.63.107.

Great. Now restore the package body backup that you have made putting back the commented line.

Method 2:

We have also another way to change the target name inside EMc 12c Metadata. We can directly call the procedure that we changed on "Method 1":

SQL> exec sysman.em_target.rename_target('oracle_listener','COLISEU_10.221.63.104','LISTENER_10.221.63.104');

begin sysman.em_target.rename_target('oracle_listener','COLISEU_10.221.63.104','LISTENER_10.221.63.104'); end;

ORA-20233: -20233 Not allowed
ORA-06512: at "SYSMAN.EM_TARGET", line 5040
ORA-06512: at line 2

I got the error above because I need to comment the Package Body lines exactly the same way I did in "Method 1". So, backup it, comment them, recompile the dependencies and try again:

SQL> exec sysman.em_target.rename_target('oracle_listener','COLISEU_10.221.63.104','LISTENER_10.221.63.104');

begin sysman.em_target.rename_target('oracle_listener','COLISEU_10.221.63.104','LISTENER_10.221.63.104'); end;

ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package "SYSMAN.EM_TARGET" has been invalidated
ORA-04065: not executed, altered or dropped package "SYSMAN.EM_TARGET"
ORA-06508: PL/SQL: could not find program unit being called: "SYSMAN.EM_TARGET"
ORA-06512: at line 2

If you get this error, just reconnect the session that was opened before you made the package change, and try again:

SQL> exec sysman.em_target.rename_target('oracle_listener','COLISEU_10.221.63.104','LISTENER_10.221.63.104');

PL/SQL procedure successfully completed

SQL> commit;

Commit complete

SQL>

Great, now let's check on EM screen:

Everything is working fine. Don't forget to restore the package body backup that you have made, putting back the commented line.

Now you finally have your target renamed.

This article was based on Metalink document Doc ID 1515413.1, with many, many adaptations.
 
Have you enjoyed? Please leave a comment or give a 👍!

10 comments

Skip to comment form

    • Eric on November 9, 2015 at 16:37
    • Reply

    Outstanding!

    • david on November 25, 2015 at 07:27
    • Reply

    OK but cannot view target status history

    1. Hi David,

      I didn't check for that. You may miss some past information, please use this procedure with caution as I mentioned in the beggining.

      Regards,
      Rodrigo

    • Peter Maloof on December 1, 2015 at 15:16
    • Reply

    In your targets.xml file, shouldn't
    IDENTIFIER="TARET_GUID=0AD03AC01B183A0E9762470BD2A4799E"> be IDENTIFIER="TARGET_GUID=0AD03AC01B183A0E9762470BD2A4799E">?

    1. Yes, you are right. Thanks for noticing and for the lince eyes!
      I've just corrected it.

      Regards,
      Rodrigo J

    • Prakash J on July 1, 2016 at 04:03
    • Reply

    I have two Oracle RAC databases with same SID. Hence, I could not able to add one of the rac database to the EM as I am getting error message as

    "Failed: Target is already monitored using : rac database"

    With your article, I have successfully renamed the existing database target. But, when I tried to add the new database, still getting the above error. Please suggest.

    1. Well, in that case I recommend you to remove and add the target again.
      PS: Sorry for late response, this message was lost in my spam folder.

  1. Hi Rodrigo,

    I tried to rename database target and it didnt allowed me.

    oracle@bttstdev64:/data/app/oracle/oms13c/bin$ ./emcli rename_target -target_type="oracle_database" -target_name="S1D2ST_1" -new_target_name="S1D2ST"
    Rename not supported for the given Target Type.

    Any restriction of type of target type?

    1. Hi Rajkishore,
      Yes there are restrictions. I recommend to drop/create the target or do the comment in the procedure as I showed. Only than you'll be able to execute the "emcli rename_target" utility.

      Thanks,
      RJ

  2. Great post!

Leave a Reply

Your email address will not be published.