Thursday, September 15, 2016

Creating the Recovery Catalog


Problem:
********

You are planning to use a recovery catalog so we will procceed with creating recovery catalog database and will create a recovery catalog in that database.

Solution:
*********

Therefore we are creating a database in silent mode. Creating the recovery catalog consists of two major steps. First, you must create the recovery catalog owner or schema in the database where you want to house the recovery catalog. Second, once you successfully create the recovery catalog schema, you must create the recovery catalog itself.

Step 1:
********

Creating a database in silent mode:
****************************************

We are procceeding to creating database (rmancatalog) on (dell) server in (RMAN_CATALOG) diskgroup.


[oracle@dell trace]$ dbca -silent \
>   -createDatabase \
>   -asmsnmpPassword asm \
>   -characterSet WE8MSWIN1252 \
>   -continueOnNonFatalErrors false \
>   -disableSecurityConfiguration ALL \
>   -diskGroupName RMAN_CATALOG \
>   -emConfiguration NONE \
>   -gdbName rmancatalog.local \
>   -listeners LISTENER \
>   -memoryPercentage 40 \
>   -recoveryAreaDestination RMAN_CATALOG \
>   -sid rmancatalog \
>   -SysPassword sys \
>   -SystemPassword sys \
>   -storageType ASM \
>   -sampleSchema true \
>   -templateName General_Purpose.dbc
Copying database files
1% complete
3% complete
10% complete
17% complete
24% complete
31% complete
35% complete
Creating and starting Oracle instance
37% complete
42% complete
47% complete
52% complete
53% complete
56% complete
58% complete
Registering database with Oracle Restart
64% complete
Completing Database Creation
68% complete
71% complete
75% complete
85% complete
96% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/rmancatalog/rmancata.log" for further details.

Step 2:
********


Creating the Recovery Catalog Owner:
********************************************

Follow these steps to create the recovery catalog owner:

1. Using SQL*Plus, connect as the user sys to the database where you want to create the recovery catalog. For example:

[oracle@dell trace]$ . oraenv
ORACLE_SID = [prod] ? rmancatalog
The Oracle base remains unchanged with value /u01/app/oracle

[oracle@dell trace]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Sep 14 11:29:28 2016

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

2. Create a default tablespace for the RMAN recovery catalog owner you’re about to create. Otherwise, the system tablespace may be used by default to hold the recovery catalog structures, and it’s not a smart idea to let that happen. This example creates a tablespace named RMAN_CATALOG_TABLESPACE:

SQL> create tablespace rman_catalog_tablespace datafile '+RMAN_CATALOG' size 500M;

    Tablespace created.

3. Create the recovery catalog owner. This example creates a user named rman to own the catalog:

SQL> create user rman identified by rmanpwd
temporary tablespace temp
default tablespace rman_catalog_tablespace
quota unlimited on rman_catalog_tablespace;  2    3    4

User created.

The default tablespace of the recovery catalog owner in this example is the RMAN_CATALOG_TABLESPACE tablespace, which was created in the previous step.

4. Once you create the recovery catalog owner, you must grant that user the recovery_catalog_owner privilege in order for that user to have the authority to work with the recovery catalog you’ll create in the next step. This recovery catalog owner is named rman, so grant the recovery_catalog_owner privilege to that user:

SQL> grant recovery_catalog_owner, connect, resource to rman;

Grant succeeded.

SQL> exit


Creating the Recovery Catalog:
************************************

Once you’ve created the recovery catalog schema, your next step is to create the recovery catalog. You must connect to the recovery catalog, but not to a target database, when you do this. Here are the steps you must follow to create he recovery catalog:

1. Connect to the RMAN catalog database. You must connect as the recovery catalog owner you created in the previous section.

2. Using the create catalog command, create the recovery catalog. RMAN will create the recovery catalog in the default tablespace of the recovery catalog owner (RMAN_CATALOG_TABLESPACE in our example here). For example:

[oracle@dell trace]$ echo $ORACLE_SID
rmancatalog

[oracle@dell trace]$ rman catalog rman/rmanpwd

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Sep 14 12:02:14 2016

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

