Tuesday, July 11, 2017

Steps to Configure Unicode Fonts in Oracle Reports



                A.  Steps to install fonts to server
                A.1 )  Create a directory for new fonts
     Ex -  #  mkdir /usr/share/fonts/truetype
             A.2) Copy the font to the above directory 
             A.3)  Navigate to the directory & Execute below Commands
                # mkfontscale && mkfontdir
               # fc-cache
                A.4)  Add the new font directory to the X11 font path

                # chkfontpath --add /usr/share/fonts/truetype
                A.5) Restart X font server
                # /etc/rc.d/init.d/xfs restart

Step 2 .  Copy the Fonts to the Below Folder & change the ownership to the app server user
                 $ORACLE_INSTANCE/reports/fonts/
Step 3 .   Add the Fonts to [PDF:Subset] section in uifont.ali File as follows. 

Ex - 
[PDF:Subset]
"Khmer OS System"="KhmerOS_sys.ttf"
"Khmer OS"="KhmerOS.ttf"

 Step 4 .   To display fonts in Styles use the settings as follows in uifont.ali file.

 Ex -

[PDF:Subset]
"Roboto"..Italic.Bold..="Roboto-BoldItalic.ttf"
"Roboto"...Bold..="Roboto-Bold.ttf"
"Roboto"..Italic...="Roboto-Italic.ttf"
             "Roboto".....="Roboto-Regular.ttf"

 Step 5.   To Enable Unicode fonts In report, Change the  

                NLS_LANG To  AMERICAN_AMERICA.UTF8  in            
                $ORACLE_INSTANCE /config/reports/bin/reports.sh

 I.e.  NLS_LANG=AMERICAN_AMERICA.UTF8;

Step 6.   To Effect the changes Restart the opmnctl

Please Note
This font configuration Document Created based on Khmer & Roboto font configuration

Standby database Troubleshooting

------------------------------------------
LogFileNameConvert = Log_File_Name_Convert
DbFileNameConvert  = db_file_name_convert
----------------------------------------------

To remove the  log_archive_dest_2
--alter system set log_archive_dest_2=" ";

----------------------------------------------
If you get an error like folder is not there.
follow below steps
1. Create the folder as requests.
2. Issue the below from standby
select * from v$recover_file where error like '%FILE%';
get the file name and execute below
select file#,name from v$datafile where file#=5;
 and execute the above query from primary
select file#,name from v$datafile where file#=5;
so will understand the miss match
Now
Execute below from standby
alter database create datafile '/u01/app/oracle/product/11.2.0/db_1/dbs/UNNAMED00005' as '/u01/app/oracle/oradata/dell/hasaral01.dbf';
alter database recover managed standby database disconnect from session;
change the below parameter if get an error when adding a datafile—
on standby
alter system set standby_file_management=auto;
sho parameter standby;
-----------------------------------------------------



steps to configure active data guard



Active data guard means standby database in read only mode and still archive logs will apply

 From standby db

SQL>Shu immediate;
SQL> startup mount;
SQL> alter database open read only;
SQL> alter database recover managed standby database disconnect from session;

 select name,open_mode,database_role,protection_mode from v$database;

* Check the archive location in DR and change accordingly

Convert standby DB to snapshot standby DB and Revert Back



Convert standby database to Snapshot database

1.       Shutdown immediate;
       2.       startup mount;
       3.       alter database recover managed standby database cancel;
       4.       select flashback_on from v$database;  --  Answer should be NO
       5.       alter database convert to snapshot standby;
6.       alter database open;
7.    select open_mode from v$database;





Convert  Back to Physical standby DB

1.   Shutdown immediate;
      2.     startup mount;
      3       alter database convert to physical standby;
      4.     Shutdown immediate;
      5.     startup mount;
      6.    select open_mode from v$database;
      7.     alter database recover managed standby database disconnect  from session;
     


Friday, July 7, 2017

Oracle Database Restoration

Read the full doc once before do anything first

1.
. oraenv
-- enter dbname and the oracle home location
2.
startup nomount pfile='/asd.ora';
-- include only below in the above asd.ora file
*.db_name='fortedev'
*.compatible='11.2.0.4.0'

