search
HomeDatabaseMysql TutorialOracle的体系结构概览

Oracle的体系结构概览

Jun 07, 2016 pm 04:35 PM
oracleArchitecturestatementVersion

声明:版本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的体系结构概览

Statement
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
MySQL: An Introduction to the World's Most Popular DatabaseMySQL: An Introduction to the World's Most Popular DatabaseApr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

The Importance of MySQL: Data Storage and ManagementThe Importance of MySQL: Data Storage and ManagementApr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

Why Use MySQL? Benefits and AdvantagesWhy Use MySQL? Benefits and AdvantagesApr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Describe InnoDB locking mechanisms (shared locks, exclusive locks, intention locks, record locks, gap locks, next-key locks).Describe InnoDB locking mechanisms (shared locks, exclusive locks, intention locks, record locks, gap locks, next-key locks).Apr 12, 2025 am 12:16 AM

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.

What are common causes of poor MySQL query performance?What are common causes of poor MySQL query performance?Apr 12, 2025 am 12:11 AM

The main reasons for poor MySQL query performance include not using indexes, wrong execution plan selection by the query optimizer, unreasonable table design, excessive data volume and lock competition. 1. No index causes slow querying, and adding indexes can significantly improve performance. 2. Use the EXPLAIN command to analyze the query plan and find out the optimizer error. 3. Reconstructing the table structure and optimizing JOIN conditions can improve table design problems. 4. When the data volume is large, partitioning and table division strategies are adopted. 5. In a high concurrency environment, optimizing transactions and locking strategies can reduce lock competition.

When should you use a composite index versus multiple single-column indexes?When should you use a composite index versus multiple single-column indexes?Apr 11, 2025 am 12:06 AM

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)Apr 10, 2025 am 09:36 AM

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL: Essential Skills for DevelopersMySQL and SQL: Essential Skills for DevelopersApr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor