DBA_SCRIPT_UPGRADE

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

    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.

-- 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.

-- Create the directory if not present
create directory EXPDIR as '/export/home/oracle/ORADUMP'

-- Below is the parfile for full db export

cat parfile=compressed.par

dumpfile=schema.dmp
logfile=tables.log
directory=EXPDIR
FULL=Y
compression=ALL

-- Run expdp command
expdp parfile=compressed.par

-- Create the directory if not present
create directory EXPDIR as '/export/home/oracle/ORADUMP'

-- Par file for export with parallel degree 4

cat parfile=parallel.par

dumpfile=parallel_%U.dmp
logfile=tables.log
directory=EXPDIR
schemas=PROD_DATA
parallel=4

NOTE - mention parallel value as per cpu core.

-- Run expdp command

expdp parfile=parallel.par

Same is the command for IMPDP.

-- Create the directory if not present

create directory EXPDIR as '/export/home/oracle/ORADUMP'

-- Par file for export of SCHEMAS(PROD_DATA,DEV_DATA)

cat parfile=schema.par

dumpfile=schema.dmp
logfile=tables.log
directory=EXPDIR
schemas=PROD_DATA,
DEV_DATA

-- Run expdp

expdp parfile=schema.par

For impdp also use the similar command.

-- Create the directory if not present

create directory EXPDIR as '/export/home/oracle/ORADUMP'

--- Par file for export of multiple tables

cat parfile=tables.par

dumpfile=tables.dmp
logfile=tables.log
directory=EXPDIR
tables=PROD_DATA.EMPLOYEE,
PROD_DATA.DEPT,
DEV_DATA.STAGING

-- Run expdp command

expdp parfile=tables.par

--- For exporting table data with query condition

----select * from DBACLASS.EMP_TAB WHERE created > sysdate -40;

-- Parfile

cat expdp_query.par

dumpfile=test.dmp
logfile=test1.log
directory=TEST
tables=dbaclass.EMP_TAB
QUERY=dbaclass.EMP_TAB:"WHERE created > sysdate -40"

It can be used, only with impdp. This helps in generating the DDLs from a dumpfile.
Suppose We have a dump file of table DBACLASS.DEP_TAB . If you need the DDL of the table, then use sqlfile with impdp command as below.

PARFILE SAMPLE:

dumpfile=test.dmp
logfile=test1.log
directory=TEST
tables=DBACLASS.DEP_TAB
sqlfile=emp_tab.sql

note- DDL output will be logged in the emp_tab.sql file

TABLE_EXISTS_ACTION option in IMPDP:

TABLE_EXISTS_ACTION
Action to take if imported object already exists.
Valid keywords are: APPEND, REPLACE, [SKIP] and TRUNCATE.

 

TABLE_EXISTS_ACTION=SKIP:

This is the default option with impdp. I.e if the the table exists, it will skip that table.

TABLE_EXISTS_ACTION=APPEND:

while importing the table, if the table exists in the database, then it will append the data on top the existing data in the table.

impdp dumpfile=emp_tab.dmp logfile=emp_tab.log directory=VEN table_exists_action=APPEND

TABLE_EXISTS_ACTION=TRUNCATE:

While importing the table, if the table exists in database, it will truncate the table and load the data.

impdp dumpfile=emp_tab.dmp logfile=emp_tab.log directory=VEN table_exists_action=TRUNCATE

TABLE_EXISTS_ACTION=REPLACE:

While importing, if the table exists in database, then it will drop it and recreate it from the dump

impdp dumpfile=emp_tab.dmp logfile=emp_tab.log directory=VEN table_exists_action=REPLACE

EXCLUDE/INCLUDE option:

These two options can be used in both expdp or impdp to exclude or include, particular objects or object_types:

Export a schemas DBACLASS, excluding TABLE EMP_TAB and DEPT

dumpfile=test.dmp
logfile=test1.log
directory=TEST
exclude=TABLE:"IN ('EMP_TAB','DEPT')"
schemas=DBACLASS

Exclude few schemas while import:

dumpfile=test.dmp
logfile=test1.log
directory=TEST
EXCLUDE=SCHEMA:"IN ('WMSYS', 'OUTLN')"

export/Import only TABLE and INDEX ( OBJECT_TYPE)

dumpfile=FULL.dmp
logfile=full.log
directory=exp_dir
directory=DBATEST
INCLUDE=TABLE,INDEX

Suppose you wish to take a expdp backup of a big table,
but you don’t sufficient space in a single mount point to keep the dump.
In this case, we take expdp dump to multiple directory.

Create directories to pointing to diff PATH

SQL> create directory DIR1 as '/home/oracle/DIR1';

Directory created.

SQL> create directory DIR2 as '/home/oracle/DIR2';

Directory created.

parfile content

dumpfile=DIR1:test_%U.dmp,
DIR2:test_%U.dmp
logfile=test.log
directory=DIR1
parallel=2
tables=raj.test

Create a directory pointing to asm diskgroup( for dumpfiles)

SQL> create directory SOURCE_DUMP as '+NEWTST/TESTDB2/TEMPFILE';
Directory created

Create a directory pointing to a normal filesystem ( required for logfiles)

SQL> create directory EXPLOG as '/export/home/oracle';
Directory created.

export parfile

dumpfile=test.dmp
logfile=EXPLOG:test.log
directory=SOURCE_DUMP
tables=dbatest.EMPTAB
exclude=statistics

In a RAC database, if you are taking export with parallel option and the
datapump directory is not shared between the nodes, then set CLUSTER=N in expdp/impdp

parfile content:

dumpfile=asset_%U.dmp
logfile=asset.log
directory=VEN
parallel=32
cluster=N