DBA SCRIPTS

DB MONITORING

find current running sqls


Find active sessions in oracle database
Find waitevents in database
Find sessions generating undo
Find the temp usage of the sessions
Find sessions generating lot of redo
Monitor tablespace usage
Script to Monitor undo tablespace usage
Monitor TEMP tablespace usage
Find blocking sessions
Find long running operations
Find locks present in database
Find queries triggered from a procedure
Get sid from os pid
Kill all sessions of a sql_id
kill all session of a user
get parallel query detail
Kill snipped session in db
Top Query with high elapsed time
Monitor parallel queries
Find the locked objects
Check open cursors
Session login history from ASH
Buffer Cache hit ratio
Find top disk_reads by an user
Get os pid from sid
Get active sid of a pl/sql object
Find buffer cache usage
Monitor rollback transations
Find column usage statistics
Get background process details
oracle db is 32bit or 64 bit?
oracle license usage info
db optimizer processing rate
Purge recyclebin in database

DB MONITORING

xplain plan of sql_id from cursor


xplain plan of sql_id from AWR
Get sql_text from sid
xplain plan of a sql statement
xplain plan of a sql baseline
Get bind values of a sql_id
Flush a sql query from cursor
Enable trace for a sql_id
10053 OPTIMIZER TRACE
Enable trace for a session
Tracing all session of a user
Enable tracing for a listener
execution detail of a sql_id in cursor
Pga usage by sessions
segments with high physical read
I/O usage of each tempfile
Current SGA usage
Top running queries from ASH
Find blocking sessions from ASH
Top cpu consuming sessions
Sessions holding library cache lock
Objects locked by library cache
Sessions accessing an object
Sqls doing full table scan
Dictionary cache hit ratio
Top sql queries using literal values
Objects causing flushing of shared pool
Latch type and sql hash value
Objects causing latch contention
Queries causing high physical read
Mutex sleep in database
Sql tuning advisor for sql_id from cursor
run sga target advisory
Run shared pool advisory
Generate addm report

DATABASE INFO

Get redo log member info


Get DDL of all tablespaces
Get DDL of all privileges granted to user
Get size of the database
View hidden parameter setting
Get ACL details in database
Archive generation per hour
Find active transactions in db
Find who locked your account
Find duplicate rows in table
Database growth per month
generate resize datafile script without ORA-03297 error
Get database uptime
Scn to timestamp and viceversa
Disable/enable all triggers of schema
Ger row_count of all the tables of a schema
Spool sql query output to HTML
Monitor index usage
Get installed sqlpatches in db
Cleanup orphaned datapump jobs
Get Alert log location in db
Installed RDBMS components
Characterset info of database
View/modify AWR retention
Find optimal undo retention size
Purge old awr snapshots
Modify moving window size
Open database link information
utilization of current redo log ( in % )
Generate multiple AWR report
Table not having index on fk column
Get cpu memory info of db server
Get database incarnation info
View timezone info in db



ASM

Get asm disk info


Get ASM diskgroup details
drop an asm disk
Monitor ASM disk rebalance
execute runcluvfy.sh for RAC precheck
copy asm file to remote asm instance
Mount/dismount ASM diskgroups
Drop ASM diskgroup
Clock Synchronization status in RAC
Create ASM disk in Linux using oracleasm
Change asm rebalance power
Create password file in ASM DG
Stop/start cluster in rac standalone.
Modify asm user password
Monitor asm diskgroup i/o
Enable tracing for asmcmd
How to Change ASM sys password

SRVCTL COMMANDS

Stop and start db using srvctl


add/remove db using srvctl
Add/remove instance using srvctl
Stop and start instance using srvctl
Enable/disable db/instance using srvctl
Relocate a service
Add/remove a service
stop/start a service
Manage MGMTDB in 12c RAC
Set env variables using srvctl
Enable trace for srvctl commands

CRSCTL & RAC

Enable/Disable autorestart of crs


Find the cluster name in RAC
Stop and start CRS
Find OCR and VD location
Find the grid version
check cluster component status
Get cluster_interconnect details
Manual backup of ocr and list backups
Move voting disk to new diskgroup
get disktimeout values
get node info using olsnodes
Get interface info in RAC
Get OLR info in RAC



