暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle数据库常用脚本(五)

lh11811 2025-03-28
171

1.角色

select grantee,granted_role from dba_role_privs where GRANTED_ROLE='DBA';

2.数据库用户

set line 300col profile for a10select * from dba_profiles where profile='DEFAULT' and resource_name in ('PASSWORD_LIFE_TIME','FAILED_LOGIN_ATTEMPTS');

如需改成无限制,执行下面语句:

ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;alter profile default limit FAILED_LOGIN_ATTEMPTS unlimited;

数据库用户检查

对象信息

3.数据库大小

select trunc(sum(bytes) / 1024 / 1024 / 1024,2) as db_GB from dba_segments;
col owner for a15select owner, trunc(sum(bytes) / 1024 / 1024,2) as db_MBfrom dba_segmentsgroup by ownerorder by 1;

4.用户信息

set line 200set pagesize 100col ACCOUNT_STATUS for a20col default_tablespace for a15col username for a10select username,to_char(created,'YYYY-MM-DD') created,default_tablespace,ACCOUNT_STATUS from dba_users order by 2;

5.业务用户权限

select grantee,granted_role from dba_role_privs where grantee in ('username') order by 1;Select grantee,privilege from dba_sys_privs where grantee in ('username') order by 1;Select grantee,privilege from dba_tab_privs where grantee in ('username') order by 1;Select role,privilege from role_sys_privs where role in ('CONNECT','RESOURCE') order by role;

6.数据库用户对象检查

---表数量col owner for a10select owner, count(*)from dba_tablesgroup by ownerorder by 1;
---临时表数量select owner, count(*)from dba_tableswhere temporary = 'Y'group by ownerorder by 1;
---索引信息select owner, count(*)from dba_indexesgroup by ownerorder by 1;
---视图数量select owner, count(*)from dba_viewsgroup by ownerorder by 1;
---触发器信息select owner, count(*)from dba_triggersgroup by ownerorder by 1;
---存储过程select owner, count(*)from dba_proceduresgroup by ownerorder by 1;
---无效的对象set line 100set pagesize 300col owner for a20col object_name for a30select owner,object_type,count(*)from dba_objectswhere status = 'INVALID' group by owner,object_type;select owner,object_name,object_typefrom dba_objectswhere status = 'INVALID';

7.分区表信息

注意是否需要手动添加分区

SELECT OWNER,TABLE_NAME,PARTITIONING_TYPE FROM DBA_PART_TABLES ORDER BY 1;

8.查看分区名称等

set line 300set pagesize 1000col table_owner for a20col table_name for a20col PARTITION_NAME for a20col SUBPARTITION_COUNT for a20col MAX_SIZE for a20col HIGH_VALUE for a50select table_owner,table_name,PARTITION_NAME,HIGH_VALUE from dba_tab_PARTITIONS where table_owner not in ('SYS','SYSTEM') ORDER BY 3;

9.JOB和定时任务

set line 150col INTERVAL for a35col SCHEMA_USER for a15col what for a30SELECT job,schema_user,broken,interval,what,last_date,last_sec,BROKEN from dba_jobs;
set line 100col start_date for a20select owner,job_name,job_type,start_date,state from dba_scheduler_jobs;

10.查询索引列 

set line 300set pagesize 100col TABLE_OWNER for a15col TABLE_NAME for a30col COLUMN_NAME for a15col INDEX_NAME for a35select TABLE_OWNER,TABLE_NAME,COLUMN_NAME,INDEX_NAME from dba_ind_columns where TABLE_NAME in ('XXXXXX') order by 2,3;
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论