首页 > 代码库 > oracle 常用随笔
oracle 常用随笔
---统计失效索引
select sum(a.aa) from (
select count(*) aa from dba_indexes where status=‘UNUSABLE‘
union all
select count(*) aa from dba_ind_partitions where status=‘UNUSABLE‘
union all
select count(*) aa from dba_ind_subpartitions where status=‘UNUSABLE‘
)a
select count(*) aa from dba_indexes where status=‘UNUSABLE‘
union all
select count(*) aa from dba_ind_partitions where status=‘UNUSABLE‘
union all
select count(*) aa from dba_ind_subpartitions where status=‘UNUSABLE‘
)a
--查失效索引,并且生成重建语句:
select ‘alter index ‘||owner||‘.‘||index_name||‘ rebuild parallel 4 online;‘
from dba_indexes where status=‘UNUSABLE‘
union all
select ‘alter index ‘||index_owner||‘.‘||index_name||
‘ rebuild partition ‘||partition_name||‘ parallel 4 online;‘
from dba_ind_partitions where status=‘UNUSABLE‘
union all
select ‘alter index ‘||index_owner||‘.‘||index_name||
‘ rebuild subpartition ‘||subpartition_name||‘ parallel 4 online;‘
union all
select ‘alter index ‘||index_owner||‘.‘||index_name||
‘ rebuild partition ‘||partition_name||‘ parallel 4 online;‘
from dba_ind_partitions where status=‘UNUSABLE‘
union all
select ‘alter index ‘||index_owner||‘.‘||index_name||
‘ rebuild subpartition ‘||subpartition_name||‘ parallel 4 online;‘
from dba_ind_subpartitions where status=‘UNUSABLE‘;
例如:
alter index DEVELOP.IDX_RULE_REL_ID rebuild parallel 4 online;
alter index DEVELOP.IDXULE_REL_TIME rebuild parallel 4 online;
alter index DEVELOP.THRES_DAY rebuild parallel 4 online;
--- 清理归档日志脚本
XXXXdb2@oracle$more /data/del_archlog.sh
#!/bin/bash
cd /data
source ~/.bash_profile
rman log=‘/data/del_archlog.log‘ append <<EOF
connect target /;
run{
DELETE NOPROMPT ARCHIVELOG ALL COMPLETED BEFORE ‘SYSDATE-3‘;
}
EOF
echo "executed rman at: `date +‘%Y-%m-%d %H:%M:%S‘`" >>del_archlog.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
-- oracle删除重复数据
delete from t_site a
where a. I_SITE_ID in (select b.I_SITE_ID from t_res_site b group by b.I_SITE_ID having count(b.I_SITE_ID) > 1)
and rowid not in (select min(rowid) from t_res_site b group by b.I_SITE_ID having count(b.I_SITE_ID)>1)
-- 增加表空间大小的四种方法
Meathod1:给表空间增加数据文件
ALTER TABLESPACE app_data ADD DATAFILE
‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF‘ SIZE 50M;
Meathod2:新增数据文件,并且允许数据文件自动增长
ALTER TABLESPACE app_data ADD DATAFILE
‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP04.DBF‘ SIZE 50M
AUTOEXTEND ON NEXT 5M MAXSIZE 100M;
Meathod3:允许已存在的数据文件自动增长
ALTER DATABASE DATAFILE ‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF‘
AUTOEXTEND ON NEXT 5M MAXSIZE 100M;
Meathod4:手工改变已存在数据文件的大小
ALTER DATABASE DATAFILE ‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP02.DBF‘
Meathod1:给表空间增加数据文件
ALTER TABLESPACE app_data ADD DATAFILE
‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF‘ SIZE 50M;
Meathod2:新增数据文件,并且允许数据文件自动增长
ALTER TABLESPACE app_data ADD DATAFILE
‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP04.DBF‘ SIZE 50M
AUTOEXTEND ON NEXT 5M MAXSIZE 100M;
Meathod3:允许已存在的数据文件自动增长
ALTER DATABASE DATAFILE ‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF‘
AUTOEXTEND ON NEXT 5M MAXSIZE 100M;
Meathod4:手工改变已存在数据文件的大小
ALTER DATABASE DATAFILE ‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP02.DBF‘
RESIZE 100M;
--- 创建小文件表空间 (小文件SMALLFILE 单个文件最大30G;)
CREATE SMALLFILE
TABLESPACE "OPENTDB"
LOGGING
DATAFILE ‘+DATA/XXXdb/datafile/db_data01.dbf‘ SIZE 20480M AUTOEXTEND ON NEXT 512M MAXSIZE 30480M,
‘+DATA/XXXdb/datafile/db_data02.dbf‘ SIZE 20480M AUTOEXTEND ON NEXT 512M MAXSIZE 30480M,
‘+DATA/XXXdb/datafile/db_data03.dbf‘ SIZE 20480M AUTOEXTEND ON NEXT 512M MAXSIZE 30480M,
‘+DATA/XXXdb/datafile/db_data04.dbf‘ SIZE 20480M AUTOEXTEND ON NEXT 512M MAXSIZE 30480M,
‘+DATA/XXXdb/datafile/db_data05.dbf‘ SIZE 20480M AUTOEXTEND ON NEXT 512M MAXSIZE 30480M
EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
----核实安装数据库时有没修改默认的帐号密码有效期:
select * from dba_profiles where profile = ‘DEFAULT‘ and resource_name = ‘PASSWORD_LIFE_TIME‘;
oracle 10g的密码没有默认期限,但11g默认只有180天,需要手工调整:
sqlplus / as sysdba
--查看概要文件的密码有效期设置,一般为default
select * from dba_profiles where profile = ‘DEFAULT‘ and resource_name = ‘PASSWORD_LIFE_TIME‘;
--将概要文件的密码有效期由默认的180天修改成无限制,不用重启数据库
alter profile default limit password_life_time unlimited;
--将已经提示ORA_28002警告的用户解锁
alter user 用户名 identified by 密码 account unlock;
oracle 常用随笔
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。