Download doc - dba lect

Transcript
Page 1: dba lect

DATABASE ADMINISTRATION

RESPONSIBILITIES OF DBA.1-instal and update the oracle application software’s.2.start and stop the oracle instance.3.maintain security policies, such as control user access to resources and information.4- tunes the database.5. Perform the physical database design.6- be on call when problems occur with the database.7- keeps current with database, operating system and application development techonologies.8- performs database backup and recovery as required daily, weekly and monthly.9 - assists developer in designing tables and queries for high efficiency.10- keep your and users skill up to date.11- performs future year planning.12- provides necessary support and guidance to the user and programmers.----------------------------------------------------------IMPORTANT DBA TASKS (is the database secure enough?)There are four major arias that need to be considering for database security.1 - traditional backup & recovery mechanism that provide security against losing data due to media failure.2- security against unauthorized instruction into the system and possible alternation of the data.3- accident corruption of the data by an authorized user of the system.4-ability to keep the system running in the event of the destruction of the data center or office in which your database server sits.

Page 2: dba lect

-----------------------------------------------------------SUGGESTION TO MAKE DATABASE SECURE1-change the default oracle password, because the most of the people know the default password of administration level user are system/manger, internal/oracle, sys/chang_on_install.2- keeps the users privileges or rights to the minimum with respect to job title.3- avoid easy password.4- keeps changes your password after some time provide.5- keeps the backup media very secure and away from data center.-----------------------------------------------------------

ORACLE MEMORY STRUCTURE

ORACLE INSTANCE

SGA (SYSTEM GLOBAL AREA)

DATABASE BUFFER CACHE REDO LOG BUFFER SHARED POOL

35% CHANGES 20% COMMANDS 45%

RECORD INSERT RECOVERY

SMONPMON DBWR LGWR CKPT

DATA FILES REDO

LOG FILES

CONTROL FILES

SERVER PROCESSOR

USER PROCESS

SSA

DDL

ARCC

Parameter FilePassword File

Archive Log file

Page 3: dba lect

ORACLE SERVERConsist of an oracle instance and oracle database.

ORACLE INSTANCEConsist of memory structure called sga (system global area) SGAConsist in memory region, which contains data and control information, where oracle server resides. The sga including shared pool, dtatbase buffer cache and redo log buffer.

SHARED POOLUsed to store information such as the most recently execute sql commands from data dictionary.

DATABASE BUFFER CACHEIt is the most important area when a query is processed; the server process looks for the blocks needed in the database buffer cache. If record not available then dbwr search the information TYPES OF DATABASE BUFFER CACHEThere are two types of database buffer cache.1.cache hit (fast work)2.cache miss (slow work)DATABASE BUFFER CACHE LISTSDatabase buffer cache has two lists1- LRU (list recent used) mru (most recent used end) Lru (least recent used end)2- Dirty list (image of blocks before reuse)

SERVER PROCESSWhen user process connect the front-end tool in oracle database server, basically connected sga. This is called server process. We do not directly connected sga. Firstly we create a server process then he transfers sga.SERVER PROCESS HAS THREE STEPS.

1- Parsing User process sends the query to server process to check syntax, validity of commands.

2- Execute

Page 4: dba lect

The processing of the query, server process prepare to database.3- Fetch

To transfer result of query to the users

BACKGROUND PROCESS

1- Database writer (DBWR)Responsibilities for writing change the data to the database buffer cache. 2- Log writer (LGWR)Records change registered in the redo log buffer to database.3- System Monitor (SMON)Its primary function is to check for consistency and initiate recovery of database when the database is opened.4- Process Monitor (PMON)

Cleanup the resources, if one of the process fail. NOTE= if above four process are damaging then sga will also damage automatically order that database is damage and then again restart.

5- Check Point (CKPT) To check any task perform to control all dirty database buffer covered by the log being ckpt are written to the data files by dbwr.

6- Archived (ARC)Make duplicate files of any information in off line media.

DATABASE FILESAn oracle database has consisted of the following types of file.

1- Data File Store the data dictionary, user objects and before image of data that are modified by current transactions.A database has at least one data file.

