Total Pageviews

Saturday, July 30, 2016

Scheduler Architecture

Scheduler Architecture

The Scheduler architecture consists of the job table, job coordinator, and the job workers (or slaves, as Oracle calls them). The job table contains information about jobs, such as the job name, program name, and job owner. You can examine the job table by using the DBA_SCHEDULER_JOBS view. The job coordinator regularly looks in the job table to find out what jobs to execute. The job coordinator creates and manages the job worker processes, which actually execute the job. When you create a new job or execute a job, a background process (cjqnnn) wakes up and coordinates the running of the job. When the job coordinator tells a job worker to execute a job, the worker process starts a new database session and starts a transaction. It executes the job, and once completed, it commits and ends the transaction and terminates the database session. The job worker updates the job table, the run count, and the job log table.

Scheduler Privileges:
Oracle creates all jobs, programs, and schedules in the schema of the user that creates these objects, but it creates all the advanced Scheduler components, like job classes, windows, and window groups, at the database level, and their owner is the SYS schema. The SCHEDULER_ADMIN role contains all Scheduler system privileges, with the WITH ADMIN OPTION clause. The DBA role contains the SCHEDULER_ADMIN role. The MANAGE SCHEDULER system privilege lets you do the following:
• Create, drop, and alter job classes, windows, and window groups. • Stop any job. • Start and stop windows prematurely.

Note:  All Scheduler objects are of the form [schema.]name. By default, all scheduler object names are in uppercase, unless you wrap the lowercase names in double quotes, as in "test_job".

You must have the CREATE JOB privilege to create Scheduler components (jobs, schedules, programs, chains, and events). To use the advanced Scheduler components (windows, window groups, and job classes), you need the MANAGE SCHEDULER system privilege. You can assign other users the right to use one of your components by giving them EXECUTE privileges on that component:
• The EXECUTE ANY PROGRAM privilege lets a user execute any program under any schema.
• The EXECUTE ANY CLASS privilege lets you assign a job to any job class.

In order for users to modify Scheduler components, they must use the GRANT ALTER SQL statement for each Scheduler component.
Note : To be able to create a job in a job class you generate, you must have a separate EXECUTE privilege on that job class.

Note the following basic points regarding Scheduler privileges:
• To create a job, you must have the CREATE JOB privilege. • You don’t need any special privileges to specify a schedule, a window or window group, or a program that you own.
• If you specify a program owned by a different user, you must have the EXECUTE privilege on that program, or the EXECUTE ANY PROGRAM system privilege.

Eg.
Creating a Basic Scheduler Job Without a Program or Schedule:
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
JOB_NAME   =>  'test_job',
JOB_TYPE   =>  'PLSQL_BLOCK',
JOB_ACTION         =>  'insert into ashwani.suppliers select * from ashwani.suppliers;',
START_DATE         =>  '11-APRIL-2016 06.30.00 PM',
repeat_interval    => 'FREQ=MINUTELY;INTERVAL=1',
END_DATE           =>  '20-APRIL-2016 07.00.00 PM',
COMMENTS           =>  'Insert new suppliers into the suppliers table',
ENABLED            =>  TRUE);
END;
/
Query to find out the details about TEST_JOB jobs in your database:
SQL>SELECT job_name, program_name FROM dba_scheduler_jobs WHERE job_style='TEST_JOB'

Command for disabling scheduler:

EXEC DBMS_SCHEDULER.DISABLE(name => '"SYS"."TEST_JOB"');

Command for enabling scheduler:

EXEC DBMS_SCHEDULER.ENABLE(name => '"SYS"."TEST_JOB"');

Command for running job manually:

EXEC DBMS_SCHEDULER.RUN_JOB('"SYS"."TEST_JOB"');


Flashback Recovery Techniques

Flashback Recovery Techniques


 Quite often, you may be called upon to help recover from a logical corruption of the database, rather than from a hardware failure. You can use the following flashback techniques in Oracle Database 11g to recover from logical errors:
          Flashback Database: Takes the entire database back to a specific point in time
          Flashback Table: Returns individual tables to a past state
          Flashback Drop: Undoes a DROP TABLE command and recovers the dropped table
          Flashback Query, Flashback Version Query, and Flashback Transaction Query: Retrieve data from a time (or an interval) in the past
          Flashback Transaction Backout: Lets you undo a transaction, together with all its dependent transactions as well, with just a single click in the Database Control
          Flashback Data Archive: Stores history of the changes made to a table, which you can use to make queries using older versions of data and for auditing purposes as well


