Flash_Recovery_Area

Mointer Space in Flash_recovery_are

1- sqlplus / as sysdba
2- Run the Below Query 

SELECT 
NAME,
TO_CHAR(SPACE_LIMIT, '999,999,999,999') AS SPACE_LIMIT,
TO_CHAR(SPACE_LIMIT - SPACE_USED + SPACE_RECLAIMABLE, '999,999,999,999')
AS SPACE_AVAILABLE,
ROUND((SPACE_USED - SPACE_RECLAIMABLE)/SPACE_LIMIT * 100, 1)
AS PERCENT_FULL
FROM V$RECOVERY_FILE_DEST;

 There’s many scripts you can use to monitor FRA Or Arvhive I will post Few Of them :

Select file_type, percent_space_used from v$flash_recovery_area_usage;
SELECT NAME,
TO_CHAR(SPACE_LIMIT, '999,999,999,999') AS SPACE_LIMIT,
TO_CHAR(SPACE_LIMIT - SPACE_USED + SPACE_RECLAIMABLE, '999,999,999,999') AS SPACE_AVAILABLE,
ROUND((SPACE_USED - SPACE_RECLAIMABLE)/SPACE_LIMIT * 100, 1) AS PERCENT_FULL
FROM V$RECOVERY_FILE_DEST;
 
 

 Query the V$RECOVERY_FILE_DEST view to find out the current location, disk quota, space in use, space reclaimable by deleting files, and total number of files in the Flash Recovery Area. For example :

SQL> SELECT * FROM V$RECOVERY_FILE_DEST;

NAME                        SPACE_LIMIT SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
----------- ---------- ----------------- ---------------
D:\Oracle\flash_recovery_area 838860800  292490752                 0              44

Query the V$FLASH_RECOVERY_AREA_USAGE view to find out the percentage of the total disk quota used by different types of files. Also, you can determine how much space for each type of file can be reclaimed by deleting files that are obsolete, redundant, or already backed up to tape. For example :

SELECT * FROM   V$FLASH_RECOVERY_AREA_USAGE;

FILE_TYPE    PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES
------------ ------------------ ------------------------- ---------------
CONTROLFILE                   0                         0               0
ONLINELOG                     2                         0              22
ARCHIVELOG                 4.05                      2.01              31
BACKUPPIECE                3.94                      3.86               8
IMAGECOPY                 15.64                     10.43              66
FLASHBACKLOG                .08                         0               1
 

You Can check 
Flash Recovery area – Space management Warning & Alerts [ID 305812.1]

 thank you
Osama Mustafa

Unable to login to Database Because Archivelog

Regarding to heavy duty On Database , Database start Generates Archive log with time size for flash recovery become full , so what i have to do :

first you will not be able login for database or rman

Solution :

Step1 :

-Go to archivelog detestation and delete archivelog (old first) , if you have space on your server you can move them from direcotry to another .

-Flash Recovery On ASM , Follow the below steps

export ORACLE_SID=+ASM1
asmcmd 

now you are inside ASM head to Archivelog destation and delete archive log manually (old first )

 Step 2 :

Now you will be able to login to rman :

Run
{

ALLOCATE CHANNEL c1 DEVICE TYPE DISK FORMAT '/u01/'; 
backup archivelog all delete input ;
release c1 ; } 

 Now you clean Archivelog .

THis solution for Both Cluster and Single Node Database

Enjoy

Thank you
Osama mustafa

Moving Spfile From File-System To ASM

1. Create spfile in ASM “+DATA” disk group :
 
SQL> connect / as sysdba

SQL> show parameter spfile

 
NAME TYPE VALUE
------- ------- ------------------------------
spfile string /u01/app/oracle/product/11.2.0/db_1/dbs/spfileracdb11.ora
 
SQL> create pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initracdb11.ora' from spfile='/u01/app/oracle/product/11.2.0/db_1/dbs/spfileracdb11.ora';

SQL> create pfile from spfile
File created.
 
SQL> create spfile='+DATA' from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initracdb11.ora';
File created.

