Tuesday, 6 September 2016

Monitoring Multiple Oracle database tablespaces on multiple machines.

This post help you to monitor your multiple database's tablespaces on multiple servers by collecting information into a table from each database using a job and then use that table to report the tablespace status.


CREATE TABLE scripts.VERIFY_TABLESPACE
(
  TABLESPACE_NAME  VARCHAR2(30 BYTE),
  MEGS_ALLOC       NUMBER,
  MEGS_FREE        NUMBER,
  MEGS_USED        NUMBER,
  PCT_FREE         NUMBER,
  PCT_USED         NUMBER,
  MAX              NUMBER,
  USED_PCT_OF_MAX  NUMBER
)
TABLESPACE USERS
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING
/

create or replace public synonym VERIFY_TABLESPACE for scripts.VERIFY_TABLESPACE
/
GRANT INSERT, SELECT ON scripts.VERIFY_TABLESPACE TO PUBLIC
/

CREATE PUBLIC DATABASE LINK monitor_db
CONNECT TO smbackup
IDENTIFIED BY smbackup
USING 'backuprep';
/

grant select any dictionary to scripts
/
create or replace force view scripts.v_verify_tablespace
as
select  a.tablespace_name,
       round(a.bytes_alloc / 1024 / 1024) megs_alloc,
       round(nvl(b.bytes_free, 0) / 1024 / 1024) megs_free,
       round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) megs_used,
       round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_Free,
       100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_used,
       round(maxbytes/1048576) Max,
       round(round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) / round(maxbytes/1048576)*100) used_pct_of_max
from  ( select  f.tablespace_name,
               sum(f.bytes) bytes_alloc,
               sum(decode(f.autoextensible, 'YES',f.maxbytes,'NO', f.bytes)) maxbytes
        from dba_data_files f
        group by tablespace_name) a,
      ( select  f.tablespace_name,
               sum(f.bytes)  bytes_free
        from dba_free_space f
        group by tablespace_name) b
where a.tablespace_name = b.tablespace_name (+)
union all
select h.tablespace_name,
       round(sum(h.bytes_free + h.bytes_used) / 1048576) megs_alloc,
       round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 1048576) megs_free,
       round(sum(nvl(p.bytes_used, 0))/ 1048576) megs_used,
       round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100) Pct_Free,
       100 - round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100) pct_used,
       round(sum(f.maxbytes) / 1048576) max,
       round( round(sum(nvl(p.bytes_used, 0))/ 1048576)  / round(sum(f.maxbytes) / 1048576) *100) used_pct_of_max
from   sys.v_$TEMP_SPACE_HEADER h, sys.v_$Temp_extent_pool p, dba_temp_files f
where  p.file_id(+) = h.file_id
and    p.tablespace_name(+) = h.tablespace_name
and    f.file_id = h.file_id
and    f.tablespace_name = h.tablespace_name
group by h.tablespace_name
/

create or replace public synonym v_verify_tablespace for scripts.v_verify_tablespace
/


create or replace procedure scripts.p_log_tablespace
as
begin
insert into verify_tablespace(
TABLESPACE_NAME, MEGS_ALLOC, MEGS_FREE, MEGS_USED, PCT_FREE, PCT_USED, MAX, USED_PCT_OF_MAX
)
select
TABLESPACE_NAME, MEGS_ALLOC, MEGS_FREE, MEGS_USED, PCT_FREE, PCT_USED, MAX, USED_PCT_OF_MAX
from v_verify_tablespace;
delete from smbackup.verify_tablespace@monitor_db where client = 'ASPEN';
commit;
insert into smbackup.verify_tablespace@monitor_db(
CLIENT, TABLESPACE_NAME, MEGS_ALLOC, MEGS_FREE, MEGS_USED, PCT_FREE, PCT_USED, MAX, USED_PCT_OF_MAX
)
select
'ASPEN', TABLESPACE_NAME, MEGS_ALLOC, MEGS_FREE, MEGS_USED, PCT_FREE, PCT_USED, MAX, USED_PCT_OF_MAX
from verify_tablespace;
commit;
exception
when others then null;
end;
/
create or replace public synonym  p_log_tablespace for scripts.p_log_tablespace
/


