Saturday, February 15, 2014

Oracle Database Administration Scripts | DBA Bundle

Introduction:

Today I'm glad to share with you one of the most helpful tools I ever created to make the common database administration tasks faster, safer and more easier.

This tool I named it DBA Bundle , it's a tar file contains a group of most useful shell scripts that help the database administrator in day to day activities in a smart, safe and easy way, some of these scripts are old but still doing it's job efficiently :-)


Please DOWNLOAD the bundle from this link: [V. 1.7]
https://www.dropbox.com/s/vrhslrg4l5xhzyb/DBA_BUNDLE1.tar?dl=0

You can watch this video tutorial on how to use this bundle: (watch this video in full screen mode)



The most greatest feature in this bundle that it can work on complicated environments to save the DBA time and reduce the human errors.

All scripts in this bundle can easily understand the environment whatever it's Linux or UNIX, most scripts can work fine on different database versions and different oracle homes and different oracle users owners on the same server, all scripts have been designed to smartly handle wrong user inputs.

Now let's get started with the main functions in this bundle ...


How to use the bundle:
=================

First, download the bundle tar file and extract it under Oracle owner home directory, e.g. /home/oracle, please note that each script inside this bundle is independent, in other words, there is no script depend on another script in this bundle, the deletion of any script will not affect the successful execution of other scripts.


Second, I've created a script called "aliases_DBA_BUNDLE.shit will add an alias for each script inside the bundle to the user's profile to make it easy for you to call any script using one command "alias" from any working directory. This is not all, this script creates aliases to easily access the database configuration files and logs
e.g.
alert     command alias will tail -f the ALERTLOG of the selected database|instance.
vialert  command alias will vi the ALERTLOG of the selected database|instance.
tns        command alias will open the tnsnames.ora file using vi editor
lis         command alias will open the listener.ora file using vi editor
There is still more of nice and easy shortcuts will be listed along with it's description after you execute "aliases_DBA_BUNDLE.sh"script .
In order to keep this post abbreviated, I'll let you discover the rest of aliases yourself !

To call script "aliases_DBA_BUNDLE.sh" use "." command: e.g.
#  .  aliases_DBA_BUNDLE.sh

What if I've more than one database on the server, how can I use  "aliases_DBA_BUNDLE.sh" script?

Simple, let's say you've two databases running on the same server 
(SALESDB & ORCL), if you want to use the shortcuts (alert,tns,bdump,..) for SALESDB just run script "aliases_DBA_BUNDLE.sh" and select SALESDB, later if you want to use the shortcuts (aliases) for ORCL DB re-run "aliases_DBA_BUNDLE.shscript then select ORCL, and so on.

Note: Each time you run "aliases_DBA_BUNDLE.shscript it will replace the aliases added in the last execution with new aliases referring to the database you selected.
running script "aliases_DBA_BUNDLE.sh" more than once will not harm.

If you didn't manage to run "aliases_DBA_BUNDLE.sh" 
script , each time you want to call a script you have to step under the location where you extracted the bundle then run the script you want.

Now let me give you a brief description of each script in the bundle:


Script Name      |  Description
------------------|--------------------------------------------
rebuild_table.sh| Script to rebuild a table and its related indexes (New in V. 1.5)
------------------|--------------------------------------------
export_data.sh  | Script Export Full DB|SCHEMA|TABLE data 
                             (gives your the option of using exp or expdp utility for the export).
------------------|--------------------------------------------
RMAN_full.sh | Script Takes an online RMAN full backup for the database 
                           (gives you the option of compressed backup).
------------------|--------------------------------------------
tablespaces.sh   | Script Lists All TABLESPACES and it's size on a database.
------------------|---------------------------------------------
datafiles.sh        | Script Lists All DATAFILES and it's size on a database.
------------------|---------------------------------------------
audit_records.sh | Retrieves AUDIT data for a DB user in a specific date or number of days back.
                            http://dba-tips.blogspot.ae/2014/02/extract-oracle-audit-records-script.html