FLASHBACK TABLE DATA through SCN and TIMESTAMP




19:06:31 SQL> ---FLASHBACK TABLE SCENERIO (SCN)
19:06:43 SQL>
19:06:43 SQL>
19:06:43 SQL>
19:06:44 SQL> SELECT * FROM ASHWANI.KEY;

no rows selected

19:06:53 SQL> INSERT INTO ASHWANI.KEY VALUES ('HELLO1');

1 row created.

19:07:25 SQL> /

1 row created.

19:07:27 SQL> /

1 row created.

19:07:27 SQL> /

1 row created.

19:07:28 SQL> /

1 row created.

19:07:28 SQL> COMMIT;

Commit complete.

19:07:31 SQL> INSERT INTO ASHWANI.KEY VALUES ('HELLO2');

1 row created.

19:07:39 SQL> /

1 row created.

19:07:40 SQL> /

1 row created.

19:07:40 SQL> /

1 row created.

19:07:41 SQL> /

1 row created.

19:07:41 SQL> COMMIT;

Commit complete.

19:07:44 SQL> INSERT INTO ASHWANI.KEY VALUES ('HELLO3');

1 row created.

19:07:49 SQL> /

1 row created.

19:07:51 SQL> /

1 row created.

19:07:52 SQL> /

1 row created.

19:07:52 SQL> /

1 row created.

19:07:53 SQL> COMMIT;

Commit complete.

19:07:55 SQL> SELECT * FROM ASHWANI.KEY;

NAME                                                                           
--------------------------------------------------                              
HELLO2                                                                         
HELLO2                                                                         
HELLO2                                                                         
HELLO2                                                                         
HELLO3                                                                         
HELLO3                                                                         
HELLO3                                                                         
HELLO3                                                                         
HELLO3                                                                         
HELLO1                                                                          
HELLO1                                                                         

NAME                                                                           
--------------------------------------------------                             
HELLO1                                                                         
HELLO1                                                                         
HELLO1                                                                          
HELLO2                                                                         

15 rows selected.

19:08:07 SQL> SELECT * FROM ASHWANI.KEY ORDER BY NAME;

NAME                                                                            
--------------------------------------------------                             
HELLO1                                                                         
HELLO1                                                                          
HELLO1                                                                         
HELLO1                                                                         
HELLO1                                                                         
HELLO2                                                                         
HELLO2                                                                         
HELLO2                                                                         
HELLO2                                                                         
HELLO2                                                                         
HELLO3                                                                         

NAME                                                                            
--------------------------------------------------                             
HELLO3                                                                         
HELLO3                                                                          
HELLO3                                                                         
HELLO3                                                                         

15 rows selected.

19:08:18 SQL> select timestamp_to_scn(to_timestamp('19-FEB-2016 19:07:41','DD-MON-YY  HH24.MI.SS')) from dual;

TIMESTAMP_TO_SCN(TO_TIMESTAMP('19-FEB-201619:07:41','DD-MON-YYHH24.MI.SS'))    
---------------------------------------------------------------------------    
                                                                    4940959    

19:08:51 SQL> FLASHBACK TABLE ASHWANI.KEY TO SCN   5383106;

FLASHBACK TABLE ASHWANI.KEY TO SCN   5381450
                        *
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled


SQL> ALTER TABLE ASHWANI.KEY ENABLE ROW MOVEMENT;

Table altered.

19:08:51 SQL> FLASHBACK TABLE ASHWANI.KEY TO SCN   5381450;

Flashback complete.

19:09:03 SQL> SELECT * FROM ASHWANI.KEY ORDER BY NAME;

NAME                                                                           
--------------------------------------------------                             
HELLO1                                                                         
HELLO1                                                                          
HELLO1                                                                         
HELLO1                                                                         
HELLO1                                                                          



19:13:52 SQL> FLASHBACK TABLE ASHWANI.KEY TO TIMESTAMP TO_TIMESTAMP('19-FEB-2016 19:06:44', 'DD-MM-YYYY HH24:MI:SS');

Flashback complete.

19:14:06 SQL> SELECT * FROM ASHWANI.KEY;

no rows selected

19:14:18 SQL>