Nov 14, 2016

Step to Reconfig Oracle Enterprise Manager (On oracle databaseversion 10.2.0.4)

Step to Reconfig Oracle Enterprise Manager (10.2.0.4)

Solution 1 (Drop and Recreate EM)
Step 1) Manual Drop Repository
1.1) Login to Unix Server
UNIX> su – oracle
1.2) Set ORACLE_SID
          UNIX> export ORACLE_SID=<Your SID>
1.3) Login to database
          UNIX> sqlplus / as sysdba
1.4) Check dbname is correct ? (must be same as <Your SID>)
          SQL> select name from v$database;
1.5) Run script below this step not put database to quiesce mode
(Reference Oracle Doc id : 278100.1)
DECLARE
CURSOR c1 IS
SELECT owner , synonym_name name
FROM dba_synonyms
WHERE table_owner = 'SYSMAN';
BEGIN
FOR r 1 IN c1 LOOP
IF r1.owner = 'PU BLIC' THEN
EXECUTE IMMEDIATE 'DROP PUB LIC SYNONYM '||r1.name;
ELSE
EXEC UTE IMMEDIATE 'DROP SYNONYM '||r1.owner||'.'||r1.name;
END IF;
END LOO P;
END;
/

DROP USER mgmt_view CASCADE;
DROP ROLE mgmt_user;
DROP USER sysman CASCADE;

          1.6) Delete folder that contain old EM file (If it existing)
                   UNIX> cd $ORACLE_HOME
UNIX> rm –rf <hostname>_<sid>
UNIX> cd $ORACLE_HOME/oc4j/j2ee
UNIX> rm –rf OC4J_DBConsole_<hostname>_<sid>
          ***Be careful do not remove OC4J_DBConsole please specify host and sid
Step 2) Create EM
2.1) Check Parameter ORACLE_HOSTNAME
UNIX> echo $ORACLE_HOSTNAME
(If have any value at this parameter need unset, run step below)
UNIX> unset ORACLE_HOSTNAME
2.2) Check ORACLE_HOME
          UNIX> echo $ORACLE_HOME
2.3) Check database instance port
          UNIX> ps –ef|grep lsnr
          UNIX> lsnrctl status <Your listener name>
2.4) Check ORACLE_SID
          UNIX> echo $ORACLE_SID
2.4) Create new EM
          UNIX> emca -config dbcontrol db -repos create -SID <Your SID> -PORT <Your db port> -ORACLE_HOME <Your oracle home>
          ***This step need old SYS,DBSNMP password and new SYSMAN password

Option 1) Stop oracle EM
          UNIX> emctl stop dbconsole
Option 2) Check emagent process need to kill if it avaliable
          UNIX> ps –ef|grep emagent
Option 3) Kill oracle em console by using script in patch 8350262 (patch can apply all platform)

Step 3) Verify oracle EM Status to confirm it is running
UNIX> emctl status dbconsole
***Remark : Oracle version 10g status may be show as not running.

Step 4) Open web browser and test login
https://<Your IP Address>:<Your port>/em/console/aboutApplication


====== If solution 1 not work with you ======
Solution 2 (Edit sysman library)
Step 1) Stop oracle EM
          UNIX> emctl stop dbconsole
Step 2) Check emagent process need to kill if it avaliable
UNIX> ps –ef|grep emagent
Step 3) Make a copy of $ORACLE_HOME/sysman/lib/env_sysman.mk file
          UNIX> cd $ORACLE_HOME/sysman/lib
UNIX> cp –p env_sysman.mk BAK_env_sysman.mk
Step 4) Edit the script $ORACLE_HOME/sysman/lib/env_sysman.mk file
          4.1) Search for the section having "MK_EMDW_LIBNMEMSO_SHLIB"
4.2) Replace the line
$(LIBNMEM) $(LIBNMER) \
with
$(LIBNMEM) $(LIBNMER) $(LIBNMO) \
Step 5) Perform the following relink
          UNIX> cd $ORACLE_HOME/sysman/lib
