Oracle dbf文件移动的方法

背景

oracle空间不足,发现dbf文件未按设计的路径存放,linux磁盘挂载空间未利用,需要移动一下位置错误的dbf文件。

检查文件系统

/home/oracle \>df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/lv01-root 22G 4.5G 16G 23% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 96K 3.9G 1% /dev/shm
tmpfs 3.9G 153M 3.7G 4% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 190M 132M 44M 75% /boot
/dev/mapper/lv02-home 20G 19G 0 100% /home
/dev/mapper/oradatalv-oradata 30G 18G 9.8G 65% /oradata
tmpfs 781M 16K 781M 1% /run/user/42
tmpfs 781M 0 781M 0% /run/user/1001
tmpfs 781M 0 781M 0% /run/user/0

home挂载点下空间已达到100%。

检查大文件

/home/oracle/oradata/ora12c \>ls -lh
总用量 8.7G
\-rw-r-----. 1 oracle oinstall 6.7G 5月 20 13:54 upbs_data.dbf
\-rw-r-----. 1 oracle oinstall 2.0G 5月 20 05:06 upbs_index.dbf

发现是dbf文件过大后,准备移动一下。应该存放数据库文件的oradata挂载点下还有剩余空间可以存放dbf文件。

/home/oracle/oradata/ora12c >sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on
Wed May 20 14:18:36 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
ERROR:
ORA-09817: Write to audit file failed.
Linux-x86_64 Error: 28: No space left on device
Additional information: 12
ORA-09945: Unable to initialize the audit trail file
Linux-x86_64 Error: 28: No space left on device

oracle sqlplus直接登录失败,显示空间不足。

删除审计文件日志

/home/oracle/audit \>rm \*
/home/oracle/audit \>ll
总用量 0

删除后查看磁盘空间,发现刚删的审计文件有点少

/home/oracle/audit \>df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/lv01-root 22G 4.5G 16G 23% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 96K 3.9G 1% /dev/shm
tmpfs 3.9G 153M 3.7G 4% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 190M 132M 44M 75% /boot
/dev/mapper/lv02-home 20G 19G 60K 100% /home
/dev/mapper/oradatalv-oradata 30G 18G 9.8G 65% /oradata
tmpfs 781M 16K 781M 1% /run/user/42
tmpfs 781M 0 781M 0% /run/user/1001
tmpfs 781M 0 781M 0% /run/user/0

删除后有60k空间剩余,开始没发现aud文件路径有问题, 不是正常的aud路径。

重新查找清理审计日志释放空间

/home/oracle/app/oracle/admin/orcl \>find ./ -name \*aud

查询出结果后清除前30天的

/home/oracle/app/oracle/admin/orcl \>find ./ -name \*aud -mtime +30 \|xargs rm
-f

关闭数据库

/home/oracle/audit \>sqlplus / as sysdba
SQL\*Plus: Release 12.1.0.2.0 Production on Wed May 20 14:14:30 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing
options
SQL\> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

复制dbf文件

/home/oracle/oradata/ora12c \>cp upbs_data.dbf
/oradata/orcl/appdata/upbs_data.dbf

登录数据库修改dbf文件路径

home/oracle/app/oracle/admin/orcl \>sqlplus / as sysdba
SQL\*Plus: Release 12.1.0.2.0 Production on Wed May 20 14:33:30 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to an idle instance.
SQL\> startup mount;
ORACLE instance started.
Total System Global Area 2466250752 bytes
Fixed Size 2927384 bytes
Variable Size 671089896 bytes
Database Buffers 1778384896 bytes
Redo Buffers 13848576 bytes
Database mounted.
SQL\> alter database rename file '/home/oracle/oradata/ora12c/upbs_data.dbf' to
'/oradata/orcl/appdata/upbs_data.dbf';
Database altered.

重启数据库服务

SQL\> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL\> startup
ORACLE instance started.
Total System Global Area 2466250752 bytes
Fixed Size 2927384 bytes
Variable Size 671089896 bytes
Database Buffers 1778384896 bytes
Redo Buffers 13848576 bytes
Database mounted.
Database opened.
SQL\>

plsql重新连接数据库成功,删除原来的dbf文件释放空间

总结

相关推荐