SQL PROF/BASELINE

create baselines for all sqls of a schema


Create sql baseline from cursor cache
drop a sql baseline
drop a sql profile
Get sql_profile of a sql_id
Disable/enable sql profile
Find sql baseline info from sql_id
Alter/disable a sql plan baseline

PARTITIONING

Adding partitions 11g/12c


Dropping partition 11g/12c
Truncate partitions
merge partition
Make a partition ready only(12CR2)
Split partition online(12cR2 only)
Non-partitioned to partitioned online(12CR2 only)
Rename a partition
Get row_count of partitions of a table
Find the table partition keys
Move partition to new tablespace

STATISTICS

Gather stats for schema


Gather stats for a table
Lock/unlock statistics
Export import statistics
Check stale stats
Table statistics history
Publish Pending stats
Get statistics preference setting
View/modify stats retention in db
Space used to store stats
Enable incremental stats collection
Delete statistics
Upgrade statistics in db



FLASHBACK TECH

Flashback a table to point in time


Recover a dropped table
Flashback query as of timestamp
Enable flashback for database
Create/drop flashback restore point
Flashback db using restore point
Flashback a procedure/package
How far we can flashback
Flashback area usage info
Enable archivelog mode in standalone db
List flashback restore points

RMAN SCRIPTS

rman full db backup run block script


RMAN INCR db backup run block
rman tablespace backup run block
RMAN datafile(s) backup run block
delete archive older than 1 day
backup archivelogs using RMAN
Copy archive from ASM to File system
backup archive b/w 2 sequence
Enable trace for RMAN
Recover dropped table with RMAN 12c
Monitor rman backup progress
Restore archivelog from rman tape
Enable block change tracking
check the syntax of RMAN commands

USER MANAGEMENT

Create user in oracle


Alter an user
Change default tablespace of user
Tablespace quota for a user
View Privileges granted to an user
grant table/column privilege to user
Connect to user without knowing password
Common user/role in CDB
User creation details in user$ table
Create /alter profile in database
Default users in oracle 12c



TABLESPACE & DATAFILE

Create tablespace in oracle db


Rename tablespace in oracle db
Drop tablespace in oracle db
Add/alter datafile
Add/drop Tempfile
Rename/move a datafile
Checkpoint time of datafiles
Occupants usage in sysaux tablespace

MULTITENANT(CDB-PDB)

Status of PDBS in multitenant


Tablespace info in Multitenant
Temp tablespace details in Multitenant
show History of PDBS
currently connected PDB name
stop and start pluggable db:
Drop a pluggable database
Check undo mode in Multitenant db (oracle 12.2)
Is the Database is a Multitenant or not
Services associated with PDBs
View container DB information

SCHEDULER & JOBS

Manage dbms_schedulerjobs


Create and scheduler a scheduler job
Drop a schedule
scheduler shell script in dbms_scheduler
Monitor scheduler jobs
All scheduler windows
View all scheduler schedules
history of all scheduler job runs
log information for all Scheduler jobs
Get DDL of a scheduler job
Scheduler job detail in CDB
Copy scheduler job from one user to other
Definition of job in dbms_jobs
Enable/disable/dop a dbms_job



DATAGUARD MONITORING New Post

Check DB role(PRIMARY/STANDBY)


Monitor standby background process
View dataguard message or errors
Last log applied/Received in standby
Get standby redo log info
Monitor lag in standby including RAC
Monitor recovery progress in standby db
Stop/start MRP process in standby

OBJECT MANAGEMENTNew Post

Move LOB segment to another tablespace


Find tables with LOB seg in DB
space usage by LOB column
Find chained rows in table
object with mix or lowercase name
Find nested tables in db
Create/drop database link
Top index sizes of table/schema
managing columns of table
Create/drop synonyms
Find column usage statistics
Estimate space require for index creation
Compile invalid objects
Enable/disable triggers of a schema
Find dependents of an object
Index rebuild in oracle
Make index invisible

Auditing

Enable auditing in database


