When a host is rebuilt before we have a chance to remove the agent and its targets you must go into the repository and remove the targets manually

1. Connect to the OEM Grid Repository as sysman

2. Select a list of agents (hostname:port) for proper syntax in the next step

SQL> select target_name from mgmt_targets where target_type=’oracle_emd’;

3. Execute the mgmt_agent.cleanup agent procedure as illustrated below

SQL> exec mgmt_admin.cleanup_agent(‘Server1:3872′);

This technique works like a charm for 11g but should never be used for 12c OEM.

The SQL+ technique will cause repository database performance issues, so don’t do it.

Use emcli instead.

> emcli get_targets -targets=”oracle_emd” | grep [agent’s hostname]
> emcli delete_target -name=”[agent name from query above]” -type=”oracle_emd” -delete_monitored_targets -async;

Quotation marks are required, the brackets indocate values you must provide.