jeudi 3 novembre 2011

Oracle11g: How to create a Recovery Catalog for RMAN



Prerequisites

1) Database must be in archivelog
To perform backup through rman, the database must be in archivelog mode:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 1238732800 bytes
Fixed Size                  1336204 bytes
Variable Size             788532340 bytes
Database Buffers          436207616 bytes
Redo Buffers               12656640 bytes
Database mounted.

SQL> alter database archivelog;

Database altered.
SQL> alter database open;

Database altered.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     193
Next log sequence to archive   195
Current log sequence           195

As we can see, the archive destination references the USE_DB_RECOVERY_FILE_DEST value. To identify the real location where the archivelog will be written we can display the value of the DB_RECOVERY_FILE_DEST init parameter:
SQL> show parameter DB_RECOVERY_FILE_DEST;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /database/TEST/flash_recovery_
                                                 area
db_recovery_file_dest_size           big integer 3852M


2) Configure severals destinations of archive log files

It is recommanded to configure more than one archive log file destination because if only one is configured, the database may frozen if the unique destination is full.

Local and remote destination are configured through the LOG_ARCHIVE_DEST_n paraemeters where n is in range [1..31].
For each LOG_ARCHIVE_DEST_n parameter there is a LOG_ARCHIVE_DEST_STATE_n parameter which indicates if the destination is enabled or not. By default the destination is enabled.

The LOG_ARCHIVE_DEST_n parameter may contain :
a) a local destination : LOG_ARCHIVE_DEST_n='LOCATION=/disk1/arch'
b) a remote destination through a net service name : LOG_ARCHIVE_DEST_n='SERVICE=remote_service'
The service name must be defined in the tnsnames.ora configuration file.

A destination may be declared MANDATORY or OPTIONAL. If a destination marked as MANDATORY fails, then the archiving process fails and the database frozen whatever the value defined in the LOG_ARCHIVE_MIN_SUCCEED_DEST. We can conclude that a the LOG_ARCHIVE_MIN_SUCCEED_DEST is ignored when a MANDATORY destination fails.

remark: Under the Oracle Database Standard Edition, only two archive log destinations are available : LOG_ARCHIVE_DEST & LOG_ARCHIVE_DUPLEX_DEST. Under Enterprise Edition, Oracle recommands LOG_ARCHIVE_DEST_n.

remark: The view V$ARCHIVE_DEST contains all information about archivelog destinations.

3) Ensuring success for archiving log files

When having severals archivelog destinations, it is usefull to define the minimum number of destination that must succeed in order to consider that the archiving process is successful. This is done through the LOG_ARCHIVE_MIN_SUCCEED_DEST parameter.
By default this parameter is setted to 1.

4) Defining a conservation strategies for backups

It is necessary to define a period of time during which it is possible to repair the database from backups. This strategy could be based on
a) a recovery window of n days
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF <days> DAYS;
b) or a number of backups to keep available.
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY <copies>;

remark: If you don't use a rman catalog, then the retention policy (recovery window or redundancy) must be less than the value of the CONTROL_FILE_RECORD_KEEP_TIME. The default value for CONTROL_FILE_RECORD_KEEP_TIME is 7 days.

remark: If you use a rman catalog, then ensure that the value of the CONTROL_FILE_RECORD_KEEP_TIME parameter is more then the time between 2 catalog resynchronizations. Resynchronizations are performed when you create a new backup or when you use the RESYNC CATALOG command.

remark: If you desactivate the retention policy then backups are keeped by rman as long as defined by the CONTROL_FILE_RECORD_KEEP_TIME parameter. To desactivate the retention policy :
RMAN> CONFIGURE RETENTION POLICY TO NONE;


5) Configure deletion policy for archivelog files

It is possible to configure a deletion policy for archivelog file as well as backupset or image copies.
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO {CLEAR | TO {APPLIED ON [ALL] STANDBY |
  BACKED UP integer TIMES TO DEVICE TYPE deviceSpecifier |
  NONE | SHIPPED TO [ALL] STANDBY}
  [ {APPLIED ON [ALL] STANDBY | BACKED UP integer TIMES TO DEVICE TYPE deviceSpecifier |
  NONE | SHIPPED TO [ALL] STANDBY}]...}
The extended syntax allows for configurations where logs are eligible for deletion only after being applied to, or transferred to, one or more standby database destinations.

Creating a recovery catalog for RMAN

The RMAN data are always stored in the control file but they can be duplicated to a distinct database called Recovery Catalog in order to enhance historization of backups (remember that the control file record backups for a fixed period defined through CONTROL_FILE_RECORD_KEEP_TIME parameter).

1) Create a database using dbca (for example)

2) Create a tablespace used by the catalog owner
    a) Create the directory on filesystem where will be located the tablespace (Not necessary if the database is manged through OMF)
$> mkdir /database/TEST/rcat
    b) Create the tablespace used by the catalog
SQL> CREATE TABLESPACE rcat_ts datafile '/database/TEST/rcat/rcat01.dbf' size 15M;
Tablespace created.
Each database registered inside an RMAN catalog require generally 15MB of free space.

3) Create the database owner of the RMAN catalog
SQL> CREATE USER rcatowner IDENTIFIED BY rcatowner
    TEMPORARY TABLESPACE TEMP
    DEFAULT TABLESPACE rcat_ts
    QUOTA UNLIMITED ON rcat_ts;

User created.
Grant the RECOVERY_CATALOG_OWNER role to the rcatowner user;
SQL> GRANT RECOVERY_CATALOG_OWNER to rcatowner;

Grant succeeded.
The RECOVERY_CALATOG_OWNER grants the following system priviledges:
SQL> select * from dba_sys_privs where grantee='RECOVERY_CATALOG_OWNER';

GRANTEE                        PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
RECOVERY_CATALOG_OWNER         CREATE SYNONYM                           NO
RECOVERY_CATALOG_OWNER         CREATE CLUSTER                           NO
RECOVERY_CATALOG_OWNER         ALTER SESSION                            NO
RECOVERY_CATALOG_OWNER         CREATE DATABASE LINK                     NO
RECOVERY_CATALOG_OWNER         CREATE PROCEDURE                         NO
RECOVERY_CATALOG_OWNER         CREATE SEQUENCE                          NO
RECOVERY_CATALOG_OWNER         CREATE TABLE                             NO
RECOVERY_CATALOG_OWNER         CREATE SESSION                           NO
RECOVERY_CATALOG_OWNER         CREATE TYPE                              NO
RECOVERY_CATALOG_OWNER         CREATE VIEW                              NO
RECOVERY_CATALOG_OWNER         CREATE TRIGGER                           NO

11 rows selected.

4) Connect to the instance and create the RMAN catalog
$> rman
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Nov 8 11:14:57 2011

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

RMAN> connect CATALOG rcatowner/rcatowner

connected to recovery catalog database

RMAN> CREATE CATALOG;

recovery catalog created
5) Register a database inside the RMAN catalog
Connect both to the database instance and the rman catalog.
$> export ORACLE_SID=TEST
$> rman TARGET / CATALOG rcatowner/rcatowner
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Nov 8 11:31:42 2011

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

connected to target database: TEST (DBID=2058702964)
connected to recovery catalog database
Register all information in relation to the targetted database inside the rman catalog
RMAN> REGISTER DATABASE;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

remark: To unregister a database from the recovery catalog, use UNREGISTER DATABASE;

6) Configure the retention policy
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

mercredi 2 novembre 2011

Oracle 11g: what is the oracle version and patches applied


To know what is the oracle version regardless the patch installed, you can use the following request under sqlplus :
sql> select * from v$version
If you need to know which patch has been installed on your database, it will be recommended to use the opatch utility located under the $ORACLE_BASE/11.2.0/OPatch directory :
$>./optach lsinventory
Invoking OPatch 11.1.0.6.6

Oracle Interim Patch Installer version 11.1.0.6.6
Copyright (c) 2009, Oracle Corporation.  All rights reserved.


Oracle Home       : /opt/oracle/11.2.0
Central Inventory : /opt/oracle/oraInventory
   from           : /etc/oraInst.loc
OPatch version    : 11.1.0.6.6
OUI version       : 11.2.0.1.0
OUI location      : /opt/oracle/11.2.0/oui
Log file location : /opt/oracle/11.2.0/cfgtoollogs/opatch/opatch2011-11-02_16-20-24PM.log

Patch history file: /opt/oracle/11.2.0/cfgtoollogs/opatch/opatch_history.txt

Lsinventory Output file location : /opt/oracle/11.2.0/cfgtoollogs/opatch/lsinv/lsinventory2011-11-02_16-20-24PM.txt

--------------------------------------------------------------------------------
Installed Top-level Products (1):

Oracle Database 11g                                                  11.2.0.1.0
There are 1 products installed in this Oracle Home.


There are no Interim patches installed in this Oracle Home.


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

OPatch succeeded.

Oracle 10g : How to remove XPT services

To remove XPT services from Oracle 10g then add the following parameter in the intialization parameter file :
__dg_broker_service_names=''

jeudi 8 septembre 2011

Oracle 11g: What is the id of the current session

To know the id of the current session :
SQL>select SYS_CONTEXT('USERENV', 'SESSIONID') from dual;
SYS_CONTEXT('USERENV','SESSIONID')
----------------------------------
4294967295

See this page to retrieve all parameters defined at the user session level :
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/functions172.htm

Oracle 11g : SQLLoader

See the following reference for more information :

Oracle 11g : How to retrieve the source code of a procedure

Look the content of the user_source table:
desc user_source;
NAME   VARCHAR2(30)
TYPE   VARCHAR2(12)
LINE   NUMBER
TEXT   VARCHAR2(4000)

You can issue the following SQL request to find the source code of a specific procedure :
SELECT text
FROM   user_source
WHERE  name = 
AND    type = 'PROCEDURE'
ORDER BY line;

jeudi 1 septembre 2011

Oracle 11g: How to display explain plan