Statements audited in oracle
Privileges Audited in database:
audit records of an user:
Enable audit for sys operations
Enable pure unified auditing 12c
Unified audit policies present in db
View unified audit report
Create unified audit policy
Enable auditing for datapump jobs
Move aud$ table to new tablespace
Check encryption wallet status
encrypt or decrypt a column

NETWORK MANAGEMENT

Enable tracing for a listener


Create/drop database link
create db link w/o modifying tnsnames.ora
Modify scan listener port
Create static listener for oracle db
Manage listener in oracle
Manage ACLS in oracle
Find active services in db
Set local_listener in db
View ACL information in db

OEM/CLOUD CONTROLNew Post

Stop/start oms in cloud control


stop/start agent in oem cloud control
Get oms repository details
Get oms/agent url details
target list monitored by OEM
Plugins installed on OMS server
change sysman pwd in oem cloud
Enable/disable em express 12c

EXPDP/IMPDP

expdp with compression parameter


expdp/impdp with parallel option
expdp/impdp for schemas
expdp/impdp for TABLES
expdp with query clause
sqlfile option with impdp
TABLE_EXISTS_ACTION option with impdp
EXCLUDE/INCLUDE option in expdp
expdp to multiple directories
expdp to asm diskgroup
CLUSTER PARAMETER IN RAC

    1. Please suggest new scripts that can be added to this script collections
    For any queries or suggestion ,Please post in forum.dbaclass.com.

Keep visiting us.