connected to recovery catalog database

RMAN> create catalog;

 recovery catalog created

You’re now ready to use RMAN with the recovery catalog, which will store RMAN’s backup and recovery metadata.


Registring Database in created Recovery Catalog:
*********************************************************

once you've done with creating recovery catalog then you can register multipel database with this recovery catalog like I am procceding to register prod database which is host on diffrent server [db01.localdomain (192.168.56.102)].

1. Create Listner on dell server where recovery catalog is hosted.

[grid@dell ~]$ cat /u01/app/grid/11.2.0/grid_home/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/grid/11.2.0/grid_home/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = dell.localdomain)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = rmancatalog)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
)
)
ADR_BASE_LISTENER = /u01/app/grid

ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON              # line added by Agent


2. Create tnsname entry source database (which database want to register) here on dba01 server:

[oracle@db01 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.


LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.103)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rmancatalog.local)
)
)


3. Connect your prod database on db01 server with recovery catalog and Register.

[oracle@db01 admin]$ rman target sys/sys@prod catalog rman/rmanpwd@LISTENER

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Sep 14 12:40:02 2016

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

connected to target database: PROD (DBID=326975078)
connected to recovery catalog database

RMAN> register database;

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

4. You can check what are table & views created to you recovery catalog when you hit create catalog in rmancatalog database.

[oracle@dell trace]$ echo $ORACLE_SID