UNIX> make -f ins_sysman.mk agent
***This will not affect the other database components as only the agent is being relinked.
(Reference Oracle Doc id : 437417.1)
Step 6) Follow all step on solution 1

====== If solution 1 and 2 not work with you ======
Solution 3 (Apply interim patch)
Step 1) Stop oracle EM
          UNIX> emctl stop dbconsole
Step 2) Check emagent process need to kill if it avaliable
UNIX> ps –ef|grep emagent
Step 3) To patch sysman library by opatch number 8350262 (patch can apply all platform)
         
Patch Installation Steps
3.1) Shutdown EM DB Console using the following command
UNIX> $ORACLE_HOME/bin/emctl stop dbconsole
3.2) Set your current directory to the directory where the patch is located
UNIX> cd <PATCH_TOP>/8350262
3.3) Apply patch
UNIX> $ORACLE_HOME/OPatch/opatch apply
          3.4) Verify patch that apply to your db_home
                   UNIX> $ORACLE_HOME/OPatch/opatch lsinventory

Step 4) Follow all step on solution 1

Oct 12, 2016

Understand Oracle Password File

สิ่งที่ต้องรู้คือ path ของ unix และ window ต่างกันนะ

Default path of oracle password file
Unix : $ORACLE_HOME/dbs

Window : %ORACLE_HOME%\database

This case I found because RMAN can't connect to database to do daily backup ..
วันก่อนมี case ที่ต้องแก้ไขการ Backup RMAN เพราะ RMAN เข้าใช้งานเป็น sysdba ไม่ได้ 

Because I create new password file .. after created found new password file contain only "SYS" schema
เพราะว่ามีการสร้าง password file ใหม่ .. หลังจากสร้างเสร็จลอง query ดู พบว่ามีแค่ schema "SYS" ที่ใช้ได้

see result from => 
SELECT * FROM V$PWFILE_USERS;




if you need to use sysdba for other schema need to grant sysdba to other like this
ถ้าคุณต้องการใช้ sysdba กับ schema อื่น ต้องทำการ GRANT SYSDBA ให้กับ schema อื่นก่อน

GRANT SYSDBA TO RMAN;

then see result from => SELECT * FROM V$PWFILE_USERS;


now, we can use RMAN schema like this => sqlplus rman/password as sysdba
ตอนนี้สามารถใช้งาน schema RMAN ได้แล้วตามตัวอย่างคำสั่ง => sqlplus rman/password as sysdba 

How to create oracle password file
วิธีการสร้าง oracle password file
----------------------------------------------------------------------------------------------------
ORAPWD
You can create a password file using orapwd utility. For some Operating systems, you can create this file as part of standard installation.

Users are added to the password file when they are granted the SYSDBA or SYSOPER or SYSASM privilege.

The Oracle orapwd utility assists the DBA while granting SYSDBA, SYSOPER and SYSASM privileges to other users. By default, SYS is the only user that has SYSDBA and SYSOPER privileges. Creating a password file, via orapwd, enables remote users to connect with administrative privileges.

orapwd file=password_file_name [password=the_password] [entries=n] [force=Y|N] [ignorecase=Y|N] [nosysdba=Y|N]

Examples:
$ orapwd file=orapwSID password=sys_password force=y nosysdba=y
$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=secret
$ orapwd file=orapwprod entries=30 force=y
C:\orapwd file=%ORACLE_HOME%\database\PWD%ORACLE_SID%.ora password=2012 entries=20
C:\orapwd file=D:\oracle11g\product\11.1.0\db_1\database\pwdsfs.ora password=id entries=6 force=y
$ orapwd file=orapwPRODB3 password=abc123 entries=10 ignorecase=n
$ orapwd file=orapwprodb password=oracle1 ignorecase=y
----------------------------------------------------------------------------------------------------

มีอะไรที่ผมเข้าใจผิดแจ้งด้วยนะครับ
hope this helps
Young Oracle DBA Thailand ..

Feb 1, 2016

ORA-65149: PDB name conflicts with existing service name in the CDB or the PDB