122 thoughts on “DBA SCRIPTS”

    1. Dear Pavan,

      There is some issue with the backend code, on which we are working. By Tomorow EOD, it will be fixed.

  1. Really great help. Makes our regular works much easier and efficient.
    Thanks a lot and hope the alignment issue will be fixed soon.

    Regards
    Ranajit

    1. Dear Karteek,

      Please post the question in our forum.(forum.dbaclass.com).

      Toad is the best utility for doing schema comparison. If you need, I can share the steps.

      Regards
      Rajkishore

    1. You can use the below script.

      SELECT o.OWNER , o.OBJECT_NAME , o.SUBOBJECT_NAME , o.OBJECT_TYPE ,
      t.NAME “Tablespace Name”, s.growth/(1024*1024) “Growth in MB”,
      (SELECT sum(bytes)/(1024*1024)
      FROM dba_segments
      WHERE segment_name=o.object_name) “Total Size(MB)”
      FROM DBA_OBJECTS o,
      ( SELECT TS#,OBJ#,
      SUM(SPACE_USED_DELTA) growth
      FROM DBA_HIST_SEG_STAT
      GROUP BY TS#,OBJ#
      HAVING SUM(SPACE_USED_DELTA) > 0
      ORDER BY 2 DESC ) s,
      v$tablespace t
      WHERE s.OBJ# = o.OBJECT_ID
      AND s.TS#=t.TS#
      AND rownum < 51 ORDER BY 6 DESC /

      1. Thanks for the script but i have a query here. I don’t find anything related to 60 days in the provided script. If we want to query the result for 90 days how can we change the given script.

  2. Hi Admin – Could you provide query to find out the debug enabled at db resource level..i.e package …table…etc..

    1. Hi Sai,

      Currently i dont have the zip format. But i am working a small interactive tool, Which will be a bundle of all these scripts.

      Regards
      Admin

  3. Hi Team,

    I am Not able to view any of the scripts under DBA SCRIPTS. It was going as Blank page.

    I was using Google Chrome Browser.

    Please suggest, how can I view all these scripts.

    Thanks in Advance.

    Regards,
    Abhinay.

    1. Hi, It seems java scripts/popup were blocked by your browser. These are working in my browser.
      Could you please check by removing adblocker if you have.

  4. Hi Admin,

    Please send a script for Performance scripts or commands for concurrent request.

    Thanks,
    Pratyush

  5. Hi Admin,

    Can you please help me and give us the consolidate command(.sh) or .sql file if I enter request id,it will fetch all the details.
    Request timings,
    Request history(sysdate-30),
    session details and its statistics,
    sql id,sql_text,
    progress details
    plan details(running with same or plan change).
    etc.

      1. request id stands for if user submit concurrent request from Oracle EBS Applications front END and he will to share a request id to monitor the request.
        That is why we need a consolidate script.

        Thanks
        Pratyush

  6. What is the input for DB Growth script per month :
    select to_char(creation_time, ‘MM-RRRR’) “Month”, sum(bytes)/1024/1024/1024 “Growth in GB
    from sys.v_$datafile
    where to_char(creation_time,’RRRR’)=’&YEAR_IN_YYYY_FORMAT’
    group by to_char(creation_time, ‘MM-RRRR’)
    order by to_char(creation_time, ‘MM-RRRR’);

      1. i have give year as : 2018 getting error
        select to_char(creation_time, ‘MM-RRRR’) “Month”, sum(bytes)/1024/1024/1024 “Growth in GB
        from sys.v_$datafile
        2 3 where to_char(creation_time,’RRRR’)=’&YEAR_IN_YYYY_FORMAT’
        group by to_char(creation_time, ‘MM-RRRR’)
        order by to_char(creation_time, ‘MM-RRRR’); 4 5
        Enter value for year_in_yyyy_format: year,2018
        old 3: where to_char(creation_time,’RRRR’)=’&YEAR_IN_YYYY_FORMAT’
        new 3: where to_char(creation_time,’RRRR’)=’year,2018′
        ERROR:
        ORA-00972: identifier is too long

  7. I am using 12c pluggable DB’s on Exadata with 44 cores (88 cpu’s). I can’t seem to find a convenient method for finding out how much CPU resources are being used using AWR statistics. AWR gives me the load stats as if all of the cores are available, but of course I am using the resource manager so those stats are not reflecting the resource manager settings for the CPU resource.

    Please suggest what I need to do.

    Thanks-
    Mark

  8. My Application table owner granted DML privs to PUBLIC as Grantee, I want to rollback all DML pivs from PUBLIC and need to allocate it to newly created ROLE. Could you please provide me the script for this. Unable to get it from Google. Please help.

    I need to assing privs to ROLE same as Public. Public user having nearly 10k+privs.

    1. Dear Gopal,

      Use similar below dynaimc script to generate required sql file.

      spool revoke_public.sql
      select ‘REVOKE ‘||PRIVILEGE||’ from ‘||OWNER||’.’||TABLE_NAME||’ from PUBLIC;’ from dba_tab_privs where grantee=’PUBLIC’ and owner=’APP’ and PRIVILEGE in (‘INSERT’,’UPDATE’,’DELETE’);
      spool off;

      For quick response , Please post in the Q&A Forum.

      Regards
      Admin

    1. what is your problem in visiting the site and accessing the scripts. You don’t have internet in you pc or mobile. These days many telecom operators are providing internet service at very low cost. Go and buy them. And better access scripts from website only.

  9. Hi Admin,

    Need your help to create blocking script and also kept in shell script which create a output in
    in html tabular format to get information of all waiter session at how much time with object_type,pid,sid,client information,module,action,program,last_call_et,status etc .

    Regards,
    Prasoon

  10. Hi Admin,

    These blocking commands are not working showing no rows but blocking is there..

    Can you please send the command and also add detail how much time holding/blocking session is blocked waiter session.

    Thanks,
    Prasoon

  11. set lines 120
    col sess format a15
    SELECT DECODE(request,0,’Holder: ‘,’ Waiter: ‘)||sid sess,id1,id2, lmode,inst_id, request, type
    FROM GV$LOCK WHERE (id1, id2, type)
    IN
    (SELECT id1, id2, type FROM GV$LOCK WHERE request>0) ORDER BY id1, request
    /

    Hi team,

    I have used this command to find out blocking session it is showing session is there but suggested commands is shoing no rows.
    Can you please send the command and also add detail how much time holding/blocking session is blocked waiter session?

    SESS ID1 ID2 LMODE INST_ID REQUEST TY
    ————— ———- ———- ———- ———- ———- —
    Holder: 2397 524319 548489 6 1 0 TX
    Waiter: 474 524319 548489 0 6 6 TX
    Holder: 2981 6815776 391294 6 1 0 TX
    Waiter: 542 6815776 391294 0 5 6 TX
    Holder: 1918 10223642 429877 6 2 0 TX
    Waiter: 1754 10223642 429877 0 2 6 TX
    Waiter: 2565 10223642 429877 0 1 6 TX
    Holder: 1924 11927575 573769 6 2 0 TX
    Waiter: 1918 11927575 573769 0 2 6 TX
    Holder: 2895 28180490 1078657 6 5 0 TX
    Waiter: 1905 28180490 1078657 0 2 6 TX

    SESS ID1 ID2 LMODE INST_ID REQUEST TY

    SQL> SELECT
    s.inst_id,
    s.blocking_session,
    s.sid,
    s.serial#,
    s.seconds_in_wait,
    s.event
    FROM
    gv$session s
    WHERE
    blocking_session IS NOT NULL and s.seconds_in_wait > 10; 2 3 4 5 6 7 8 9 10 11

    no rows selected

    SQL>

    Please clarify and help..

    Thanks,
    Prasoon

    1. Hi Pablo,

      Thanks for suggestions, However we dont have expertise on exadata. We would be glad, if you can help us.

      Regards
      Admin

  12. Great portal and collection Dear brother Good job …..exellent yar …very usful for all DBA

  13. Please add some RDS related queries also, rdsadmin.packages*, which will be help of the peoples working on AWS cloud RDS oracle

    1. Hi Suresh,

      We dont have expertise on amazon RDS. If you have set of scripts on RDS, share with us, we will happily publish the same.

      Regards
      Admin

  14. Hi Admin, i was searching for the dba scripts and came across this website, this has all the scripts for day to day dba tasks, i really appreciate your effort to gather all the scripts at one place.

    if you dont mind, can you please email me all the scripts to [email protected]

    1. Dear,

      All the scripts are embedded in the website page. I don’t have it in one place with me.

      Admin

  15. Awesome web congrats, I realized people requesting those script, like send to me to my email,exuse me …
    you already have those script in the website .

  16. Hello,
    Add this script for tablespace utilization an it calculate the autoextendable size.

    set pages 50000 lines 32767
    col tablespace_name format a30
    col TABLESPACE_NAME heading “Tablespace|Name”
    col Allocated_size heading “Allocated|Size(GB)” form 99999999.99
    col Current_size heading “Current|Size(GB)” form 99999999.99
    col Used_size heading “Used|Size(GB)” form 99999999.99
    col Available_size heading “Available|Size(GB)” form 99999999.99
    col Pct_used heading “%Used (vs)|(Allocated)” form 99999999.99

    select a.tablespace_name
    ,a.alloc_size/1024/1024/1024 Allocated_size
    ,a.cur_size/1024/1024/1024 Current_Size
    ,(u.used+a.file_count*65536)/1024/1024/1024 Used_size
    ,(a.alloc_size-(u.used+a.file_count*65536))/1024/1024/1024 Available_size
    ,((u.used+a.file_count*65536)*100)/a.alloc_size Pct_used
    from dba_tablespaces t
    ,(select t1.tablespace_name
    ,nvl(sum(s.bytes),0) used
    from dba_segments s
    ,dba_tablespaces t1
    where t1.tablespace_name=s.tablespace_name(+)
    group by t1.tablespace_name) u
    ,(select d.tablespace_name
    ,sum(greatest(d.bytes,nvl(d.maxbytes,0))) alloc_size
    ,sum(d.bytes) cur_size
    ,count(*) file_count
    from dba_data_files d
    group by d.tablespace_name) a
    where t.tablespace_name=u.tablespace_name
    and t.tablespace_name=a.tablespace_name
    order by t.tablespace_name
    /

  17. Hi Team,

    Can you please add scripts for Golden gate like(Start/stop, Monitor,Replicate, Monitor)

    Also please add scripts for PSU patch RAC database when GG is there and when DG is configured.

    Thanks

  18. SELECT le.leseq “Current log sequence No”,
    100*cp.cpodr_bno/le.lesiz “Percent Full”,
    cp.cpodr_bno “Current Block No”,
    le.lesiz “Size of Log in Blocks”
    FROM x$kcccp cp, x$kccle le
    WHERE le.leseq =CP.cpodr_seq
    AND bitand(le.leflg,24) = 8
    /

    i have executed the above script. i’m unable to process the output process. Can you guide me.

  19. Dear Admin,

    Thanks for great stuff, if time permits please add performance administration scripts like plan fix, etc.

    Many thanks

  20. one particular tablespace in my database is growing rapidly and i want to know why is this happening. Is there a way i can check how much data has grown in last few months and the table which consumes more space belongs to which owner(user).

  21. Hi Team,

    Can you please add scripts for Golden gate like(Start/stop, Monitor,Replicate, Monitor)

    Also please add scripts for PSU patch RAC database when GG is there and when DG is configured.

    Please add script for relinking CRS and Oracle binary .

    Thanks

  22. Hello Blogger ,

    Issue in this script .

    select module,parsing_schema_name,inst_id,sql_id,plan_hash_value,child_number,sql_fulltext,
    to_char(last_active_time,’DD/MM/YY HH24:MI:SS’ ),sql_plan_baseline,executions,
    elapsed_time/executions/1000/1000,rows_processed from gv$sql
    where sql_id in (‘&sql_id’);

    SQL>
    SQL> select module,parsing_schema_name,inst_id,sql_id,plan_hash_value,child_number,sql_fulltext,
    to_char(last_active_time,’DD/MM/YY HH24:MI:SS’ ),sql_plan_baseline,executions,
    elapsed_time/executions/1000/1000,rows_processed from gv$sql
    where sql_id in (‘&sql_id’); 2 3 4
    Enter value for sql_id: 5573pf9s2vwmh
    old 4: where sql_id in (‘&sql_id’)
    new 4: where sql_id in (‘5573pf9s2vwmh’)
    ERROR:
    ORA-01476: divisor is equal to zero

    no rows selected

    1. Try below one:

      select module,parsing_schema_name,inst_id,sql_id,plan_hash_value,child_number,sql_fulltext,
      to_char(last_active_time,’DD/MM/YY HH24:MI:SS’ ),sql_plan_baseline,executions,
      elapsed_time/executions/1000/1000,rows_processed from gv$sql
      where sql_id in (‘&sql_id’) and executions >0

  23. Hi Admin,first of all i wanna say kudos for the great job put out here,I was
    wondering if you guys can come up with something this great in Golden gate.
    I have a personal issues,can i please get help with a monitoring script,precisely
    setting an alert on table increment…i received the below ticket and i have been working on it

    The issue is whenever there is a LOCK in INCREMENT table users will not be able to access the application and we will reach out to DBA team to get the information under which session the increment table got locked and once we receive the information we provide our confirmation to kill the session. Now we are looking to set up an proactive mechanism which will alert us before user reports the issue. Once the issue has been occurred we will expect the alert to provide us the session name and the server name details.
    Thanks in Advance Admin

  24. excellent information…you made all our days easier with the scripts…….Thank you so much and much appreciated.

  25. Hi Admin,

    Thank you very much for providing such great information in one place.
    Could you please let me know how can I download all these scripts to my desktop at once as we are not having permission to access the google at client place,is there any link like that if yes could you please send me @[email protected].

  26. Hi Admin,

    How to find what bind value with input parameter passing in SQL query from Oracle database backend. Can you provide any other option suggest me.

    ” Application team insert,update,delete or select from third party applications. I need to see what bind (:b1) variables with input parameter values from Oracle database.” How to enable trace particular SQL ID, session, sid in Database.

  27. Thank you for your dedication in IT. I am new to database and this site has everything a newbies need.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

-- Before encrypting decrypting make sure TDE is enabled in database.
-- Encrypt a column

alter table SCOTT.EMP modify ( emp_name encrypt);

alter table SCOTT.EMP modify ( emp_name encrypt using 'AES256');

-- Decrypt a column:

alter table SCOTT.EMP modify ( emp_name decrypt);

NOTE - This activity will take time, according to the table size and it might block other session.
Better to take downtime before doing this activity.