oracle参数与启停

参数文件位置
[root@localhost ~]# cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
[root@localhost dbs]# ls
hc_orcl.dat  init.ora  lkORCL  orapworcl  spfileorcl.ora
参数文件里包含数据库初始化参数,用于设置数据库实例和数据库的运行特征及使用限制。

oracle支持两种类型的参数文件,oracle按照参数文件的设定启动实例并打开数据库
initorcl.ora是实例的文本参数文件        文本型必须通过手工修改
spfileoracl.ora是实例的服务器参数文件    二进制型通过alter system命令修改

pfile    文本型,通常命名为initSID.ora,pfile并不一定存在,可以手动创建,过程如下
sqlplus / as sysdba
SQL> create pfile from spfile;
File created.
spfile     二进制,通常命名为spfileSID.ora。

参数大多使用了默认值,因此参数文件里的参数实际上是非默认的参数。11gr1,r2支持289-342个显式参数,还有相当多未文档化的隐式参数。

Oracle 9i以后启动的时候默认使用的初始化文件是spfile,但是如何判断数据库启动是使用spfile还是pfile初始化文件.可以以下方法,
1、show parameter spfile
2、show parameter pfile
3、看v$spparameter视图

[oracle@localhost dbs]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 10 15:17:59 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

SQL> conn / as sysdba
Connected.

下面是修改为pfile启动过程
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create pfile from spfile;

File created.
也可以用 create spfile from pfile,二者可以相互转化。
SQL> startup pfile=$ORACLE_HOME/dbs/initorcl.ora
ORACLE instance started.

Total System Global Area 1653518336 bytes
Fixed Size                  2213896 bytes
Variable Size            1006635000 bytes
Database Buffers          637534208 bytes
Redo Buffers                7135232 bytes
Database mounted.
Database opened.
SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string
SQL> show parameter pfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string
SQL> select decode(count(*),1,'spfile','pfile') from v$spparameter where rownum=1 and isspecified = 'TRUE';

DECODE
------
pfile

[oracle@localhost dbs]$ sqlplus /nolog



SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 10 15:29:14 2015



Copyright (c) 1982, 2009, Oracle.  All rights reserved.



SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup

ORACLE instance started.



Total System Global Area 1653518336 bytes

Fixed Size                  2213896 bytes

Variable Size            1006635000 bytes

Database Buffers          637534208 bytes

Redo Buffers                7135232 bytes

Database mounted.

Database opened.

SQL> show parameter spfile



NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

spfile                               string      /u01/app/oracle/product/11.2.0

                                                 /dbhome_1/dbs/spfileorcl.ora

通过spfile启动,用alter system修改参数

[oracle@localhost dbs]$ sqlplus /nolog



SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 10 15:32:51 2015



Copyright (c) 1982, 2009, Oracle.  All rights reserved.



SQL> conn / as sysdba

Connected.

SQL> alter system set sga_max_size=1524M scope=spfile;



System altered.



SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.



Total System Global Area 1603411968 bytes

Fixed Size                  2213776 bytes

Variable Size             956303472 bytes

Database Buffers          637534208 bytes

Redo Buffers                7360512 bytes

Database mounted.

Database opened.

SQL> show parameter sga_max_size



NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

sga_max_size                         big integer 1536M

 

动态参数是指在运行过程中可以动态修改的参数

静态参数是指必须通过重启来调整的参数,随着oracle的不断升级,参数逐渐动态化,在11g中,静态已没有几个了。

SQL> show parameter optimizer_index_caching



NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

optimizer_index_caching              integer     0

SQL> alter system set optimizer_index_caching=50 scope=both;

both的含义是指在内存与文件中,并且立刻生效。重启oracle后还是生效。

如果改为memory,则只对当前实例有效,即内存中,重启后失效。

如果改为spfile,则对当前实例无效,重启后生效。

一些参数也可以在会话级使用alter session来调整,如

alter session set sql_trace=true;

SQL> alter system set parallel_max_servers=100 scope=memory;



System altered.



SQL> show parameter optimizer_index_caching



NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

optimizer_index_caching              integer     50

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.