Intallation
To retrieve the execution plan for a specific sql request or session, you need to install the PLAN_TABLE table in your database.
Oracle provide the utlxplan.sql script located under ${ORACLE_HOME}/rdbms/admin/ to perform its installation.
SQL>@?/rdbms/admin/utlxplan;
Calculate plan for a specific request
To populate the PLAN_TABLE table for a specific request :
SQL>truncate table PLAN_TABLE;
SQL>explain plan for select * from user_tables;
Display plan for the previous request
SQL>set linesize 400
SQL>@?/rdbms/admin/utlxpls

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
Plan hash value: 4164660786

---------------------------------------------------------------------------------------------
| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |               |  1831 |  4173K|   515   (1)| 00:00:07 |
|*  1 |  HASH JOIN RIGHT OUTER      |               |  1831 |  4173K|   515   (1)| 00:00:07 |
|   2 |   INDEX FAST FULL SCAN      | I_OBJ2        | 12815 |   300K|    33   (0)| 00:00:01 |
|*  3 |   HASH JOIN RIGHT OUTER     |               |  1831 |  4130K|   482   (2)| 00:00:06 |
|   4 |    TABLE ACCESS FULL        | USER$         |    93 |  1581 |     3   (0)| 00:00:01 |
|*  5 |    HASH JOIN RIGHT OUTER    |               |  1831 |  4100K|   478   (1)| 00:00:06 |

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
|   6 |     INDEX FAST FULL SCAN    | I_OBJ1        | 12815 |   100K|    11   (0)| 00:00:01 |
|*  7 |     HASH JOIN               |               |  1831 |  4085K|   466   (1)| 00:00:06 |
|   8 |      TABLE ACCESS FULL      | TS$           |     5 |    95 |     3   (0)| 00:00:01 |
|*  9 |      HASH JOIN RIGHT OUTER  |               |  1831 |  4051K|   463   (1)| 00:00:06 |
|  10 |       TABLE ACCESS FULL     | SEG$          |  5235 |   230K|    43   (0)| 00:00:01 |
|* 11 |       HASH JOIN RIGHT OUTER |               |  1831 |  3971K|   419   (1)| 00:00:06 |
|  12 |        TABLE ACCESS FULL    | DEFERRED_STG$ |  2783 | 64009 |     7   (0)| 00:00:01 |
|* 13 |        HASH JOIN            |               |  1831 |  3930K|   412   (1)| 00:00:05 |
|* 14 |         TABLE ACCESS FULL   | TAB$          |  2729 |   261K|   367   (0)| 00:00:05 |
|  15 |         MERGE JOIN CARTESIAN|               |  1831 |  3754K|    44   (3)| 00:00:01 |
|* 16 |          HASH JOIN          |               |     1 |  2070 |     1 (100)| 00:00:01 |

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
|* 17 |           FIXED TABLE FULL  | X$KSPPI       |     1 |    55 |     0   (0)| 00:00:01 |
|  18 |           FIXED TABLE FULL  | X$KSPPCV      |   100 |   196K|     0   (0)| 00:00:01 |
|  19 |          BUFFER SORT        |               |  1831 | 54930 |    44   (3)| 00:00:01 |
|* 20 |           TABLE ACCESS FULL | OBJ$          |  1831 | 54930 |    43   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("T"."BOBJ#"="CO"."OBJ#"(+))
   3 - access("CX"."OWNER#"="CU"."USER#"(+))

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
   5 - access("T"."DATAOBJ#"="CX"."OBJ#"(+))
   7 - access("T"."TS#"="TS"."TS#")
   9 - access("T"."FILE#"="S"."FILE#"(+) AND "T"."BLOCK#"="S"."BLOCK#"(+) AND
              "T"."TS#"="S"."TS#"(+))
  11 - access("T"."OBJ#"="DS"."OBJ#"(+))
  13 - access("O"."OBJ#"="T"."OBJ#")
  14 - filter(BITAND("T"."PROPERTY",1)=0)
  16 - access("KSPPI"."INDX"="KSPPCV"."INDX")
  17 - filter("KSPPI"."KSPPINM"='_dml_monitoring_enabled')
  20 - filter("O"."OWNER#"=USERENV('SCHEMAID') AND BITAND("O"."FLAGS",128)=0)

43 rows selected.

Remark : An other way to display a plan under sqlplus is :
SQL> set autotrace on;
To trace only the plan and associated statistics:
SQL> set autotrace traceonly explain statistics;
Note that you may need to enable the PLUSTRACE role for the user that activates the autotrace feature. ($ORACLE_HOME/sqlplus/admin/plustrce.sql)
If you have an error then give the 'select any dictionary' role to the user.

Remark : Using the dbms_xplan package:
  •  To display the plan from the plan table
    SQL> select * from table( dbms_xplan.display);
  •  To display the plan from the shared pool
    SQL> select * from table( dbms_xplan.display_cursor);
 

Displaying current plan with dbms_xplan
  • Retrieve the sql_id associated to the current request in the v$sql view
  • Display the plan like this:
    SQL> select * from table( dbms_xplan.display_cursor('<sql_id>', NULL));
Note that under 11g, the adaptive cursor sharing can generate several suboptimal plan for a sql request depending on statistics and histograms. The second parameter of the display_cursor procedure correspond to the child number so a specific plan in relation to the selectivity of parameters used in the request.
To known if a sql request is sensitive to bind values and adaptive cursor sharing:
SELECT sql_id, child_number, is_bind_sensitive, is_bind_aware
FROM   v$sql WHERE  sql_text = '...';

SQL_ID        CHILD_NUMBER I I
------------- ------------ - -
9bmm6cmwa8saf            0 Y N
9bmm6cmwa8saf            1 Y Y

2 rows selected.
 

Oracle 11g: Export import DATA PUMP

Data pump export/import is a utility for unloading and loading data and metadata from a database into a set of system files. Because the dump files are written by the server, rather than by the client, the database administrator must create directory objects where the utility can managed the files set.
SQL>create or replace directory export_dir as '/opt/oracle/admin/export';
SQL>grant read, write on directory export_dir to fmosse;
DATA_PUMP_DIR directory
By default Oracle create the DATA_PUMP_DIR that references the file system directory '/opt/oracle/admin/<sid>/dpdump/'. User must have the EXP_FULL_DATABASE or IMP_FULL_DATABASE privileges to use the DATA_PUMP_DIR database directory object.
If for some reason the system directory defined in DATA_PUMP_DIr is not found then Oracle use the $ORACLE_HOME/rdbms/log directory instead.

Data Pump Export Modes

Export provides different modes for unloading different portions of the database. The mode is specified on the command line, using the appropriate parameter. The available modes are as follows:
  • Full Export Mode
  • Schema Mode
  • Table Mode
  • Tablespace Mode
  • Transportable Tablespace Mode
Remark : You need the dba privilege to export or import the entire database or some tablespaces.

Exporting the full database
expdb system content=ALL full=y directory=DATA_PUMP_DIR dumpfile=export_full.dmp logfile=export_full.log
The 'content' parameter specifies which data to export. this parameter can have the following values :
  • ALL : To export all data and metadata
  • DATA_ONLY : Only data will be exported
  • METADATA_ONLY: only the structure of the database will be exported
The 'full' parameter specifies that we will export the entire database.

Exporting some schemas
expdb system content=ALL schemas=fmosse directory=DATA_PUMP_DIR dumpfile=export_full.dmp logfile=export_full.log
/br>Exporting some tables of a specific schema
expdb system content=ALL schemas=fmosse tables="TABLE1,TABLE2,TABLE3" directory=DATA_PUMP_DIR dumpfile=export_full.dmp logfile=export_full.log

Exporting a database with a set of dumpfile that does not exceed a specific size
expdp system content=all full=y directory=DATA_PUMP_DIR dumpfile=export_full_%u.dmp logfile=export_full.log filesize=250000
If the 'parallel' parameter is defined with the %U, then oracle create initially a set of dump files defined using the value of the 'parallel' attribute.Oracle can create more files than defined in the parallel attribute if the filesize is specified with a value that requires more files than defined in the parallel attribute.

Exporting a database using several processes in parallel
expdp system content=all full=y directory=DATA_PUMP_DIR dumpfile=export_full.dmp logfile=export_full.log parallel=4

Overwrite export files if already exists
expdp system content=all full=y directory=DATA_PUMP_DIR dumpfile=export_full_%u.dmp  logfile=export_full.log parallel=4 filesize=250000 reuse_dumpfiles=Y

Estimating the size of the export
expdp system content=all full=y directory=DATA_PUMP_DIR estimate_only=y estimate=statistics
If estimate_only=y is specified then the dumpfile parameter must not be defined.
The 'estimate' parameter defines the algorithm to use for estimation. The available values are:
  • BLOCKS : The default value
  • STATISTICS


Importing data
impdp hr directory=DATA_PUMP_DIR dumpfile=hr_export.dmp content=all tables="EMPLOYEES" parallel=1

DataPump import transformation
It is possible with the impdp tool to remap parts of the object when importing a dump file:
  • REMAP_DATAFILE : to remap datafiles
  • REMAP_TABLESPACES : to remap tablespaces
  • REMAP_SCHEMA : to remap a schema to an other one
  • REMAP_TABLE : to remap the name of a table
  • REMAP_DATA : to alter data before the import
To change the name of a table yuo can write REMAP_TABLE="EMPOYEE:EMP".

Consistent backup
Use the parameter flashback_time=to_timestamp( '24/10/2011 18:19:00', 'DD/MM/YYYY HH24:MI:SS')

mercredi 31 août 2011

Oracle 11g : Backup and recovery

Some useful information @ http://wap.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ

Oracle 11g : Using Flashback table and Managing the recycle bin

what is the recycle bin
Oracle says : "The recycle bin is actually a data dictionary table containing information about dropped objects.Dropped tables and any associated objects such as indexes, constraints, nested tables, and the likes are not removed and still occupy space. They continue to count against user space quotas, until specifically purged from the recycle bin or the unlikely situation where they must be purged by the database because of tablespace space constraints."

Viewing the content of the recycle bin
SQL>select * from recyclebin;

