Oracle的体系结构概览
声明:版本11gR2,CentOS5.8 1 物理结构(文件) 主要性能影响在IO上 (1)controlfile select * from v$controlfile (2)datafile select * from dba_data_files (3)redo?(online logfile) select * from v$logfileselect * from v$log (4)password file
声明:版本11gR2,CentOS5.8
1 物理结构(文件)
主要性能影响在IO上
(1)controlfile
select * from v$controlfile
(2)datafile
select * from dba_data_files
(3)redo?(online logfile)
select * from v$logfile select * from v$log
(4)password file(sys)
select * from dba_users
(从11g开始password项里变为空了,以免被破解)
2 逻辑结构
2.1 实例
instance(memory[sga]+process[background])
实例=内存(sga)+后台进程(background)
查看内存,可以通过以下视图
select * from v$sga_dynamic_components
?后台进程,可以通过下面视图查看
select * fromv$bgprocess where paddr!='00';
? 我们只关心paddr不等于0的就可以了,等于0的都是没启用
2.2实例的管理
参数文件spfilesid.ora,initsid.ora
两个文件可以互相转化
create spfile from pfile; create pfile from spfile;
(1)开启实例分为nomount,mount,open三个阶段

l? nomount阶段
在开启到nomount阶段需要使用到参数文件,而从9i版本开始默认优先使用spfile参数文件,如果spfile文件没有就去使用pfile文件,如果pfile文件还没有,就会报找不到pfile文件的错误。
11g有一个新功能,也许是我才发现吧!!!首先先说下数据库开启时,如果参数文件丢失或者损坏,不会导致数据库直接宕掉,但是如果数据库重新启动的话,就会报错,而且如果要是没有个好的备份的话,那是非常麻烦的事情,如果数据库在运行时及时发现了参数文件丢失或者损坏,可以使用如下方法处理:
create pfile from memory;
所以参数文件一定要有个良好的备份。
可以通过v$instance视图查看数据库状态
select status from v$instance;
通过v$bgprocess视图可以查看后台进程的情况
select * from v$bgprocess where paddr’00’;

