Table of Contents
1 物理结构(文件)
2 逻辑结构
2.1 实例
2.2实例的管理
2.3 参数的粗略概述
2.4 session(process)
3 深入逻辑结构
3.1 表空间
3.2 表空间和数据文件的管理
3.3 undo表空间
Home Database Mysql Tutorial Oracle的体系结构概览

Oracle的体系结构概览

Jun 07, 2016 pm 04:35 PM
oracle Architecture statement Version

声明:版本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
Copy after login

(2)datafile

select * from dba_data_files
Copy after login

(3)redo?(online logfile)

select * from v$logfile
select * from v$log
Copy after login

(4)password file(sys)

select * from dba_users
Copy after login

(从11g开始password项里变为空了,以免被破解)

2 逻辑结构

2.1 实例

instance(memory[sga]+process[background])

实例=内存(sga)+后台进程(background)

查看内存,可以通过以下视图

select * from v$sga_dynamic_components


?后台进程,可以通过下面视图查看

  select * fromv$bgprocess where paddr!='00';
Copy after login

? 我们只关心paddr不等于0的就可以了,等于0的都是没启用

2.2实例的管理

参数文件spfilesid.ora,initsid.ora

两个文件可以互相转化

create spfile from pfile;
create pfile from spfile;
Copy after login

(1)开启实例分为nomount,mount,open三个阶段


l? nomount阶段

在开启到nomount阶段需要使用到参数文件,而从9i版本开始默认优先使用spfile参数文件,如果spfile文件没有就去使用pfile文件,如果pfile文件还没有,就会报找不到pfile文件的错误。

11g有一个新功能,也许是我才发现吧!!!首先先说下数据库开启时,如果参数文件丢失或者损坏,不会导致数据库直接宕掉,但是如果数据库重新启动的话,就会报错,而且如果要是没有个好的备份的话,那是非常麻烦的事情,如果数据库在运行时及时发现了参数文件丢失或者损坏,可以使用如下方法处理:

create pfile from memory;
Copy after login

所以参数文件一定要有个良好的备份。

可以通过v$instance视图查看数据库状态

select status from v$instance;
Copy after login

通过v$bgprocess视图可以查看后台进程的情况

select * from v$bgprocess where paddr’00’;
Copy after login

l? mount阶段

开启mount阶段需要用到控制文件

可以使用参数control_files查看控制文件所在位置:

show parameter control_files
Copy after login

如果控制文件损坏,在开启数据库的时候就会报错,而且告诉你去alert_sid.log里看具体错误信息,而这个文件所在位置,可以通过background_dump_dest参数去查看:

show parameter background
Copy after login

注:alert_sid.log最大支持到2G大小,所以当业务特殊繁忙或者文件变的比较大的时候需要备份。

l? open阶段

11gR2版本—经测试,其他版本不确定

可以从open阶段到mount阶段在到nomount阶段

alter database close;
alter database dismount;
shutdown immediate
Copy after login

(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
Copy after login

从ISSYS_MOD字段可以看出db_cache_size参数是立即生效,所以从这个可以看出db_cache_size字段是动态参数。

注意:其中processes参数如果过多比如更改为50000个数量的时候,数据库在重新启动的时候会挂住。

?

2.4 session(process)

A)process

select * from v$process;
Copy after login

包含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
Copy after login

注:如果是windows环境下情况较复杂,具体的进程ID需要去查看线程,而Windows不能直接查看进程下的线程必须通过第三方工具去查看。

l? 从进程资源占用情况追溯到session

这种情况下,可以查找到是哪个session在占用大量资源,甚至能查找到

B)session

l? 资源视图—重要

select * from v$resource_limit;
Copy after login

l? 命令类型视图,根据v$session视图里的command列判断

select * from audit_actions;
Copy after login

l?通过session视图的sql_id列,查看到sql语句

select * from v$sql where sql_id=’  ’;
Copy after login

模拟消耗资源的死循环的语句

declare
number:=0;
begin loop
i:=1;
end loop:
end;
Copy after login

找到后Kill掉session

alter system kill session ’67,23’;
Copy after login

或者直接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;
Copy after login

?--一个表空间可以包含最多1023个数据文件

注:从11g开始有延迟段的概念,就是表中无数据的话,Oracle不分配空间

通过参数deferred_segment_creation查看延迟段的开启情况

--show parameterdeferred_segment_creation

===============================================

