Thursday, 4 September 2014

expdp/impdp without table data






expdp/impdp without table data (metadata only)

Export Schema without data (META DATA ONLY)

expdp system/s 
directory=backup_dir 
CONTENT=METADATA_ONLY 
dumpfile=testmetaddl.dmp 
schemas=testmeta 
logfile=testmetalog.$Date.log

Import DMP File:
 
impdp system/s 
directory=backup_dir 
dumpfile=testmetaddl.dmp 
sqlfile=metaddl.sql 
logfile=imp_log_of_meta.log

SCAN in Oracle 11GR2



SCAN -Single Client Access Name






Figure 1
SCAN is new Oracle Real Application Clusters (RAC) 11gR2 feature. It gives a single name for clients to access oracle database running in a cluster.

Basics of SCAN

- Single client access name (SCAN) is the virtual hostname to provide for all clients connecting to the cluster (as opposed to the vip hostnames in 10g and 11gR1).
- SCAN is a domain name registered to at least one and up to three IP addresses, either in the domain name service (DNS) or the Grid Naming Service (GNS).
- By default, the name used as the SCAN is also the name of the cluster and must be globally unique throughout your enterprise.
- For installation to succeed, the SCAN must resolve to at least one address. There can be a maximum of three ip addresses that can be used for the SCAN.
- SCAN VIP addresses must be on the same subnet as virtual IP addresses and public IP addresses.
- SCAN VIPs can float in the cluster while Node VIPs as default run on specific nodes only.
- SCAN Listeners are simply used for redirecting the request received from client, this is usually considered a lightweight process when we compare it to the functioning of Node VIP Listeners as these actually fork a new process to create database conenction.
-  SCAN IP address and SCAN listeners are managed as resources in Oracle Clusterware.
- For high availability and scalability, Oracle recommends that you configure the SCAN to use DNS Round Robin resolution to three addresses.


Benefits of SCAN

1) the SCAN makes it possible to add or remove nodes from the cluster without needing to reconfigure clients (Because the SCAN is associated with the cluster as a whole, rather than to a particular node). Before SCAN, if the cluster changed, then the client TNSNAMES.ORA files (or other tns connect strings like Easy Connect strings) would need to change. So your DBA  can easily add or delete a node without changing the configuration files.
For example, connection to database “11g” using SCAN would use this tnsnames entry:


11g =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=rac-scan.corp.to)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=11g))
)
While without SCAN we were using


11g_old =
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=rac1-vip.corp.to)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=rac2-vip.corp.to)(PORT=1521))
)
(CONNECT_DATA=(SERVICE_NAME=11g))

2) It also adds location independence for the databases, so that client configuration does not have to depend on which nodes are running a particular database.

Working
“When a client submits a request, the SCAN listener listening on a SCAN IP address and the SCAN port is contracted on a client’s behalf. Because all services on the cluster are registered with the SCAN listener, the SCAN listener replies with the address of the local listener on the least-loaded node (Each scan listener keeps updated cluster load statistics) where the service is currently being offered. Finally, the client establishes connection to the service through the listener on the node where service is offered.All of these actions take place transparently to the client without any explicit configuration required in the client.”


 Figure 2 ( taken from Oracle documentation)
Figure 2 above shows where SCAN and Local listeners fits into picture.


Connection flow in case of SCAN is :
1) Client sends connection to SCAN name and a SCAN IP address is provided in return if DNS is used.  SCAN IPs are returned in round-robin process. If GNS is used for SCAN ip management then DNS delegates the request to GNS services and GNS services in turn return a SCAN IP address ( again in round-robin fashion)
2) The TNS request is now forwarded to the SCAN Listeners (shown in Fig 2)
3) SCAN listeners in turn forward the request to local listeners ( least loaded one)
4) Local listeners take care of client request.


Setup
In order to successful install grid infrastructure you need to configure your DNS  prior to  installing the grid infrastructure to resolve the name accordingly. Oracle requires at least one IPs to be configured for the scan name.
You can have two options to define SCAN name
1) Define it in your DNS (Domain Name Service
2) Use GNS (Grid Naming Service)

Also after the setup is done, the remote_listener parameter is made to point to SCAN  tnsnames.ora entry and local_listener uses VIP Listener entry. The  remote listeners which points to SCAN listeners will do the load balancing and local listeners will take care of new process spawning and connection to database. PMON registers with SCAN listener as defined in parameter ‘ remote_listener’ setting and also with the node listener depending on the local listener settings. On the basis of  PMON provided details SCAN will choose the least loaded node to forward the request received from client.



NAME                                    TYPE         VALUE
———————————— ———– ——————————
remote_listener                        string         rac-scan.global.to:1521
NAME                          TYPE          VALUE
———————————— ———– ————————————————
local_listener         string         (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) (HOST=196.1.2.50)(PORT=1521))))

