oracle数据库:体系结构概述_笔记1
2.1定义数据库和实例
实例就是一组操作系统进程以及一些内存。这些进程可以操作数据库;而数据库只是一个文件集合(包括数据文件、临时文件、重做日志文件和控制文件)。在任何时刻,一个实例只能有一组相关的文件(与一个数据库关联)。大多数情况下,反过来也成立:一个数据库上只有一个实例对其进行操作。不过,Oracle的真正应用集群是一个例外,这是Oracle提供的一个选项,允许在集群环境中的多台计算机上操作,这样就可以有多台实例同时装载并打开一个数据库(位于一组共享物理磁盘上)。由此,我们可以同时从多台不同的计算机访问这个数据库。Oracle RAC能支持高度可用的系统,可用于构建可扩展性极好的解决方案。
测试用例
使用ps命令,可以看到用户oracle运行的所有进程
[root@localhost ~]# su - oracle
[oracle@localhost ~]$ pwd
/home/oracle
[oracle@localhost ~]$ ps -aef |grep ora
root 3282 3258 0 19:03 ? 00:00:00 hald-addon-storage: polling /dev/hdc
root 4203 4175 0 19:06 pts/1 00:00:00 su - oracle
oracle 4204 4203 0 19:06 pts/1 00:00:00 -bash
oracle 4233 4204 0 19:06 pts/1 00:00:00 ps -aef
oracle 4234 4204 0 19:06 pts/1 00:00:00 grep ora
然后用ipcs命令,这个Unix命令可用于显示进程间的通信设备。
[oracle@localhost ~]$ ipcs -a
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 4620289 root 644 80 2
0x00000000 4653059 root 644 16384 2
0x00000000 4685828 root 644 280 2
------ Semaphore Arrays --------
key semid owner perms nsems
------ Message Queues --------
key msqid owner perms used-bytes messages
然后启动SQL*Plus,并作为sysdba连接。开始时假设还没有设置环境变量ORACLE_SID,将看到将有错误发生,因为数据库软件不知道该连接谁。连接时,Oracle软件将查找一个TNS连接字符串。如果没有连接字符串,Oracle软件将查找名为ORACLE_SID的变量。ORACLE_SID是Oracle的站点标识符,它是访问实例的键。
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Wed Aug 28 19:07:24 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
Enter user-name:
...
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
[oracle@localhost ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
. ~/.bashrc
fi
# User specific environment and startup programs
#ORACLE_SID=vcenter
ORACLE_BASE=/db/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1
export ORACLE_SID ORACLE_BASE ORACLE_HOME
PATH=$PATH:/$ORACLE_HOME/bin:$HOME/bin
export PATH
~
[oracle@localhost ~]$ export ORACLE_SID=vcenter
连接将会成功,SQL*Plus报告称连上了一个空闲的实例:
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Wed Aug 28 19:08:34 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to an idle instance.
我们的“实例”现在只包括一个Oracle服务器进程。
SQL> !ps -aef |grep ora
root 3282 3258 0 19:03 ? 00:00:00 hald-addon-storage: polling /dev/hdc
root 4203 4175 0 19:06 pts/1 00:00:00 su - oracle
oracle 4204 4203 0 19:06 pts/1 00:00:00 -bash
oracle 4243 4204 0 19:08 pts/1 00:00:00 sqlplus as sysdba
oracle 4246 4243 0 19:08 ? 00:00:00 oraclevcenter (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 4249 4243 0 19:08 pts/1 00:00:00 /bin/bash -c ps -aef |grep ora
oracle 4250 4249 0 19:08 pts/1 00:00:00 ps -aef
SQL> !ipcs -a
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 4620289 root 644 80 2
0x00000000 4653059 root 644 16384 2
0x00000000 4685828 root 644 280 2
------ Semaphore Arrays --------
key semid owner perms nsems
------ Message Queues --------
key msqid owner perms used-bytes messages
对于这个ps输出,需要说明一个有趣的东西——这里名为oraclevcenter的进程。不论你在系统中多么努力地查找,都不可能找到文件名为oraclevcenter的可执行文件。实际上所执行的Oracle二进制文件是$ORACLE_HOME/bin/oracle
init.ora通常叫参数文件,是启动实例时必须要有的一个文件,我们需要有一个参数文件或者要有一个存储参数文件
默认情况下,文件位于$ORACLE_HOME/dbs目录,名为init${ORACLE.SID}.ora
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/db/oracle/product/11.1.0/db_1/dbs/initvcenter.ora'
SQL> exit
Disconnected
[oracle@localhost ~]$ cd $ORACLE_HOME
[oracle@localhost db_1]$ pwd
/db/oracle/product/11.1.0/db_1
[oracle@localhost db_1]$ cd dbs
[oracle@localhost dbs]$ pwd
/db/oracle/product/11.1.0/db_1/dbs
[oracle@localhost dbs]$ ls
20130828.init.ora
[oracle@localhost dbs]$ echo db_name=ORCL > init.ora
[oracle@localhost dbs]$ cat init.ora
db_name=ORCL
SQL> startup nomount
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/db/oracle/product/11.1.0/db_1/dbs/initvcenter.ora'
SQL> exit
Disconnected
[oracle@localhost dbs]$ ls
20130828.init.ora init.ora
[oracle@localhost dbs]$ mv init.ora initvcenter.ora
然后再回到SQL*Plus
SQL> startup nomount
ORACLE instance started.
Total System Global Area 238034944 bytes
Fixed Size 2227136 bytes
Variable Size 180356160 bytes
Database Buffers 50331648 bytes
Redo Buffers 5120000 bytes
现在就有了所谓的“实例”
SQL> !ps -aef |grep ora
root 3282 3258 0 19:03 ? 00:00:00 hald-addon-storage: polling /dev/hdc
root 4203 4175 0 19:06 pts/1 00:00:00 su - oracle
oracle 4204 4203 0 19:06 pts/1 00:00:00 -bash
root 4290 4261 0 19:10 pts/2 00:00:00 su - oracle
oracle 4291 4290 0 19:10 pts/2 00:00:00 -bash
oracle 4349 4204 0 19:16 pts/1 00:00:00 sqlplus as sysdba
oracle 4358 1 0 19:16 ? 00:00:00 ora_pmon_vcenter
oracle 4362 1 0 19:16 ? 00:00:00 ora_psp0_vcenter
oracle 4366 1 0 19:16 ? 00:00:00 ora_vktm_vcenter
oracle 4372 1 0 19:16 ? 00:00:00 ora_gen0_vcenter
oracle 4376 1 0 19:16 ? 00:00:00 ora_diag_vcenter
oracle 4380 1 0 19:16 ? 00:00:00 ora_dbrm_vcenter
oracle 4384 1 0 19:16 ? 00:00:00 ora_dia0_vcenter
oracle 4388 1 0 19:16 ? 00:00:00 ora_mman_vcenter
oracle 4392 1 0 19:16 ? 00:00:00 ora_dbw0_vcenter
oracle 4396 1 0 19:16 ? 00:00:00 ora_lgwr_vcenter
oracle 4400 1 0 19:16 ? 00:00:00 ora_ckpt_vcenter
oracle 4404 1 0 19:16 ? 00:00:00 ora_smon_vcenter
oracle 4408 1 0 19:16 ? 00:00:00 ora_reco_vcenter
oracle 4412 1 0 19:16 ? 00:00:00 ora_mmon_vcenter
oracle 4416 1 0 19:16 ? 00:00:00 ora_mmnl_vcenter
oracle 4419 4349 0 19:16 ? 00:00:00 oraclevcenter (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 4431 4349 0 19:17 pts/1 00:00:00 /bin/bash -c ps -aef |grep ora
oracle 4432 4431 0 19:17 pts/1 00:00:00 ps -aef
oracle 4433 4431 0 19:17 pts/1 00:00:00 /bin/bash -c ps -aef |grep ora
再使用ipcs命令,它报告指出使用了共享内存和信号量,这是UNIX上的两个重要的进程间通信设备
SQL> !ipcs -a
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 4620289 root 644 80 2
0x00000000 4653059 root 644 16384 2
0x00000000 4685828 root 644 280 2
0x00000000 4980747 oracle 640 8388608 16
0x00000000 5013516 oracle 640 230686720 16
0x04b79190 5046285 oracle 640 2097152 16
------ Semaphore Arrays --------
key semid owner perms nsems
0x6ab6e080 131073 oracle 640 124
------ Message Queues --------
key msqid owner perms used-bytes messages
注意,还没有“数据库”呢!
SQL> select name from v$datafile;
select name from v$datafile
*
ERROR at line 1:
ORA-01507: database not mounted
SQL> create database;
Database created.
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-01100: database already mounted
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/db/oracle/product/11.1.0/db_1/dbs/dbs1vcenter.dbf
/db/oracle/product/11.1.0/db_1/dbs/dbx1vcenter.dbf
/db/oracle/product/11.1.0/db_1/dbs/dbu1vcenter.dbf
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/db/oracle/product/11.1.0/db_1/dbs/log1vcenter.dbf
/db/oracle/product/11.1.0/db_1/dbs/log2vcenter.dbf
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/db/oracle/product/11.1.0/db_1/dbs/cntrlvcenter.dbf
Oracle使用默认设置,把所有内容都放在一起,并把数据库创建为一组持久的文件。如果关闭这个数据库,再试图打开,就会发现数据库无法打开。
SQL> alter database close;
Database altered.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-16196: database has been previously opened and closed
一个实例在其生存期中最多只能装载和打开一个数据库。???要想再打开这个(或其他)数据库,必须先丢弃这个实例,并创建一个新的实例。
本文来源 我爱IT技术网 http://www.52ij.com/jishu/5143.html 转载请保留链接。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