DECLARE
  X NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
  ( job       => X
   ,what      => 'scripts.p_log_tablespace;'
   ,next_date => to_date('19/07/2011 7:00:00','dd/mm/yyyy hh24:mi:ss')
   ,interval  => 'trunc(SYSDATE+1)+6/24'
   ,no_parse  => FALSE
  );
  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;
END;
/

Reporting_server Tns

BACKUPREP =
 (DESCRIPTION = 
   (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.20.23)(PORT = 1521))
   )
 (CONNECT_DATA =
   (SERVICE_NAME = ORA12)
 ) 
) 

 Step – 1:

add your reporting server tns entry on client machine in                        tnsnames.ora to create db link.
 Step – 2:

Replace client name in last procedure in attached script file 
 Step – 3:

Execute scripts in attached file one-by-one carefully on client                database. And also create database job at suitable time as in my                case is 6:45 AM 
 Step – 4:

Test result data on BACKUPREP {tns given above}



Monday, 13 June 2016

Create/Configuring the Recovery Catalog Database


Allocate space for the recovery catalog. Consider:
– Number of databases supported by the recovery catalog
– Number of archived redo log files and backups recorded
– Use of RMAN stored scripts





Connect to the database where recovery catalog needs to be created and execute following Commands.

sqlplus sys as sysdba


Create a tablespace for the recovery catalog, which becomes the default tablespace for the recovery catalog owner.

CREATE TABLESPACE rmanbkup datafile '/home/oracle/product/11.2.0/dbhome_1/oradata/ow12c/rmanbkup.dbf' SIZE 75M autoextend ON NEXT 2M MAXSIZE UNLIMITED;


Create the recovery catalog owner.


CREATE USER rmanbkup IDENTIFIED BY oracle
 TEMPORARY TABLESPACE temp
 DEFAULT TABLESPACE rmanbkup
 QUOTA UNLIMITED ON rmanbkup ;

Grant the RECOVERY_CATALOG_OWNER role

GRANT recovery_catalog_owner TO rmanbkup;

Connect to the recovery catalog database as the catalog owner and create catalog.

[oracle@rhel6 ~/Desktop]$ rman catalog rmanbkup/oracle@ow12c

Recovery Manager: Release 11.2.0.3.0 - Production on Fri May 27 16:17:18 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to recovery catalog database

RMAN> CREATE CATALOG;

recovery catalog created

RMAN>  exit;


Now connect to catalog with target database to register database to recovery catalog 


RMAN performs the following actions:

• Creates rows in the recovery catalog tables for the target database
• Copies data from the target database control file to the recovery catalog tables
• Synchronizes the recovery catalog with the control file


[oracle@rhel6 oradata]$ rman target sys/oracle@ow11g catalog rmanbkup/oracle@ow12c

Recovery Manager: Release 11.2.0.3.0 - Production on Mon Jun 13 13:00:11 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: OW11G (DBID=1397584131)
connected to recovery catalog database

RMAN> base: OW11G (DBID=1397584131)

connected to recovery catalog database


RMAN> REGISTER DATABASE;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete


Manually Resynchronizing the Recovery Catalog

RMAN> resync catalog;




To Unregistering a Target Database from the Recovery Catalog

• This removes information about the target database from the recovery catalog.
• Use this when you no longer want the target database to be defined in the recovery catalog.


$ rman target sys/oracle@ow11g catalog rmanbkup/oracle@ow12c

RMAN> UNREGISTER DATABASE;

database name is "OW11G" and DBID is 1397584131

Do you really want to unregister the database (enter YES or NO)? yes
database unregistered from the recovery catalog



Cataloging Additional Backup Files

Examples of cataloging a control file, data file, archived redo log file, and backup piece follow:

RMAN> CATALOG CONTROLFILECOPY
'/disk1/controlfile_bkup/2009_01_01/control01.ctl';
RMAN> CATALOG DATAFILECOPY
'/disk1/datafile_bkup/2009_01_01/users01.dbf';
RMAN> CATALOG ARCHIVELOG '/disk1/arch_logs/archive1_731.log',
'/disk1/arch_logs/archive1_732.log';
RMAN> CATALOG BACKUPPIECE '/disk1/backups/backup_820.bkp';



You can catalog all files in the currently enabled Flash Recovery Area as follows:
RMAN> CATALOG RECOVERY AREA NOPROMPT;


START WITH Option
Use the START WITH option to catalog all files found in the directory tree specified. Provide a
prefix that indicates the directory and possibly a file prefix to look for. You cannot use wildcards;
this is only a prefix.


