因为数据表每天有上百万的数据写入表,加上建立索引,导致表空间不停增长,表空间被设置为自动增长,因此dbf文件在不断增大,硬盘
1、环境介绍
服务器硬件:dell r710
服务器os:红帽子linux rhel4.8
数据库:oracle 10g
2、出现的问题
因为数据表每天有上百万的数据写入表,加上建立索引,导致表空间不停增长,表空间被设置为自动增长,因此dbf文件在不断增大,硬盘空间在每天约400m的速度减少。数据库虽有自清理的脚本,清理3个月前的数据,但实际增加的数据太多,清理释放的空间不能满足需求了。
3、处理过程
解决思路是,该服务器的硬盘有预留空间,未完全划分的约有100g,可以建立新的分区,将已经存满的分区的数据库文件移动,来避免挂载点使用率达到100%,同时可以扩充表空间。
3.1 建立分区
以root账号登陆,查看目前使用情况:
[root@ccsvr ~]# df -h
filesystem size used avail use% mounted on
/dev/sda1 7.1g 3.2g 3.6g 48% /
/dev/sda3 44g 9.6g 32g 24% /afc/data
/dev/sda5 15g 3.9g 9.9g 29% /afc/log
/dev/sda2 63g 54g 5.8g 91% /afc_db
/dev/sdb1 56g 39g 15g 73% /afc_db2
none 4.0g 0 4.0g 0% /dev/shm
/dev/sda6 4.9g 3.3g 1.4g 72% /oracle
/dev/sdb2 56g 52g 529m 100% /afc_db3
其中 /dev/sdb2已经快接近用完了。
查看下分区情况:
[root@ccsvr ~]# fdisk -l
disk /dev/sda: 146.1 gb, 146163105792 bytes
255 heads, 63 sectors/track, 17769 cylinders
units = cylinders of 16065 * 512 = 8225280 bytes
device boot start end blocks id system
/dev/sda1 * 1 936 7518388+ 83 linux
/dev/sda2 937 9222 66557295 83 linux
/dev/sda3 9223 14959 46082452+ 83 linux
/dev/sda4 14960 17769 22571325 5 extended
/dev/sda5 14960 16871 15358108+ 83 linux
/dev/sda6 16872 17508 5116671 83 linux
/dev/sda7 17509 17769 2096451 82 linux swap
disk /dev/sdb: 299.4 gb, 299439751168 bytes
255 heads, 63 sectors/track, 36404 cylinders
units = cylinders of 16065 * 512 = 8225280 bytes
device boot start end blocks id system
/dev/sdb1 1 7296 58605088+ 83 linux
/dev/sdb2 7297 14592 58605120 83 linux
/dev/sdb3 14593 32829 146488702+ 5 extended
/dev/sdb5 14593 21888 58605088+ 83 linux
可以看到有两块硬盘,sda为第一块scsi硬盘,sdb为第二块scsi硬盘,其实服务器时四块硬盘,做的raid1。
其中,第一块硬盘,dell的标配146g,安装的操作系统,oracle数据库,已经分完了,三个主分区,三个扩展分区,/dev/sda2 (/afc_db)是开始建立的数据库文件存放目录。
第二块硬盘,是后来增加的300g,/dev/sdb1(/afc_db2),/dev/sdb2(/afc_db3)是两个主分区,作用也是来放数据库文件的,后面还有一个扩展分区/dev/sdb5,这个应该
也是后来加这块硬盘的人创建的,但是没有挂载上。
我的工作就是把/dev/sdb5挂载上,把硬盘还有的空间(32829~21888)的柱面建立成第二个扩展分区,/dev/sdb6。
[root@ccsvr ~]# fdisk /dev/sdb
command (m for help): p
disk /dev/sdb: 299.4 gb, 299439751168 bytes
255 heads, 63 sectors/track, 36404 cylinders
units = cylinders of 16065 * 512 = 8225280 bytes
device boot start end blocks id system
/dev/sdb1 1 7296 58605088+ 83 linux
/dev/sdb2 7297 14592 58605120 83 linux
/dev/sdb3 14593 32829 146488702+ 5 extended
/dev/sdb5 14593 21888 58605088+ 83 linux
/dev/sdb6 21889 32829 87883551 83 linux
注:对第二块硬盘进行分区操作,p:查看分区情况;
command (m for help): n
command action
l logical (5 or over)
p primary partition (1-4)
l
first cylinder (21889-32829, default 21889):
using default value 21889
last cylinder or +size or +sizem or +sizek (21889-32829, default 32829):
using default value 32829
注:n:创建新的分区,
接下来选择分区类型:l:逻辑分区,p主分区
l logical (5 or over),指创建逻辑分区,分区编号要大于5,因为已经存在db5了
p primary partition (1-4),指创建主分区,编号1—4,,linux规定主分区只能有四个。
我这里输入的l,创建逻辑分区。
first cylinder (21889-32829, default 21889):
using default value 21889
注:这个就是填写分区的start柱面,这里直接打回车,使用默认值;
last cylinder or +size or +sizem or +sizek (21889-32829, default 32829):
using default value 32829
注:这里填写分区的end柱面,或者填写+??m,k的方式,linux会自动算出柱面号。我这里要把剩余的硬盘空间全都分到这个分区,所以使用默认值。
command (m for help): p
disk /dev/sdb: 299.4 gb, 299439751168 bytes
255 heads, 63 sectors/track, 36404 cylinders
units = cylinders of 16065 * 512 = 8225280 bytes
device boot start end blocks id system
/dev/sdb1 1 7296 58605088+ 83 linux
/dev/sdb2 7297 14592 58605120 83 linux
/dev/sdb3 14593 32829 146488702+ 5 extended
/dev/sdb5 14593 21888 58605088+ 83 linux
/dev/sdb6 21889 32829 87883551 83 linux
再次查看下分区情况,发现/dev/sdb6/已经创建好了。
command (m for help): w
the partition table has been altered!
calling ioctl() to re-read partition table.
warning: re-reading the partition table failed with error 16: device or resource busy.
the kernel still uses the old table.
the new table will be used at the next reboot.
syncing disks.
执行w命令,写入分区表。
注意:以上操作中如果有误,可以随时撤销,但执行写入后,就不能更改了。
发现,写入后系统提示错误,资源正忙,新的分区表重启后有效。
于是,重启机器,注意重启前,关闭生产程序进程,和oracle数据:
$xxx/bin/xxx_stop
[root@ccsvr ~]# su - oracle
[oracle@ccsvr ~]$ sqlplus / as sysdba;
connected to:
oracle database 10g enterprise edition release 10.2.0.1.0 - production
with the partitioning, olap and data mining options
sql> shutdown immediate;
database closed.
database dismounted.
oracle instance shut down.
sql>
重启后,对/dev/sdb5,/dev/db6格式化:
[root@ccsvr /]# mkfs -t ext3 /dev/sdb6
mke2fs 1.35 (28-feb-2004)
filesystem label=
os type: linux
block size=4096 (log=2)
fragment size=4096 (log=2)
10993664 inodes, 21970887 blocks
1098544 blocks (5.00%) reserved for the super user
first data block=0
maximum filesystem blocks=25165824
671 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000
writing inode tables: done
creating journal (8192 blocks): done
writing superblocks and filesystem accounting information: done
this filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. use tune2fs -c or -i to override.
然后,创建需要挂载的目录,将分区挂载:
[root@ccsvr /]# mkdir afc_db5
[root@ccsvr /]# mkdir afc_db6
[root@ccsvr /]# ll
total 216
drwxr-xr-x 6 afc aas 4096 dec 2 2013 aas
drwxrwxr-x 13 afc aas 4096 dec 27 00:32 afc
drwxr-xr-x 5 oracle oinstall 4096 apr 14 2014 afc_db
drwxr-xr-x 6 oracle oinstall 4096 apr 14 2014 afc_db2
drwxr-xr-x 4 oracle oinstall 4096 apr 14 2014 afc_db3
drwxr-xr-x 2 root root 4096 may 17 21:18 afc_db5
drwxr-xr-x 2 root root 4096 may 17 21:18 afc_db6
这里有一步失误,目录afc_db5和afc_db6是用来存放oracle数据文件的,最好用oracle账号创建,
我已经用root账号创建了,就给它最高权限算了。
[root@ccsvr /]# chmod 777 afc_db5
[root@ccsvr /]# chmod 777 afc_db6
然后,进行挂载:
[root@ccsvr /]# mount /dev/sdb5 /afc_db5
[root@ccsvr /]# mount /dev/sdb6 /afc_db6
修改fstab文件,使开机启动时自动挂载,
这是原fstab文件:
[root@ccsvr /]# more /etc/fstab
# this file is edited by fstab-sync - see 'man fstab-sync' for details
