oracle常见配置和问题

linux环境下oracle的配置和遇到的问题

1. 常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 切换为oracle用户
su - oracle

# 以管理员身份登录
sqlplus sys/123456 as sysdba

#启动数据库
startup

#关闭数据库
shutdown immediate

# 停止监听
lsnrctl stop
# 启动监听
lsnrctl start
# 监听状态
lsnrctl status

2. 监听文件配置

  1. 切换为oracle用户

    1
    su - oracle
  2. 切换到监听文件的位置

    1
    cd  $ ORACLE_HOME/network/admin/
  3. 编辑监听文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    vim listener.ora


    SID_LIST_LISTENER =
    (SID_LIST =

    SID_DESC = #BEQUEATH CONFIG
    (GLOBAL_HostName = HostName)#数据库名
    (SID_NAME = HostName)#数据库名
    (ORACLE_HOME = /oracle/app/11.2.0/db_1/network/admin)#配置文件目录
    #PRESPAWN CONFIG
    (PRESPAWN_MAX = 20)
    (PRESPAWN_LIST =
    (PRESPAWN_DESC =(PROTOCOL = tcp))(POOL_SIZE = 2)(TIMEOUT = 1))





    LISTENER =
    (ADDRESS_LIST =
    (ADDRESS =(PROTOCOL = TCP)(HOST = HostName)(PORT = 1521))#主机名和端口号


  4. 重启监听

1
2
3
4
5
6
# 停止
lsnrctl stop
# 启动
lsnrctl start
# 状态
lsnrctl status
  1. 确认监听起来了
1
netstat -anp|grep 1521

3. 归档模式开启和关闭

  1. 查看是否开启了归档模式

    1
    2
    3
    4
    5
    6
    SQL> archive log list        #查看是否开启,下文显示未开启
    Database log mode No Archive Mode
    Automatic archival Disabled
    Archive destination USE_DB_RECOVERY_FILE_DEST
    Oldest online log sequence 8
    Current log sequence 10
  2. 开启归档

    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
    27
    28
    29
    30
    31
    32
    33
    34
    35
    SQL> shutdown immediate #关闭实例
    Database closed.
    Database dismounted.
    ORACLE instance shut down.

    SQL> startup mount #启动到mount
    ORACLE instance started.
    Total System Global Area 1286066176 bytes
    Fixed Size 2228024 bytes
    Variable Size 352321736 bytes
    Database Buffers 922746880 bytes
    Redo Buffers 8769536 bytes
    Database mounted.

    SQL> alter database archivelog; #开启归档模式
    Database altered.

    SQL> archive log list; #再次查看是否开启归档,下文显示已归档
    Database log mode Archive Mode
    Automatic archival Enabled
    Archive destination USE_DB_RECOVERY_FILE_DEST
    Oldest online log sequence 8
    Next log sequence to archive 10
    Current log sequence 10

    SQL> alter database open; #打开数据库
    Database altered.

    SQL> show parameter db_recovery
    # 查看参数db_recovery_file_dest归档日志目录(默认闪回恢复区)、db_recovery_file_dest_size大小

    NAME TYPE VALUE
    ------------------------------------ ----------- ------------------------------
    db_recovery_file_dest string /data/oracle/app/oracle/fast_recovery_area
    db_recovery_file_dest_size big integer 4182M

    默认情况下,归档日志会存放到USE_DB_RECOVERY_FILE_DEST(闪回恢复区flash_recovery_area)内,如果闪回恢复区已满,归档日志就有可能无法继续归档,通常的解决方法是增大闪回恢复区,可以用以下SQL实现:

    1
    SQL> alter system set db_recovery_file_dest_size=3G;

    另外,还可以修改归档日志的路径,将归档日志放到其他不受限制的路径下来解决这个问题,即通过下面的SQL来修改归档日志的存放路径:

    1
    2
    3
    4
    5
    6
    7
    8
    SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog';
    SQL> archive log list;
    Database log mode Archive Mode
    Automatic archival Enabled
    Archive destination /u01/app/oracle/archivelog
    Oldest online log sequence 15
    Next log sequence to archive 17
    Current log sequence 17
  3. 查看归档日志位置

1
2
3
4
5
6
7
8
9
10
11
12
13
# 查看归档日志位置
SQL> show parameter log_archive_dest;

# 归档日志格式
SQL> show parameter log_archive_format
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_format string %t_%s_%r.dbf

# 设置归档日志格式
SQL> alter system set log_archive_format ="archive_%t_%s_%r.log" scope=spfile;
System altered.

  1. 关闭归档模式

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    SQL> shutdown immediate
    Database closed.
    Database dismounted.
    ORACLE instance shut down.

    SQL> startup mount
    ORACLE instance started.
    Total System Global Area 1286066176 bytes
    Fixed Size 2228024 bytes
    Variable Size 352321736 bytes
    Database Buffers 922746880 bytes
    Redo Buffers 8769536 bytes
    Database mounted.

    SQL> alter database noarchivelog;

    SQL> alter database open;

    SQL> archive log list;
    Database log mode No Archive Mode
    Automatic archival Disabled
    Archive destination /home/oracle/archive_log
    Oldest online log sequence 16
    Current log sequence 18

4. 问题

4.1 Oracle的undotbs01.dbf文件太大(占用大量磁盘空间)处理方法 ORA-01654 空间不足 ORA-01653

  1. 以dba用户登录

  2. 确认使用的undo空间就是undotbs01

    1
    show parameter undo_tablespace;

    查询结果为:

    nametypevalue
    undo_tablespacestringundotbs1
  3. 查看表空间和文件的对应关系

    1
    select file_name, tablespace_name, online_status from dba_data_files where tablespace_name='UNDOTBS1';

    查询结果为:

    file_nametablespace_nameonline_status
    /oradata/DB/undotbs01.dbfUNDOTBS1ONLINE
  4. 查询当前回退表空间状态

    1
    select tablespace_name, status from dba_rollback_segs;

    查询结果为:10条UNDOTBS1,状态全部为ONLINE

  5. 设置一个临时空间供undo_tablespace 使用

    1
    2
    create undo tablespace UNDOTBS2 datafile '/oradata2/DB/undotbs02.dbf' size 100M;
    alter system set undo_tablespace=UNDOTBS2;
  6. 重新查询当前回退表空间状态

    1
    select tablespace_name, status from dba_rollback_segs;

    查询结果为:10条UNDOTBS1,状态全部为OFFLINE;10条UNDOTBS2,状态全部为ONLINE;证明回退表空间已经设置到UNDOTBS2

  7. 删除回退表空间UNDOTBS1

    1
    drop tablespace UNDOTBS1 including contents and datafiles;
  8. 重启oracle

    1
    2
    shutdown immediate;
    startup;
  9. 重新设置回来

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    create undo tablespace UNDOTBS1 datafile '/oradata/DB/undotbs1.dbf' size 100M autoextend on maxsize 25G;

    alter system set undo_tablespace=UNDOTBS1;

    select tablespace_name, status from dba_rollback_segs;

    drop tablespace UNDOTBS2 including contents and datafiles;

    shutdown immediate;
    startup;

4.2 表空间不够,改变大小

1
alter database datafile '物理路径' resize 1000m ;