SQL>desc RECYCLEBIN;
OBJECT_NAME      NOT NULL VARCHAR2(30)
ORIGINAL_NAME    VARCHAR2(32)
OPERATION        VARCHAR2(9)
TYPE             VARCHAR2(25)
TS_NAME          VARCHAR2(30)
CREATETIME       VARCHAR2(19)
DROPTIME         VARCHAR2(19)
DROPSCN          NUMBER
PARTITION_NAME   VARCHAR2(32)
CAN_UNDROP       VARCHAR2(3)
CAN_PURGE        VARCHAR2(3)
RELATED          NOT NULL NUMBER
BASE_OBJECT      NOT NULL NUMBER
PURGE_OBJECT     NOT NULL NUMBER
SPACE            NUMBER

Object naming in the recycle bin
When a dropped table is moved to the recycle bin, the table and its associated objects are given system-generated names.
Format of objects is : BIN$unique_id$version

where:
  • unique_id is a 26-character globally unique identifier for this object, which makes the recycle bin name unique across all databases
  • version is a version number assigned by the database

Enabling and Disabling the Recycle Bin
To disable the recycle bin, issue one of the following statements:
SQL>ALTER SESSION SET recyclebin = OFF;
or
SQL>ALTER SYSTEM SET recyclebin = OFF scope=SPFILE;

To enable the recycle bin, issue one of the following statements:
SQL>ALTER SESSION SET recyclebin = ON;
or
SQL>ALTER SYSTEM SET recyclebin = ON scope=SPFILE;

Remark :For modification at the system level, you need to restart your database.

Viewing the content of the recycle bin
2 views available :
  • USER_RECYCLEBIN
  • DBA_RECYCLEBIN

SQL>SELECT object_name, original_name FROM dba_recyclebin
   WHERE owner = 'XXX';
SQL>show recyclebin

Restoring table from recycle bin
Issue the following command :
FLASHBACK TABLE <my_table> TO BEFORE DROP;

If you want to rename in the same time the table :
SQL>FLASHBACK TABLE <my_table> TO BEFORE DROP RENAME TO <new_table_name>;

More reference on flashback database: see @ http://abcdba.com/abcdbabackupdataguardhowtoconfigureaflashbackdb

mardi 30 août 2011

Oracle 11g: Recover loss of datafile in NOARCHIVELOG database

Using SQLplus
First of all, you have to identify the missing or corrupted file using the alert log or the v$recover_file view.

Once the datafile identified, you need to stop the database :
SQL>shutdown immediate;

Copy your backup of the file at the same place of your missing datafile.

Startup your database :
SQL>startup;
ORACLE instance started.

Total System Global Area  728199168 bytes
Fixed Size                  1338924 bytes
Variable Size             213909972 bytes
Database Buffers          503316480 bytes
Redo Buffers                9633792 bytes
Database mounted.
ORA-01113: file 44 needs media recovery
ORA-01110: data file 44: '/database/VOLATI/data/DATA_TEST.dbf'
SQL>

As you can see the file you copy need media recovery.

if you check the status of the database, you can see that the database is not opened but stay MOUNT state:
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL>

Now copy the corrupted file or missing one from your last backup to the previous location of the file.

Here you can ask for media recovery on datafile with file id 44 :
SQL>recover datafile 44;

May be you may need to set the datafile online :
SQL>alter database datafile '/database/VOLATI/data/DATA_TEST.dbf' online;
or
SQL>alter database datafile 44 online;

If the recovery on a unique file fails, then try to recover the entire database by restoring all the data files and also the control files from the last backup of your database (remember as your database is in noarchive log, may be you lost some data).


Using RMAN
$>rman target /
RMAN>sql 'alter database datafile 44 offline';
RMAN>restore datafile 44;
RMAN>recover datafile 44;
RMAN>sql 'alter database datafile 44 online';

Oracle 11g : How to know which file to recover

Using SQLplus
Connect to the database and use the following sql instruction :
SQL>select * from v$recover_file;
     FILE# ONLINE  ONLINE_ ERROR                                                                CHANGE# TIME
---------- ------- ------- ----------------------------------------------------------------- ---------- ---------
        44 ONLINE  ONLINE  FILE NOT FOUND                                                             0
As you can see the file with id 44 is missing.

To retrieve the name of the datafile you can write :
SQL>select file#, name from v$datafile join v$recovery_file using( file#);

Using RMAN
To validate the structure of the database.
$>rman target /
RMAN>validate database;
If you want to validate also logical block failure :
$>rman target /
RMAN>validate database CHECK LOGICAL;

To list all database failure that need to be restored or recovered:
$>rman target /
RMAN>list failure all;

To ask an advise from the data recovery advisor :
$>rman target /
RMAN>advise failure;

To ask rman to recover all failure that could be repaired automatically :
$>rman target /
RMAN>repair failure;
The 'repair failure' command need to be executed after the 'advise failure' command because 'advise failure' registers all problems in the Automatic Diagnostic Repository.

Oracle 11g: Recover the lost of a redo log


Redo log file is part of a redo log group that have more than one file
  • Identify the missing or corrupted redo log file from alert log
  • Drop the log file member from the group:
    SQL>alter database drop logfile member '<redo_log_file_name>';
  • Add a new file redo log file member in the previous group :
    SQL>alter database add logfile member '<redo_log_file_name>' to group #;

Redo log file is unique inside a redo log group
  • May be you can drop the group and recreate a new one (if redo log not ACTIVE or CURRENT) :
    SQL>alter database drop logfile group #;
    SQL>alter database add logfile group # ('<redo_log_file_name>') SIZE 150M;
  • May be you can clear the log file of the group that is corrupted or missing.
    • If the database is in NOARCHIVELOG or if the redo log has been archived you can write :
      SQL>alter database clear logfile group #;
    • If the database is in ARCHIVELOG and the redo log file has not been archived :
      SQL>alter database clear unarchived logfile group #;
  • If the redo log is ACTIVE then you can try :
    SQL>alter system checkpoint;
    If the checkpoint fails then you need to perform a complete recovery from a previous backup.


Remark : A log cannot be dropped or cleared until the thread's checkpoint has advanced out of the log.
If the database is not open, then open it. Crash recovery will advance the checkpoint.
If the database is open force a global checkpoint. If the log is corrupted so that the database cannot be opened, it may be necessary to do incomplete recovery until cancel at this log.

For an incomplete recovery :
SQL>RECOVER DATABASE UNTIL CANCEL;
SQL>ALTER DATABASE OPEN RESETLOGS;
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP;

Remark : If you are unable to recover a datafile with redolog (cause redolog is corrupted) and you accept to loose data from datafile then you can use :
SQL>alter database clear logfile unrecoverable datafile;
Oracle requires that you use the unrecoverable datafile option when the particular redo log group is both unarchived and you cannot get the data from it. It looks like Oracle expects that you had already tried to recover the datafile and could not because of a bad redo log.

