Oracle DBA学习杂记(一)

来源:互联网 发布:windows下安装webpack 编辑:程序博客网 时间:2024/05/21 20:25


Oracle DBA Summary

Oracle DB大体包括两个部分:InstanceDatabase。其中Instance主要是指内存结构,主要由SGAPMONSMONDBWRCKPT等构成;Database主要是指物理结构,主要由三种文件Control fileData fileOnline Redo log file构成。

Oracle Server is a databse management system that consistsof an Oracle instance and an Oracle databse.

Oracle Instance

An Oracle instance is a means to access an Oracle databse.

Always opens one and only one database

Consists of memory and background process structures.

Connection指的是Client端与Oracle Server端建立的一个TCP连接

Background Process专注于数据库核心任务,Server Process专注与服务响应客户端。在建立连接并通过身份验证,安全审计之后才允许建立一个会话Session

An Oracle databse is a collection of data that is treatedas a unit

Oracle Database除了三种基础文件之外,还有Password file Parameter fileArchived log file等多种辅助文件

Oracle’s memory structure consits of two memory areas: SGAand PGA.

PGA is allocated when the server process is started. SGA isallocated at instance start up.

SGA consists of serveral memory structures:

1SharedPool

2DatabaseBuffer Cache

3RedoLog Buffer

4Other(LockLatchLarge Pool/Java Pool等可选项)

通过sqlplus中的show sga命令可以看到SGA的当前分配大小

SGA is sized by the SGA_MAX_SIZE parameter(在9i版本之后可以动态的变化适应增长)

GranulesSGA增长新分配的最小单位,SGA小于128MGranules默认为4M,超过了128M之后Granules16M

查看GranulesSQL语句:select component,granule_size from v$sga_dynamic_components

Shared Pool主要作用是存储最近执行的SQL语句和最近被用到的数据定义。由LibraryCacheDataDictionary Cache两块共享内存,直接影响到数据库性能。更改SharedPool尺寸的命令是:ALTERSYSTEM SET SHARED_POOL_SIZE=64M

Library Cache stores information about the most recentlyused SQL and PL/SQL statements (均为经过编译解析之后的,使用LRU算法)

Data Dictionary CacheA collection of the most recently used definitions in thedatabase. Includes information about database files, tables, indexes, columns,users, privileges, and other database objects.

Database Buffer Cache (最大的一块共享内存)

Stores copies of data blocks that have been retrieved fromthe data files. DB_BLOCK_SIZE determines primary block size. 针对它的统计信息可以在V$DB_CACHE_ADVICE表中查看

Redo Log Buffer records all changes made to the databasedata blocks. Its size defined by LOG_BUFFER.

Large Pool用于处理一些额外工作,比如I/OServer processes或者RMANBackup的时候

对于同一台机器的两个进程通讯有两种方式:一种是走IPC,包括共享内存、队列和信号量等几种形式;另外一种是方法是走模拟TCP/IP,即走look back环路网卡通信。

DBWn writes when: Checkpoint occursDirty buffers reach thresholdThere are no free buffersTimeout occursRAC ping request is madeTablespace OFFLINETablespace READ ONLYTable DROP or TRUNCATE等等

LGWR writes at commitWhen one-third fullWhen there is 1MB of redoEvery three seconds Before DBWn writes

Block Oracle最小的逻辑单位,由若干个OS 文件系统Block组成,重要相关参数是DB_BLOCK_SIZE,连续的Block组成了Extent

DB Administration Tools:

1OUI:used to install, upgrade, or remove software components

2DBCA:简单的GUI帮助创建数据库Instance

3SQL*Plus

4OEM:全面的管理控制界面,但每一代都变化很大

如果要在字符界面安装,需要准备一个responsefile,运行静默安装命令:

./runInstaller –responsefile myrespfile –silent

这个responsefileOracle的解压目录有模板文件,只需要稍加修改就可以直接使用。(在加压Oracle目录下的response目录中)