SQL> exit
 
2. Modify initracdb11.ora on rac1 and initracdb12.ora on rac2 files to point to location in ASM
 
[oracle@rac1 dbs]$ echo "SPFILE='+RACDB_DATA/racdb1/spfileracdb1.ora'" > /u01/app/oracle/product/11.2.0/db_1/dbs/initracdb11.ora
[oracle@rac1 dbs]$ ssh rac2 "echo \"SPFILE='+RACDB_DATA/racdb1/spfileracdb1.ora'\" > /u01/app/oracle/product/11.2.0/db_1/dbs/initracdb12.ora"
 
3. Update OCR with new SPFILE location
 
[oracle@rac1 dbs]$ srvctl modify database -d racdb1 -p +RACDB_DATA/racdb1/spfileracdb1.ora 

4. Rename any existing spfiles in $ORACLE_HOME/dbs
5. Restart all instances to switch to new SPFILE 
6. Check New Location For Spfile .
 
 
Thank you 
Osama mustafa  
  


Migrate the database From File System to ASM

I posted before Migration Database from ASM to File System,But today i will talk about How to migration File System to ASM and this is the common case I hope i will describe this topics so well,Please if you have any In-query Contact me,Comment i will answer you,Helping you is my pleasure:


Steps:

1.configure flash recovery area.
2.Migrate datafiles to ASM.
3.Control file to ASM.
4.Create Temporary tablespace.
5.Migrate Redo logfiles
6.Migrate spfile to ASM.


step 1:Configure flash recovery area.

SQL> connect sys/sys@orcl as sysdba
Connected.
 
SQL> alter database disable block change tracking;

Database altered.

SQL> alter system set db_recovery_file_dest_size=500m;

System altered.

SQL> alter system set db_recovery_file_dest=’+FRAG’;

System altered

step 2 and 3: Migrate data files and control file to ASM

Use RMAN to migrate the data files to ASM disk groups,All data files will be migrated to the newly
 created disk group, DATA
 
SQL> alter system set db_create_file_dest='+DATA';

System altered.

SQL> alter system set control_files='+DATA/control_new.ctl' scope=spfile;

System altered.

SQL> shutdown immediate

[oracle@rac1 bin]$ ./rman target /


RMAN> startup nomount
RMAN> restore controlfile from '/u01/new/oracle/oradata/mydb/control01.ctl';
RMAN> alter database mount;
RMAN> backup as copy database format '+DATA';
RMAN> switch database to copy;
RMAN> alter database open;

RMAN>Exit ;

SQL> conn sys/oracle as sysdba

Connected.

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME FILE_NAME

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

USERS +DATA/mydb/datafile/users.261.705064915

UNDOTBS1 +DATA/mydb/datafile/undotbs1.259.705064821

SYSAUX +DATA/mydb/datafile/sysaux.258.705064283

SYSTEM +DATA/mydb/datafile/system.257.705063763


SQL> select name from v$controlfile;


NAME
----

+DATA/control_new.ctl


step 4:Migrate temp tablespace to ASM.
 
SQL> alter tablespace temp add tempfile size 100m;

Tablespace altered.

SQL> select file_name from dba_temp_files;
FILE_NAME

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

+DATA/mydb/tempfile/temp.263.705065455

otherwise,Create temporary tablespace in ASM disk group.

SQL> CREATE TABLESPACE temp1 TEMPFILE ‘+diskgroup1’;

SQL> alter database default temporary tablespace temp1;

Database altered.


step 5:Migrate redo logs to ASM.
 
SQL> select member,group# from v$logfile;

you will find i above query the redo-log in file system start adding new one to ASM after this you can delete .

SQL> alter database add logfile group 5 size 5m;

Database altered.

SQL> alter database add logfile group 6 size 5m;

Database altered.

For example to drop , you can do the following :

SQL> alter system switch logfile;

System altered.

SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database drop logfile group 3;

Database altered.

SQL> alter database drop logfile group 4;

Database altered.

SQL> alter database drop logfile group 1;

Database altered.