2- Control file Contain the information needed to maintain and verify database integrity. Oracle’ name information in control file.If control file damage then never database start.At least one control file needed for database.

3- Redo log file

Page 5: dba lect

Contain a record of damage made to database to ensure reconstruction of database in case of failure. A database requires at least two redo log files.

OTHER KEY PHYSICAL STRUCTURE

1- Parameter FileUse to define the characteristics of an oracle instance, how much area cover by sga, memory information, all names of control file in parameter files.2- Password file Use to authenticated privileged database users.3- Archived Log File Off line copies of the redo log files that may be necessary to recover from media failure.

STARTING SERVER MANAGER IN LINE MODE.

ON UNIX > SVRMGR1 (IN RUN OPTION) ONLY FOR ORACLE 8ON WINDOW NT/2000/XP > SVRMGR30 (IN RUN OPTION)

SVRMGR> CONNECT SYS/ORACLE AS SYSDBA;

STARTUP AND SHUTDOWN STAGES

Open STARTUP Mount No mountShutdown

SHUTDOWN

Database administrator can start database in one of three following different states.

1- No MountThis state is used to create the database. (Instance started).2- MountThis is used to alter file structured, modify control file, data recovery. (Control file open for dba).

Page 6: dba lect

3- Open In this state the database is available to all users.

Svrmgr>connect sys/oracle as sysdba;Svrmgr>startup;If the instance already started, force option can be used.Svrmgr> startup force;

Svrmgr>startup mount force;

Svrmgr>startup force nomount;

Mount the database if database already in no mount state. ThenSvrmgr>alter database mount;Svrmgr>alter database open;

RESTRICTED SESSIONDBA not want to allow ordinary user to connect the database.SVRMGR>startup restricts;

Enabling restricted session in open database.Svrmgr> alter system enable restricted session;Svrmgr> alter system disable restricted session;

SHUTTING DOWN THE DATABASEIt is also responsibility of dba to shutdown the database is not available to all users.Following commands can be used to shutdown the database in server manager.

1- Shutdown normal2- Shutdown transactional3- Shutdown immediately4- Shutdown abort

Shutdown normalShutdown normal is default option in database will make the dba to wait for all other users to finish but they are doing before database will actually close. In shutdown normal no new connection are allowed.Svrmgr> shutdown or Svrmgr> shutdown normal;

Shutdown transactionIt’s used to bring down the database as soon as the users complete their current transaction. This option waits for current transaction, which are not completed. When all transaction completed then close the database.

Page 7: dba lect

Svrmgr> shutdown immediate;

Shutdown immediateIn which oracle server doesn’t wait for currently connected users to log off from the database.Svrmgr>shutdown immediate;

Shutdown abortIn which current client sql statements being processed by the oracle server are not completed and abort.Svrmgr> shutdown abort;

DATABASE CREATIONIt is very important task. But this is not usual task. Creating a database is multiple steps operation, which must be performed carefully. When you can create database with two methods. One is manually and other is gui (graphic user interface). Oracle database can be altered after creation, more files can be added, and size can be changed. Some modification is not allowed after creation of database like db_block_size cannot be changed.

BEFORE CREATING A DATABASEHARDWARE RESOURCES, MEMORY AND DISK SPACEOPERATING SYSTEM PRIVILAGESLOCATION AND SIZE OF FILEPREPAREING PARAMETER FILEORACLE SOFTWAREEXISTING DATABASE BACKUP

STEPS OF CREATE DATABASE MANUALLYNOTE:. THE MINIMUM REQUIREMENT OF DATABASE CREATION IS THAT IT MUST HAVE ONE DATA FILE, ONE CONTROL FILE AND TWO REDO LOG GROUPS AND ATLEAST ONE MEMBER IN EACH GROUP.

1. CREATE A DIRECTORY AT ANY LOCATION FOR EXAMPLE D:\MYDATABASE\2. COPY INITORCL.ORA FILE FROM DEFAULT LOCATION TO

ABOVE LOCATION.FOR EXAMPLE D:\MYDATABASE\INIT.ORANOW MODIFY INIT.ORA FILE REQURIED. SOME PARAMETER SHOULD BE CHANGED FOR BETTER MANAGEMENT. FOR EXAMPLE DB_NAME= DYNAMIC CONTROL_FILE= ‘E:\MYDATABASE\CONTROL.ORA’