เจอ Error ORA-65149: PDB name conflicts with existing service name in the CDB or the PDB หลังจากทดสอบแก้ไขชื่อ Pluggable database ตามด้านล่าง
I have found error ORA-65149: PDB name conflicts with existing service name in the CDB or the PDB after rename pluggable database as this log

C:\Users\Administrator\Desktop>sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Mon Feb 1 14:16:25 2016

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions

SQL> ALTER PLUGGABLE DATABASE PDBDEV RENAME GLOBAL_NAME TO PDBUAT;
ALTER PLUGGABLE DATABASE PDBUAT RENAME GLOBAL_NAME TO PDBUAT
                                                     *
ERROR at line 1:
ORA-65046: operation not allowed from outside a pluggable database


SQL> ALTER SESSION SET CONTAINER=PDBDEV;

Session altered.

SQL> ALTER PLUGGABLE DATABASE PDBDEV RENAME GLOBAL_NAME TO PDBUAT;
ALTER PLUGGABLE DATABASE PDBDEV RENAME GLOBAL_NAME TO PDBUAT
                                                     *
ERROR at line 1:
ORA-65045: pluggable database not in a restricted mode


SQL> ALTER PLUGGABLE DATABASE PDBDEV OPEN RESTRICTED FORCE;

Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE PDBDEV RENAME GLOBAL_NAME TO PDBUAT;
ALTER PLUGGABLE DATABASE PDBDEV RENAME GLOBAL_NAME TO PDBUAT
*
ERROR at line 1:
ORA-65149: PDB name conflicts with existing service name in the CDB or the PDB


SQL>

ปรากฎว่าเป็น Bug ของ Oracle 12c ตอนนี้ผมใช้ version 12.1.0.2 ตามเอกสาร
ORA-65149 While Plugging In A Pluggable Database (PDB) (Doc ID 1569267.1)

อาการคือไม่สามารถสร้าง pluggable database ชื่อเดี่ยวกับที่ clone จาก non-cdb และที่ชื่อเดียวกับ Instance Name ของ Container ได้ครับ
Oracle แจ้งว่าจะแก้ไขใน 12c Release2 อิอิ รอต่อไป
Now I use database version 12.1.0.2 and this is oracle bug 16888264 as ORA-65149 While Plugging In A Pluggable Database (PDB) (Doc ID 1569267.1). Can't create pluggable database name same as clone from non-cdb and name same as instance name of container.  Oracle support say this issueis fixed in 12g Release 2.

มีอะไรที่ผมเข้าใจผิดแจ้งด้วยนะครับ
hope this helps
Young Oracle DBA Thailand ..

Jan 29, 2016

OracleService on window hold system01.dbf file after drop pluggable database

เจอเหตุการณ์แปลกๆ ไม่แน่ใจนะว่า bug หรือป่าวลองหาข้อมูลใน oracle support ยังไม่เจอบทความเกี่ยวกับเรื่องนี้ คือ OracleService<InstanceName> บน window ยังใช้งาน system01.dbf  หลังจากที่สั่ง Drop pluggable database ไปแล้วเรียบร้อย

C:\Users\Administrator\Desktop>sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Fri Jan 29 15:16:34 2016

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions

SQL> select name,open_mode from v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDBTEST                          READ WRITE

SQL> ALTER PLUGGABLE DATABASE PDBTEST CLOSE IMMEDIATE;

Pluggable database altered.

SQL> DROP PLUGGABLE DATABASE PDBTEST INCLUDING DATAFILES;

Pluggable database dropped.

SQL>

ปรากฎว่าเหลือไฟล์อยู่ตัวนึงคือ SYSTEM01.DBF และพอไปลบ Manual จึงเจอว่ามันยังใช้งานอยู่


แก้ไขโดย

ผมยังไม่ทราบ solution ที่ดีกว่านี้นะ workaround คือ stop - start instance ครับ


SQL> shutdown immediate
SQL> startup

หลังจากนั้นก็ไปลบไฟล์แบบ manual ครับ หายละ อิอิ