User SYS is owner of the database data dictionary, 其密码必须在安装的时候指定。

User SYSTEM is owner of additional internal tables andviews used by Oracle tools, default password is manager.

The SID is a site identifier. It and ORACLE_HOME are hashedtogether in UNIX to create a unique key name for attaching an SGA. If yourORACLE_SID or ORACLE_HOME is not set correctly, you’ll get the ORACLE NOT AVAILABLEerror, since you cann’t attach to a shared memory segment that is identified bythis unique key.

On Windows, shared memory isn’t used in the same fashion asUNIX, but the SID is still important. You can have more that one database onthe same ORACLE_HOME, so you need a way to uniquely identify each one, alongwith their configuration files.

参数文件有PFILESPFILE,其中PFILE就是一个文本文件,可以使用编辑器直接编辑,默认路径是ORACLE_HOME/dbs下,可以通过模板文件init.ora来创建,一般命名方式是initSID.oraSPFILE是一个二进制文件,相对于PFILE一直存在于Server sideSPFILE可以被RMAN备份,PFILE不行,SPFILE可自适应参数调整。可通过PFILE创建出SPFILE:

CREATE SPFILE=’spfile***.ora’ FROM PFILE=’init***.ora’;

如果要修改SPFILE里面的值,可以使用如下命令:alter systemset parameter=value <comment=’text’> <deferred><scope=memory|spfile|both> <sid=’sid|*’>

在数据库startup的时候,优先寻找spfileSID.ora,然后是DefaultSPFILE,然后是initSID.ora,最后是Default PFILE。也可以显式的指定启用使用的Parameterfile,优先使用命令指定的文件。

只有两种用户可以启停数据库:

1The user’s operating system privileges allow him or her toconnect using administrator privileges

2The user is granted the SYSDBA or SYSOPER privileges andthe database uses password files to authenticate database administrators.

数据库的启动过程经历的状态一共有四种:SHUTDOWN->NOMOUNT->MOUNT->OPEN

*   NOMOUNT状态的时候OracleInstance启动,分配SGA,启动后台进程,但此时没有任何DatabaseSGA内存关联

*   在切换到MOUNT状态的时候,theinstance finds the database control file and open them,本质上是把一个database和一个instance关联起来。OracleDatabase then reads control files to get the names of data files and redo logfiles. At this point, the database is still closed and is accessible only tothe database administrator and not available for normal operations.

*   最后进入OPEN状态,就进入了正常工作的状态。OracleDatabase opens the online redo log files and data files. 没有这两种文件的话,数据库就会报错无法启动。

受限模式:RESTRICT MODE,只有特权用户才能操作使用数据库,一般用户无法连接数据库。

只读模式:READ ONLY MODE,使用命令ALTERDATABASE OPEN READ ONLY;

如何杀掉一个连接进来的用户会话:alter system kill session ‘<SID,SERIAL#>’

关闭数据库的过程:

首先会把所有SGA中缓存的数据写入数据文件并关闭联机重做日志文件;接下来Un-mountDatabase即取消DatabaseInstance的关联关系;最后才是Shutdown内存中的Instance

Background trace file命名:SID_processname_PID.trc,location parameter is BACKGROUND_DUMP_DEST

User trace命名规则:SID_ora_PID.trc, locationparameter is USER_DUMP_DEST.,打开User Trace,推荐基于SessionLevel的命令:ALTER SESSION SET SQL_TRACE=TRUE

Alert_SID.log file records the day-to-day operationinformation, results of major events, must be managed by DBA, locationparameter is BACKGROUND_DUMP_DEST.

数据库类型:OLTP(大量并发,小型事务的联机事务处理型) OLAP(少量并发,大型事务的数据仓库型)

OFA involves three major rules(OptimalFlexible Architecture)

*   Establisha directory structure where any database file can be stored on any diskresource

*   Separateobjects with different behavior into different table-space

*   Maximizedatabase reliability and performance by separating database components acrossdifferent disk resource

 

原创粉丝点击