Page 8: dba lect

REMOTE_LOGIN_PASSWORDFILE=SHARED3. NOW RUN SERVER MANGER OR SQL/PLUS AND STARTUP

INSTANCE IN NOMOUNT STATE.

SVRMGR>STARTUP NOMOUNT PFILE=E:\MYDATABASE\INITORCL.ORAFORCE;

THEN

SVRMGR>CREATE DATABASE DYNAMICDATAFILE ‘E:\MYDATABASE\DATAFILE1.ORA’ SIZE 20 MLOGFILEGROUP 1 ‘E:\MYDATABASE\LOG1.RDO’ SIZE 500 K,GROUP 2 ‘E:\MYDATABASE\LOG2.RDO’ SIZE 500 K;

Table spaces

Bit 8bit =1 byteByte 512 bytes = 1 blockBlock 5 block = 1 extendExtend 1 extend = segmentsSegment segments = tables spacesTable space table space = databaseDatabase

Definition of table spaceThe smallest pieces of the segments in database are called table space.Every table space has one data file. Types of table space1- System table space2- User data3- Temporary data4- Rollback data

System table spaceTheir users for all user of database its work by default.Its data file name is sys1orcl.ora.

Page 9: dba lect

User dataIts user for giving space to other usersIts data file name is usr1orcl.ora

Temporary dataIf space full that will use the user then dba assign temporary space given by temporary data.Its data file name is temp1orcl.ora

Rollback dataIn this table space has keep old image of the data.Its data file name is rbs1orcl.ora

Objective:•Describing the logical structure of the database •Creating Tablespaces•Changing the size of Tablespaces using different methods •Changing the status and storage settings of Tablespaces•Relocating Tablespaces •Preparing necessary Tablespaces

TYPES OF TABLESPACE1-SYSTEM Tablespacescontains:–Data dictionary information–SYSTEM rollback segment

2-Non-SYSTEMTablespaces contains:–Rollback segments–Temporary segments–Application data–Application indexes

Creating TablespacesCREATE TABLESPACE ADNANQASIRDATAFILE ‘C:\ORANT\DATABASE\NEWDATA1.dbf’ SIZE 100M, ‘C:\ORANT\DATABASE\NEWDATA2.dbf’ SIZE 100M

Page 10: dba lect

MINIMUM EXTENT 500KDEFAULT STORAGE (INITIAL 500K NEXT 500K MAXEXTENTS 500 PCTINCREASE 0);

Storage Parameters The following parameters influence the segment storage allocation:• INITIAL

• NEXT

• MAXEXTENTS

• MINEXTENTS

• PCTINCREASE

Temporary Tablespace•Used for sort operations

• Cannot contain any permanent objectsCREATE TABLESPACE sortDATAFILE ‘/DISK2/sort01.dbf’ SIZE 50M MINIMUM EXTENT 1MDEFAULT STORAGE (INITIAL 2M NEXT 2M MAXEXTENTS 500 PCTINCREASE 0) TEMPORARY;

Adding Data Files to a TablespaceALTER TABLESPACE ADNANQASIR ADD DATAFILE ‘/DISK5/app03.dbf’ SIZE 200M;

Enabling Automatic Extension of Data FilesALTER TABLESPACE ADNANQASIR ADD DATAFILE ‘/DISK6/app04.dbf’ SIZE 200MAUTOEXTEND ON NEXT 10MMAXSIZE 500M;

Page 11: dba lect

Changing the Size of Data Files ManuallyALTER DATABASE DATAFILE ‘C:\ORANT\DATABASE\NEWDATA1.dbf’ RESIZE 50M;

Changing the Storage SettingsALTER TABLESPACE ADNANQASIR MINIMUM EXTENT 2M; ALTER TABLESPACE ADNANQASIRDEFAULT STORAGE (INITIAL 2M NEXT 2M MAXEXTENTS 999);

OFFLINE Status •The tablespace that is offline is not available for data access.• The SYSTEM tablespace and any tablespace with active rollback segments cannot be taken offline.

