Thursday, November 1, 2018

Crontab setup and steps

Hello guys, 
Here is my one more blog about the crontab scheduler which is most important future to know to every DBA.

Crontab allows a task to be run automatically in background at mentioned date/time.
Crontab has 5 variable inputs which will allow user to schedule the script to execute on the time/date/day according to the user input.

Sample:
1 2 3 4 5 /home/vinaychandra/remove_file.sh

I have a shell file which will remove the some file, lets see how can i schedule it in different events. First most we need to know which parameter is used for what.

1 - Minute (from 0 to 59)
2 - Hour (from 0 to 23)
3 - Date of the month ( from 1 to 31)
4 - Month ( from 1 to 12)
5 - Day of week (from 0 to 7, here 0 and 7 are Sunday)

And to list the existing crontab or edit it, use following

$crontab -l  --> To list
$crontab -e --> To edit

Now, lets see the events:

Please find the below examples for references:

1. Suppose we want to execute any scripts every minute then we can use below commands:

* * * * * /home/vinaychandra/remove_file.sh

Here, * asterisk or start means every. So, this above command will run for every minute, every hour, and every date of month, every month and every day of week.

2. Example for execute on Friday at 7 AM, each date and every month.

0 7 * * 5 /home/vinaychandra/remove_file.sh

3. Suppose, we want to execute our scripts only on Friday and Saturday at 5 AM.

0 5 * * 5-6 /home/vinaychandra/remove_file.sh

4. Suppose, we want to execute at every 10 min.

0,10,20,30,40,50 * * * * /home/vinaychandra/remove_file.sh

That's it.





Saturday, May 12, 2018

Some useful queries


è To get the max value occupied by column’s

SELECT peid,emp_id, LENGTH(TRIM(e1.emp_id )) FROM app_ehr_location.em_employee_employment e1 where  LENGTH(TRIM(e1.emp_id ))>15

à Moving Index and table to different tablespace

      alter index sys.SOURCE$ rebuild tablespace users;
   ALTER TABLE sys.TRIGGER$ MOVE TABLESPACE users

è Killing the pumping jobs

      drop table system.SYS_EXPORT_SCHEMA_01
select job_name, state from dba_datapump_jobs;

à Select space each Table OR Index

select *
  from (select owner, segment_name, bytes / 1024 / 1024 MG
          from dba_segments
         where segment_type = 'TABLE' and owner like'SYS%' and tablespace_name='SYSTEM'
         order by bytes / 1024 / 1024 desc)
 where rownum <= 50;


Re-creating New TEMP tablespace

Here are the steps:

First create temp tablespace
--Create Temporary Tablespace Temp2
CREATE TEMPORARY TABLESPACE TEMP2 TEMPFILE  
'/oradata/testdb/temp02.dbf' SIZE 500M;


Make the newly create tablespace as default one
--Move Default Database temp tablespace
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;


Now drop the old tablespace
--Drop temp tablespace
DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;