Now we can say we finish But we have to do Two More Steps 


Add additional control file


SQL> connect sys/sys@ORCL as sysdba
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.

SQL> alter database backup controlfile to '+DATA/Control_new02.ctl';

Database altered.

SQL> alter system set control_files='+DATA/
Control_new.ctl '
,'+DATA/
Control_new02.ctl' scope=spfile;

System altered.

SQL> shutdown immediate;
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.


Step 6:Migrate spfile to ASM:

Create a copy of the SPFILE in the ASM disk group.
 
If the database is using an SPFILE already, then run these commands:

run {
BACKUP AS BACKUPSET SPFILE;
RESTORE SPFILE TO "+DISK/spfile";

But if you are not using One :

SQL> create spfile='+DISK/spfile' from pfile='$ORACLE_HOME/dbs/initORCL.ora';





 Thank you
Osama mustafa











 
 

Step By Step To Migration ASM to File System

There’s More than One Way For this Migration you can use what you want

Lets Get The Database Data Files :


1-See your Database Files :

SQL>select file_name from dba_data_files;

 +DATA/test/datafile/undotbs1.301.697649965
+DATA/test/datafile/sysaux.300.697649963
+DATA/test/datafile/system.299.697649963
+DATA/test/datafile/users.302.697649965
+DATA/test/datafile/users.309.697650601

select tablespace_name,count(file_name) from dba_data_files group by tablespace_name ORDER BY 2

Use the above query to see how many data files under tablespace .

Now After see the DataFile , we need to create new Directory to copy the data file to it .
  mkdir /app/oracle/TEST


2- We Will Create Our Own Script And Copy our Database File to our new location :

sqlplus / as sysdba

set lines 120 pages 0

select ‘copy datafile ‘||file_id||’ to ‘||”’/app/oracle/TEST/’||substr(file_name,21,instr(file_name,’.’)-21)||’_01.dbf”’||’;’ from dba_data_files order by 1;

copy datafile 1 to ‘/app/oracle/TEST/system_01.dbf’;

copy datafile 2 to ‘/app/oracle/TEST/sysaux_01.dbf’;

copy datafile 3 to ‘/app/oracle/TEST/undotbs1_01.dbf’;

copy datafile 4 to ‘/app/oracle/TEST/users_01.dbf’;

copy datafile 5 to ‘/app/oracle/TEST/users_02.dbf’;

shutdown immediate;

startup mount;

exit

rman target /

copy datafile 1 to ‘/app/oracle/TEST/system_01.dbf’;

copy datafile 2 to ‘/app/oracle/TEST/sysaux_01.dbf’;

copy datafile 3 to ‘/app/oracle/TEST/undotbs1_01.dbf’;

copy datafile 4 to ‘/app/oracle/TEST/users_01.dbf’;

copy datafile 5 to ‘/app/oracle/TEST/users_02.dbf’;

exit

sql / as sysdba

select ‘alter database rename file ”’||file_name||”’ to ‘||”’/app/oracle/TEST/’||substr(file_name,21,instr(file_name,’.’)-21)||’_01.dbf”’||’;’ from dba_data_files order by 1;

alter database rename file ‘+DATA/test/datafile/sysaux.300.697649963’ to ‘/app/oracle/TEST/sysaux_01.dbf’;

alter database rename file ‘+DATA/test/datafile/system.299.697649963’ to ‘/app/oracle/TEST/system_01.dbf’;
alter database rename file ‘+DATA/test/datafile/undotbs1.301.697649965’ to ‘/app/oracle/TEST/undotbs1_01.dbf’;
alter database rename file ‘+DATA/test/datafile/users.302.697649965’ to ‘/app/oracle/TEST/users_01.dbf’;

alter database rename file ‘+DATA/test/datafile/users.309.697650601’ to ‘/app/oracle/TEST/users_02.dbf’;

 
 3- This not the finish , there’s some file still On A, Check it by :

open database

select name from v$controlfile
union
select name from v$tempfile
union
select member from v$logfile
union
select filename from v$block_change_tracking;

NAME
——————————————————————————–
+DATA/test/controlfile/current.303.697650047
+DATA/test/onlinelog/group_1.304.697650049
+DATA/test/onlinelog/group_2.305.697650049
+DATA/test/onlinelog/group_3.306.697650049
+DATA/test/tempfile/temp.307.697650095
+FRA/test/controlfile/current.260.697650047
+FRA/test/onlinelog/group_1.261.697650049
+FRA/test/onlinelog/group_2.262.697650049
+FRA/test/onlinelog/group_3.263.697650051

alter database rename file ‘+DATA/test/datafile/sysaux.300.697649963’ to ‘/app/oracle/TEST/sysaux_01.dbf’;

alter database rename file ‘+DATA/test/datafile/system.299.697649963’ to ‘/app/oracle/TEST/system_01.dbf’;

alter database rename file ‘+DATA/test/datafile/undotbs1.301.697649965’ to ‘/app/oracle/TEST/undotbs1_01.dbf’;

alter database rename file ‘+DATA/test/datafile/users.302.697649965’ to ‘/app/oracle/TEST/users_01.dbf’;

alter database rename file ‘+DATA/test/datafile/users.309.697650601’ to ‘/app/oracle/TEST/users_02.dbf’;

ALTER DATABASE ADD LOGFILE GROUP 4 (‘/app/oracle/TEST/redo_04a.dbf’,’/app/oracle/TEST/redo_04b.dbf’) size 50M;

ALTER DATABASE ADD LOGFILE GROUP 5 (‘/app/oracle/TEST/redo_05a.dbf’,’/app/oracle/TEST/redo_05b.dbf’) size 50M;

ALTER DATABASE ADD LOGFILE GROUP 6 (‘/app/oracle/TEST/redo_06a.dbf’,’/app/oracle/TEST/redo_06b.dbf’) size 50M; 

4-the Last Step for Control file and Spfile :


SQL>show parameter control
control_files 
————————–
+DATA/test/controlfile/current .303.697650047
SQL > Create Pfile=” from spfile ;

After Creating Pfile , Open it modify Control File Location to Our New Location /app/oracle/TEST/…

*.control_files=’/app/oracle/TEST/control01.ctl’,’/app/oracle/TEST/control02.ctl’

startup nomount

$rman target /

 restore controlfile from ‘+DATA/test/controlfile/current.303.697650047’;

 exit

create spfile=’/app/oracle/product/11.1.0/db_1/dbs/spfileTEST.ora’ from pfile=’/home/oracle/john.ora’;

File created.

shutdown immediate;
startup

show parameter control

control_files  /app/oracle/TEST/control01.ctl , /app/oracle/TEST/control02.ctl

This Steps Without Using RMAN , I will Post Another Steps Using RMAN

Thank you
Osama mustafa

Automatic Storage Management/ASM Part 2

Templates:

Templates are named groups of attributes that can be applied to the files within a disk group

Examples :

 

-- Create a new template.
ALTER DISKGROUP disk_group_1 ADD TEMPLATE my_template ATTRIBUTES (MIRROR FINE);

-- Modify template.
ALTER DISKGROUP disk_group_1 ALTER TEMPLATE my_template ATTRIBUTES (COARSE);

-- Drop template.
ALTER DISKGROUP disk_group_1 DROP TEMPLATE my_template;

Available attributes include:

  • UNPROTECTED – No mirroring or striping regardless of the redundancy setting.
  • MIRROR – Two-way mirroring for normal redundancy and three-way mirroring for high redundancy. This attribute cannot be set for external redundancy.
  • COARSE – Specifies lower granuality for striping. This attribute cannot be set for external redundancy.
  • FINE – Specifies higher granularity for striping. This attribute cannot be set for external redundancy.

 

 

Directories

A directory heirarchy can be defined using the ALTER DISKGROUP statement to support ASM file aliasing

Examples :

-- Create a directory.
ALTER DISKGROUP disk_group_1 ADD DIRECTORY '+disk_group_1/my_dir';

-- Rename a directory.
ALTER DISKGROUP disk_group_1 RENAME DIRECTORY '+disk_group_1/my_dir' TO '+disk_group_1/my_dir_2';

-- Delete a directory and all its contents.
ALTER DISKGROUP disk_group_1 DROP DIRECTORY '+disk_group_1/my_dir_2' FORCE;

 

Aliases

Aliases allow you to reference ASM files using user-friendly names

-- Create an alias using the fully qualified filename.
ALTER DISKGROUP disk_group_1 ADD ALIAS '+disk_group_1/my_dir/my_file.dbf'
FOR '+disk_group_1/mydb/datafile/my_ts.342.3';

-- Create an alias using the numeric form filename.
ALTER DISKGROUP disk_group_1 ADD ALIAS '+disk_group_1/my_dir/my_file.dbf'
FOR '+disk_group_1.342.3';

-- Rename an alias.
ALTER DISKGROUP disk_group_1 RENAME ALIAS '+disk_group_1/my_dir/my_file.dbf'
TO '+disk_group_1/my_dir/my_file2.dbf';

-- Delete an alias.
ALTER DISKGROUP disk_group_1 DELETE ALIAS

Files

Files are not deleted automatically if they are created using aliases, as they are not Oracle Managed Files (OMF), or if a recovery is done to a point-in-time before the file was created. For these circumstances it is necessary to manually delete the files, as shown below.

 

-- Drop file using an alias.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/my_dir/my_file.dbf';

-- Drop file using a numeric form filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1.342.3';

-- Drop file using a fully qualified filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/mydb/datafile/my_ts.342.3';

ASM Views:

Migrating to ASM Using RMAN:

  • Disable change tracking (only available in Enterprise Edition) if it is currently being used.
SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
  • Shutdown the database.
    SQL> SHUTDOWN IMMEDIATE 
    • Modify the parameter file of the target database as follows:
      Set the DB_CREATE_FILE_DEST and DB_CREATE_ONLINE_LOG_DEST_n parameters to the relevant ASM disk groups.
      Remove the CONTROL_FILES parameter from the spfile so the control files will be moved to the DB_CREATE_* destination and the spfile gets updated automatically. If you are using a pfile the CONTROL_FILES parameter must be set to the appropriate ASM files or aliases.
  • Start the database in nomount mode.

                            RMAN> STARTUP NOMOUNT

 

  • Restore the controlfile into the new location from the old location.

 RMAN> RESTORE CONTROLFILE FROM ‘old_control_file_name’;

  • Mount the database.
  • Copy the database into the ASM disk group.
    RMAN> BACKUP AS COPY DATABASE FORMAT '+disk_group';

  • Switch all datafile to the new ASM location.

    RMAN> SWITCH DATABASE TO COPY;
  • Open the database.

    RMAN> ALTER DATABASE OPEN;
  • Create new redo logs in ASM and delete the old ones.
  • Enable change tracking if it was being used.

    SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING; 

Automatic Storage Management (ASM) / Part 1

using SQL*Plus connect to the idle instance.

export ORACLE_SID=+ASM
sqlplus / as sysdba

Startup and Shutdown of ASM Instances

 

ASM instance are started and stopped in a similar way to normal database instances. The options for the STARTUP command are:

  • FORCE – Performs a SHUTDOWN ABORT before restarting the ASM instance.
  • MOUNT – Starts the ASM instance and mounts the disk groups specified by the ASM_DISKGROUPS parameter.
  • NOMOUNT – Starts the ASM instance without mounting any disk groups.
  • OPEN – This is not a valid option for an ASM instance.

The options for the SHUTDOWN command are:

  • NORMAL – The ASM instance waits for all connected ASM instances and SQL sessions to exit then shuts down.
  • IMMEDIATE – The ASM instance waits for any SQL transactions to complete then shuts down. It doesn’t wait for sessions to exit.
  • TRANSACTIONAL – Same as IMMEDIATE.
  • ABORT – The ASM instance shuts down instantly.

 

ASM Disk Groups

  level of redundancy:

 

  • NORMAL REDUNDANCY – Two-way mirroring, requiring two failure groups.
  • HIGH REDUNDANCY – Three-way mirroring, requiring three failure groups.
  • EXTERNAL REDUNDANCY – No mirroring for disks that are already protected using hardware mirroring or RAID. If you have hardware RAID it should be used in preference to ASM redundancy, so this will be the standard option for most installations.

Create Example : 

CREATE DISKGROUP disk_group_1 NORMAL REDUNDANCY
FAILGROUP failure_group_1 DISK
'/devices/diska1' NAME diska1,
'/devices/diska2' NAME diska2
FAILGROUP failure_group_2 DISK
'/devices/diskb1' NAME diskb1,
'/devices/diskb2' NAME diskb2;

DROP Example : 

DROP DISKGROUP disk_group_1 INCLUDING CONTENTS;

Using Alter to Add Disk : 

ALTER DISKGROUP disk_group_1 ADD DISK
'/devices/disk*3',
'/devices/disk*4';

Using Alter to Drop Disk :

ALTER DISKGROUP disk_group_1 DROP DISK diska2;

Using Alter to Re-size Disk : 

ALTER DISKGROUP disk_group_1
RESIZE DISK diska1 SIZE 100G;

 Using Alter to Re-size all disk in Failure Group:

ALTER DISKGROUP disk_group_1
RESIZE DISKS IN FAILGROUP failure_group_1 SIZE 100G;

 Using Alter to Resize all Disk In DiskGroup :

ALTER DISKGROUP disk_group_1
RESIZE ALL SIZE 100G;

Using Alter To dismiss pending disk to be Dropped :

ALTER DISKGROUP disk_group_1 UNDROP DISKS;

 Some Useful Command to Mount ASM disk group Manually : 

ALTER DISKGROUP ALL DISMOUNT;
ALTER DISKGROUP ALL MOUNT;
ALTER DISKGROUP disk_group_1 DISMOUNT;
ALTER DISKGROUP disk_group_1 MOUNT;

 Thank You 

Osama mustafa

Check Rac Status

hi All Again ,

As Oracle Database administrator its your job to check rac status on your server, i know its little creepy when we heard about RAC,DG but its all about the command and how , when to use it ? !!!

Sure you need to be careful when you are using commands such as “crs , Srvtl” and stuff like that .

I will make it easy for you save this command in the notepad (you can find in the end of this article)
so everytime you need to check RAC status and you need to do is choose your command :

Let start

*To check RAC STATUS ON OS :
Use :
crs_stat -t

*Check Node Availability :
Status nodeapps -n

*Check your ASM :
srvctl status asm -n

ok but i need to check database status how ?
*for Database status :
srvctl status database -d esxrac

And what about service for this database is it work fineeeeee :
* Database Services :
srvctl status service -d esxrac

And Finally
* Cluster Status :
crsctl check crs

As we see its all about command if you how to use it RAC will be easy otherwise don’t use it if you don’t know anything about it because it maybe destroy everything . BE CAREFUL

Where you Go its not the end , i need to check RAC inside the Database (SQL) :
lets Begin 🙂

I need to check Rac Instance if it works fine in normal database we use v$instance
here in rac just add gv$instance .
** select instance_name, host_name, archiver, thread#, status
from gv$instance ;

What About datafiles :
**select file_name, bytes/1024/1024 from dba_data_files ;

Getting the status of all the groups, type, membership :
**select group#, type, member, is_recovery_dest_file from v$logfile order by group#

But , Wait what about ASM we need to check it too :
To check ASM Disk :
**select group_number, name,allocation_unit_size alloc_unit_size,state,type,total_mb,usable_file_mb
from v$asm_diskgroup;

Information About ASM instance :
select group_number, file_number, bytes/1024/1024/1024 GB, type, striped, modification_date from v$asm_file
where TYPE != ‘ARCHIVELOG’

Thank You very Much , just Bookmark my blog all i keep post everything useful for DBA’s

And you can Download notepad from HERE