Note seen from another site (Don't remember where cause just have a copy past):
Oracle Recovery with _allow_resetlogs_corruption

Recovery of a database using the undocumented parameter _allow_resetlogs_corruption should be regarded as a last-ditch, emergency recovery scenario only, and should not be attempted until all other avenues of recovery have been exhausted.
Note that Oracle will not support a database that has been recovered using this method unless it is subsequently exported and rebuilt.
Essentially, using _allow_resetlogs_corruption forces the opening of the datafiles even if their SCNs do not match up; then, on the next checkpoint, the old SCN values are overwritten. This could leave the database in an unknown state as far as concurrency.
To use this option:
SQL>alter system set "_allow_resetlogs_corruption"=true scope=spfile;
SQL>shutdown immediate;
SQL>startup mount;
SQL>recover database until cancel;
CANCEL
SQL>alter database open resetlogs;
SQL>shutdown immediate;
SQL>startup;

lundi 29 août 2011

Oracle 11g: Recover the loss of a control file

Using RMAN
  • Shutdown the database
  • Statup the database in NOMOUNT
  • Use rman to recover the control file :
    $>rman target /
    rman>startup nomount
    rman>restore controlfile from '+DATA/<oracle_sid>/controlfile/current.xxx.yyyy';
    rman>alter database mount;
    rman>alter database open;
    
You can also restore the control file from an autobackup :
...
RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;
...
Using files from file system
  • Check the alert log file to retrieve the lost controlfile
  • Shutdown the database
  • Copy a multiplexe control file (remember control file must be multiplexed and Oracle recommends having at least three copies of the control file) into the missing one.
  • Startup the database in the NOMOUNT state
  • Execute the following command under SQLplus:
    SQL> RECOVER CONTROLFILE USING BACKUP CONTROLFILE UNTIL CANCEL;
  • Open the database with RESETLOGS option:
    SQL> ALTER DATABASE MOUNT;
    SQL> ALTER DATABASE OPEN RESETLOGS;

Oracle 11g : Data recovery advisor activation


To activate the Data recovery advisor in single instance :
$> rman target /
rman> list failure all;

vendredi 26 août 2011

Oracle 11g: Online user backup

Today I have learned a new thing about backup and recovery on how to keep a database in backup mode.
Even if i know that Oracle strongly recommend the use of RMAN for backup and recovery . I thought, this would be good thing to learn how to make an online backup of the database using the legacy method of backup, i.e. ALTER TABLESPACE | DATABASE BEGIN/END BACKUP.

Database in Archive log
First of all, the database must be in archive log mode.
To do this, shutdown the database and be sure that the database will not be in recovery state (avoid shuting down with abort option).
After shuting down, start the database in mount state (archive log could only be activated in mount state).
SQL>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 1807921152 bytes
Fixed Size                  1337128 bytes
Variable Size            1073744088 bytes
Database Buffers          721420288 bytes
Redo Buffers               11419648 bytes
Database mounted.

Now, the database can be set in archivelog mode.
SQL>alter database archivelog;
Database altered.

SQL>archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /opt/oracle/11.2.0/dbs/arch
Oldest online log sequence     299
Current log sequence           306

SQL>alter database open;
Database altered.

Backup the entire database
Since Oracle 11g all the files could be set in backup at once :
SQL>alter database begin backup;

Then you can check if all file are in backup mode :
select * from v$backup;

     FILE# STATUS                CHANGE# TIME
---------- ------------------ ---------- ---------
         1 ACTIVE                      0
         2 ACTIVE                      0
         3 ACTIVE                      0
         4 ACTIVE                      0
         5 ACTIVE                      0
         6 ACTIVE               33564182 26-AUG-11
         7 ACTIVE                      0

7 rows selected.

Now you can copy all the database files using the system command line.

To remove the database from the backup mode, use:
SQL>alter database end backup;

Backup some parts of the database
Instead of using the alter database begin/end backup, it is possible to set each tablespace in backup mode using the following sql command :
SQL>alter tablespace <tablespace_name> begin backup;

To retrieve all tablespaces and associated datafiles use the DBA_DATA_FILES table.

Here is an example showing the procedure to set the system table space in backup mode :
SQL>alter tablespace system begin backup;
Tablespace altered.
SQL>select * from v$backup;

     FILE# STATUS                CHANGE# TIME
---------- ------------------ ---------- ---------
         1 ACTIVE               33587729 26-AUG-11
         2 NOT ACTIVE                  0
         3 NOT ACTIVE                  0
         4 NOT ACTIVE                  0
         5 NOT ACTIVE                  0
         6 NOT ACTIVE           33564182 26-AUG-11
         7 NOT ACTIVE                  0

7 rows selected.

SQL>alter tablespace system end backup;
Tablespace altered.

Remark : READ ONLY, INVALID & OFFLINE tablespaces could not be set in backup mode. They could be copied directly because they could not be accessed or modified by any users.

Remark : Don't forget to backup the server parameter file, the control files and current redo log files.
To backup the controle file in a specific location and file name :
SQL>alter database backup controlfile to '&repertoire/control.ctl' REUSE ;
Before to copy the redo log, look at which redo log is currently in used :
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME          NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ -------------------
         1          1        306  209715200        512          1 YES INACTIVE              33559556 26/08/2011 12:03:45     33584866 26/08/2011 14:44:25
         2          1        307  209715200        512          1 YES INACTIVE              33584866 26/08/2011 14:44:25     33585365 26/08/2011 14:46:41
         3          1        308  209715200        512          1 YES INACTIVE              33585365 26/08/2011 14:46:41     33585368 26/08/2011 14:46:43
         8          1        305  209715200        512          1 YES INACTIVE              33559526 26/08/2011 12:02:37     33559556 26/08/2011 12:03:45
         5          1        302  209715200        512          1 YES INACTIVE              33302574 22/08/2011 01:18:56     33428871 24/08/2011 14:36:26
         6          1        303  209715200        512          1 YES INACTIVE              33428871 24/08/2011 14:36:26     33512626 25/08/2011 17:04:01
         7          1        304  209715200        512          1 YES INACTIVE              33512626 25/08/2011 17:04:01     33559526 26/08/2011 12:02:37
         4          1        309  209715200        512          1 NO  CURRENT               33585368 26/08/2011 14:46:43   2.8147E+14

8 rows selected.
The current redo log is the redo log member #1 of the group #4.
To retrieve the name of the redo log take a look at the v$logfile table or use the following command :
select l.status, l.group#,l.members, f.member from v$log l inner join v$logfile f on( l.group#=f.group#);

Once the current redo log file identified, perform a swith log file using:
SQL>alter system switch logfile;

Then you can copy the redo log file in your backup or recovery area.

jeudi 25 août 2011

Oracle 11g : Dynamic Performance Statistics

Oracle 11g provides 3 levels of performance statistics :
  • System statistics
  • Session statistics
  • Service statistics

For each level, Oracle provide cumulative statistics and Wait event statistics.

Dynamic Statistics Views
System level Session level Service level
Cumulative view V$SYSSTAT V$SESSSTAT V$SERVICE_STAT
Wait event view V$SYSTEM_EVENT V$SESSION_EVENT V$SERVICE_EVENT


For memory, you can also take a look at :
Memory views
V$SGAINFO
V$SGASTAT
V$PGASTAT
V$BUFFER_POOL_CACHE
V$LIBRARYCACHE

For contention, you can look at :
Contention views
V$LOCK
V$UNDOSTAT
V$WAITSTAT
V$LATCH

Oracle 11g : AMM & ASMM

AMM - Automatic Memory Management
AMM allows the dba to define precisely the global use of memory for the entire database.
This memory allocation is divided between the SGA component and all PGA components. This memory distribution is done automatically by the database memory size advisor.
There is 2 parameters to set in order to activate the Automatic Memory Management :
  • MEMORY_TARGET : Minumum memory we wish to allow for SGA and all PGAs
  • MEMORY_MAX_TARGET : Maximum memory that MEMORY_TARGET should not exceed
you enable the automatic memory management by setting only a target memory size initialization parameter (MEMORY_TARGET) and optionally a maximum memory size initialization parameter (MEMORY_MAX_TARGET).

When using automatic memory management, the SGA_TARGET and PGA_AGGREGATE_TARGET act as minimum size settings for their respective memory areas. To allow Oracle to take full control of the memory management, these parameters should be set to zero.

The activation of the AMM implies the activation of ASMM and the activation of the PGA memory advisor.

Remark :
  • If MEMORY_TARGET is set and MEMORY_MAX_TARGET is omitted then MEMORY_MAX_TARGET is set automatically with the value of MEMORY_TARGET.
  • If MEMORY_MAX_TARGET is set and MEMORY_TARGET omitted then MEMORY_TARGET is set to 0. MEMORY_TARGET could be updated dynamicaly using ALTER SYSTEM. After startup, you can then dynamically change MEMORY_TARGET to a nonzero value, provided that it does not exceed the value of MEMORY_MAX_TARGET.
  • We assume commonly that MEMORY_TARGET = SGA_TARGET + PGA_AGGREGATE_TARGET.

Remark : Any modification on these parameters implies the reboot of the entire database. MEMORY_MAX_TARGET is not a dynamic initialization parameter.

ASMM - Automatic Shared Memory Management
ASMM allows the dba to define the memory used by the SGA only.

There is 2 parameters to set in order to activate the Automatic Shared Memory Management :
  • SGA_TARGET : Minumum memory we wish to allow for SGA (not the PGAs)
  • SGA_MAX_SIZE : Maximum memory that SGA_TARGET should not exceed
You enable the automatic shared memory management feature by setting the SGA_TARGET parameter to a nonzero value.
Note:
The STATISTICS_LEVEL initialization parameter must be set to TYPICAL (the default) or ALL for automatic shared memory management to function.

Remark :
  • If SGA_TARGET is set then SGA_MAX_SIZE is set automatically with the value of SGA_TARGET.
  • If SGA_MAX_SIZE is defined then SGA_TARGET is setted by default to 0.
  • SGA_MAX_SIZE is a static parameter. You need to reboot the instance if updated.

Remark :
  • If ASMM is activated then the SGA memory size advisor is activated.
  • If ASMM is activated for the first time then it is not allowed to set a value for the following database parameters in the initialization parameters file:
    • SHARED_POOL_SIZE
    • DB_CACHE_SIZE
    • LARGE_POOL_SIZE
    • JAVA_POOL_SIZE
    • STREAM_POOL_SIZE
  • Setting a value for one component of the SGA when ASMM is activated implies that we want to overload the behaviour the advisor. If the value is less than the value calculated by ASMM then the value is defined as a minimal requirement. If the value is more then the value defined by ASMM then the size of the component is increased to fit the dba requirement. The previous parameter could be altered using ALTER SYSTEM (except for the LOG_BUFFER parameter that is static after instance startup).

mardi 23 août 2011

Oracle 11g : Alert's type and associated tables


There is 2 kind of alerts in database :
  • Stateful alerts : Alerts based on threshold (Physical reads Per sec, User commits Per sec)
  • Stateless alerts : Alerts that does not depends on any kind of threshold (Snapshot too old, Recovery are low free space)

Stateless alerts
Stateless alerts are logged in the DBA_ALERT_HISTORY table.

Stateful alerts
Stateful alerts are logged in the DBA_OUTSTANDING_ALERTS table.
When the situation is resolved, the alert is cleared from this table and moved automatically to the DBA_ALERT_HISTORY.

Action on alerts
An alert could be cleared from the history. Its status changes to cleared and is keeped in the table.
An alert could be purged from the alert log history. In this way, the alert is removed from the repository and discared.


Oracle 11g: Automatic Workload Repository

General points
  • The MMON (Managability Monitor) database process generates a snapshot of the database every 60 minutes.
  • Snapshots are logged over a period of 8 days. (Retention policy by default, could be changed using the enterprise Manager console or through DBMS_WORKLOAD_REPOSITORY package)
  • The AWR repository is the property of the SYSMAN user and stored in the SYSAUX tablespace.

Baseline AWR
A baseline AWR is a set of snapshots between two snapshot id or two dates.
A baseline is identified using a unique name.
A baseline is keep in database until the baseline is deleted.

To create a baseline use :
Function
DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(
    START_SNAP_ID   IN NUMBER,
    END_SNAP_ID     IN NUMBER,
    BASELINE_NAME   IN VARCHAR2, 
    DBID            IN NUMBER DEFAULT,
    EXPIRATION      IN NUMBER DEFAULT
) RETURNS NUMBER;
or
Procedure
DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(
    START_TIME      IN DATE,
    END_TIME        IN DATE,
    BASELINE_NAME   IN VARCHAR2,
    DBID            IN NUMBER DEFAULT,
    EXPIRATION      IN NUMBER DEFAULT
);

To drop a baseline use :
Procedure
DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE(
    BASELINE_NAME   IN VARCHAR2,
    CASCADE         IN BOOLEAN  DEFAULT,
    DBID            IN NUMBER   DEFAULT
);

Baseline information can be queried from the DBA_HIST_BASELINE view.

How to generate an extra snapshot
Write the following sql command :
SQL>exec dbms_workload_repository.create_snapshot('ALL');

How to list all snapshot registered in the AWR repository?
Select the DBA_HIST_SNAPSHOT to retrive the snapshot id from all snapshot registered in the AWR repository.
This table contains the following information :
SQL>desc DBA_HIST_SNAPSHOT;

SNAP_ID             NOT NULL NUMBER
DBID                NOT NULL NUMBER
INSTANCE_NUMBER     NOT NULL NUMBER
STARTUP_TIME        NOT NULL TIMESTAMP(3)
BEGIN_INTERVAL_TIME NOT NULL TIMESTAMP(3)
END_INTERVAL_TIME   NOT NULL TIMESTAMP(3)
FLUSH_ELAPSED       INTERVAL DAY(5) TO SECOND(1)
SNAP_LEVEL          NUMBER
ERROR_COUNT         NUMBER
SNAP_FLAG           NUMBER

Statistics level
Adjust the STATISTICS_LEVEL database parameter :
  • ALL : Generaly not used
  • TYPICAL : Use default preferences, gives more advise of the database
  • BASIC : Statistics collections not active
This parameter is dynamic.

Changing the snapshot frequency and retention policy
By default snapshots of the relevant data are taken every hour and retained for 8 days.
The default values for these settings can be altered using the following procedure.
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;
    /
An interval of "0" switches off snapshot collection, which in turn stops much of the self-tuning functionality, hence this is not recommended. Automatic collection is only possible if the STATISTICS_LEVEL parameter is set to TYPICAL or ALL. If the value is set to BASIC manual snapshots can be taken, but they will be missing some statistics.

To retirve the retention delay and snapshot interval :
SQL> select * from dba_hist_wr_control;

      DBID SNAP_INTERVAL        RETENTION            TOPNSQL
---------- -------------------- -------------------- ----------
2058702964 +00000 01:00:00.0    +00008 00:00:00.0    DEFAULT

Workload Repository Views
The following workload repository views are available:
V$ACTIVE_SESSION_HISTORY     - Displays the active session history (ASH) sampled every second.
    V$METRIC                     - Displays metric information.
    V$METRICNAME                 - Displays the metrics associated with each metric group.
    V$METRIC_HISTORY             - Displays historical metrics.
    V$METRICGROUP                - Displays all metrics groups.
    DBA_HIST_ACTIVE_SESS_HISTORY - Displays the history contents of the active session history.
    DBA_HIST_BASELINE            - Displays baseline information.
    DBA_HIST_DATABASE_INSTANCE   - Displays database environment information.
    DBA_HIST_SNAPSHOT            - Displays snapshot information.
    DBA_HIST_SQL_PLAN            - Displays SQL execution plans.
    DBA_HIST_WR_CONTROL          - Displays AWR settings.

Workload Repository Reports

Oracle provides two scripts to produce workload repository reports (awrrpt.sql and awrrpti.sql). They are similar in format to the statspack reports and give the option of HTML or plain text formats.
The two reports give essential the same output but the awrrpti.sql allows you to select a single instance. The reports can be generated as follows.
@$ORACLE_HOME/rdbms/admin/awrrpt.sql
or for a specific database instance
@$ORACLE_HOME/rdbms/admin/awrrpti.sql


to compare two periods of snapshot :
@$ORACLE_HOME/rdbms/admin/awrddrpt.sql
or for a specific database instance
@$ORACLE_HOME/rdbms/admin/awrddrpi.sql

More references
See more @ http://download.oracle.com/docs/cd/B28359_01/server.111/b28274/autostat.htm

Oracle11g: Oracle optimizer and Statistics collections

Statistics collections activation
The STATISTICS_LEVEL is the initial database parameter used to enable/disable advisories statistics collections.
There here 3 levels for the STATISTICS_LEVEL parameter :
  • BASIC : Desactivates all the advisory statistics collections
  • TYPICAL : Activates some advisory statistics collections
  • ALL : All advisory are activated

SQL>alter system set statistics_level=basic;
System altered.
SQL>SELECT statistics_name,
         session_status,
         system_status,
         activation_level,
         session_settable
  FROM   v$statistics_level
order by statistics_name;


STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
Active Session History         DISABLED        DISABLED        TYPICAL          NO
Adaptive Thresholds Enabled    DISABLED        DISABLED        TYPICAL          NO
Automated Maintenance Tasks    DISABLED        DISABLED        TYPICAL          NO
Bind Data Capture              DISABLED        DISABLED        TYPICAL          NO
Buffer Cache Advice            DISABLED        DISABLED        TYPICAL          NO
Global Cache Statistics        DISABLED        DISABLED        TYPICAL          NO
Longops Statistics             DISABLED        DISABLED        TYPICAL          NO
MTTR Advice                    DISABLED        DISABLED        TYPICAL          NO
Modification Monitoring        DISABLED        DISABLED        TYPICAL          NO
PGA Advice                     DISABLED        DISABLED        TYPICAL          NO
Plan Execution Sampling        DISABLED        DISABLED        TYPICAL          YES

STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
Plan Execution Statistics      DISABLED        DISABLED        ALL              YES
SQL Monitoring                 DISABLED        DISABLED        TYPICAL          YES
Segment Level Statistics       DISABLED        DISABLED        TYPICAL          NO
Shared Pool Advice             DISABLED        DISABLED        TYPICAL          NO
Streams Pool Advice            DISABLED        DISABLED        TYPICAL          NO
Threshold-based Alerts         DISABLED        DISABLED        TYPICAL          NO
Time Model Events              DISABLED        DISABLED        TYPICAL          YES
Timed OS Statistics            DISABLED        DISABLED        ALL              YES
Timed Statistics               ENABLED         ENABLED         TYPICAL          YES
Ultrafast Latch Statistics     DISABLED        DISABLED        TYPICAL          NO
Undo Advisor, Alerts and Fast  DISABLED        DISABLED        TYPICAL          NO

STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
V$IOSTAT_* statistics          DISABLED        DISABLED        TYPICAL          NO

23 rows selected.



SQL>alter system set statistics_level=typical;
System altered.
SQL>SELECT statistics_name,
         session_status,
         system_status,
         activation_level,
         session_settable
  FROM   v$statistics_level
order by statistics_name;

STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
Active Session History         DISABLED        DISABLED        TYPICAL          NO
Adaptive Thresholds Enabled    DISABLED        DISABLED        TYPICAL          NO
Automated Maintenance Tasks    DISABLED        DISABLED        TYPICAL          NO
Bind Data Capture              DISABLED        DISABLED        TYPICAL          NO
Buffer Cache Advice            DISABLED        DISABLED        TYPICAL          NO
Global Cache Statistics        DISABLED        DISABLED        TYPICAL          NO
Longops Statistics             DISABLED        DISABLED        TYPICAL          NO
MTTR Advice                    DISABLED        DISABLED        TYPICAL          NO
Modification Monitoring        DISABLED        DISABLED        TYPICAL          NO
PGA Advice                     DISABLED        DISABLED        TYPICAL          NO
Plan Execution Sampling        ENABLED         DISABLED        TYPICAL          YES

STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
Plan Execution Statistics      DISABLED        DISABLED        ALL              YES
SQL Monitoring                 ENABLED         DISABLED        TYPICAL          YES
Segment Level Statistics       DISABLED        DISABLED        TYPICAL          NO
Shared Pool Advice             DISABLED        DISABLED        TYPICAL          NO
Streams Pool Advice            DISABLED        DISABLED        TYPICAL          NO
Threshold-based Alerts         DISABLED        DISABLED        TYPICAL          NO
Time Model Events              ENABLED         DISABLED        TYPICAL          YES
Timed OS Statistics            DISABLED        DISABLED        ALL              YES
Timed Statistics               ENABLED         ENABLED         TYPICAL          YES
Ultrafast Latch Statistics     DISABLED        DISABLED        TYPICAL          NO
Undo Advisor, Alerts and Fast  DISABLED        DISABLED        TYPICAL          NO

STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
V$IOSTAT_* statistics          DISABLED        DISABLED        TYPICAL          NO

23 rows selected.



SQL>alter system set statistics_level=all;
System altered.
SQL>SELECT statistics_name,
         session_status,
         system_status,
         activation_level,
         session_settable
  FROM   v$statistics_level
order by statistics_name;

STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
Active Session History         DISABLED        DISABLED        TYPICAL          NO
Adaptive Thresholds Enabled    DISABLED        DISABLED        TYPICAL          NO
Automated Maintenance Tasks    DISABLED        DISABLED        TYPICAL          NO
Bind Data Capture              DISABLED        DISABLED        TYPICAL          NO
Buffer Cache Advice            DISABLED        DISABLED        TYPICAL          NO
Global Cache Statistics        DISABLED        DISABLED        TYPICAL          NO
Longops Statistics             DISABLED        DISABLED        TYPICAL          NO
MTTR Advice                    DISABLED        DISABLED        TYPICAL          NO
Modification Monitoring        DISABLED        DISABLED        TYPICAL          NO
PGA Advice                     DISABLED        DISABLED        TYPICAL          NO
Plan Execution Sampling        ENABLED         DISABLED        TYPICAL          YES

STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
Plan Execution Statistics      ENABLED         DISABLED        ALL              YES
SQL Monitoring                 ENABLED         DISABLED        TYPICAL          YES
Segment Level Statistics       DISABLED        DISABLED        TYPICAL          NO
Shared Pool Advice             DISABLED        DISABLED        TYPICAL          NO
Streams Pool Advice            DISABLED        DISABLED        TYPICAL          NO
Threshold-based Alerts         DISABLED        DISABLED        TYPICAL          NO
Time Model Events              ENABLED         DISABLED        TYPICAL          YES
Timed OS Statistics            ENABLED         DISABLED        ALL              YES
Timed Statistics               ENABLED         ENABLED         TYPICAL          YES
Ultrafast Latch Statistics     DISABLED        DISABLED        TYPICAL          NO
Undo Advisor, Alerts and Fast  DISABLED        DISABLED        TYPICAL          NO

STATISTICS_NAME                SESSION_STATUS  SYSTEM_STATUS   ACTIVATION_LEVEL SESSION_SETTABLE
------------------------------ --------------- --------------- ---------------- ----------------
V$IOSTAT_* statistics          DISABLED        DISABLED        TYPICAL          NO

23 rows selected.

The gathering of statistics is performed each day and stored in a repository for 30 days.

Gathering statistics
Use the DBMS_STATS to retrieve statistics for the entire database, a schema or a specific table (DBMS_STATS.GATHER_*_STATS()).
For the database : DBMS_STATS.GATHER_DATABASE_STATS()
For schema : DBMS_STATS.GATHER_SCHEMA_STATS()
For a table : DBMS_STATS.GATHER_TABLE_STATS()

Use DBMS_STATS.GATHER_*_STATS() when 10% of the database, schema or table changes during the last 24 hours.

Removing statistics from the repository
Use the DBMS_STATS.DELETE_*_STATS() procedures.

Statistics preferences
The DBA can assign default or prefered parameters values for users that invoke the DBMS_STATS package.
The DBMS_STATS.SET_*_PREFS() procedures of the package allows the DBA to set preferences for the following parameters :
CASCADE
DEGREE
ESTIMATE_PERCENT
NO_INVALIDATE
METHOD_OPT
GRANULARITY
INCREMENTAL
PUBLISH
STALE_PERCENT

Preferences can be deleted using DBMS_STATS.DELETE_*_PREFS()
It is all possible to reset values to the initial setup using DBMS_STATS.RESET_PARAM_PREFS()

Remark : If preferences have been setted at a table level, setting preferences at the schema or database level overwritting preferences setted previously at the table level.

View statistics parameters preferences
Object prefrences can be retrieve from the DBA_TAB_STAT_PREFS table.
For preferences setted are a global level, use the DBMS_STATS.GET_PREFS() function of the DBMS_STATS package.

vendredi 19 août 2011

Oracle11g: Auditing features

For database created manually
Manually created database doesn't have the auditing feature activated by default.
The value of the initial parameter AUDIT_TRAIL is defined to NONE.

For database created using DBCA
For database created automatically through the DBCA utility, the audit feature is activated using the parameter AUDIT_TRAIL set to DB.
All audit information and activity is traced into a vue DBA_AUDIT_TRAIL.

Mandatory auditing information
Even if the auditing feature is disabled, Oracle traces some specific actions that are mandatory to ensure the database security.
Oracle traces all audit information in a directory that is defined through the AUDIT_FILE_DEST initialization parameter.

The default auditing options for Oracle 11g are seen in the following table:
Default audited priviledge
Alter any procedure
Alter any table
Alter database
Alter profile
Alter system
Alter user
Audit system
Create any library
Create any procedure
Create any table
Create external job
Create public database link
Create session
Create user
Create any job
Drop any table
Drop profile
Drop user
Drop any procedure
Exempt access policy
Grant any object privilege
Grant any privilege
Audit system
Grant any role

Default audited statement
System audit by access
Role by access

Audit levels
There are 5 levels of audit :
  • Mandatory auditing
  • Standard database audit
  • Data audit
  • Fine grained audit
  • SYSDBA & SYSOPER audit

Available values for AUDIT_TRAIL parameter
See here under all values available for the AUDIT_TRAIL parameter that defines how the audit feature will make traces :
  • NONE : Audit is not activated
  • OS : all audit information are redirected to a file where the location is defined through the AUDIT_FILE_DEST initialization parameter.
  • DB : all audit information are write in the DBA_AUDIT_TRAIL table defined under the SYS schema.
  • DB, EXTENDED : When extended is specified the SQL text, bind variables and handled columns are traced in the DBA_AUDIT_TRAIL table.
  • XML : all audit information are writen in xml files where the location is defined through the AUDIT_FILE_DEST initialization parameter. You can check instead the V$XML_AUDIT_TRAIL view to see all the content of all xml files managed by the audit trail feature.
  • XML, EXTENDED : When extended is specified the SQL text, bind variables and handled columns are added to the audit information.

Remark : The AUDIT_TRAIL parameter is a static database initialization parameter. The database need to be shutdowned and restarted after any modification of this parameter.

Audit trail views
See here under some important views :
DBA_AUDIT_TRAIL : view used when AUDIT_TRAIL set to DB or DB,EXTENDED
DBA_FGA_AUDIT_TRAIL : view used when fine grained audit activated

DBA_COMMON_AUDIT_TRAIL : Is the merge of the 2 previous views.

Audit options
There is 3 kinds of audit options:
  • Audit of SQL instructions: Trace all DDL instructions that affect a table (CREATE TABLE, ALTER TABLE, DROP TABLE)
  • Audit of system priviledges: Audit all system priviledge used by all users or by a specific user
  • Audit of object priviledges: Audit all object priviledges used by all users or a specific user

Audit trace could be generated when used (BY ACCESS) or could be grouped and generated at the session level (BY SESSION).

How to see audit information
Check the following views :
DBA_AUDIT_TRAIL : view used when AUDIT_TRAIL set to DB or DB,EXTENDED
DBA_FGA_AUDIT_TRAIL : view used when fine grained audit activated
DBA_COMMON_AUDIT_TRAIL : Is the merge of the 2 previous views.
DBA_AUDIT_OBJECT : View used when instruction options used
DBA_AUDIT_POLICIES :
DBA_AUDIT_SESSION :

How to retrieve activated audit options
Check the following views :
DBA_OBJ_AUDIT_OPTS : display object priviledge audited
DBA_PRIV_AUDIT_OPTS : display system priviledge audited
DBA_STMT_AUDIT_OPTS : display statement audited

Data based audit
The standard audit level register the fact that something has been added in a table or something has changed but it does not take care of the value of the columns that has changed. The Data base audit enhance the standard audit by taking into account and register the values of a table that has been modified.

To handle table modification, oracle register triggers to audited tables and use the value of the AUDIT_TRAIL & AUDIT_FILE_DEST initialization parameter to how and where to trace audit information.

when a table <table> is audited, Oracle create a table SYSTEM.AUDIT_<table> to store all audit information in relation the audited table.

Fine grained audit
Fine grained audit brings more flexibility than the detailed audit.
It is possible to specify columns to audit and define also a condition for auditing.
If the result of a specific request matches the audit condition then a trace is generated in the audit trail whatever the number of lines that match the condition.

SELECT, UPDATE,DELETE & MERGE are the statement handled by the FGA audit.

A procedure can be executed if a statement matches the audit condition, audit columns and the type of statement to audit.

New FGA audit feature, can be enabled using the DBMS_FGA package through the use of the DBMS_FGA.ADD_POLICY procedure.
DBMS_FGA.ADD_POLICY(
  object_schema => '...',
  object_name => '...',
  policy_name => '...',
  audit_condition => 'employee_id > 10',
  audit_column => 'EMP_ID, SALARY',
  handler_schema => 'audit_schema',
  handler_module => 'log_audit_proc',
  enable => TRUE,
  statement_types => 'SELECT, INSERT, UPDATE, DELETE'
);

FGA policy could be deleted using DBMS_FGA_DROP_POLICY
FGA policy could be enabled/disabled using DBMS_FGA.ENABLE_POLICY, DBMS_FGA.DISABLE_POLICY

SYSDBA & SYSOPER audit
The audit level is activated using the AUDIT_SYS_OPERATIONS parameter setted to TRUE.
The default value of the parameter is FALSE.

All audit traces a written in files located under the directory defined by the value of the AUDIT_FILE_DEST parameter.

Deleting audit information
For standard auditing, truncate the SYS.AUD$ table.
For fine grained auditing, truncate the SYS.FGA_LOG$ table


Some external References :
- good samples at http://www.oracle-base.com/articles/10g/Auditing_10gR2.php
- Managment of audit trace @see : New Feature DBMS_AUDIT_MGMT To Manage And Purge Audit Information [ID 731908.1] for oracle support

mercredi 10 août 2011

Oracle11g: How to configure a database to register dynamically a service in a listener that not use the default port

First you need to define the listener with a port that is not the default port by registering your listener configuration in the listener.ora file.
# listener.ora Network Configuration File: /opt/oracle/11.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = myhost)(PORT = 1523))
  )