You need to provide SCAN related settings during installation of Grid infrastructure as shown below.

 Figure 3



Is it mandatory to use SCAN?

No but It is highly recommended to use SCAN unless there’s strong business reason preventing it from being used.




Enjoy & Cheers
Manpreet Singh

AWR Reports Vs. ASH Reports




AWR Reports Vs. ASH Reports



Sometimes when you face performance issue On your database, Usually first thing you are doing is Generate One of the above reports . But What is the benefits of these reports ? What is the difference ? When Can i use them ?


Let Start

I share in my blog earlier how to generate AWR reports . But Today we are talking About another topic .

Automatic Workload Repository Reports/(AWR):

this report appear in 10g Database, I heard that some people said "AWR used Instead Of Statpack" !! NO AWR is higher Version of statpack , statpack still exists but you have to enable it.

The AWR takes a snap shot of the database in specified intervals (default is one hour) and stores in Sysaux tablespace. and you can change this interval using the following :

BEGIN
  DBMS_WORKLOAD_REPOSITORY.modify_snapshot_settings(
    retention => 43200,        -- Minutes (= 30 Days). Current value retained if NULL.
    interval  => 30);          -- Minutes. Current value retained if NULL.
END;
/

The snap shots are taken automatically if the statistics_level parameter is set to typical/all. If it set to basic then statistics details are not gathered,The AWR contains the performance statistics and workload information on the database.

and you can take extra snapshot by :

EXEC DBMS_WORKLOAD_REPOSITORY.create_snapshot;

BEGIN
  DBMS_WORKLOAD_REPOSITORY.drop_snapshot_range (
    low_snap_id  => 22, 
    high_snap_id => 32);
END;
/


As i mention above you can enable it , disable by the following command :

Enable AWR :
alter system set  statistic_level = {typical | all} scope=spfile ;
Disable AWR :
alter system set   set statistic_level = {basic} scope=spfile
 Check Statistic if its been Gathered By Fire :
Select * from V$statistics_level;
The statistics are collected and stored in memory in SGA. The in memory statistics collection area is a circular buffer, where the old data is overwritten after flushing to disk.


