好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

详解Linux系统中Oracle数据库程序的启动和关闭方式

在单机环境下,要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下

?

1

su - oracle

Oracle数据库有以下几种启动方式:
1、

?

1

startup nomount

非安装启动,这种方式启动下可执行:重建控制文件、重建数据库
读取init.ora文件,启动instance,即启动SGA和后台进程,这种启动只需要init.ora文件。

2、

?

1

startup mount dbname

安装启动,这种方式启动下可执行:
数据库日志归档、
数据库介质恢复、
使数据文件联机或脱机,
重新定位数据文件、重做日志文件。

执行[nomount],然后打开控制文件,确认数据文件和联机日志文件的位置,
但此时不对数据文件和日志文件进行校验检查。

3、

?

1

startup open dbname

先执行[nomount],然后执行[mount],再打开包括Redo log文件在内的所有数据库文件,
这种方式下可访问数据库中的数据。

4、startup,等于以下三个命令

?

1

2

3

startup nomount

alter database mount

alter database open

5、

?

1

startup restrict

约束方式启动
这种方式能够启动数据库,但只允许具有一定特权的用户访问
非特权用户访问时,会出现以下提示:
ERROR:
ORA-01035: ORACLE 只允许具有 RESTRICTED SESSION 权限的用户使用

6、

?

1

startup force

强制启动方式
当不能关闭数据库时,可以用startup force来完成数据库的关闭
先关闭数据库,再执行正常启动数据库命令

7、startup pfile=参数文件名
带初始化参数文件的启动方式
先读取参数文件,再按参数文件中的设置启动数据库
例:

?

1

startup pfile=E:Oracleadminoradbpfileinit.ora


oracle数据库几种关闭方式:

1、

?

1

shutdown normal

  正常方式关闭数据库。
2、

?

1

shutdown immediate

  立即方式关闭数据库。
  在SVRMGRL中执行shutdown immediate,数据库并不立即关闭,
  而是在Oracle执行某些清除工作后才关闭(终止会话、释放会话资源),
  当使用shutdown不能关闭数据库时,shutdown immediate可以完成数据库关闭的操作。
3、

?

1

shutdown abort

  直接关闭数据库,正在访问数据库的会话会被突然终止,
  如果数据库中有大量操作正在执行,这时执行shutdown abort后,重新启动数据库需要很长时间。
 
启动错误问题解决
问题描述:

?

1

2

3

4

5

6

[oracle@node1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Mar 17 16:38:03 2013

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

Connected to an idle instance

SQL> startup nomount

ORA-00845: MEMORY_TARGET not supported on this system

启动数据库时,报MEMORY_TARGET 不支持,上网搜索了一下,具体原因是Linux 系统的共享内存比SGA 配置的小。而/dev/shm 是根据tmpfs 的配置来定义的。

?

1

2

3

4

5

6

7

[root@node1 ~] # df -h /dev/shm

Filesystem      Size Used Avail Use% Mounted on

tmpfs        1000M   0 1000M  0% /dev/shm

SQL> show parameter memory_target

NAME                 TYPE    VALUE

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

memory_target            big integer 1G

查了一下tmpfs 的配置,只有1000M,而SGA 配置了1G(换算系1024M),不够大。解决问题的办法就是改小SGA 或者改大tmpfs(这里SGA 1G 已经小了,不建议在改小)。
解决方法1、 修改tmpfs(修改/etc/fstab 配置):

?

1

2

3

4

5

6

7

8

[root@node1 ~] # vim /etc/fstab

# tmpfs          /dev/shm        tmpfs  defaults    0 0

tmpfs  /dev/shm     tmpfs  defaults,size=2048M   0    0

[root@node1 ~] # umount /dev/shm

[root@node1 ~] # mount /dev/shm

[root@node1 ~] # df -h /dev/shm

Filesystem      Size Used Avail Use% Mounted on

tmpfs         2.0G   0 2.0G  0% /dev/shm

 

解决方法2、修改SGA:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

SQL> show parameter sga

NAME                 TYPE    VALUE

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

lock_sga               boolean   FALSE

pre_page_sga             boolean   FALSE

sga_max_size             big integer 1G

sga_target              big integer 0

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

System altered.

SQL> shutdown immediate

ORA-01507: database not mounted

ORACLE instance shut down.

SQL> startup nomount

ORACLE instance started.

Total System Global Area 801701888 bytes

Fixed Size         2217632 bytes

Variable Size       348129632 bytes

Database Buffers     444596224 bytes

Redo Buffers        6758400 bytes

SQL> show parameter sga

NAME                 TYPE    VALUE

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

lock_sga               boolean   FALSE

pre_page_sga             boolean   FALSE

sga_max_size             big integer 768M

sga_target              big integer 0

这里建议直接修改memory_target,让Oracle 自己去管理SGA 的大小(memory_target=SGA+PGA)

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

SQL> show parameter memory_target

NAME                 TYPE    VALUE

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

memory_target            big integer 1G

SQL> alter system set memory_target=768M scope=spfile;

System altered.

SQL> shutdown immediate

ORA-01507: database not mounted

ORACLE instance shut down.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 801701888 bytes

Fixed Size         2217632 bytes

Variable Size       469764448 bytes

Database Buffers     322961408 bytes

Redo Buffers        6758400 bytes

SQL>

SQL>

SQL> show parameter memory_target

NAME                 TYPE    VALUE

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

memory_target            big integer 768M

扩展:
这里需要注意,memory_target 不能小于SGA 或PGA,不然startup 数据库的时候会报错,数据库不能启动。

?

1

2

3

SQL> startup nomount

ORA-00844: Parameter not taking MEMORY_TARGET into account

ORA-00851: SGA_MAX_SIZE 1073741824 cannot be set to more than MEMORY_TARGET 805306368.

解决办法:

?

1

2

3

4

5

6

7

[oracle@node1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Mar 17 17:14:38 2013

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

Connected to an idle instance.

SQL> create pfile from spfile;

File created.

SQL> exit

修改init.ora 文件参数

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

[oracle@node1 dbs]$ vim initoranode1.ora

oranode1.__db_cache_size=444596224

oranode1.__large_pool_size=4194304

oranode1.__oracle_base= '/u01/app/oracle' #ORACLE_BASE set from environment

*.audit_file_dest= '/u01/app/oracle/admin/oranode1/adump'

*.audit_trail= 'db'

*.compatible= '11.2.0'

*.control_files= '/u01/oradata/ora_control1' ,' /u01/fast_recovery_area/ora_control

2'

*.db_block_size=8192

*.db_domain= 'node1.example.com'

*.db_name= 'oranode1'

*.db_recovery_file_dest= '/u01/fast_recovery_area'

*.db_recovery_file_dest_size=2G

*.diagnostic_dest= '/u01/app/oracle'

*.dispatchers= '(PROTOCOL=TCP) (SERVICE=ORCLXDB)'

*.memory_target=805306368

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile= 'EXCLUSIVE'

*.sga_max_size=805306368

*.undo_tablespace= 'UNDOTBS1'

重新生成spfile

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

[oracle@node1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Mar 17 17:15:28 2013

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

Connected to an idle instance.

SQL> create spfile from pfile;

File created.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 801701888 bytes

Fixed Size         2217632 bytes

Variable Size       469764448 bytes

Database Buffers     322961408 bytes

Redo Buffers        6758400 bytes

SQL>

SQL>

SQL> show parameter memory_target

NAME                 TYPE    VALUE

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

memory_target            big integer 768M

 

查看更多关于详解Linux系统中Oracle数据库程序的启动和关闭方式的详细内容...

  阅读:31次