Total System Global Area 1603411968 bytes

Fixed Size                  2213776 bytes

Variable Size             956303472 bytes

Database Buffers          637534208 bytes

Redo Buffers                7360512 bytes

Database mounted.

Database opened.

SQL> show parameter optimizer_index_caching



NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

optimizer_index_caching              integer     50

 

SQL> alter database mount;

Database altered.

SQL> alter database open read only;

Database altered.

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

启动为限制模式,限制模式打开的数据库只有具备管理权限的数据库用户才能访问。

例如具有restricted session权限或dba角色的数据库用户。

管理员往往在执行数据库结构调整及数据库维护期间,为防止普通用户访问,则以限制模式启动数据库。

SQL> startup restrict

ORACLE instance started.

Total System Global Area 1603411968 bytes

Fixed Size                  2213776 bytes

Variable Size             956303472 bytes

Database Buffers          637534208 bytes

Redo Buffers                7360512 bytes

Database mounted.

Database opened.

将受限转为正常

SQL> alter system disable restricted session;

System altered.



关闭的四种方式

shutdown normal|transactional|immediate|abort

shutdown 等同于shutdown normal



检查数据库状态

SQL> select database_status from v$instance;

DATABASE_STATUS

-----------------

ACTIVE

挂起/暂停数据库

SQL> alter system suspend;

System altered.

SQL> select database_status from v$instance;

DATABASE_STATUS

-----------------

SUSPENDED

恢复数据库

SQL> alter system resume;

System altered.

SQL> select database_status from v$instance;

DATABASE_STATUS

-----------------

ACTIVE

 

 

1:ORACLE使用环境变量里(ORACLE_SID+ORACLE_HOME)的值进行hash运算,来确定SGA区的内存地址。
2:如果当你使用sqlplus / as sysdba 连接到一个idle的instance时,表示你使用的(ORACLE_SID+ORACLE_HOME) hash后的值在内存中没有找到相应的sga区,一个可能是数据库没有启动,另一个可能是和当前正在运行的数据库的(ORACLE_SID+ORACLE_HOME)内容不相同,导致你没有正确的连接到当前的数据库的SGA。

在提交startup命令之后,在上述目录下Oracle会自动按照如下的顺序查找参数文件完成数据库的启动。
   1)spfile$ORACLE_SID.ora
   2)spfile.ora
   3)init$ORACLE_SID.ora

注意事项
这里强调指出的一个问题是:不可像显式使用特定pfile的方法去使用spfile!
虽然可以显式指定具体pfile作为启动数据库的参数文件,但这里需要注意的是,不可以显式指定某个spfile作为启动的参数文件。
下面的用法是不正确的。
SQL> startup spfile=$ORACLE_HOME/dbs/spfilefgy.ora
SP2-0714: invalid combination of STARTUP options
错误提示:startup命令后面跟随的选项不正确。原因很简单,spfile作为系统参数文件是在启动过程中自动识别到的,其命名规则也是固定的。因此请不要尝试显式的去使用spfile启动数据库。
此时,如果我们显式的使用pfile是可以完成数据库的启动。
sys@ora10g> startup pfile='?/dbs/initora10g.ora';

 

http://blog.chinaunix.net/uid-26190190-id-2420722.html

http://www.cnblogs.com/smartvessel/archive/2009/07/06/1517690.html

 

创建数据库的步骤

1.创建口令文件

2.创建参数文件

3.创建所需目录结构

4.设置环境变量

[oracle@localhost oracle]$ orapwd file=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwfgy1 password=123456

[oracle@localhost oracle]$ sqlplus / as sysdba



SQL*Plus: Release 11.2.0.1.0 Production on Mon Jul 20 15:50:36 2015



Copyright (c) 1982, 2009, Oracle.  All rights reserved.



Connected to an idle instance.



SQL> startup nomount pfile=/u01/app/oracle/admin/fgy1/pfile/init.ora

ORACLE instance started.



Total System Global Area  283930624 bytes

Fixed Size                  2212656 bytes

Variable Size             109055184 bytes

Database Buffers          167772160 bytes

Redo Buffers                4890624 bytes