he AWR statistics snap shot are owned by Sys schema. ,The AWR is used to collect performance statistics including:
  • Wait events used to identify performance problems.
  • Time model statistics indicating the amount of DB time associated with a process from the V$SESS_TIME_MODEL and V$SYS_TIME_MODEL views.
  • Active Session History (ASH) statistics from the V$ACTIVE_SESSION_HISTORY view.
  • Some system and session statistics from the V$SYSSTAT and V$SESSTAT views.
  • Object usage statistics.
  • Resource intensive SQL statements.
 
     Active Session History (ASH) :


     The Name of this reports describe what is the major difference between it and AWR , The ASH contains recent information on active sessions sampled every second. The AWR are taken every one hour and its one hour old will not help in diagnosing issues that are current on the database. Typically to resolve issues urgenly on the database, details information pertaining o last 5 to 10 mins is critical. Because recording session activity is expensive, ASH samples V$SESSION every second and records the event for which he session are waiting.




    ASH information through V$active_session_history , you can can check this table from Oracle Documentation .

    As appear in the Documentation the View contain :
    It include

    * sql identifier of sql statement.
    * object no., file no., and block no.
    * wait event identifier & parameters.
    * user identifier, Session identifier and Serial number.
    * client identifier and name of the operating system program.


    Conclusion :

    ASH can help you when there's a sudden performance degradation of the database felt.
    AWR - historic past snapshot intervals.

    AWR, stores the session performance statistics for analysis later.
    ASH - the storage is not persistent and as time progresses, the old entries are removed to accommodate new ones. They can be viewed using V$ACTIVE_SESSION_HISTORY.

    OPEN RESETLOGS WITHOUT RECOVERY






    OPEN RESETLOGS WITHOUT RECOVERY



    Amazing Oracle Trick I found today while I am Browsing OTN , I see to post it here .

    What is Open reset log mode 
     
    Online redo logs are re-created . The log sequence is reset to 1.
    If the database is running in archive log mode, the archived redo logs should then be deleted. Otherwise, chances are, that Oracle will eventually try to create an archived redo log whose filename already exists. 

    First I will show its Normal Database this mean not in recovery mode :

    sqlplus / as sysdba
    Connected to an idle instance.
    
    SQL> ORACLE instance started.
    
    Total System Global Area  838860800 bytes
    Fixed Size                  2087672 bytes
    Variable Size             213910792 bytes
    Database Buffers          616562688 bytes
    Redo Buffers                6299648 bytes
    Database mounted.
    Database opened.
    SQL> shutdown
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> exit  

    Now Lets Open it :


    sqlplus / as sysdba

    Connected to an idle instance.
    
    SQL> startup mount
    ORACLE instance started.
    
    Total System Global Area  838860800 bytes
    Fixed Size                  2087672 bytes
    Variable Size             213910792 bytes
    Database Buffers          616562688 bytes
    Redo Buffers                6299648 bytes
    Database mounted.
    SQL> alter database open resetlogs;
    alter database open resetlogs
    *
    ERROR at line 1:
    ORA-01139: RESETLOGS option only valid after an incomplete database recovery
     
    SQL> recover database;
    ORA-00283: recovery session cancelled due to errors
    ORA-00264: no recovery required
    
    
    SQL> alter database open resetlogs;
    alter database open resetlogs
    *
    ERROR at line 1:
    ORA-01139: RESETLOGS option only valid after an incomplete database recovery
    
    
    SQL> recover database until cancel;
    Media recovery complete.
    SQL> alter database open resetlogs;
    
    Database altered.
    
    SQL> 

    ORA-00020







    ORA-00020: maximum number of processes (%s) exceeded

    SQL> show parameter processes
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    processes                            integer     150
    
    SQL> select count(*) from v$process;
    
      COUNT(*)
    ----------
           149
    
    SQL> alter system set processes=300 scope=spfile;
    
    System altered.
    
    SQL> shutdown immediate
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    
    SQL> startup
    ORACLE instance started.
    
    SQL> show parameter processes
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    processes                            integer     300

    How to change SGA in Oracle RAC



    How to change SGA in Oracle RAC




    This Article for newbie Oracle DBA Since If you trying to change SGA on RAC with wrong way , you may lost your spfile , means you can corrupt your spfile . 

    Node One : ORCL1
    Node Two : ORCL2

    Note : You Need To Check Memory Parameter On Database , if its Have Available Size .
    • Connect To Node One :

    alter system set sga_max_size=16g scope=spfile sid = 'ORCL1';
    alter system set sga_target=12g scope=spfile sid = 'ORCL1';
    alter system set sga_max_size=16g scope=spfile sid = 'ORCL2';
    alter system set sga_target=12g scope=spfile sid = 'ORCL2';

    Or In Another Way :
    sql>alter system set sga_target=12G scope=spfile sid='*';
    sql>alter system set sga_max_size=16G scope=spfile sid='*';
    sql>alter system set sga_max_size=16G scope=spfile ;
    sql>alter system set sga_target=12G scope=spfile;

     PGA :

    sql>alter system set pga_aggregate_target=4G scope =spfile sid='*';
    sql>alter system set pga_aggregate_target=4G scope=both;


    • shutdown database PROD (two instances should be shut down)
     $>srvctl stop database -d PROD
    $>srvctl START database -d PROD


    Check The New Size For Both Instance By :

    Show parameter sga ;




     

    Friday, 2 May 2014

    OC4J Configuration issue



    Problem:-

    I tried to start the DBConsole service and encountered the below error message.

    C:\Users\Administrator>SET ORACLE_SID=TESTDB

    C:\Users\Administrator>emctl start dbconsole
    OC4J Configuration issue. D:\app\Administrator\product\11.2.0\dbhome_1/oc4j/j2ee
    /OC4J_DBConsole_db1.localdomain.com_testdb not found.

    C:\Users\Administrator>emctl status dbconsole
    OC4J Configuration issue. D:\app\Administrator\product\11.2.0\dbhome_1/oc4j/j2ee
    /OC4J_DBConsole_db1.localdomain.com_testdb not found


    Solution:-

    Renamed the folder

    D:\app\Administrator\product\11.2.0\dbhome_1\oc4j\j2ee\OC4J_DBConsole_db1
    to
    D:\app\Administrator\product\11.2.\dbhome_1\oc4j\j2ee\OC4J_DBConsole_db1.localdomain.com_testdb

    Tried to start the DBConsole again but it throwed another error.

    C:\Users\Administrator>emctl start dbconsole
    EM Configuration issue. D:\app\Administrator\product\11.2.0\dbhome_1\hostname.domain.com_testdb not found.

    renamed the folder
    D:\app\Administrator\product\11.2.0\dbhome_1/db1_testdb
    to
    D:\app\Administrator\product\11.2.0\dbhome_1/db1.localdomain.com_testdb

    Now tried to start the DBConsole and it started with ease :-)

    C:\Users\Administrator>emctl start dbconsole
    Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
    Copyright (c) 1996, 2010 Oracle Corporation. All rights reserved.
    https://db1:1158/em/console/aboutApplication
    Starting Oracle Enterprise Manager 11g Database Control ...The OracleDBConsolete
    stdb service is starting.................
    The OracleDBConsoletestdb service was started successfully