All types of backup files that are found in the specified directory and subdirectories are cataloged.
Suppose you have several backup files in the /tmp/arch_logs directory. The following
command catalogs all of them:

RMAN> CATALOG START WITH '/tmp/arch_logs/';

Suppose you want to be sure to catalog only those files in the /tmp directory whose file names start
with the string bset. The following accomplishes that:

RMAN> CATALOG START WITH '/tmp/bset';

This command also catalogs any backup files that are found in directory trees that begin with
/tmp/bset.

The CATALOG command can be used without being connected to a recovery catalog.



Sunday, 12 June 2016

Oracle Dataguard Switch Over and Failover

Role Transitions/Switch-over  Involving Physical Standby Databases
------------------------------------------------------------

To check the switchover status of database issue the following commands on primary database

SQL>select switchover_status from v$database;

A value of TO STANDBY or SESSIONS ACTIVE indicates that the primary database can be
switched to the standby role.

SQL>alter database commit to switchover to physical standby with session shutdown;
then
SQL>shutdown immediate;
SQL>startup nomount;
SQL>alter database mount standby database;

Above commands with create a new marker archived log which be applied on standby database a signal that the
standby is ready to work as primary database. you can confirm it by following commands on standby database.

SQL>select switchover_status from v$database;

If you received the switchover status of commands as "TO_PRIMARY" then its mean marker archived log has been received and  your database
is ready to change the status to primary.

Now issue the following command  on standby to change the status of standby database to primary.

SQL>ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

SQL>shutdown immediate;
SQL>startup;

Now enjoy your new primary database.

following command on current standby DB .

 ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE disconnect;

select sequence#,applied from v$archived_log order by 1;


Performing a Failover to a Physical Standby Database
=====================================================
1-check V$ARCHIVE_GAP  view for any gap. If there is gap manually copy the archives and register in standby.

 select * from v$archive_gap;

2- ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';
               repeat for all missing archived files until gap resloved.

3- Change the physical standby status step by step by following commands.

Stop Redo Apply
---------------
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;


SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

Incase of error execute below statement otherwise skip it
SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
------


-----------check status and switchover to primary
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE ;


SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
SQL> ALTER DATABASE OPEN;

Open Standby Database for reporting Purpose

In this post we will perform different operations on standby like  Switch over ,Fail Over  ,Open standby database for reporting purpose,check standby database status.

Step-I Create standby control file.
SQL>alter database create standby controlfile as 'D:\docs\data\control.ctl';

move primary db and redo file plus standby control.clt file, password  and spfile.

On standby

1. make copy of standby control file
2. modify pfile with stand by parameters from oranet2
3 startup mount database with this pfile.
create spfile from pfile
alter database open

For Real Time apply.
-------------------
sqlplus / as sysdba

SQL>Startup mount

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE disconnect;


Step-II Change the status of standby database in recover mode in background mode by the following commands.

SQL>alter database recover managed standby database disconnect;



Step-III To check the status of standby database issue the following command for applied
             archived logs.

SQL>select max(sequence#) from v$archived_log where applied='YES';
SQL>select sequence#,applied from v$archived_log order by 1;

Step-IV Stop Managed recovery on standby / Open for reporting.

SQL>alter database recover managed standby database cancel;
SQL>alter database open;

===============To again start stanby process ===============
shutdown immediate;
startup mount
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE disconnect;



Saturday, 19 December 2015

Configure Standby Database / Data Guard Step By Step


1. Install Oracle database with same structure on two machines.

if you are installing on vmware or virtual box then prepare first machine and then clone it.

In this post machine names are machine01 (Primary DB)  and machine02 (Secondary DB).

2.  Make sure database structure  and SID is same on both machines this will help you to create and manage Data gaurd easily.
 
create SID with same name like alidb for both machines.


3.  On first machine  open $0ORACLE_HOME/network/admin/tnsnames.or file
and make two copies of your service entry and change the copied service entries to mdb01 and mdb02 as given below.

mdb01 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = machine01)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = alidb)
    )
  )


mdb02 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = machine02)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = alidb)
    )
  )


4. Now perform same on second machine  open $ORACLE_HOME/network/admin/tnsnames.or file
and make two copies of your service entry and change the copied service entries to mdb01 and mdb02 as given below.

mdb02 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = machine02)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = alidb)
    )
  )