--------------------------
sql --> create spfile from pfile='/vol5/backup/forte_pfile.ora';
----------------------------
** compatible parameter uses only if you get the error like below
ORA-00201: control file version 11.2.0.4.0 incompatible with ORACLE version 11.2.0.0.0
ORA-00202: control file: '/vol0/app/oracle/product/11.2.0/db_1/dbs/cntrlfortedev.dbf'
3.
RMAN> restore controlfile from '/vol5/backup/c-3948522858-20141028-01';
4.
RMAN> startup mount;

RMAN> REPORT SCHEMA;

---------------------
Use Below script if the paths are same

run {
set until sequence 1+latest THREAD 1;
restore database;
switch datafile all;
recover database;
alter database open resetlogs;
}
-------------------

run {
SET UNTIL SEQUENCE 1694 THREAD 1;
set newname for datafile 1 to '/vol0/app/oracle/oradata/system01.dbf';
set newname for datafile 2 to '/vol0/app/oracle/oradata/sysaux01.dbf';
set newname for datafile 3 to '/vol0/app/oracle/oradata/undotbs01.dbf';
set newname for datafile 4 to '/vol0/app/oracle/oradata/users01.dbf';
set newname for datafile 5 to '/vol0/app/oracle/oradata/sicl01.dbf';
restore database;
switch datafile all;
recover database;
}

SQL> select * from v$logfile;

SQL> ALTER DATABASE RENAME FILE '/vol1/app/oracle/oradata/fortedev/redo01.log' TO '/vol0/app/oracle/oradata/redo01.log';

RMAN> alter database open resetlogs;
SQL> shu immediate;
startup

create the temp file http://techblogbyh.blogspot.com/2017/07/add-or-drop-temp-tablespaces.html






RAC to Stand alone Restoration Oracle DB

Below doc used for a Same SID as RAC


1. Startup nomount;

Delete all the control, log , and datafiles .

Restore the controlfile from the Rman.

RMAN> restore controlfile from '/vol0/app/rman/c-1546876198-20140606-00';

2. Startup mount;

crosscheck backup;
delete EXPIRED backup;
crosscheckarchivelog all;
delete expired archivelog all;

Delete all the existing Rman backups

Catalog start with ‘new rman location’;

RMAN> catalog start with ' /vol0/RMAN';

List backup;


Run the below scripts accordingly.


**  SET UNTIL caluse removed from the script

RMAN> run {
2> 3> set newname for datafile 1 to '/vol0/app/oracle/oradata/YAMAHAR1/system.dbf';
4> set newname for datafile 2 to '/vol0/app/oracle/oradata/YAMAHAR1/SYSAUX01.dbf';
5> set newname for datafile 3 to '/vol0/app/oracle/oradata/YAMAHAR1/undotbs1.dbf';
6> set newname for datafile 4 to '/vol0/app/oracle/oradata/YAMAHAR1/undotbs2.dbf';
7> set newname for datafile 5 to '/vol0/app/oracle/oradata/YAMAHAR1/users.dbf';
8> restore database;
9> switch datafile all;
10> recover database;
12> }



SET UNTIL SEQUENCE 77 THREAD 1;
ALTER DATABASE ADD LOGFILE MEMBER '/oracle/dbs/log2b.rdo' TO GROUP 2;


--------------------------------

ORA-38856: cannot mark instance UNNAMED_INSTANCE_2 (redo thread 2) as enabled

Solution

Add the below entry to pfile – to the last line

Shu database;

Startup mount pfile=’asdfdsfa.ora’



And
Open the database in resetlogs mode.



ORA-01610: recovery using the BACKUP CONTROLFILE option must be done

Solution



[1] take the backup of the current control file to nay  of the directory

SQL> alter database backup controlfile to '/shared/oracle/controlnew01.ctl';

[2] create trace of the current control file 

SQL> alter database backup controlfile to trace as '/shared/oracle/controlfa.ctl';



Once the trace file is create it will contain  the script to recreate the control file
you can open the trace of the control file in the notepad and edit the creating the control file script according to your environment

Run accordingly in SQL—



And 

alter database open resetlogs;


Errors..



SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-00392: log 4 of thread 2 is being cleared, operation not allowed
ORA-00312: online log 4 thread 2: '/vol0/oradata/ROAM/redo07.log'

Solution


SQL> alter database clear logfile group 2;

Database altered.

*
ERROR at line 1:
ORA-19751: could not create the change tracking file
ORA-19750: change tracking file:
'+DATA_ETSL01/roam/changetracking/ctf.307.844435057'



Solution