创建一个表空间

 create tablespace orcl datafile 'E:\ORADATA\orcl\orcl01.dbf' size 10M;
Copy after login

然后创建一个表并指定存到orcl表空间中

 create table t(id int) tablespace orcl;
Copy after login

表空间的分配方式 (extent为单位)

autoallocate(默认)

>1g???? 64m???8096blocks

Uniform [指定增长大小]

始终都会按指定的大小增长

分配方式可以查看dba_tablespace视图中allocate_type字段为system就是默认??

在关掉这个表空间

 alter tablespace orcl offline;
Copy after login

->notes:虽然表不能访问和修改了,但可以删除,相当于数据库

? 关闭了,只不过这是局部关闭。

回收站命令 show recyclebin 可以查询,但不可以对回收站里的表执行DDL/DML

 select * from " BIN$wHUg/RiVRxuXtwyypSxnTw==$0 TABLE" ;
Copy after login

从回收站里拿出来?闪回

flashback table t to before drop;
Copy after login

?

================================================

可以使用EM来观察表空间的使用率

?--登录->administration->tablespace

3.2 表空间和数据文件的管理

创建一个表

 create table tt tablespace orcl as select * from dba_objects;
Copy after login

持续插入数据

insert into tt select * from tt;
Copy after login

当表空间大小不足时,扩展表空间大致有以下几种方式:

1.直接扩展数据文件大小

 alter database datafile file_id resize 20M;
Copy after login

2.自动扩展数据文件大小

 alter database datafile 5 autoextend on next 1M maxsize 1024M;
Copy after login

3.手动扩展表空间的大小

alter tablespace orcl add datafile 'D:\oradata\orcl\orcl02.dbf'
 autoextend on next 1M maxsize 1024M;
Copy after login

为tt表分配了40M的空间大小且会显示但里面没有数据是空的(插入会遵循有空间的优先插入)

alter table tt allocate extent(datafile'D:\oradata\orcl\orcl02.dbf' size 40M);
Copy after login

查看表中块的使用情况方法:

1.包的方式

execdbms_stats.gather_table_stats(‘table’,’TEST’);
Copy after login

2.分析表—这种更准确

analyze table tt computestatistics;
Copy after login

从10g开始可以为tt表紧缩

alter table t shrink space;
Copy after login
Copy after login

但紧缩需要行移动(row movement)

alter table t shrink space;
Copy after login
Copy after login

这样就可以紧缩了。。。

查看row movement 是否可以移动

select * from dba_tables where table_name='T';
Copy after login

===============================================================

把表t移动到表空间2里,观察会有什么变化

alter table t move tablespace orcl02;
Copy after login

案例一:

?优化问题,观察磁盘读取速率及各个文件的读取情况。

?视图:

?--dba打头的属于静态数据来自于system里的数据字典

??--v$打头的属于动态,一般来自于控制文件等,且存储在内存中,所以服务器尽量不要重启,重启后,动态信息会消失,当然从10g

?开始oracle已经每隔一个小时会存储下动态信息

select * from v$filestat;
Copy after login

3.3 undo表空间

创建undo表空间

create undo tablespace undotbs2 database'E:\oradata\orcl\undotbs02.dbf' size 10M;
Copy after login

在表t中加入一列

alter table t add name varchar2(10) default 'a';
 insert into t values(1,'elvis');
 insert into t values(2,'elvis');
 commit;
Copy after login

然后更新下列值

 updata t set name='c' where id=1;
 select * from t;
Copy after login

不提交通过另外一个窗口同一个用户身份去查询观察。

?--当然不会看到,因为没有提交


作者:elvis_dataguru 发表于2013-6-21 15:07:40 原文链接

阅读:38 评论:0 查看评论

Oracle的体系结构概览

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to paginate oracle database How to paginate oracle database Apr 11, 2025 pm 08:42 PM

Oracle database paging uses ROWNUM pseudo-columns or FETCH statements to implement: ROWNUM pseudo-columns are used to filter results by row numbers and are suitable for complex queries. The FETCH statement is used to get the specified number of first rows and is suitable for simple queries.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

How to solve garbled code in oracle How to solve garbled code in oracle Apr 11, 2025 pm 10:09 PM

Oracle garbled problems can be solved by checking the database character set to ensure they match the data. Set the client character set to match the database. Convert data or modify column character sets to match database character sets. Use Unicode character sets and avoid multibyte character sets. Check that the language settings of the database and client are correct.

See all articles