rmancatalog
[oracle@dell trace]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Sep 14 12:04:43 2016

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> connect rman/rmanpwd
Connected.
SQL> select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
AL                             TABLE
AL_V                           VIEW
BCB                            TABLE
BCB_V                          VIEW
BCF                            TABLE
BCF_V                          VIEW
BCR                            TABLE
BCR_V                          VIEW
BDF                            TABLE
BDF_V                          VIEW
BP                             TABLE

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
BP_V                           VIEW
BRL                            TABLE
BRL_V                          VIEW
BS                             TABLE
BSF                            TABLE
BSF_V                          VIEW
BS_V                           VIEW
CCB                            TABLE
CCB_V                          VIEW
CCF                            TABLE
CCF_V                          VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
CDF                            TABLE
CDF_V                          VIEW
CFS                            TABLE
CFS_V                          VIEW
CKP                            TABLE
CKP_V                          VIEW
CONF                           TABLE
CONFIG                         TABLE
CONFIG_V                       VIEW
CONF_V                         VIEW
DB                             TABLE

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
DBINC                          TABLE
DBINC_V                        VIEW
DB_V                           VIEW
DF                             TABLE
DF_V                           VIEW
FB                             TABLE
FB_V                           VIEW
GRSP                           TABLE
GRSP_V                         VIEW
NODE                           TABLE
NODE_V                         VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
NRSP                           TABLE
NRSP_V                         VIEW
OFFR                           TABLE
OFFR_V                         VIEW
ORL                            TABLE
ORL_V                          VIEW
RCVER                          TABLE
RCVER_V                        VIEW
RC_ARCHIVED_LOG                VIEW
RC_BACKUP_ARCHIVELOG_DETAILS   VIEW
RC_BACKUP_ARCHIVELOG_SUMMARY   VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
RC_BACKUP_CONTROLFILE          VIEW
RC_BACKUP_CONTROLFILE_DETAILS  VIEW
RC_BACKUP_CONTROLFILE_SUMMARY  VIEW
RC_BACKUP_COPY_DETAILS         VIEW
RC_BACKUP_COPY_SUMMARY         VIEW
RC_BACKUP_CORRUPTION           VIEW
RC_BACKUP_DATAFILE             VIEW
RC_BACKUP_DATAFILE_DETAILS     VIEW
RC_BACKUP_DATAFILE_SUMMARY     VIEW
RC_BACKUP_FILES                VIEW
RC_BACKUP_PIECE                VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
RC_BACKUP_PIECE_DETAILS        VIEW
RC_BACKUP_REDOLOG              VIEW
RC_BACKUP_SET                  VIEW
RC_BACKUP_SET_DETAILS          VIEW
RC_BACKUP_SET_SUMMARY          VIEW
RC_BACKUP_SPFILE               VIEW
RC_BACKUP_SPFILE_DETAILS       VIEW
RC_BACKUP_SPFILE_SUMMARY       VIEW
RC_CHECKPOINT                  VIEW
RC_CONTROLFILE_COPY            VIEW
RC_COPY_CORRUPTION             VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
RC_DATABASE                    VIEW
RC_DATABASE_BLOCK_CORRUPTION   VIEW
RC_DATABASE_INCARNATION        VIEW
RC_DATAFILE                    VIEW
RC_DATAFILE_COPY               VIEW
RC_LOG_HISTORY                 VIEW
RC_OFFLINE_RANGE               VIEW
RC_PROXY_ARCHIVEDLOG           VIEW
RC_PROXY_ARCHIVELOG_DETAILS    VIEW
RC_PROXY_ARCHIVELOG_SUMMARY    VIEW
RC_PROXY_CONTROLFILE           VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
RC_PROXY_COPY_DETAILS          VIEW
RC_PROXY_COPY_SUMMARY          VIEW
RC_PROXY_DATAFILE              VIEW
RC_REDO_LOG                    VIEW
RC_REDO_THREAD                 VIEW
RC_RESTORE_POINT               VIEW
RC_RESYNC                      VIEW
RC_RMAN_BACKUP_JOB_DETAILS     VIEW
RC_RMAN_BACKUP_SUBJOB_DETAILS  VIEW
RC_RMAN_BACKUP_TYPE            VIEW
RC_RMAN_CONFIGURATION          VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
RC_RMAN_OUTPUT                 VIEW
RC_RMAN_STATUS                 VIEW
RC_SITE                        VIEW
RC_STORED_SCRIPT               VIEW
RC_STORED_SCRIPT_LINE          VIEW
RC_TABLESPACE                  VIEW
RC_TEMPFILE                    VIEW
RC_UNUSABLE_BACKUPFILE_DETAILS VIEW
RLH                            TABLE
RLH_V                          VIEW
ROUT                           TABLE

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
ROUT_V                         VIEW
RR                             TABLE
RR_V                           VIEW
RSR                            TABLE
RSR_V                          VIEW
RT                             TABLE
RT_V                           VIEW
SCR                            TABLE
SCRL                           TABLE
SCRL_V                         VIEW
SCR_V                          VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
SITE_DFATT                     TABLE
SITE_DFATT_V                   VIEW
SITE_TFATT                     TABLE
SITE_TFATT_V                   VIEW
TEMPRES                        TABLE
TF                             TABLE
TF_V                           VIEW
TS                             TABLE
TSATT                          TABLE
TSATT_V                        VIEW
TS_V                           VIEW

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
VPC_DATABASES                  TABLE
VPC_DATABASES_V                VIEW
VPC_USERS                      TABLE
VPC_USERS_V                    VIEW
XAL                            TABLE
XAL_V                          VIEW
XCF                            TABLE
XCF_V                          VIEW
XDF                            TABLE
XDF_V                          VIEW

142 rows selected.





#RMAN, #RECOVERY CATALOG, #BACKUP, #CATALOG, #ORACLE, #ORACLE 11G

Wednesday, September 14, 2016

ORA-17503: ksfdopn:2 Failed to open file +PROD_DATA_01/prod/spfileprod.ora & ORA-12547: TNS:lost contact




Problem:
************

 You attempted to start you database after silent installation and received this error message:

[root@dell ~]# su - oracle
[oracle@dell ~]$ . oraenv
ORACLE_SID = [oracle] ? prod
The Oracle base has been set to /u01/app/oracle
[oracle@dell ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Sep 14 08:50:02 2016

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

Connected to an idle instance.

SQL> startup
ORA-01078: failure in processing system parameters
ORA-01565: error in identifying file '+PROD_DATA_01/prod/spfileprod.ora'
ORA-17503: ksfdopn:2 Failed to open file +PROD_DATA_01/prod/spfileprod.ora
ORA-12547: TNS:lost contact

 This message indicates you start you database, you need check you oracle utility permissions.

Solution:
***********


To place your database in archivelog mode, perform the following steps:

  1. Check listener status.
  2. Check oracle utility permission for both users grid & oracle.
  3. Change permission of oracle utility for both users grid & oracle.
  4. Startup your database.


Check listener status:
***************************

LSNRCTL> status

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                14-SEP-2016 08:17:33
Uptime                    0 days 0 hr. 32 min. 6 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/grid/11.2.0/grid_home/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/dell/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dell.localdomain)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM", status READY, has 1 handler(s) for this service...
The command completed successfully


Check oracle utility permission for both users grid & oracle:
*************************************************************************


[grid@dell bin]$ ls -al oracle
-rwxrwxr-x 1 grid oinstall 209914513 Sep 11 08:23 oracle

[oracle@dell bin]$ ls -al oracle
-rwxrwsr-x 1 oracle asmadmin 239626683 Sep 11 09:28 oracle


Change permission of oracle utility for both users grid & oracle:
******************************************************************************

[root@dell ~]# cd /u01/app/grid/11.2.0/grid_home/bin
[root@dell bin]# chmod 6751 oracle

[root@dell bin]# ls -lrth oracle
-rwsr-s--x 1 grid oinstall 201M Sep 11 08:23 oracle

[root@dell bin]# cd /u01/app/oracle/product/11.2.0/db_1/bin/
[root@dell bin]# chmod 6555 oracle

[root@dell bin]# ls -lrth oracle
-r-sr-sr-x 1 oracle asmadmin 229M Sep 11 09:28 oracle


Startup your database:
****************************