ADR_BASE_LISTENER = /opt/oracle

Run the listener using the following command:
>lsnrctl start
or using the srvctl command:
>srvctl start listener

Then you can update your database parameter in order to define the address of the listener:
Using sql ;
SQL>ALTER SYSTEM SET LOCAL_LISTENER='(ADDRESS=(PROTOCOl=TCP)(HOST=myhost)(PORT=1523))' SCOPE=BOTH;

If you listener is running on a different host then the database, you need to update the REMOTE_LISTER database parameter. This parameter will reference a network alias that must be declared in the tnsnames.ora file of the database.
For example, you can write in your tnsnames.ora file where is located your database :
# tnsnames.ora Network Configuration File: /opt/oracle/11.2.0/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

MY_REMOTE_ALIAS =
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = myhost2)(PORT = 1523))
  )

and update the remote_listener database parameter in this way :
SQL>ALTER SYSTEM SET REMOTE_LISTENER='MY_REMOTE_ALIAS' SCOPE=BOTH;
The database will try to connect on host2 and port number 1523 to register dynamically all its services.

Remark:
Check the following situation :
  1. Define a listener that has a name different than the default one (for example MY_LISTNER  instead of  LISTENER)
    # listener.ora Network Configuration File: /opt/oracle/11.2.0/network/admin/listener.ora
    # Generated by Oracle configuration tools.
    
    MY_LISTENER =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = myhost)(PORT = 1523))
      )
    
    ADR_BASE_LISTENER = /opt/oracle
  2. start the listener
    >lsnrctl start MY_LISTENER
    or
    >srvctl start listener -l MY_LISTNER
  3. Set the LOCAL_LISTENER parameter to its initial value (an empty string)
    SQL> ALTER SYSTEM SET LOCAL_LISTENER='' SCOPE=BOTH;
    SQL> show parameter local_listener
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    local_listener                       string
    
  4. Start the default listener
    >lsnrctl start