------------------|---------------------------------------------
zAngA_zAngA.sh | Script Retrieves the AUDIT data for a DB user in a specific date
                                or number of days back. 
                                (this is the one linked to the alias if used "aliases_DBA_BUNDLE.sh" script).
                                 http://dba-tips.blogspot.ae/2014/02/extract-oracle-audit-records-script.html
zanga zanga is a Libyan term used in one of the Gaddafi speeches(the ex-leader of Libya), when he vowed to hunt down protesters alleyway by alleyway but indeed the rebels hunted him down in a sewerage tube.
------------------|--------------------------------------------
gather_stats.sh  | Script Gathers STATISTICS on a SCHEMA or TABLE using DBMS_STATS    
------------------|--------------------------------------------
invalid_objects.sh | Script Lists All Invalid Objects on the DB + it's compile statements.
------------------|---------------------------------------------
biggest_50_objects.sh | Script Lists the Biggest 50 Objects on a database. 
------------------|---------------------------------------------
session_details.sh| Script Lists the Details of a user session. 
                               (if no input, will list all sessions on the instance).
------------------|---------------------------------------------
all_sessions_info.sh| Script Lists All current sessions on all running instances [RAC DB].
------------------|---------------------------------------------
db_locks.sh       | Script Lists the Blocking LOCKS on a database.
------------------|---------------------------------------------
unlock_user.sh | Script Unlocks a specific DB User Account + the option of reset the user's password.
------------------|---------------------------------------------
sql_id_details.sh | Script Shows the details of a specific SQL STATEMENT by providing it's SQL_ID.
------------------|---------------------------------------------
parameter_val.sh | Script Shows the value of a Visible or Hidden initialization Parameter.
------------------|---------------------------------------------
db_jobs.sh         | Script Lists All database Jobs (dba_jobs + dba_scheduler_jobs).
------------------|---------------------------------------------
process_info.sh| Script Shows the DB Session details when providing it's Unix PID.
------------------|---------------------------------------------
oracle_cleanup.sh| Script Backup & Clean up All DB & it's Listener LOGs.
------------------|---------------------------------------------
last_logon_report.sh| Script Shows the last login date of ALL users in the database.
------------------|---------------------------------------------
failed_logins.sh| Script Shows the failed login attempts in the last provided n of days.
------------------|---------------------------------------------
start_tracing.sh | Script Start TRACING an Oracle Session activities in a logfile.  
                             http://dba-tips.blogspot.ae/2014/02/script-to-trace-oracle-sesson.html  
------------------|---------------------------------------------
stop_tracing.sh | Script Stop TRACING an already traced Oracle Session 
                            + provide the logfile and it's TKPROFED log.  
                             http://dba-tips.blogspot.ae/2014/02/script-to-trace-oracle-sesson.html  
------------------|---------------------------------------------
user_details.sh | Script Generates the Full SQL Creation script for a DB user + important info.
------------------|---------------------------------------------
object_ddl.sh    | Script Generates Full SQL Creation script for a database Object.
------------------|--------------------------------------------
Archives_Delete.sh| Script Deletes all Archivelogs older than (provided) number of days.
------------------|--------------------------------------------
analyze_objects.sh| Script Analyze All tables under a specific SCHEMA (using ANALYZE command).
------------------|--------------------------------------------
table_info.sh     | Show all important info about specific table (size, indexes, non indexed FK, constraints,...).