[root@dell ~]# su - oracle
[oracle@dell ~]$ . oraenv
ORACLE_SID = [oracle] ? prod
The Oracle base has been set to /u01/app/oracle
[oracle@dell ~]$
[oracle@dell ~]$
[oracle@dell ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Sep 14 09:51:57 2016

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  839282688 bytes
Fixed Size                  2257880 bytes
Variable Size             545262632 bytes
Database Buffers          289406976 bytes
Redo Buffers                2355200 bytes
Database mounted.
Database opened.
SQL>

ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode




Problem:
************

You attempted to use RMAN to back up your database and received this error message:

RMAN-03009: failure of backup command on ORA_DISK_1 channel
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode

This message indicates that before you can create an RMAN online backup, you need to place your database into archivelog mode.

Solution:
***********

To place your database in archivelog mode, perform the following steps:

1. Connect as sysdba.
2. Shut down your database.
3. Start up in mount mode.
4. Alter the database into archivelog mode.
5. Open your database for use.

If you want to disable archivelog mode, then you would execute all the previous steps, with one change; in step 4, you will need to use the noarchivelog parameter (instead of archivelog mode).

Enabling Archivelog Mode:
**********************************

You first need to connect to your database with a schema that has sysdba privileges (usually the sys schema). The following example connects as sys and then issues the commands to enable archivelog mode:

SQL> connect sys/pradeep as sysdba
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;


Disabling Archivelog Mode:
**********************************

If for some reason you want to disable archiving, issue these commands:

SQL> connect sys/pradeep as sysdba
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database noarchivelog;
SQL> alter database open;

Displaying Archive Information:
***************************************

After you have changed the archivelog mode of your database, you might want to verify that the mode has been set properly. To display the status of archiving, you can query V$DATABASE as follows:

SQL> select log_mode from v$database;
LOG_MODE
--------------------
ARCHIVELOG

The SQL*Plus archive log list command displays a useful summary of the archiving
configuration of your database. As shown in the following output, it includes information such
as the archivelog mode, automatic archiving, archive destination, and log sequence numbers.

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination  +FRA
Oldest online log sequence 87950
Next log sequence to archive 87952
Current log sequence 87952

Enabling archivelog mode is a prerequisite for online backups. The previous commands give you a quick way to verify the archivelog mode status of your database.

Friday, September 9, 2016

How to check tablespace with low space alert.


********************************

Query to find Tablespace utilization:

********************************


set lines 300 pagesize 300
compute sum of "TOTAL SIZE in MB" on report
compute sum of "ALLOCATED SIZE in MB" on report
compute sum of "USED %" on report
compute sum of "FREE %" on report
select a.tablespace_name,
    round(nvl(a.total,0)) "TOTAL SIZE in GB",
    round(nvl(a.asize,0)) "ALLOCATED SIZE in GB",
    round(nvl(a.asize-nvl(f.free,0),0)) "USED",
    round(nvl(a.total-a.asize+f.free,0)) "FREE",
    nvl(f.maxfree,0) "MAX_FREE",
    round(((a.total-nvl(a.total-a.asize+f.free,0))/a.total)*100) "USED %",
    round((nvl(a.total-a.asize+f.free,0)/a.total)*100) "FREE %"
    from (select tablespace_name,sum(bytes)/1024/1024/1024 "ASIZE",sum(case when maxbytes > bytes
   then maxbytes else bytes end)/1024/1024/1024 total from dba_data_files group by tablespace_name) a,
   (select tablespace_name, round(sum(bytes/(1024*1024*1024))) free,round(max(bytes)/1024/1024/1024) maxfree
   from dba_free_space group by tablespace_name) f
   WHERE a.tablespace_name = f.tablespace_name(+)
   and a.tablespace_name='&Tablespace'
   order by round((nvl(a.total-a.asize+f.free,0)/a.total)*100)
   /
========================================================================

Enter value for tablespace: USERS
old  14:    and a.tablespace_name='&Tablespace'
new  14:    and a.tablespace_name='USERS'

TABLESPACE_NAME TOTAL SIZE in GB ALLOCATED SIZE in GB  USED  FREE MAX_FREE  USED % FREE %
--------------- ---------------- -------------------- ------ ----  -----    ------ ------
USERS            32                  0           0      32     0         0     100




**********************************************
Datafiles In Tablespace on Disk group or filesystem
**********************************************

set pagesize 300
set lines 300
col TABLESPACE_NAME for a15
col FILE_NAME for a60
col Size_GB for 9999999
select 
TABLESPACE_NAME,
FILE_ID,
FILE_NAME,
BYTES/1024/1024/1024 Size_GB,
MAXBYTES/1024/1024/1024 MAXBYTES,
AUTOEXTENSIBLE 
from 
dba_data_files
where 
TABLESPACE_NAME ='&Tablespace_Name'
order by 
FILE_NAME;

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

TABLESPACE_NAME FILE_ID FILE_NAME                                         SIZE_GB   MAXBYTES AUT
--------------- ------- ------------------------------------------------- -------- ---------- ---
USERS                 4 +DELL_DATA01/prod/datafile/users.259.921999959      0      31.9999847 YES




*****************
ASM_Disk_Uses
*****************


set pages 400 lines 200
col NAME for a15
col STATE for a15
col FREE_MB for 9999999999
select 
GROUP_NUMBER,
NAME,
ALLOCATION_UNIT_SIZE,
STATE,
TYPE,
TOTAL_MB/1024 "Totalspace(GB)",
FREE_MB/1024 "Freespace(GB)",
(free_mb/total_mb)*100 "Pct_FREE_%",
OFFLINE_DISKS
from 
v$asm_diskgroup;


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

GROUP_NUMBER NAME            ALLOCATION_UNIT_SIZE STATE           TYPE   Totalspace(GB) Freespace(GB) Pct_FREE_% OFFLINE_DISKS
------------ --------------- -------------------- --------------- ------ -------------- ------------- ---------- -------------
           1 DELL_DATA01                  1048576 CONNECTED       NORMAL     11.9960938    7.99609375 66.6558124             0
           2 FRA                          1048576 MOUNTED         EXTERN     11.9960938    11.9472656 99.5929665             0


*********************************
To Add Datafile In Tablespace
*********************************


ALTER TABLESPACE NFL_TSQ02 ADD DATAFILE '+DATA_DELL/' SIZE 100m AUTOEXTEND ON NEXT 20m MAXSIZE 32767m