Then, you will see that the database register its configuration under the listener MY_LISTENER listening on port 1523 but also in the default listener LISTENER listening on port 1521. This is due to the fact that we do not update the LOCAL_LISTNER value !

Oracle11g: Dealing with dynamic service registration

Oracle11g provides a dynamic service registration.
Unlike static service registration, dynamic registration need less information in listerner.ora file and more configuration in database parameter.

listener.ora configuration
The listener.ora file will contain only the adress of the listener :
# listener.ora Network Configuration File: /opt/oracle/11.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = myhost.gemalto.com)(PORT = 1521))
  )

ADR_BASE_LISTENER = /opt/oracle

Database configuration
The SERVICE_NAMES database parameter contains a string that list all services that the database will register automaticatlly in the default listener.
This parameter goes along with the DB_DOMAIN parameter.

For example, if you define this parameters like here under :
  • SERVICE_NAMES = 'MY_BASE'
  • DB_DOMAIN = 'gemalto.com'
then the database will register the service 'MY_BASE.gemalto.com' in the default listener.

if DB_DOMAIN is defined using an empty string then the service will be 'MY_BASE'.

To define more then one services in the listener then you can write the following
  • SERVICE_NAMES='DB1, DB2,DB3'
  • DB_DOMAIN = 'gemalto.com'