Scripts without alias:
****************
The following scripts doesn't have aliases because it's not applicable or need to be used carefully:
--------------------------------------------------------------
dbalarm.sh | Script Monitors CPU utilization + Filesystem usage + ALERTLOGs of ALL Databases and
                     Listeners running on the server and instantly report ORA- errors and TNS- errors
                     that appears in these logs to the DBA E-mail Address
                     by sending an email to the DBA 
                     (you have to modify this parameter in line number 16 to point to your E-mail Address):
                      MAIL_LIST="youremail@yourcompany.com"

                      > Of course the sendmail service should be configured on the server.


                                  *The best use of this script is to schedule it's execution in the crontab 

                                    to run every 5 minutes (or less) to report ORA- and TNS- errors 
                                    when they appear in the DBs & listeners logs.
                                    http://dba-tips.blogspot.ae/2014/02/database-monitoring-script-for-ora-and.html
-------------------------|----------------------------------------------
SHUTDOWN_All.sh  | Script to SHUTDOWN ALL running Databases & Listeners on The server.
-------------------------|----------------------------------------------
COLD_BACKUP.sh  | Script Takes a COLD BACKUP of a specific database 
                                     (It will also creates another script to help you restore the taken cold backup easily) 
                                     This script will shutdown the database, takes a cold backup, 
                                     creates a restore script (in case you want to restore this cold backup
                                     later ) then indeed it will startup the database.
                                     http://dba-tips.blogspot.ae/2014/02/cold-backup-script.html
--------------------------------------------------------------

That's all regarding this bundle, please note that time by time I'll update this bundle (adding new scripts, fixing bugs, adding new features). (This topic did not cover everything in this bundle).

LASTLY, as I mentioned in each script, I'M SHARING THIS BUNDLE AND IT'S SCRIPTS IN THE HOPE THAT IT WILL BE USEFUL FOR YOU, BUT WITHOUT ANY WARRANTY. ALL SCRIPTS IN THIS BUNDLE ARE PROVIDED "AS IS".

                                           No one is perfect... that's why pencils have erasers.

Again you can download the Database administration Bundle from here: [V. 1.7]
https://www.dropbox.com/s/vrhslrg4l5xhzyb/DBA_BUNDLE1.tar?dl=0

Older versions are downloadable from here: 
https://app.box.com/s/l4cmpxfrfy8t6emqrpgo [V. 1.1]
http://snk.to/f-cdufbjic [V. 1.2]
http://snk.to/f-cdpmy98p [V. 1.3]
http://snk.to/f-cdt3e98p [V. 1.4]
http://snk.to/f-ctp8rmpx  [V. 1.5]
http://snk.to/f-cdnqo5mu [V. 1.6]

Your suggestions, bug reporting and comments are most welcome :-)

Lastly, a special thanks to my friend Sr. DBA: Abd El-Gawad Othman for his support and encouragement.

16 comments:

mohamed said...

Thanks a lot

Anonymous said...

great job, thanks for sharing!

Rahul N said...

Great work. Thank you!!

Mahmmoud ADEL said...

Mohamed, Anonymous gentleman, Rahul
Thanks to you, I hope this bundle be beneficial for you.

manoj said...

Superb Mohamed, its one thing to spend your time on developing this beauty..but to share it for free, its something else.. :) Thanks a ton..

Mahmmoud ADEL said...

Manoj,
Thank you for your nice compliment, long time back since I started my career in Oracle world, I've got tons of invaluable information from others web sites and blogs. now it's time to reciprocate the favor to the Oracle community by sharing my humble knowledge hoping that help others.

gnz_bLog said...

Thanks a lot for sharing

Venk@t Oracle DBA's said...

Thanks a lot Mahmmoud Adel it's very useful for daily activity for DBA.

Anonymous said...

Thanks Mahmomoud! That is really useful set of scripts!

Jean-Pierre Tomes said...

thank you, i am going read all yours scripts
Jean-Pierre

Jean-Pierre Tomes said...

thank you for yours scripts

Jean-Pierre Tomes said...

thanks you for yours scripts
Jean-Pierre

Vishal Pawar said...

Thank you sir for valuable information.

vikram reddy said...

Thanks Mohamed!! Appreciate your efforts.

Anonymous said...

Very kind of you! Thanks

Anonymous said...

this is really awesome....Greatly appreciate...