l? mount阶段
开启mount阶段需要用到控制文件
可以使用参数control_files查看控制文件所在位置:
show parameter control_files
如果控制文件损坏,在开启数据库的时候就会报错,而且告诉你去alert_sid.log里看具体错误信息,而这个文件所在位置,可以通过background_dump_dest参数去查看:
show parameter background
注:alert_sid.log最大支持到2G大小,所以当业务特殊繁忙或者文件变的比较大的时候需要备份。
l? open阶段
11gR2版本—经测试,其他版本不确定
可以从open阶段到mount阶段在到nomount阶段
alter database close; alter database dismount; shutdown immediate
(2)关闭实例
1.normal
2.transactional
系统有事务的时候就关闭不了
系统有没有事务可以查看v$transaction视图
3.immediate
4.abort
2.3 参数的粗略概述
用db_cache_size和processes两个参数举例
首先查看v$parameter视图可以查看是否是静态参数或者是动态
select name,issys_modifiablefromv$parameter wherename in ('db_cache_size','processes'); NAME ISSYS_MOD -------------------- --------- processes FALSE db_cache_size IMMEDIATE
从ISSYS_MOD字段可以看出db_cache_size参数是立即生效,所以从这个可以看出db_cache_size字段是动态参数。
注意:其中processes参数如果过多比如更改为50000个数量的时候,数据库在重新启动的时候会挂住。
?
2.4 session(process)
A)process
select * from v$process;
包含v$bgprocess
l? 通过如下以下方法可以追溯到OS系统的进程
SQL> select distinct sid fromv$mystat; SID ---------- 37 SQL> select sid,paddr fromv$session where sid=37; SID PADDR ---------- -------- 37 43BC365C SQL> select addr,pid,spidfrom v$process where addr='43BC365C'; ADDR PID SPID -------- ---------------------------------- 43BC365C 20 11633 [root@elvis ~]# ps -ef | grepora root 3762 3732 0 May30 ? 00:01:02 hald-addon-storage: polling/dev/hdc oracle 4604 1 0 May30 ? 00:00:02/u01/oracle/product/11.2.0/dbhome_1/bin/tnslsnr LISTENER -inherit oracle 7624 1 0 06:22 ? 00:00:07 ora_pmon_elvis oracle 7628 1 0 06:22 ? 00:00:35 ora_vktm_elvis oracle 7634 1 0 06:22 ? 00:00:00 ora_gen0_elvis oracle 7638 1 0 06:22 ? 00:00:01 ora_diag_elvis oracle 7642 1 0 06:22 ? 00:00:00 ora_dbrm_elvis oracle 7646 1 0 06:22 ? 00:00:01 ora_psp0_elvis oracle 7650 1 0 06:22 ? 00:00:35 ora_dia0_elvis oracle 7654 1 0 06:22 ? 00:00:05 ora_mman_elvis oracle 7658 1 0 06:22 ? 00:00:03 ora_dbw0_elvis oracle 7662 1 0 06:22 ? 00:00:02 ora_lgwr_elvis oracle 7666 1 0 06:22 ? 00:00:16 ora_ckpt_elvis oracle 7670 1 0 06:22 ? 00:00:06 ora_smon_elvis oracle 7674 1 0 06:22 ? 00:00:00 ora_reco_elvis oracle 7678 1 0 06:22 ? 00:00:11 ora_mmon_elvis oracle 7682 1 0 06:22 ? 00:00:07 ora_mmnl_elvis oracle 7686 1 0 06:23 ? 00:00:00 ora_d000_elvis oracle 7690 1 0 06:23 ? 00:00:00 ora_s000_elvis oracle 9125 1 0 10:26 ? 00:00:00 ora_arc0_elvis oracle 9129 1 0 10:26 ? 00:00:00 ora_arc1_elvis oracle 9133 1 0 10:26 ? 00:00:00 ora_arc2_elvis oracle 9137 1 0 10:26 ? 00:00:00 ora_arc3_elvis oracle 9177 1 0 10:31 ? 00:00:00 ora_smco_elvis root 11596 11564 0 16:36 pts/0 00:00:00 su - oracle oracle 11597 11596 0 16:36 pts/0 00:00:00 -bash oracle 11629 11597 0 16:36 pts/0 00:00:00 rlwrapsqlplus / as sysdba oracle 11630 11629 0 16:36 pts/1 00:00:00sqlplus as sysdba oracle 11633 11630 0 16:36 ? 00:00:00oracleelvis (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 11637 1 0 16:36 ? 00:00:01 oracleelvis (LOCAL=NO) oracle 11678 1 0 16:38 ? 00:00:00 oracleelvis (LOCAL=NO) oracle 11682 1 0 16:39 ? 00:00:00 ora_w000_elvis root 11735 11695 0 16:42 pts/2 00:00:00 grep ora
注:如果是windows环境下情况较复杂,具体的进程ID需要去查看线程,而Windows不能直接查看进程下的线程必须通过第三方工具去查看。
l? 从进程资源占用情况追溯到session
这种情况下,可以查找到是哪个session在占用大量资源,甚至能查找到
B)session
l? 资源视图—重要
select * from v$resource_limit;
l? 命令类型视图,根据v$session视图里的command列判断
select * from audit_actions;
l?通过session视图的sql_id列,查看到sql语句
select * from v$sql where sql_id=’ ’;
模拟消耗资源的死循环的语句
declare number:=0; begin loop i:=1; end loop: end;
找到后Kill掉session
alter system kill session ’67,23’;
或者直接Kill掉进程
Window下是orakill命令,服务器端具备
Linux下是kill,top,ps –ef | grep ora等命令
Kill用法
--kill -9 sid 强制kill掉
C)connection
专有连接
共享连接
基本不使用,了解即可
池中连接
3 深入逻辑结构
3.1 表空间
database->tablespace->segments->extents->osblocks
===============================================
selelct * from dba_tablespaces; select * from dba_data_files; select * from dba_temp_files; select * from dba_segment;
?--一个表空间可以包含最多1023个数据文件
注:从11g开始有延迟段的概念,就是表中无数据的话,Oracle不分配空间
通过参数deferred_segment_creation查看延迟段的开启情况
--show parameterdeferred_segment_creation
===============================================
创建一个表空间
create tablespace orcl datafile 'E:\ORADATA\orcl\orcl01.dbf' size 10M;
然后创建一个表并指定存到orcl表空间中
create table t(id int) tablespace orcl;
表空间的分配方式 (extent为单位)
autoallocate(默认)
>1g???? 64m???8096blocks
Uniform [指定增长大小]
始终都会按指定的大小增长
分配方式可以查看dba_tablespace视图中allocate_type字段为system就是默认??
在关掉这个表空间
alter tablespace orcl offline;
->notes:虽然表不能访问和修改了,但可以删除,相当于数据库
? 关闭了,只不过这是局部关闭。
回收站命令 show recyclebin 可以查询,但不可以对回收站里的表执行DDL/DML
select * from " BIN$wHUg/RiVRxuXtwyypSxnTw==$0 TABLE" ;
从回收站里拿出来?闪回
flashback table t to before drop;
?
================================================
可以使用EM来观察表空间的使用率
?--登录->administration->tablespace
3.2 表空间和数据文件的管理
创建一个表
create table tt tablespace orcl as select * from dba_objects;
持续插入数据
insert into tt select * from tt;
当表空间大小不足时,扩展表空间大致有以下几种方式:
1.直接扩展数据文件大小
alter database datafile file_id resize 20M;
2.自动扩展数据文件大小
alter database datafile 5 autoextend on next 1M maxsize 1024M;
3.手动扩展表空间的大小
alter tablespace orcl add datafile 'D:\oradata\orcl\orcl02.dbf' autoextend on next 1M maxsize 1024M;
为tt表分配了40M的空间大小且会显示但里面没有数据是空的(插入会遵循有空间的优先插入)
alter table tt allocate extent(datafile'D:\oradata\orcl\orcl02.dbf' size 40M);
查看表中块的使用情况方法:
1.包的方式
execdbms_stats.gather_table_stats(‘table’,’TEST’);
2.分析表—这种更准确
analyze table tt computestatistics;
从10g开始可以为tt表紧缩
alter table t shrink space;
但紧缩需要行移动(row movement)
alter table t shrink space;
这样就可以紧缩了。。。
查看row movement 是否可以移动
select * from dba_tables where table_name='T';
===============================================================
把表t移动到表空间2里,观察会有什么变化
alter table t move tablespace orcl02;
案例一:
?优化问题,观察磁盘读取速率及各个文件的读取情况。
?视图:
?--dba打头的属于静态数据来自于system里的数据字典
??--v$打头的属于动态,一般来自于控制文件等,且存储在内存中,所以服务器尽量不要重启,重启后,动态信息会消失,当然从10g
?开始oracle已经每隔一个小时会存储下动态信息
select * from v$filestat;
3.3 undo表空间
创建undo表空间
create undo tablespace undotbs2 database'E:\oradata\orcl\undotbs02.dbf' size 10M;
在表t中加入一列
alter table t add name varchar2(10) default 'a'; insert into t values(1,'elvis'); insert into t values(2,'elvis'); commit;
然后更新下列值
updata t set name='c' where id=1; select * from t;
不提交通过另外一个窗口同一个用户身份去查询观察。
?--当然不会看到,因为没有提交
作者:elvis_dataguru 发表于2013-6-21 15:07:40 原文链接
阅读:38 评论:0 查看评论
原文地址:Oracle的体系结构概览, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

Oracle can read dbf files through the following steps: create an external table and reference the dbf file; query the external table to retrieve data; import the data into the Oracle table.

The amount of memory required for an Oracle database depends on the database size, workload type, and number of concurrent users. General recommendations: Small databases: 16-32 GB, Medium databases: 32-64 GB, Large databases: 64 GB or more. Other factors to consider include database version, memory optimization options, virtualization, and best practices (monitor memory usage, adjust allocations).

To create a scheduled task in Oracle that executes once a day, you need to perform the following three steps: Create a job. Add a subjob to the job and set its schedule expression to "INTERVAL 1 DAY". Enable the job.