SQL> alter database disable block change tracking;


-------------------------
SQL> alter database open RESETLOGS;
alter database open RESETLOGS
*
ERROR at line 1:
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/u01/app/oracle/oradata/PRIME/system.dbf'


solution

RMAN> list backup of archivelog all; -- add one to the highest sequence
recover database until sequence 21;

SQL> alter database open RESETLOGS;

Database altered.






















Restore Oracle DB to Same server with Different Name ( Duplicate )

1.        Create a init file for the new database  (DUP)
 initdup.ora
SQL> create pfile='/tmp/initDUP.ora' from spfile;
Change the highlighted parameters more importantly
*.audit_file_dest='/vol0/app/oracle/admin/DUP/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/vol0/app/oracle/oradata/DUP/control01.ctl','/vol0/app/oracle/oradata/DUP/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='DUP'
*.diagnostic_dest='/vol0/app/oracle'
*.java_pool_size=0
*.log_archive_dest_1='LOCATION=/vol0/app/archive_dup'
#*.memory_target=417333248
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
               


2.       Create the password file

cp orapwORIG orapwDUP

3.       Add a TNS Entry

DUP =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.20.2.178)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = DUP)
    )
  )

4.       Add listener
             
     Run netmgr and  add database dup




5.       Take a Rman backup of ORIG database (OLD)

RMAN> backup database;

6.       Bring the DUP database to nomount state using the created pfile.

SQL> startup nomount pfile='/tmp/initdup.ora';

7.       rman target sys/oracle@ORIG AUXILIARY sys/oracle@DUP    -- Execute this command from the dup env

RMAN-00554: initialization of internal recovery manager package failed
RMAN-04006: error from auxiliary database: ORA-12528: TNS:listener: all appropriate instances are blocking new connections

Solution

Added the highlighted parameter…. Worked fine for me.. Awesome


DUP =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.20.2.178)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = DUP)
     (UR = A)
    )
  )


8.       duplicating the database


RMAN>

run
{
set newname for datafile 1 to '/vol0/app/oracle/oradata/DUP/system01.dbf';
set newname for datafile 2 to '/vol0/app/oracle/oradata/DUP/sysaux01.dbf';
set newname for datafile 3 to '/vol0/app/oracle/oradata/DUP/undotbs01.dbf';
set newname for datafile 4 to '/vol0/app/oracle/oradata/DUP/users01.dbf';
set newname for datafile 5 to '/vol0/app/oracle/oradata/DUP/tbs_hasaral01.dbf   ';

duplicate target database to DUP
pfile=/tmp/initDUP.ora
nofilenamecheck

logfile group 1 ('/vol0/app/oracle/oradata/DUP/redo01.log') size 50M,
            group 2 ('/vol0/app/oracle/oradata/DUP/redo02.log') size 50M,
            group 3 ('/vol0/app/oracle/oradata/DUP/redo03.log') size 50M;
}

9.       add temp tablespace
  
alter TABLESPACE temp add TEMPFILE '/vol0/app/oracle/oradata/DUP/temp01.dbf' size 10M autoextend off;

alter tablespace temp drop tempfile '/vol0/app/oracle/oradata/ORIG/temp01.dbf';


10.SQL> create spfile from pfile='/tmp/initDUP.ora';

Wednesday, July 5, 2017

Create a Local Yum Repository

* Install below Packages

deltarpm-3.5-0.5.20090913git.el6.ppc64.rpm
python-deltarpm-3.5-0.5.20090913git.el6.ppc64.rpm
createrepo-0.9.8-4.el6.noarch.rpm


* Copy the RPM's from the CD & *.xml files in repodata folder                             
  to a Folder.


createrepo -g repomd.xml /pkgs

Create the repo file.

vi /etc/yum.repos.d/rhel6x.repo

----------------------------
[RHEL-Repository]
name=RHEL 6.x
baseurl=file:///pkgs
enabled=1
gpgcheck=0
------------------------------

yum clean all
Yum list
yum repolist

Ex -
Yum install ABC
Yum update ABC

------------------------------------------------------------------------------------
If you get the below error

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 37017186

Do the following
rpm --import /etc/pki/rpm-gpg/RPM*
--------------------------------------------------------------


Restore and recover with Incremental backups


**** there should not be any other backup in between level 0 & Level 1 backup

BACKUP INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG;

BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;