ALTER TABLESPACE app_data OFFLINE;

Moving Data Files:ALTER TABLESPACE

•The tablespace APP_DATA must beoffline. •The target data files must exist.

ALTER TABLESPACE app_data RENAME DATAFILE ‘/DISK4/app01.dbf’ TO ‘/DISK5/app01.dbf’;

Moving Data Files:BY OPERATING SYSTEM (DOS)

Page 12: dba lect

MOVE C:\ORANT\DATABASE\NEWDATA2.DBF E:\MYDATABASE\NEWDATA2.DBF

Moving Data Files: ALTER DATABASE •The database must be mounted. •The target data file must exist.ALTER DATABASE RENAME FILE ‘/DISK1/system01.dbf’ TO ‘/DISK2/system01.dbf’;

The READ-ONLY Tablespace StatusALTER TABLESPACE app_data READ ONLY;

The tablespace APP_DATA is only available The tablespace APP_DATA is only available for read operations. for read operations.

Making Tablespace Read-Only •The tablespace must be online.

• No active transactions are allowed.

• The tablespace must not contain active rollback segments.• The tablespace must not currently be involved in an online backup.

Dropping TablespacesThe following statement removes the APP_DATA tablespaceThe following statement removes the APP_DATA tablespace and all its contents.and all its contents.DROP TABLESPACE app_data INCLUDING CONTENTS;

Obtaining Tablespace Information(Select * from v$dba_tablespace)DBA_TABLESPACES •TABLESPACE_NAME•NEXT_EXTENT•MAX_EXTENTS•PCT_INCREASE•MIN_EXTLEN•STATUS•CONTENTS

Page 13: dba lect

Obtaining Data File InformationDBA_DATA_FILESDBA_DATA_FILES•FILE_NAME•TABLESPACE_NAME•BYTES•AUTOEXTENSIBLE •MAXBYTES•INCREMENT_BY

Storage Structure and RelationshipsObjective:•Listing the different segment types and their uses•Controlling the use of extents by segments•Stating the use of block space utilization parameters by objects•Obtaining information about storage structures from the data dictionary•Locating the segments by considering fragmentation and life-spans

Types of SegmentsTableTableTable partitionTable partitionClusterClusterIndexIndexIndex-organized tableIndex-organized tableIndex partitionIndex partitionRollback segmentRollback segmentTemporary segmentTemporary segmentLOB segmentLOB segmentLOB index LOB index Nested tableNested tableBootstrap segmentBootstrap segment

Extent Allocation and Deallocation•Allocated when the segment is+Created +Extended+Altered•Deallocated when the segment is

Page 14: dba lect

–Dropped–Altered–Truncated–Automatically resized (rollback segments only)

Database Block: Review•Minimum unit of I/O•Consists of one or more O/S blocks•Set by DB_BLOCK_SIZE•Set at database creation

Database Block Contents

Block Space Utilization Parameters

Page 15: dba lect

Block Space UsagePCTFREE=20PCTFREE=20 PCTUSED=40PCTUSED=40

InsertsInserts1

Data Dictionary Views Used extentsDBA_EXTENTS

2-freextentsDBA_FREE_SPACESegments

DBA_SEGMENTSData files

DBA_DATA_FILESTablespaces

DBA_TABLESPACES

Querying Segment InformationDBA_SEGMENTS–General information–OWNERSEGMENT_NAME –SEGMENT_TYPE –TABLESPACE_NAME

–Size– EXTENTS– BLOCKS

–Storage settings– INITIAL_EXTENT– NEXT_EXTENT – MIN_EXTENTS – MAX_EXTENTS – PCT_INCREASE

Page 16: dba lect

Organizing Tablespaces Based on Fragmentation Propensity

Relevant only if tablespace Relevant only if tablespace PERMANENTPERMANENT

TablespaceSYSTEMTOOLSDATAn

INDEXn

RBSn

TEMPn

FragmentationZeroVery lowLowLowHighVery high*

Usage Data dictionaryApplicationsData segmentsIndex segmentsRollback segmentsTemporary segments

Page 17: dba lect

Recommended