Custom Search . . .

Sunday, April 22, 2007

DBMS_SCHEDULER

In Oracle 10g the DBMS_JOB package is replaced by the DBMS_SCHEDULER package. The DBMS_JOB package is now depricated and in Oracle 10g it's only provided for backward compatibility. From Oracle 10g the DBMS_JOB package should not be used any more, because is could not exist in a future version of Oracle.

With DBMS_SCHEDULER Oracle procedures and functions can be executed. Also binary and shell-scripts can be scheduled.

Rights

If you have DBA rights you can do all the scheduling. For administering job scheduling you need the privileges belonging to the SCHEDULER_ADMIN role. To create and run jobs in your own schedule you need the 'CREATE JOB' privilege.

With DBMS_JOB you needed to set an initialization parameter to start a job coordinator background process. With Oracle 10g DBMS_SCHEDULER this is not needed any more.

If you want to user resource plans and/or consumer groups you need to set a system parameter:


ALTER SYSTEM SET RESOURCE_LIMIT = TRUE;

The basic elements of the Scheduler are:

Schedules

Jobs

Events

Chains

Programs

Job

A job instructs the scheduler to run a specific program at a specific time on a specific date.

Programs

A program contains the code (or reference to the code ) that needs to be run to accomplish a task. It also contains parameters that should be passed to the program at runtime. And it’s an independent object that can referenced by many jobs

Schedules

A schedule contains a start date, an optional end date, and repeat interval with these elements; an execution schedule can be calculated.

Windows

A window identifies a recurring block of time during which a specific resource plan should be enabled to govern resource allocation for the database.

Job groups

A job group is a logical method of classifying jobs with similar characteristics.

Window groups

A window groups is a logical method of grouping windows. They simplify the management of windows by allowing the members of the group to be manipulated as one object. Unlike job groups, window groups don’t set default characteristics for windows that belong to the group.

Using Job Scheduler

SQL> drop table emp;

SQL> Create table emp (eno int, esal int);

SQL > begin

dbms_scheduler.create_job (

job_name => 'test_babu',

job_type => 'PLSQL_BLOCK',

job_action => 'update emp set esal=esal*10 ;',

start_date => SYSDATE,

repeat_interval => 'FREQ=DAILY; INTERVAL=10',

comments => 'Babu tesing scheduler');

end;

PL/SQL procedure successfully completed.

Verification

To verify that job was created, the DBA ALL USER_SCHEDULER_JOBS view can be queried.

SQL> select job_name,enabled,run_count from user_scheduler_jobs;

JOB_NAME ENABL RUN_COUNT

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

TEST_BABU FALSE 0

Note :

As you can see from the results, the job was indeed created, but is not enabled because the ENABLE attribute was not explicitly set in the CREATE_JOB procedure.

Run your job

SQL> begin

2 dbms_scheduler.run_job('TEST_BABU',TRUE);

3* end;

SQL> /

PL/SQL procedure successfully completed.

SQL> select job_name,enabled,run_count from user_scheduler_jobs;

JOB_NAME ENABL RUN_COUNT

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

TEST_BABU FALSE 0

Copying Jobs

SQL> begin

2 dbms_scheduler.copy_job('TEST_BABU','NEW_TEST_BABU');

3 END;

4 /

PL/SQL procedure successfully completed.

SQL> select job_name,enabled,run_count from user_scheduler_jobs;

JOB_NAME ENABL RUN_COUNT

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

TEST_BABU FALSE 0

NEW_TEST_BABU FALSE 0

SQL> begin

2 dbms_scheduler.stop_job(job_name => 'TEST_BABU', force => TRUE);

3* end;

SQL> /

begin

*

ERROR at line 1:

ORA-27366: job "SCOTT.TEST_BABU" is not running

ORA-06512: at "SYS.DBMS_ISCHED", line 164

ORA-06512: at "SYS.DBMS_SCHEDULER", line 483

ORA-06512: at line 2

Dropping Jobs

SQL> begin

2 dbms_scheduler.drop_job( job_name => 'NEW_TEST_BABU' , force => TRUE );

3 end;

4 /

PL/SQL procedure successfully completed.

Saturday, April 21, 2007

Manually Create DataBase

DataBase creation there are two type's

1. Using Database configuration assistant. Start -> run -> type " Dbca"

2. manually crated database using Command based method.

Here i have used manually cteated.

1. Create folder in %ORACLE_BASE%/admin/

%ORACLE_BASE%\admin>mkdir iso
%ORACLE_BASE%\admin>cd iso
%ORACLE_BASE%\admin\iso>mkdir adump
%ORACLE_BASE%\admin\iso>mkdir bdump
%ORACLE_BASE%\admin\iso>mkdir cdump
%ORACLE_BASE%\admin\iso>mkdir dpdump
%ORACLE_BASE%\admin\iso>mkdir pfile
%ORACLE_BASE%\admin\iso>mkdir scripts
%ORACLE_BASE%\admin\iso>mkdir udump