--- Restore the Latest Controlfile
--- Restore the database
--- Recover the database
--- Archive logs should be present in the time of recovery

ADD or DROP TEMPORARY tablespace


To drop or add a temporary tablespace follow the steps below


1. create another temporary tablespace

CREATE TEMPORARY TABLESPACE TEMPNEW  TEMPFILE '/vol5/temp03.dbf' size 500m  autoextend off;

2. make it as default temporary tablespace

ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMPNEW;

3. drop the old temporary tablespace

DROP  TABLESPACE TEMP INCLUDING CONTENTS AND datafiles;



* Use the SQL below to add a File to a TEMPORARY Tablespace.



alter tablespace TEMP add tempfile '/vol5/temp04' size 50m reuse autoextend on next 1m maxsize 500m;







Thursday, June 29, 2017

Restoring the GAP Between Live & Standby Database

Rolling forward a standby database using Incremental Backup



1) On the standby database

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

  2) On the STANDBY DATABASE, find the 'lowest SCN' which will be used for the incremental backup at the primary database:

SQL> SELECT to_char(CURRENT_SCN) FROM V$DATABASE;

CURRENT_SCN
--------------
3164433 

SQL> select min(f.fhscn) from x$kcvfh f, v$datafile d where f.hxfil =d.file# and d.enabled != 'READ ONLY' ;

MIN(F.FHSCN)
----------------
3162298


3) In RMAN, connect to the PRIMARY database and create an incremental backup from the SCN derived in the previous step:

RMAN> BACKUP INCREMENTAL FROM SCN 3162298 DATABASE FORMAT '/tmp/ForStandby_%U' tag 'FORSTANDBY';

4) Transfer all backup sets created on the primary system to the standby system.

scp /tmp/ForStandby_* standby:/tmp

5) On the STANDBY catalog the backuppieces:

RMAN> CATALOG START WITH '/tmp/ForStandby'; 
RMAN> RECOVER DATABASE NOREDO; 

6) In RMAN, connect to the PRIMARY database and create a standby control file backup:

RMAN> BACKUP CURRENT CONTROLFILE FOR STANDBY FORMAT                 '/tmp/ctlForStandby.bck';

7) Copy the standby control file backup to the STANDBY system. 

scp /tmp/ctlForStandby.bck standby:/tmp



8) From RMAN, connect to STANDBY database and restore the standby control file:

RMAN> SHUTDOWN IMMEDIATE ;
RMAN> STARTUP NOMOUNT; 
RMAN> RESTORE STANDBY CONTROLFILE FROM '/tmp/ctlForStandby.bck'; 

9) Shut down the STANDBY database and startup mount:

RMAN> SHUTDOWN; 
RMAN> STARTUP MOUNT;
RMAN> CATALOG START WITH '+DATA/mystd/datafile/'; 
RMAN> SWITCH DATABASE TO COPY; 

10) On standby database

  alter database open;

11) On the STANDBY database, start the recovery process

SQL> alter database recover managed standby database disconnect from session;

switch-over database roles..



On primary

select name,open_mode,database_role,db_unique_name,protection_mode from v$database;
alter database commit to switchover to standby;
startup mount;
alter database recover managed standby database disconnect from session;
select name,open_mode,database_role,db_unique_name,protection_mode from v$database;


Now go to the originally standby database

alter database commit to switchover to primary;
alter database open;
select name,open_mode,database_role,db_unique_name,protection_mode from v$database;


---------------------------------------------------------------

Errors Handled 


SQL> alter database commit to switchover to primary;
SQL> alter database commit to switchover to primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required


SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
RECOVERY NEEDED

SQL> RECOVER MANAGED STANDBY DATABASE FINISH;
Media recovery complete.
SQL> alter database commit to switchover to primary;

Database altered.
----------------------------------------
If you get an error in the above command like

ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected
Did followng and worked fine for me
select switchover_status from v$database;
select sid, process, program from v$session where type = 'USER';

alter database commit to switchover to primary with session shutdown;
---------------------------------------------



Standby database configuration - 11G/12c/19c


* Archival should be Enabled to start the below configurations

 
In this Document Primary DB Unique Name is 'KANDY' and Standby DB Unique Name is 'COLOMBO'

- Execute below command on the Primary DB

alter database force logging; 

 
select FORCE_LOGGING from v$database; ( Result should be 'YES' )

alter system set log_archive_config='dg_config=(kandy,colombo)';