มีอะไรที่ผมเข้าใจผิดแจ้งด้วยนะครับ
Young Oracle DBA Thailand ..

Jan 28, 2016

ORA-65114: space usage in container is too high

Error : ORA-65114: space usage in container is too high

วันนี้ทดสอบสร้าง และ Import Database ด้วย impdp ดังนี้

CREATE PLUGGABLE DATABASE PDBTEST
  ADMIN USER PDBADMIN IDENTIFIED BY password
  ROLES = (dba)
  DEFAULT TABLESPACE USERS
    DATAFILE 'E:\oracle\oradata\PDBTEST\users01.dbf' SIZE 50M AUTOEXTEND ON
  FILE_NAME_CONVERT=('E:\oracle\oradata\pdbseed\','E:\oracle\oradata\PDBTEST\')
  PATH_PREFIX = 'E:\oracle\oradata\PDBTEST\'
  STORAGE (MAXSIZE 2G);

แต่ในระหว่างการ import data นั้นเจอ ORA-65114: space usage in container is too high

*ใช้วิธีการ Import ปกติ

วิธีแก้ไข

C:\Users\Administrator>sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Thu Jan 28 16:53:06 2016

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> alter session set container=PDBTEST;

Session altered.

SQL> ALTER PLUGGABLE DATABASE STORAGE UNLIMITED;

Pluggable database altered.

SQL>

เกิดจากการ limit STORAGE MAXSIZE ไว้ที่ 2G หรือเราจะแก้ไขเป็นตาม size ที่เราต้องการก็ได้ เช่น

ALTER PLUGGABLE DATABASE STORAGE (MAXSIZE 5G);
ALTER PLUGGABLE DATABASE STORAGE (MAXSIZE 10G);


มีอะไรที่ผมเข้าใจผิดแจ้งด้วยนะครับ
Young Oracle DBA Thailand ..

Jan 27, 2016

ORA-39087: directory name DATA_DUMP_DIR is invalid [Oracle Database 12c]

เจอ Error ORA-39087: directory name DATA_DUMP_DIR is invalid บน Oracle Database 12c ระหว่างที่ import datapump เข้า pdb ครับ

ใช้คำสั่ง import data pump แบบปกติ
impdp \"sys@pdb as sysdba\" dumpfile=DATA_DUMP_DIR:<dumpfile> logfile=DATA_DUMP_DIR:<logfile> schemas=<schema_name>

ปรากฎว่าเจอ error ORA-39087: directory name DATA_DUMP_DIR is invalid



Import: Release 12.1.0.2.0 - Production on Fri Jan 29 16:58:09 2016

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit
Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-39087: directory name DATA_DUMP_DIR is invalid



เราก็ลองเข้า sqlplus และ select * from dba_directories; ดู

SQL> select * from dba_directories where DIRECTORY_NAME='DATA_PUMP_DIR';

OWNER                                                                        
--------------------------------------------------------------------------------
DIRECTORY_NAME                                                                
--------------------------------------------------------------------------------
DIRECTORY_PATH                                                                
--------------------------------------------------------------------------------
ORIGIN_CON_ID                                                                
-------------                                                                
SYS                                                                          
DATA_PUMP_DIR                                                                
E:\oracle\data_pump_file                                                      
            1                                                                

กำละ (= ="

วิธีแก้ไขปัญหา
Command> sqlplus / as sysdba
SQL> alter session set container=pdb;
SQL> CREATE DIRECTORY PDB_DUMP_DIR AS 'E:\oracle\data_pump_file';

Command> impdp \"sys@pdb as sysdba\" dumpfile=DATA_DUMP_DIR:<dumpfile> logfile=DATA_DUMP_DIR:<logfile> schemas=<schema_name>

เนื่องจาก 12c แบ่ง directory โดยแยก directory ของ container และ pluggable จากการ select * from dba_directories ภายใน pdb ได้ข้อมูลตามภาพด้านล่าง



มีอะไรที่ผมเข้าใจผิดแจ้งด้วยนะครับ
Young Oracle DBA Thailand ..