Sunday 3 July 2016

Tablespace Management



By default each database will have five tablespaces in oracle 10g.
  1. System       :  Tablespace-contains data dictionary of database
  2. Sysaux       :   Contains database statistics
  3. Undo         :   Conatins Pre Image data
  4. Temporary : Temporary oprations are performed in this if pga is not enough
  5. Users         :  Default tablespace for all DB users / Application schemas

Creating tablespace :
Sql> create tablespace USER1 datafile '/u01/home/prod1/user.dbf' size 10m autoextend on maxsize 100m default storage (next 10m);

To check tablespace information
Sql> select tablespace_name from dba_tablespaces;

Adding  a datafile to a tablespace
Sql> alter tablespace USER1 add datafile  ‘/u02/user/oratab/prod/uuser2.dbf’ size 100m autoextend on;

Deleting a datafile from a tablespace
Sql> alter tablespace USER1 drop datafile  '/u01/home/prod1/user.dbf';

Droping a tablespace
Sql> drop tablespace USER1;
// it will drop tablespace logically at database level.

Sql> drop tablespace USER1 including contents and datafiles;
// it will drop tablespace logically(database level) and physically(o/s level)

Reusing orphan datafile
Sql> create tablespace USER1 datafile '/u01/home/prod1/user.dbf' reuse;

Resize a Datafile
     Sql> alter database datafile  '/u01/home/prod1/user.dbf' resize 50m;

Making  a tablespace as read only
Sql> alter tablespace user1 read only;
Sql> select tablespace_name,status from dba_tablespaces;
Sql> alter tablespace user1 read write;

Making a tablespace offline
Sql> alter tablespace user1 offline; // Users can not access this tablespace in this state.
Sql> alter tablespace user1 online;

Renaming of tablespace
Sql> alter tablespace user1 rename to employes1;



Steps for Renaming a datafile in tablespace
Steps:-
1.make tablespace offline
Sql> alter tablespace user1 offline;
2. at os level rename the datafile
$cd /u01/app/oracle/data/
$mv user1.dbf  user00.dbf
3. Update the controlfile for this datafile.
Sql> alter database rename file ‘/u01/app/oracle/data/user1.dbf’ to
‘/u01/app/oracle/data/user00.dbf’;
4. Online the tablespace
Sql> alter tablespace user1 online;
Select tablespace_name, file_name from dba_data_files;



Moving table (‘emp’) from one tablespace to another tablespace (users)
Sql> alter table emp move tablespace users;

Moving index from one tablespace to another tablespace
Sql> alter index emp_indx rebuild tablespace user;

To check database size
Select  sum(bytes)/1024/1024 “size in MB” from dba_data_files     

To check free space in database
            Select sum(bytes)/1024/1024 from dba_free_space;

Views:-
V$tablespace                                                   V$datafile
Dba_tablespaces                                             User_tablespaces
Dba_data_files                                                Dba_segments            
Dba_extents                                                    sm$ts_free
Sm$ts_used                                                     sm$ts_avail


Saturday 2 July 2016

Understanding the Upgradation Process




To upgrade oracle database manually from 10g to 11g, we need to use Oracle-supplied pre- and post-upgrade scripts.
If I’m upgrading from an Oracle Database 10g release database to Oracle Database 11g and would need to use the following scripts in turn to perform the manual upgrade.

-          utlu111i.sql
-          catupgrd.sql
-          utilu111s.sql
-          catuppst.sql and
-          utlrp.sql

Following is a summary of the functions performed by each of the upgrade scripts:

utlu111i.sql  (Pre-Upgrade Information Tool)
This gathers information from the database and analyses it to make sure that it meets all the upgrade requirements,… such as whether the database already contains the SYSAUX tablespace or not.
The Pre-Upgrade Information Tool will issue warnings about potential upgrade issues such as database version and compatibility, redo log size, initialization parameters, and tablespace size estimates, and generates warnings if your database doesn’t satisfy the
requirements for upgrading to Oracle Database 11g.

catupgrd.sql This performs the actual upgrading of the database to the Oracle Database 11g release and it now supports parallel upgrades of the database.

utlu111s.sql (Upgrade Status Utility script)
This lets you check the status of the upgrade… whether the upgraded database’s components have a valid status.

catuppst.sql (This is new in Oracle Database 11g Release 1.)
This is the script you run to perform post-upgrade actions.

utlrp.sql This script re-compiles and re-validates any remaining application objects.


Tips :


Tip #1: Either take a Cold or Hot backup of source 10g database (advisable to have cold backup).

Since 11g upgrade requires downtime of oracle database, I strongly suggest to take cold backup beforehand. The reason to do that is to minimize downtime as much as possible. If anything wrong happens during upgrade, we get the most straightforward way to restore source database.