( kandy and colombo are the DB_UNIQUE_NAME's of the primary and standby databases)


alter system set log_archive_dest_2='service=TNS_COL LGWR ASYNC NOAFFIRM max_failure=10 max_connections=5 reopen=180 valid_for=(online_logfiles,primary_role) db_unique_name=colombo' scope=both;

( service is tns alies in the standby db db_unique_name is standby db_unique_name )

 
alter system set log_archive_dest_state_2=enable;
alter system set remote_login_passwordfile=exclusive scope=spfile;
alter system set fal_server=
TNS_COL

( fal_server is the TNS allies of the Standby DB)

 
alter system set db_file_name_convert='colombo','kandy' scope=spfile;

alter system set log_file_name_convert='colombo','kandy' scope=spfile;

ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

-- Restart the PRIMARY DB
-- ADD TNS Entry for both DR and LIVE server accordingly


TNS_KANDY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.10.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = KANDY)
    )
  )

TNS_COL =

  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.10.12)(PORT = 1521))
    )
    (CONNECT_DATA =
   (SERVICE_NAME = COLOMBO)
    )
  )



-- Take a rman backup of DB and Controlfile

RMAN --> 

backup database format '/vol0/RMAN/%U';

backup archivelog all format '/vol0/RMAN/%U';

SQL  --> 

alter database create standby controlfile as 

'/vol0/RMAN/stdcontrol.ctl';

-- Copy backups to standby db Server

scp /vol0/RMAN/* 172.16.10.12:/vol0/RMAN/

-- Copy the pwd file to standby db Server

scp /vol0/app/oracle/product/11.2.0.4/db_1/dbs/orapwKANDY 172.16.10.12:/vol0/app/oracle/product/11.2.0.4/db_1/dbs/orapwCOLOMBO


-- GO TO Standby DB Server

export ORACLE_SID=COLOMBO
-- Create a pfile and add below Entries.
-----------------------
*.compatible='11.2.0.4.0'
*.db_file_name_convert='KANDY','COLOMBO'  
*.log_file_name_convert='KANDY','COLOMBO'
*.db_name='KANDY'
*.db_unique_name='COLOMBO'
*.fal_server='TNS_COL'
*.log_archive_config='dg_config=(kandy,colombo)' 
*.log_archive_dest_2='service=TNS_KANDY LGWR ASYNC NOAFFIRM max_failure=10 max_connections=5 reopen=180 valid_for=(online_logfiles,primary_role) db_unique_name=kandy'
*.log_archive_dest_state_2='ENABLE'
*.standby_file_management='AUTO'


-------------------------------

-- create spfile from the pfile
-- Startup nomount

RMAN --> 

Restore controlfile from '/vol0/RMAN/stdcontrol.ctl';
RMAN --> alter database mount;
RMAN --> restore database;

-- Set the size of the standby logfiles as same as the redo logfiles
-- Add standby logfile groups as much as the redo logfile groups

alter database add standby logfile thread 1 group 4 ('/vol0/oradata/COLOMBO/stnadby_redo04.log') size 50m;
alter database add standby logfile thread 1 group 5 ('/vol0/oradata/COLOMBO/stnadby_redo05.log') size 50m;
alter database add standby logfile thread 1 group 6 ('/vol0/oradata/COLOMBO/stnadby_redo06.log') size 50m;

select member from v$logfile where type ='STANDBY';
select member from v$logfile;

-- log into primary DB and create standby redo log files

alter database add standby logfile thread 1 group 4 ('/vol0/oradata/KANDY/stnadby_redo04.log') size 50m;
alter database add standby logfile thread 1 group 5 ('/vol0/oradata/KANDY/stnadby_redo05.log') size 50m;
alter database add standby logfile thread 1 group 6 ('/vol0/oradata/KANDY/stnadby_redo06.log') size 50m;

alter system set log_archive_dest_state_2=enable; 


select member from v$logfile where type ='STANDBY';
select member from v$logfile;

-- Issue the bellow command from standby DB

alter database recover managed standby database disconnect from session;

-- if you need to cancel applying, execute below command from standby DB
-- alter database recover managed standby database cancel ;

-- From the Primary db Execute below

alter system switch logfile;
select max(sequence#) from V$ARCHIVED_LOG group by thread#;
select max(sequence#) from V$ARCHIVED_LOG where applied='YES' group by thread#;