in this way, three services will be registered dynamically in the listener : DB1.gemalto.com, DB2.gemalto.com and DB3.gemalto.com

To set the parameters you can use the following SQL syntax:
SQL>ALTER SYSTEM SET SERVICE_NAMES='MY_BASE,MY_PROD' scope=BOTH;

scope=BOTH indicates that the memory of the database will be altered and the spfile will be updated in the same time.

The DB_DOMAIN name is a static parameter and could not be modified dynamically.
You can try the following syntax
SQL>ALTER SYSTEM SET SERVICE_NAMES='MY_BASE,MY_PROD' scope=SPFILE DEFERRED
or modify your init<SID>.ora initialization file.
To be taken into account, restart your database.

Checking the listener
>lsnrctl status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost.gemalto.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                10-AUG-2011 17:32:49
Uptime                    0 days 0 hr. 36 min. 10 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/11.2.0/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/myhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=myhost.gemalto.com)(PORT=1521)))
Services Summary...
Service "MY_BASE" has 1 instance(s).
  Instance "INSTANCE", status READY, has 1 handler(s) for this service...
Service "MY_PROD" has 1 instance(s).
  Instance "INSTANCE", status READY, has 1 handler(s) for this service...
The command completed successfully

mardi 9 août 2011

Oracle11g : ASM mandatory parameters

An ASM instance can be configured through 74 parameters.
Only 8 parameters are required :
INSTANCE_TYPE = ASM
ASM_POWER_LIMIT = 1
ASM_DISKSTRING = '/dev/sda1','/dev/sda2','/dev/sdb*'
ASM_DISKGROUPS = DATA,FRA
ASM_PREFERRED_READ_FAILURE_GROUPS = DATA.FailGroup1
DIAGNOSTIC_DEST = /u01/app/oracle
LARGE_POOL_SIZE = 12M
REMOTE_LOGIN_PASSWORDFILE = EXCLUSIVE

The INSTANCE_TYPE is the only mandatory parameter !

ASM_POWER_LIMIT is used to define the rebalancing speed. Value is in range [0,11]
ASM_DISKSTRING is used for disk automatic discovery
ASM_DISKGROUPS defines all groups that will be monted automatically at startup
ASM_PREFERRED_READ_FAILURE_GROUPS defined the disk failure group that will be used in a cluster environment
DIAGNOSTIC_DEST defines the location of the ADR repository (Automatic Diagnostic Repository)
REMOTE_LOGIN_PASSWORDFILE check the availability of a password file. Default value is EXCLUSIVE.

Ant: Deploy an application over a Weblogic instance or cluster

Some ant stuff to help deployment of an application over a veblogic cluster or instance :
<project name="deployment tool">
    <!-- ********************************************************************************** -->
    <!-- Imports the properties files used for correct deployment                           -->
    <!-- ********************************************************************************** -->
    <property file="deploy.properties" />

    <!-- ********************************************************************************** -->
    <!-- Taks definitions                                                                   -->
    <!-- ********************************************************************************** -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${ant.lib.dir}/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>

    <taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
        <classpath>
            <pathelement path="${commonlibs.dir}/Storage/wlfullclient.jar" />
        </classpath>
    </taskdef>


    <!-- ********************************************************************************** -->
    <!-- deploying/undeploying module in application server                                 -->
    <!-- ********************************************************************************** -->
    <macrodef name="deploy-module">
       <attribute name="file" default="NOT_SET"/>
       <attribute name="wl.name" default="NOT_SET"/>
       <attribute name="wl.username" default="weblogic"/>
       <attribute name="wl.password" default="testpwd"/>
       <attribute name="wl.adminurl" default="t3://localhost:7001"/>
       <attribute name="wl.targets" default="NOT_SET"/>
       <sequential>
           <!-- Check that the admin server is running before deployment -->
           <property name="weblogic.console" value="http://${server-host}:${server-adminPort}/console"/>
           <waitfor maxwait="2" maxwaitunit="minute" checkevery="100" checkeveryunit="millisecond">
               <http url="${weblogic.console}" />
           </waitfor>
           <if>
               <not>
                   <http url="${weblogic.console}" />
               </not>
               <then>
                   <fail message="Admin Server on http://${server-host}:${server-adminPort} is not in running state. Unable to deploy ${final.ear.name}"/>
               </then>
               <else>
                   <echo message="_____Admin Server on http://${server-host}:${server-adminPort} is running. Starting deployment of ${final.ear.name}"/>
               </else>
           </if>
           <!-- starting the deployment -->
           <echo>_____Deploying file @{file} to @{wl.adminurl} on targets @{wl.targets} </echo>
           <if>
               <equals arg1="${server-host}" arg2="localhost"/>
               <then>
                   <property name="wl.upload" value="false"/>
               </then>
               <else>
                   <property name="wl.upload" value="true"/>
                   <echo>_____Uploading file @{file} to @{wl.adminurl} </echo>
               </else>
           </if>
           <if>
               <equals  arg1="@{wl.targets}" arg2="NOT_SET"/>
               <then>
                   <wldeploy action="deploy" source="@{file}" name="@{wl.name}" user="@{wl.username}" password="@{wl.password}" adminurl="@{wl.adminurl}" verbose="true" debug="true" upload="${wl.upload}"/>
               </then>
               <else>
                   <wldeploy action="deploy" source="@{file}" name="@{wl.name}" user="@{wl.username}" password="@{wl.password}" adminurl="@{wl.adminurl}" targets="@{wl.targets}" verbose="true" debug="true" upload="${wl.upload}"/>
               </else>
           </if>
       </sequential>
    </macrodef>

    <macrodef name="undeploy-module">
       <attribute name="wl.name" default="NOT_SET"/>
       <attribute name="wl.username" default="weblogic"/>
       <attribute name="wl.password" default="testpwd"/>
       <attribute name="wl.adminurl" default="t3://localhost:7001"/>
       <attribute name="wl.targets" default="NOT_SET"/>
       <sequential>
           <echo>_____Undeploying module @{wl.name} to @{wl.adminurl} from targets @{wl.targets} </echo>
           <if>
               <equals  arg1="@{wl.targets}" arg2="NOT_SET"/>
               <then>
                   <wldeploy action="undeploy" name="@{wl.name}" user="@{wl.username}" password="@{wl.password}" adminurl="@{wl.adminurl}" verbose="true" debug="true" failonerror="false"/>
               </then>
               <else>
                   <wldeploy action="undeploy" name="@{wl.name}" user="@{wl.username}" password="@{wl.password}" adminurl="@{wl.adminurl}" targets="@{wl.targets}" verbose="true" debug="true" failonerror="false"/>
               </else>
           </if>
       </sequential>
    </macrodef>

    <!-- ********************************************************************************** -->
    <!-- deploying/undeploying ear in application server                                    -->
    <!-- ********************************************************************************** -->
    <target name="deploy-ear">
        <!-- deploy now the module -->
        <deploy-module file="${final.module.name}"
                       wl.name="${project.name}"
                       wl.username="${serverWL-adminuser}"
                       wl.password="${serverWL-adminpasswd}"
                       wl.adminurl="t3://${server-host}:${server-adminPort}"
                       wl.targets="${cluster-name}"
                />
    </target>

    <target name="undeploy-ear">
        <undeploy-module wl.name="${project.name}"
                         wl.username="${serverWL-adminuser}"
                         wl.password="${serverWL-adminpasswd}"
                         wl.adminurl="t3://${server-host}:${server-adminPort}"
                         wl.targets="${cluster-name}"
                />
    </target>

</project>

and use a property file like this:
ant.lib.dir=D:/tools/apache-ant/lib

# Weblogic home dir and domain location
# Variable only used to start and stop the server when localhost is used
# in server location
weblogic.home.dir=D:/weblogic.10.3.4
weblogic.domain.dir=D:/weblogic.10.3.4/user_projects/domains/YuuWaa

# The command to run for starting and stoping web logic
start-admin-server=startWebLogic.cmd
stop-admin-server=stopWebLogic.cmd
start-managed-server=startManagedWebLogic.cmd
stop-managed-server=stopManagedWebLogic.cmd

# Cluste name where to deploy
cluster-name=

# host and port of the listening admin console
server-host=localhost
server-adminPort=7001

# User/Password used when connecting to the admin console of WLS
serverWL-adminuser=weblogic
serverWL-adminpasswd=testpwd

final.module.name=testEjb.ear

Ant : Starting/Stoping a weblogic instance or cluster