SQL> create database fgy1
  2  datafile '/u01/app/oracle/oradata/fgy1/system01.dbf' size 300M reuse autoextend on next 10240K
  3  maxsize unlimited extent management local
  4  sysaux
  5  datafile '/u01/app/oracle/oradata/fgy1/sysaux01.dbf' size 120M reuse autoextend on next 10240K
  6  maxsize unlimited
  7  smallfile default temporary tablespace
  8  temp
  9  tempfile '/u01/app/oracle/oradata/fgy1/temp01.dbf' size 20M reuse autoextend on next 640K maxsize unlimited
 10  smallfile undo tablespace "UNDOTBS1"
 11  datafile '/u01/app/oracle/oradata/fgy1/undotbs01.dbf' size 200M reuse autoextend on next 5120K maxsize unlimited
 12  character set zhs16gbk
 13  national character set al16utf16
 14  logfile group 1 ('/u01/app/oracle/oradata/fgy1/redo01.log') size 51200K,
 15  group 2 ('/u01/app/oracle/oradata/fgy1/redo02.log') size 51200K,
 16  group 3 ('/u01/app/oracle/oradata/fgy1/redo03.log') size 51200K
 17  user sys identified by 123456
 18  user system identified by 123456;

Database created.

针对应用创建所需要的表空间,这里创建表空间users,
SQL> create smallfile tablespace users logging
  2  datafile '/u01/app/oracle/oradata/fgy1/users01.dbf' size 5M reuse autoextend on next 1280K maxsize unlimited
  3  extent management local
  4  segment space management auto;

Tablespace created.
并设置为数据库默认表空间
SQL> alter database default tablespace users;

Database altered.

SQL> create user fgy1 identified by 123456 default tablespace users;

User created.

SQL> grant dba to fgy1;

Grant succeeded.

安装数据字典视图
SQL> @/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/catalog.sql;
SQL> @/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/catproc.sql;
以system 用户登录,创建pl/sql资源集
SQL> connect system/123456
SQL> @/u01/app/oracle/product/11.2.0/dbhome_1/sqlplus/admin/pupbld.sql;
SQL> connect system/123456
SQL> @/u01/app/oracle/product/11.2.0/dbhome_1/sqlplus/admin/help/hlpbld.sql helpus.sql;

此时在toad中以fgy1用户便可以登录,没有创建数据字典之前,不可登录。
17:26:26 12 ~:#sqlplus fgy1/123456@fgy1
总共有两条连接,一个是toad,一个是sqlplus
oracle    2454     1  0 17:26 ?        00:00:00 oraclefgy1 (LOCAL=NO)
oracle    2419     1  0 17:12 ?        00:00:01 oraclefgy1 (LOCAL=NO)

netstat -natp
tcp        0      0 ::ffff:192.168.1.70:1521    ::ffff:192.168.1.88:55289   ESTABLISHED
tcp        0      0 ::ffff:192.168.1.70:1521    ::ffff:172.16.1.44:54267    ESTABLISHED
tcp        0      0 ::ffff:127.0.0.1:1521       ::ffff:127.0.0.1:20814      ESTABLISHED
tcp        0      0 127.0.0.1:20814             127.0.0.1:1521              ESTABLISHED

[oracle@localhost fgy1]$ ss -np
State       Recv-Q Send-Q                                                        Local Address:Port                                                          Peer Address:Port
ESTAB       0      0                                                                 127.0.0.1:20814                                                            127.0.0.1:1521   users:(("oracle",2100,20))
ESTAB       0      0                                                       ::ffff:192.168.1.70:1521                                                   ::ffff:192.168.1.88:55289  users:(("oracle",2419,14))
ESTAB       0      0                                                              192.168.1.70:22                                                             172.16.1.44:47037
ESTAB       0      0                                                       ::ffff:192.168.1.70:1521                                                    ::ffff:172.16.1.44:54267  users:(("oracle",2454,14))
ESTAB       0      0                                                          ::ffff:127.0.0.1:1521                                                      ::ffff:127.0.0.1:20814  users:(("tnslsnr",2290,13))

 

你可能感兴趣的:(oracle)