oracle常见配置和问题
linux环境下oracle的配置和遇到的问题
1. 常用命令
1 | 切换为oracle用户 |
2. 监听文件配置
切换为oracle用户
1
su - oracle
切换到监听文件的位置
1
cd $ ORACLE_HOME/network/admin/
编辑监听文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24vim 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))#主机名和端口号
)重启监听
1 | 停止 |
- 确认监听起来了
1 | netstat -anp|grep 1521 |
3. 归档模式开启和关闭
查看是否开启了归档模式
1
2
3
4
5
6archive 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开启归档
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
35shutdown immediate #关闭实例
Database closed.
Database dismounted.
ORACLE instance shut down.
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.
alter database archivelog; #开启归档模式
Database altered.
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
alter database open; #打开数据库
Database altered.
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
alter system set db_recovery_file_dest_size=3G;
另外,还可以修改归档日志的路径,将归档日志放到其他不受限制的路径下来解决这个问题,即通过下面的SQL来修改归档日志的存放路径:
1
2
3
4
5
6
7
8alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog';
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查看归档日志位置
1 | 查看归档日志位置 |
关闭归档模式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
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.
alter database noarchivelog;
alter database open;
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
以dba用户登录
确认使用的undo空间就是undotbs01
1
show parameter undo_tablespace;
查询结果为:
name type value undo_tablespace string undotbs1 查看表空间和文件的对应关系
1
select file_name, tablespace_name, online_status from dba_data_files where tablespace_name='UNDOTBS1';
查询结果为:
file_name tablespace_name online_status /oradata/DB/undotbs01.dbf UNDOTBS1 ONLINE 查询当前回退表空间状态
1
select tablespace_name, status from dba_rollback_segs;
查询结果为:10条UNDOTBS1,状态全部为ONLINE
设置一个临时空间供undo_tablespace 使用
1
2create undo tablespace UNDOTBS2 datafile '/oradata2/DB/undotbs02.dbf' size 100M;
alter system set undo_tablespace=UNDOTBS2;重新查询当前回退表空间状态
1
select tablespace_name, status from dba_rollback_segs;
查询结果为:10条UNDOTBS1,状态全部为OFFLINE;10条UNDOTBS2,状态全部为ONLINE;证明回退表空间已经设置到UNDOTBS2
删除回退表空间UNDOTBS1
1
drop tablespace UNDOTBS1 including contents and datafiles;
重启oracle
1
2shutdown immediate;
startup;重新设置回来
1
2
3
4
5
6
7
8
9
10create 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 ; |