mdb01 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = machine01)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = alidb)
    )
  )



5. on both machines in /etc/hosts register both systems so that both machine can access each other .
     and test connectivity of both service created earlier from both machines.
Example /etc/hosts entry on both machines

192.168.0.143    machine01   machine01.com
192.168.0.144    machine02   machine02.com



6. create standby Redolog files on primary database with formula Total Existing +1. i.e I have 3 so I need to create 4 new files as given below.

Query to check existing log files and there path.

sqlplus / as sysdba

select member from v$logfile;

===========================
Add Standby Redolog file
===========================
alter database add standby logfile '$ORACLE_HOME/oradata/alidb/redo04.log' size 50m;

alter database add standby logfile '$ORACLE_HOME/oradata/alidb/redo05.log' size 50m;

alter database add standby logfile '$ORACLE_HOME/oradata/alidb/redo06.log' size 50m;

alter database add standby logfile '$ORACLE_HOME/oradata/alidb/redo07.log' size 50m;

select member from v$logfile;


7. create pfile='$ORACLE_BASE/admin/alidb/pfile/init.ora' from spfile;


8. Now open $ORACLE_BASE/admin/alidb/pfile/init.ora on your machine in text editor and
   Paste following parameters in above pfile opened in last step

###########################################
#Data Guard Parameter for db1 in pfile
###########################################
DB_UNIQUE_NAME=mdb01
LOG_ARCHIVE_CONFIG='DG_CONFIG=(mdb01,mdb02)'
LOG_ARCHIVE_DEST_1=
 'LOCATION=/d01/apps/flash_recovery_area/arch_alidb
  VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
 DB_UNIQUE_NAME=mdb01'
LOG_ARCHIVE_DEST_2=
 'SERVICE=mdb02 LGWR ASYNC
  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
  DB_UNIQUE_NAME=mdb02'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=Arch_%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
FAL_SERVER=mdb02
FAL_CLIENT=mdb01
STANDBY_FILE_MANAGEMENT=AUTO



9. Create following arch_alidb directory in flash_recovery_area on your both machines .

mkdir   /d01/apps/flash_recovery_area/arch_alidb


10. Now mount primary DB  with new pfile create above and perform following on primary database.

sqlplus  / as sysdba


SQL> shutdown immediate;



sqlplus  / as sysdba

startup mount pfile='$ORACLE_BASE/admin/alidb/pfile/init.ora'


Switch to archivelog mode 

archive log list;

alter database archivelog;

archive log list;


On Primary db create control file that would be used at secondary db.

alter database create standby controlfile as '$ORACLE_HOME/oradata/alidb/control_std.ctl';


Create spfile on primary database.

create spfile from pfile= '$ORACLE_BASE/admin/alidb/pfile/init.ora';


11. Shutdown  Secondary database machines.

sqlplus / as sysdba
shutdown immediate;


12 Now on machine02 and perform following

Copy control file from primary db $ORACLE_HOME/oradata/alidb/control_std.ctl ,  password file and all datafiles redologs except control files (control01,control02) to a folder and move this folder to standby db server
then rename $ORACLE_HOME/oradata/alidb/ to $ORACLE_HOME/oradata/alidb_old db  folder on standby server and  create new folder $ORACLE_HOME/oradata/alidb then move these files there.

Also rename existing control files on standby database and replace control_sdt.clt on the same location with old name.

i.e if control01.clt rename it control01_old.clt .
and paste control_std.ctl in this folder and rename it control01.ctl.

=====================================


13. add following parameters to pfile on standby
you can get pfile from Primary db '$ORACLE_BASE/admin/alidb/pfile/init.ora';

vi $ORACLE_BASE/admin/alidb/pfile/init.ora
change following line as given below



remove earlier added parameters starting from the below line as following part that we add
###########################################
#Data Guard Parameter for db1 in pfile
###########################################

Add following in the '$ORACLE_BASE/admin/alidb/pfile/init.ora' on Secondary db.


###########################################
#Data Guard Parameter db2
###########################################
DB_UNIQUE_NAME=mdb02
LOG_ARCHIVE_CONFIG='DG_CONFIG=(mdb01,mdb02)'
LOG_ARCHIVE_DEST_1=
 'LOCATION=/d01/apps/flash_recovery_area/arch_alidb
  VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
  DB_UNIQUE_NAME=mdb02'