Here "ISO" is a my database name.

2. set oracle enviorment variable


F:\>set oracle_sid=iso

3. create password file for iso database

F:\>orapwd file=F:\oracle\product\10.2.0\db_1\database\PWDiso.ora entries=5 password=oracle force=y

4. Create Oracle instance and start your new service

F:\>oradim -new -sid iso -startmode manual
Instance created.


F:\>oradim -edit -sid iso -startmode auto


F:\>sqlplus /nolog


SQL*Plus: Release 10.2.0.1.0 - Production on Sat Apr 21 16:44:52 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> connect sys as sysdba

Enter password:
Connected to an idle instance.


5. create initialization parameter file


in %ORACLE_HOME%\database\initISO.ora


SQL> startup nomount
ORACLE instance started.
Total System Global Area 281018368 bytes
Fixed Size 1248528 bytes
Variable Size 92275440 bytes
Database Buffers 180355072 bytes
Redo Buffers 7139328 bytes


6. Here run your Database script


SQL> CREATE DATABASE "ISO"
2 MAXINSTANCES 8
3 MAXLOGHISTORY 1
4 MAXLOGFILES 16
5 MAXLOGMEMBERS 3
6 MAXDATAFILES 50
7 DATAFILE 'F:\oracle\product\10.2.0\oradata\iso\SYSTEM01.DBF' SIZE 300M
REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
8 SYSAUX DATAFILE 'F:\oracle\product\10.2.0\oradata\iso\SYSAUX01.DBF'
SIZE 120M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE
UNLIMITED
9 DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE
'F:\oracle\product\10.2.0\oradata\iso\TEMP01.DBF' SIZE 50M REUSE
AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
10 UNDO TABLESPACE "UNDOTBS1" DATAFILE
'F:\oracle\product\10.2.0\oradata\iso\UNDOTBS01.DBF' SIZE 200M REUSE
AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
11 CHARACTER SET WE8MSWIN1252
12 NATIONAL CHARACTER SET AL16UTF16
13 LOGFILE GROUP 1 ('F:\oracle\product\10.2.0\oradata\iso\REDO01.LOG') SIZE
10240K,
14 GROUP 2 ('F:\oracle\product\10.2.0\oradata\iso\REDO02.LOG') SIZE
10240K,
15 GROUP 3 ('F:\oracle\product\10.2.0\oradata\iso\REDO03.LOG') SIZE
10240K
16 USER SYS IDENTIFIED BY "&SYSPWD"
17 USER SYSTEM IDENTIFIED BY "&SYSTEMPWD";
Enter value for syspwd: babu
old 16: USER SYS IDENTIFIED BY "&SYSPWD"
new 16: USER SYS IDENTIFIED BY "babu"
Enter value for systempwd: babu
old 17: USER SYSTEM IDENTIFIED BY "&SYSTEMPWD"
new 17: USER SYSTEM IDENTIFIED BY "babu"
Database created.


7. Create user tablespace


SQL> CREATE TABLESPACE "USER" LOGGING DATAFILE 'F:\oracle\product\10.2.0\oradata\iso\USERS01.DBF' SIZE 10m REUSE AUTOEXTEND ON NEXT 1280k MAXSIZE
2* UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
3 /
Tablespace created.


SQL> ALTER DATABASE DEFAULT TABLESPACE "USER";
Database altered.

8. Execute the following script


@%ORACLE_HOME%\RDBMS\ADMIN\catalog.SQL
@%ORACLE_HOME%\RDBMS\ADMIN\catproc.sql
@%ORACLE_HOME%\SQLPLUS\ADMIN\pupbld.sql


9. Finally create Spfile using your Pfile


SQL> CREATE SPFILE FROM PFILE='F:\oracle\product\10.2.0\db_1\database\initISO.ora';
File created.


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> startup
ORACLE instance started.
Total System Global Area 281018368 bytes
Fixed Size 1248528 bytes
Variable Size 92275440 bytes
Database Buffers 180355072 bytes
Redo Buffers 7139328 bytes
Database mounted.
Database opened.

Thursday, April 12, 2007

Get Buffer Hit Ratio

Make select from v$sysstat.

When you make select from v$sysstat you get the following statistics:

Consistent gets - number of the data blocks which were accessed in the buffer cache for SQL statements, that do not modify data - just SELECT statements


DB block gets - number of the data blocks which were accessed in the buffer cache for SQL statements that modify data - INSERT, UPDATE, DELETE and SELECT FOR UPDATE statements;

Physical reads - number of the data blocks that where read from the disk.

The sum of consistent gets and db block gets is the number of the logical reads.

The buffer hit ratio is:

(logical reads - physical reads) / logical reads

or

(consistent gets + db block gets - physical reads) / (consistent gets + db block gets)

Thanks & Regards

Babu B