Here some ant script used to start/stop a weblogic instance or cluster
<!-- ********************************************************************************** -->
    <!-- Taks definitions                                                                   -->
    <!-- ********************************************************************************** -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${ant.lib.dir}/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>

    <!-- ********************************************************************************** -->
    <!-- startWeblogic                                                                      --v
    <!-- For remote access using ssh define the properties :                                -->
    <!--       server-user                                                                  -->
    <!--       server-passwd                                                                -->
    <!-- ********************************************************************************** -->
    <target name="start-weblogic" description="Start weblogic">
        <if>
         <equals arg1="${server-host}" arg2="localhost" />
         <then>
             <echo message="__________  Check Weblogic" />
             <if>
                 <available file="${weblogic.home.dir}/wlserver_10.3/server/lib/weblogic.jar"/>
                 <then>
                     <echo message="Weblogic server found" />
                 </then>
                 <else>
                     <fail message="No Weblogic server has been found" />
                 </else>
             </if>

             <echo message="__________ Check if libraries correctly installed" />

             <echo message="__________ Stop Weblogic server if started" />
             <antcall target="stop-weblogic" inheritrefs="true" />

             <echo message="__________ Start Weblogic" />

             <property name="weblogic.console" value="http://${server-host}:${server-adminPort}/console"/>
             <if>
                 <not>
                     <http url="${weblogic.console}" />
                 </not>
                 <then>
                     <echo message="Weblogic is not running" />
                     <echo message="Starting Weblogic server..." />
                     <forget>
                         <exec executable="${weblogic.domain.dir}/bin/${start-admin-server}" dir="${weblogic.domain.dir}/bin" />
                     </forget>
                     <waitfor maxwait="2" maxwaitunit="minute" checkevery="100" checkeveryunit="millisecond">
                         <http url="${weblogic.console}" />
                     </waitfor>
                     <echo message="Weblogic started" />
                 </then>
                 <else>
                     <echo message="Weblogic server is already running" />
                 </else>
             </if>
         </then>
         <else>
             <sshexec host="${server-host}" username="${server-user}" password="${server-passwd}" command="${weblogic.domain.dir}/bin/${start-managed-server}" trust="yes" failonerror="no" />
             <sleep seconds="60" />
         </else>
        </if>
	</target>

    <!-- ********************************************************************************** -->
    <!-- stopWeblogic                                                                       -->
    <!-- For remote access using ssh define the properties :                                -->
    <!--       server-user                                                                  -->
    <!--       server-passwd                                                                -->
    <!-- ********************************************************************************** -->
	<target name="stop-weblogic" description="Stop weblogic">
        <if>
           <equals arg1="${server-host}" arg2="localhost" />
           <then>
               <echo message="__________ Stop Weblogic" />
               <property name="weblogic.console" value="http://${server-host}:${server-adminPort}/console"/>

               <if>
                   <http url="${weblogic.console}" />
                   <then>
                       <echo message="Weblogic is running" />
                       <echo message="Stopping Weblogic server..." />
                       <forget>
                           <exec executable="${weblogic.domain.dir}/bin/${stop-admin-server}" dir="${weblogic.domain.dir}/bin" />
                       </forget>
                       <waitfor maxwait="2" maxwaitunit="minute" checkevery="100" checkeveryunit="millisecond">
                           <not>
                               <http url="${weblogic.console}" />
                           </not>
                       </waitfor>
                       <echo message="Weblogic stopped" />
                   </then>
                   <else>
                       <echo message="Weblogic server is already stopped" />
                   </else>
               </if>
           </then>
           <else>
		       <sshexec host="${server-host}" username="${server-user}" password="${server-passwd}" command="${weblogic.domain.dir}/bin/${stop-managed-server}" trust="yes" failonerror="no" />
		       <sleep seconds="20" />
           </else>
        </if>
	</target>


Define also some properties :
# Weblogic home dir and domain location
# Variable only used to start and stop the server when localhost is used
# in server location
weblogic.home.dir=D:/weblogic.10.3.4
weblogic.domain.dir=D:/weblogic.10.3.4/user_projects/domains/YuuWaa

# The command to run for starting and stoping web logic
start-admin-server=startWebLogic.cmd
stop-admin-server=stopWebLogic.cmd
start-managed-server=startManagedWebLogic.cmd
stop-managed-server=stopManagedWebLogic.cmd

# Cluste name where to deploy
cluster-name=

# host and port of the listening admin console
server-host=localhost
server-adminPort=7001

# User/Password used when connecting to the admin console of WLS
serverWL-adminuser=weblogic
serverWL-adminpasswd=testpwd

Oracle11g : How to obtain the name of all views defined in the database

To retrieve the name of all views in database, use the following command under SqlPlus :
SQL>select * from V$FIXED_TABLE;

Oracle11g : How to manage an instance using srvctl

Under Oracle11g you can use the srvctl executable to manage all components of your database:

To start a specific database
>srvctl start database -d your_db_sid -o open

To stop the database
>srvctl stop database -d your_db_sid -o immediate

To obtain the status of a database
>srvctl status database -d your_db_sid


To start a listener
>srvctl start listener -l your_listener_name

To stop a listener
>srvctl stop listener -l your_listener_name

To obtain the status of a listener
>srvctl status listener -l your_listener_name


To start an asm instance
>srvctl start asm -n node_name -i asm_instance_name -o oracle_home

where :
-n node_name Node name.
-i asm_instance_name The ASM instance name.
-o oracle_home Oracle home for the database.

for example :
>srvctl start asm -i asm1 -o /opt/oracle/11.2.0


To stop an asm instance
>srvctl stop asm -i asm_instance_name

To obtain the status of an asm instance
>srvctl status asm -i asm_instance_name

Oracle11g: find trace files localisation

To display the localisation of all trace files under Oracle11g, use the following command under sqlplus
SQL> select * from v$diag_info;

The result will be something like this:
INST_ID NAME                      VALUE
---------- ------------------------- --------------------------------------------------
1 Diag Enabled              TRUE
1 ADR Base                  /database/DB/sgbd/DB/bdump
1 ADR Home                  /database/DB/sgbd/DB/bdump/diag/rdbms/db/
DB
1 Diag Trace                /database/DB/sgbd/DB/bdump/diag/rdbms/db/
DB/trace
1 Diag Alert                /database/DB/sgbd/DB/bdump/diag/rdbms/db/
DB/alert
1 Diag Incident             /database/DB/sgbd/DB/bdump/diag/rdbms/db/
DB/incident
1 Diag Cdump                /database/DB/sgbd/DB/cdump
1 Health Monitor            /database/DB/sgbd/DB/bdump/diag/rdbms/db/
DB/hm

1 Default Trace File        /database/DB/sgbd/DB/bdump/diag/rdbms/db/
DB/trace/DB_ora_7534.trc
1 Active Problem Count      0
1 Active Incident Count     0

How to define trace location for an Oracle instance

The root directory of the ADR referential is defined with the value of the DIAGNOSTIC_DEST initialization parameter.

If the parameter DIAGNOSTIC_DEST is not defined :
If the DIAGNOSTIC_DEST initialization parameter is not set and if the ORACLE_BASE is defined then the DIAGNOSTIC_DEST takes the value of the ORACLE_BASE variable. In this way, trace files are located under the directory :
$ORACLE_BASE/diag/rdbms/<database_id>/<instance_id>/trace

If ORACLE_BASE is not defined and ORACLE_HOME is defined then the DIAGNOSTIC_DEST takes the value of ORACLE_HOME/log. In this way trace files are located under :
$ORACLE_HOME/log/diag/rdbms/<database_id>/<instance_id>/trace

If DIAGNOSTIC_DEST is defined :
Trace files are located using the DIAGNOSTIC_DEST database parameter.
Oracle use this parameter in order to define the full directory path of all trace files like this :
DIAGNOSTIC_DEST/diag/<instance_type>/<database_id>/<instance_id>/
For example, if the instance name is ORCL and the value of the DIAGNOSTIC_DEST parameter is /opt/oracle then the path will be /opt/oracle/diag/rdbms/orcl/ORCL.
The trace directory will be /opt/oracle/diag/rdbms/orcl/ORCL/trace.

Alert log location
Alert log in text format is defined under the trace directory of the ADR referential :
DIAGNOSTIC_DEST/diag/<instance_type>/<database_id>/<instance_id>/trace

Alert log in xml format is defined under the alert directory of the ADR referential :
DIAGNOSTIC_DEST/diag/<instance_type>/<database_id>/<instance_id>/alert
The alert log file is commonly named log.xml.

Oracle : adrci - How to display alerts...

To display trace and alerts from a 11g database use the adrci tools in $ORACLE_HOME/bin
>adrci
and after ask the alert log
adrci> show alert -tail -f
and other way to display alerts under adrci could be
>adrci exec="show alert -tail -f"
To display alerts generated by the listener you can use also the adrci tool:
>adrci
adrci>set homepath diag/tnslsnr
adrci>show alert -tail 200 -f

To display incident of the orcl database
$>adrci
adrci> set homepath diag/rdbms/orcl/orcl
adrci> show incident

note: To display adrci policy :
adrci> show control

note :To package an incident see use of ips command with adrci tool.

note : To visualize the report of health monitor task use
adrci>show hm_run
----------------------------------------------------------                                                                                                    RUN_ID                       11081
RUN_NAME                     HM_RUN_11081
CHECK_NAME                   Cross Check
NAME_ID                      2
MODE                         2
START_TIME                   2007-04-13 03:20:31.161396 -07:00
RESUME_TIME
END_TIME                     2007-04-13 03:20:37.903984 -07:00
MODIFIED_TIME                2007-04-17 01:16:37.106344 -07:00
TIMEOUT                      0
FLAGS                        0
STATUS                       5
SRC_INCIDENT_ID              0
NUM_INCIDENTS                0
ERR_NUMBER                   0
REPORT_FILE

adrci> create report hm_run HM_RUN_11081
adrci> show report hm_run HM_RUN_11081

mercredi 9 décembre 2009

Memo : Weblogic JDBC Persistent Store

Script to use for table creation of a JDBC persistent store :

CREATE TABLE TABLE_NAME (
id int not null primary key,
type int not null,
handle int not null,
record blob not null
);

The table name is computed with the prefix name defined at persistent store configuration with the appended string WLSTORE. So for exemple if prefix name is MYAPPLI, the table name will be MYAPPLIWLSTORE.

The command line to create the table could be :

java utils.Schema url JDBC_driver [options] DDL_file


options could be :
  • -u for database connection username
  • -p for the user password
  • -s for the database SID


You will find hereunder is an example of the installation command line :

java utils.Schema jdbc:weblogic:oracle:DEMO weblogic.jdbc.oci.Driver -u user1 -p password1 -verbose createTab.ddl

Command line to use the Jconsole to connect on Weblogic 10.3.1

This is the command line that is usefull for the connection of the jconsole on a Weblogic server 10.3.1

%JAVA_HOME%\bin\jconsole -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;%JAVA_HOME%\lib\tools.jar;%BEA_HOME%\server\lib\wljmxclient.jar -J-Djmx.remote.protocole.provider.pkgs=weblogic.management.remote -J-Dcom.sun.management.jmxremote

where JAVA_HOME references the jdk and BEA_HOME the installation directory of the weblogic server