Tip #2: Running utlu111i.sql would be helpful to solve possible pre-requisite problem of upgrade.

Script utlu111i.sql does more than gathering information from database and analysing database. It solves problems which could break the process of upgrade.
For instance, the time zone files required in Oracle 11g has been updated to version 4. Failing doing that will cause break out of upgrade while we do upgrade with running catupgrd.sql. By running script utlu111i.sql, the new time zone file (version 4) will be recorded in view registry$database.

Tip #3: With running utlu111i.sql, making necessary change on parameter file if required.

Running utlu111i.sql will present the report about warnings in upgrade issues such as database version and compatibility, and so on…
Before doing real upgrade, I followed the generated report to change parameter file as per as below.

**********************************************************************

Obsolete/Deprecated Parameters: [Update Oracle Database 11.1 init.ora or spfile]

**********************************************************************

–> "background_dump_dest" replaced by  "diagnostic_dest"

–> "user_dump_dest" replaced by  "diagnostic_dest"

–> "core_dump_dest" replaced by  "diagnostic_dest"

Also, it’s critical that the parameter “compatible" need to be changed from 10.*.*.*.* to 11.1.0.0.0. Otherwise, upgrade process will raise problem and it’s very likely that control file of source database would be corrupt and need to be recovered if upgrade failed. That absolutely make DBA in timely trouble to recover source database.


See Also


Server Maintenance Tasks for a DBA


General Tips to Prepare for an Oracle DBA Job Interview  *HOT*



Click here to Join Our Blog and Stay Updated

DBA Environments



For a DBA, there are two types of environments 

·         Development Environment



·         Production Environment



  • Development Environment


There are 4 stages in this environment 

·         DEV Env.- Development
This is the starting phase of a project. The following tasks are accomplished within this period.
Ø  E-R Modeling

Ø  Database Design

Ø  Database Creation

Ø  Schema/table Creations

Ø  Client- Server configuration.

Ø  Coordinating the team mates to solve day-to-day issues

Ø  Backup and Recovery

Ø  Tuning

·         IT Env.- System Integration Test
After Development stage, vendors (i.e, Projects Developers/ Management) will test all the modules for the validity (both functional and technical). If they find any issues the project will be handed over to developers to fix those issues

·         UAT Env.- User Acceptance Test
This environment is mainly used by the PT (Performance Testing) Team.
The following tasks are done in the phase of the cycle
Ø  DB server CPU Utilization
Ø  DB server IO Utilization
Ø  DB server Memory Utilization
Ø  Application server CPU Utilization
Ø  Application server IO Utilization
Ø  Application server Memory Utilization
Ø  Highly CPU/IO/Memory Utilized Modules


·         OAT Env.- Operations Acceptance Test
This environment is used by Clients. It holds 1 year data or Maximum retention period of production data. Client will test all his functionality and do PT as per his requirements.


·         PRD Env.- Production environment
Testing is no more performed in the environment. This holds real data from the customer/client. This environment will be handled by Client’s DBA or Production DBA.


Ø  PRD Database Creation

Ø  Backup and Recovery

Ø  Schema Refresh from OAT to UAT/SIT/DEV

Ø  Performance Tuning

Ø  Implementing Changes




  • PRODUCTION Environment


There will be more than 2000 databases to be handled. Generally, these databases will be in data centers. The DBAs will work on 24X7 shifts to maintain these databases. The DBAs may work from Client’s place, Data Center or even connect from home. DBAs might sit in different locations and they may get the requests through emails or in the form of tickets. Requests are also called as tickets, work orders, tasks etc. In most cases, DBAs work in shift and they work from various geographical locations.


How Tickets Work?
If the DBAs get requests through mail, they will discuss via chat (chat software like ibm -same time or mind-align etc) and assign the request among themselves.
In some organizations they use ticketing software like ‘remedy’ where the DBAs can assign tickets/requests within themselves or a Team lead will assign the tickets to any of them randomly. Once the request is completed the dba will close the tickets. Once the shift time (normally 8 hrs) of a DBA is over and if he has a task to perform that takes about 3 hours, the task is handed over to the colleague of the subsequent shift and it is called ‘Hand Over’.


The general terms that is used 


·         GOLIVE –To implementation on production

·         SIGN OFF - acceptance mail from client.
·         HANDSHAKE – handing over the incomplete job to another dba after shift timing.
·         WINDOW TIME – maintenance time for database.
·         BOUNCE DB - restart the database.
·         SLA – Service level agreement. Agreement between client and vendor.
·         CLIENT – Who gives work/project
VENDOR- Who does the service