LOG_ARCHIVE_DEST_2=
 'SERVICE=mdb01 LGWR ASYNC
  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
  DB_UNIQUE_NAME=mDB01'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=Arch%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
FAL_SERVER=mDB01
FAL_CLIENT=mDB02
STANDBY_FILE_MANAGEMENT=AUTO

#======================

14. Mount secondary db using following command.

sqlplus / as sysdba

startup mount pfile='$ORACLE_BASE/admin/alidb/pfile/init.ora'

check archive log status with following command is should be enabled.

archive log list


create spfile with this command.

create spfile from pfile= '$ORACLE_BASE/admin/alidb/pfile/init.ora';

15. Open primary DB

alter database open;


16. on standby execute following For Real Time apply.
-------------------
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE disconnect;


To check the status of standby database issue the following command for applied archived logs.

select max(sequence#) from v$archived_log where applied='YES';

select sequence#,applied from v$archived_log order by 1;

===================== Stand by created ======================-



Thursday, 17 December 2015

YuM on RHEL 7

RHEL7: Create a local repository.



Configuration Procedure

Create a directory for the RHEL 7 distribution:
# mkdir -p /var/www/html/rhel7
Note: By creating the local repository in the /var/www/html directory, you will be ready to make it available on the network after installing an Apache webserver at a later stage.
Mount the previously downloaded Rhel 7 distribution  (called here rhel-workstation-7.1-x86_64-dvd.iso) and copy it locally:
# mount -o loop rhel-workstation-7.1-x86_64-dvd.iso /mnt
# cd /mnt
# tar cvf - . | (cd /var/www/html/rhel7; tar xvf -)
# cd /; umount /mnt
Go to the directory where the repository configuration is:
# cd /etc/yum.repo.d
Create the rhel7.repo file and type:
[rhel7]
name=rhel7
baseurl=file:///var/www/html/rhel7/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rhel-7
Clean up the yum configuration and check it:
# yum clean all
# yum repolist all
If you regularly add new packages in your local repository, don’t forget to update it. To do that, install the createrepo package and execute it with the repository path as argument:
# yum install -y createrepo
# createrepo /var/www/html/rhel7
# yum clean all
# yum repolist all

Thursday, 15 October 2015

Configure Oracle Enterprise Manager on Windows







This post will Specially help you to run Oracle Enterprise Manager on Windows 7,Windows 8 and Windows 2012

If you are receiving following error this will help.

CONFIG: OpenSCManager FAILED: Access is denied.

Tips

0. Always Assign Static IP to your Machine in windows host file.
1. Change IP to Machine name as listed below.
2. Run CMD as administrator
3. Execute Drop EM Repo Command
4. Unlock DBSNMP and SYSMAN  users
5. Execute Create EM Repo Command

These are the steps:
1. Change the %ORACLE_HOME%\network\admin\listener.ora file from an IP number to machine name.
2. Change the %ORACLE_HOME%\network\admin\tnsnames.ora file from an IP number to a machine name.
3. Change the C:\WINDOWS\System32\drivers\etc\hosts file by adding this line beneath the default localhostline (for the new Hostname value):
127.0.0.1       localhost
192.168.10.22  win7-22
4. Change the Windows hostname by right click mycomputer >properties>change settings>change
and change the computername
5. Reboot the machine to set the networking. Unlock the SYSMAN account because it ensures that emca can drop it and all dependencies. Then, drop the em configuration with the following commands.
Start cmd As administrator
C:\Data> set ORACLE_SID=orcl
C:\Data> emca -deconfig dbcontrol db -repos drop


6. You’ll receive the following prompts, enter the Oracle SID and Port number without double quotes but you must enter all passwords with double quotes (at least in Oracle Database 11g):
Oracle Database 11gR1
STARTED EMCA at Jul 13, 2008 8:26:42 AM
EM Configuration Assistant, Version 11.1.0.5.0 Production
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
 
Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for SYS user:
Password for SYSMAN user:
Password for SYSMAN user:
Do you wish to continue? [yes(Y)/no(N)]: y
Oracle Database 11gR2
STARTED EMCA at Sep 3, 2012 7:40:07 PM
EM Configuration Assistant, Version 11.2.0.0.2 Production
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
 
Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for SYS user:
Password for SYSMAN user:
 
Do you wish to continue? [yes(Y)/no(N)]: y
7. If you failed to unlock the SYSMAN account in step #5, you should drop the SYSMAN user manually. If youdon’t drop the SYSMAN schema, you’ll raise an error when you try to recreate it:
CONFIG: ORA-20001: SYSMAN already EXISTS..
ORA-06512: at line 17
 
oracle.sysman.assistants.util.sqlEngine.SQLFatalErrorException: ORA-20001: SYSMAN already EXISTS..
ORA-06512: at line 17
The Java stack trace will look like this, more or less based on version and release:
at oracle.sysman.assistants.util.sqlEngine.SQLEngine.executeImpl(SQLEngine.java:1530)
at oracle.sysman.assistants.util.sqlEngine.SQLEngine.executeScript(SQLEngine.java:880)
at oracle.sysman.assistants.util.sqlEngine.SQLPlusEngine.executeScript(SQLPlusEngine.java
at oracle.sysman.assistants.util.sqlEngine.SQLPlusEngine.executeScript(SQLPlusEngine.java
at oracle.sysman.emcp.EMReposConfig.createRepository(EMReposConfig.java:492)
at oracle.sysman.emcp.EMReposConfig.invoke(EMReposConfig.java:218)
at oracle.sysman.emcp.EMReposConfig.invoke(EMReposConfig.java:147)
at oracle.sysman.emcp.EMConfig.perform(EMConfig.java:222)
at oracle.sysman.emcp.EMConfigAssistant.invokeEMCA(EMConfigAssistant.java:535)
at oracle.sysman.emcp.EMConfigAssistant.performConfiguration(EMConfigAssistant.java:1215)
at oracle.sysman.emcp.EMConfigAssistant.statusMain(EMConfigAssistant.java:519)
at oracle.sysman.emcp.EMConfigAssistant.main(EMConfigAssistant.java:468)
Drop the user and dependent on version a few other objects, like:
DROP USER sysman CASCADE;
DROP PUBLIC SYNONYM setemviewusercontext;
DROP ROLE mgmt_user;
DROP PUBLIC SYNONYM mgmt_target_blackouts;
DROP USER mgmt_view;
8. You can then create the em environment with the following syntax:
C:\Data> emca -config dbcontrol db -repos create
9. Again, you’ll receive the following prompts, enter the Oracle SID and Port number without double quotes but you must enter all passwords with double quotes (at least in Oracle Database 11g):

C:\>emca -config dbcontrol db -repos create

STARTED EMCA at Oct 15, 2015 2:57:02 PM
EM Configuration Assistant, Version 11.2.0.3.0 Production
Copyright (c) 2003, 2011, Oracle.  All rights reserved.

Enter the following information:
Database SID: ow113
Listener port number: 1521
Listener ORACLE_HOME [ C:\oracle\product\11.2.0\dbhome_1 ]:
Password for SYS user:
Password for DBSNMP user:
Password for DBSNMP user: Oct 15, 2015 2:57:22 PM oracle.sysman.emcp.util.Genera
lUtil initSQLEngineLoacly
WARNING: ORA-28000: the account is locked
Password for SYSMAN user: Terminate batch job (Y/N)? y
C:\Windows\system32>sqlplus sys as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Thu Oct 15 14:57:34 2015
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter user DBSNMP account unlock;
User altered.
SQL> exit
C:\>emca -config dbcontrol db -repos create
STARTED EMCA at Oct 15, 2015 3:03:55 PM
EM Configuration Assistant, Version 11.2.0.3.0 Production
Copyright (c) 2003, 2011, Oracle.  All rights reserved.

Enter the following information:
Database SID: ow113
Listener port number: 1521
Listener ORACLE_HOME [ C:\oracle\product\11.2.0\dbhome_1 ]:
Password for SYS user:
Password for DBSNMP user:
Password for SYSMAN user:
Password for SYSMAN user: Email address for notifications (optional):
Outgoing Mail (SMTP) server for notifications (optional):
-----------------------------------------------------------------
You have specified the following settings
Database ORACLE_HOME ................ C:\oracle\product\11.2.0\dbhome_1
Local hostname ................ SUPPER-1049
Listener ORACLE_HOME ................ C:\oracle\product\11.2.0\dbhome_1
Listener port number ................ 1521
Database SID ................ ow113
Email address for notifications ...............
Outgoing Mail (SMTP) server for notifications ...............
-----------------------------------------------------------------
Do you wish to continue? [yes(Y)/no(N)]: y