栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

linux磁盘满了之后清理

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux磁盘满了之后清理

cd /
df -h
du -h --max-depth=1
选择较大的目录cd继续
du -h --max-depth=1
按目录大小排序
du  -h --max-depth=2 | sort -n
ls -lhS


直接查找大于莫个值的文件
find / -size +1G -print

发现是oracle数据占用了空间,需要清理日志和缩小表空间

oracle监听日志清理
1、先停监听日志
su - oracle
lsnrctl set log_status off;
2、删除日志
(11g监听日志路径)
/u01/app/oracle/diag/tnslsnr/“实例名”/listener/alert
/u01/app/oracle/diag/tnslsnr/“实例名” /listener/trace
3、删除后再执行命令把日志启动
lsnrctl set log_status on;

检查log.xml和listener.log文件是否创建

oracle表空间很大,但是数据很少,可以缩小下表空间,释放下磁盘;

--查询表空间使用情况
SELECt a.tablespace_name "表空间名",
       total "表空间大小",
       free "表空间剩余大小",
       (total - free) "表空间使用大小",
       total / (1024 * 1024 * 1024) "表空间大小(G)",
       free / (1024 * 1024 * 1024) "表空间剩余大小(G)",
       (total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)",
       round((total - free) / total, 4) * 100 "使用率 %"
  FROM (SELECt tablespace_name, SUM(bytes) free
          FROM dba_free_space
         GROUP BY tablespace_name) a,
       (SELECt tablespace_name, SUM(bytes) total
          FROM dba_data_files
         GROUP BY tablespace_name) b
 WHERe a.tablespace_name = b.tablespace_name;
 -- 查询表空间保存的文件位置
 SELECt * FROM dba_data_files
 

-- 清理表空间
 alter tablespace USERS coalesce;

-- 重新修改表空间大小
 alter database datafile '/opt/oracle/oradata/orcl/users.dbf' resize 3G;

有时因为原表空间上有些数据占用了大小之外的位置导致不能缩小的,就需要把数据都移动到其他表空间,然后缩小表空间之后再从其他表空间里把数据都移动回来。

-- /opt/oracle/oradata/orcl/users01.dbf    4    USERS
-- 要改小数据文件,我们先要对文件上的表和索引移动一下位置,具体做法如下:
-- 1、移动表前先对表空间做整理
 alter tablespace USERS coalesce;
-- 2、在dba_extents找到与ID=4(id从这里查询 SELECt * FROM dba_data_files )的数据文件相关的表及索引
 select segment_name,partition_name,segment_type  from dba_extents  where file_id=4;
-- 3、对id=4的文件上的表和索引移动位置
 set heading off
 set echo off
 set feedback off
 set termout on
 spool /data/oracledata/aaa.sql
-- 移动表
SQL>select DISTINCT 'alter table '|| segment_name || ' move tablespace test_space;' from dba_extents where segment_type='TABLE' and file_id=4;
-- 移动索引
SQL>select DISTINCT 'alter index '|| segment_name || ' rebuild tablespace test_space;' from dba_extents where segment_type='INDEX' and file_id=4;
-- 移动分区表
SQL>select DISTINCT 'alter table '|| segment_name || ' move partition '|| partition_name || ' tablespace test_space;' from dba_extents where segment_type='TABLE PARTITION' and file_id=4;
-- 移动分区索引
SQL>select DISTINCT 'alter index '|| segment_name || ' rebuild partition '|| partition_name || ' tablespace test_space;' from dba_extents where segment_type='INDEX PARTITION' and file_id=4;
SQL>spool off 
-- 然后执行aaa.sql,注意保证test_space有足够的空间容纳这些数据,其实可以不移动所有的数据,但是总的测验是不是移动了300M以外的数据,所以还是移动所有数据的方便
-- 4、这样移动了所有的数据以后就可以对datafile resize了
SQL> ALTER DATAbase DATAFILE '/opt/oracle/oradata/orcl/users01.dbf' RESIZE 300M ;

数据库已更改。
-- 5、把原来表空间ic_data中的数据再移动回来,修改aaa.sql中的表空间名为ic_data再执行,然后drop tablespace test_space including contents and datafiles。

参考:

Oracle调整表空间大小ORA-03297: 文件包含在请求的 RESIZE 值以外使用的数据问题_cm_0205的博客-CSDN博客

Oracle调整表空间大小——ORA-03297: 文件包含在请求的 RESIZE 值以外使用的数据 - 小龙在线 - 博客园

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/680281.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号