oracle数据对比--用户,索引,分区,dblink,同义词,视图
问题描述:需要对比用户数据一般在数据库迁移之后,需要对比一下两个库之间的差距,如果登上去一条命令的执行,去统计,就会比较麻烦,这里整理了一些脚本可用。通过创建dblink的方式快速查询,也可以整合到一个脚本中spool到一个文本中
1.创建dblink
1.1 旧库修改tnsname到新库,在新库上添加旧库的tns配置
SQL> !tnsping fzcbdb9i
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =10.136.7.208)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = fzcbdb)))
OK (0 msec)
1.2 旧库创建有访问权限的用户
create user comp identified by comp default tablespace USERS;
grant connect,resource,dba to comp;
1.3 新库创建dblink到旧库
create database link t_s_link connect to comp identified by comp using 'fzcbdb1';
select count(*) from dba_tables@t_s_link;
2.实例查询
select instance_name,status from v$instance; select instance_name,status from v$instance@t_s_link;
3.数据量大小对比
dba_segments
SQL> select sum(bytes)/1024/1024/1024 as size_g from dba_segments; SIZE_G
----------
7420.62244 SQL> select sum(bytes)/1024/1024/1024 as size_g from dba_segments@t_s_link; SIZE_G
----------
8972.52301
4.用户对比
4.1创建用户对比
select username from all_users order by created;
select username from all_users@t_s_link order by created;
4.2用户下对象总数
SELECT OWNER, COUNT(*)
FROM DBA_OBJECTS
WHERE OWNER NOT IN ( 'SYS', 'OUTLN', 'SYSTEM', 'CTXSYS', 'DBSNMP',
'LOGSTDBY_ADMINISTRATOR', 'ORDSYS', 'ORDPLUGINS', 'OEM_MONITOR',
'WKSYS', 'WKPROXY', 'WK_TEST', 'WKUSER', 'MDSYS', 'LBACSYS', 'DMSYS',
'WMSYS', 'EXFSYS', 'SYSMAN', 'MDDATA', 'SI_INFORMTN_SCHEMA', 'XDB', 'ODM')
GROUP BY OWNER; SELECT OWNER, COUNT(*)
FROM DBA_OBJECTS@t_s_link
WHERE OWNER NOT IN ( 'SYS', 'OUTLN', 'SYSTEM', 'CTXSYS', 'DBSNMP',
'LOGSTDBY_ADMINISTRATOR', 'ORDSYS', 'ORDPLUGINS', 'OEM_MONITOR',
'WKSYS', 'WKPROXY', 'WK_TEST', 'WKUSER', 'MDSYS', 'LBACSYS', 'DMSYS',
'WMSYS', 'EXFSYS', 'SYSMAN', 'MDDATA', 'SI_INFORMTN_SCHEMA', 'XDB', 'ODM')
GROUP BY OWNER;
4.4用户对象类型
set pages 12222 lines 132
select c.OWNER,c.object_type,c.cntlinux,d.cntaix,c.cntlinux-d.cntaix diff from
(select a.OWNER,a.object_type,count(*) cntlinux from dba_objects a where owner in ('DBSFWUSER','DVF','RIDP','FEX','CREDIT','ETL','TST','FDM','UPRR','JGDB','ACTIONUSER','DZDA','BKMONITOR','WKXTOAUSER','SENSORS','PUBLIC','OLAPSYS','SDM','ORACLE_OCM','AUDSYS','DVSYS','BP_QUERY','GSMADMIN_INTERN','AL','OJVMSYS','USE','GDM','APPQOSSYS','ORDDATA','BAK','SMARTBI','EXPDPUSER','REMOTE_SCHEDULE','R_AGENT') group by a.OWNER,a.OBJECT_TYPE) c,(
select b.OWNER,b.object_type,count(*) cntaix from dba_objects b group by b.OWNER,b.OBJECT_TYPE) d where c.owner=d.owner(+) and c.object_type=d.object_type(+) order by c.owner,c.object_type
/ set pages 1222 lines 132
select c.OWNER,c.object_type,c.STATUS,c.cntlinux,d.cntaix,c.cntlinux-(decode(d.cntaix,null,0,cntaix)) diff from
(select a.OWNER,a.object_type,a.status,count(*) cntlinux from dba_objects a where owner ='ODSSMIS' group by a.OWNER,a.OBJECT_TYPE,a.STATUS) c,(
select b.OWNER,b.object_type,b.STATUS,count(*) cntaix from dba_objects@t_s_link b group by b.OWNER,b.OBJECT_TYPE,b.STATUS) d where c.owner=d.owner(+) and c.object_type=d.object_type(+) and c.status=d.status(+) order by c.owner,c.object_type
/
4.5单一用户对象对比
select c.OWNER,c.object_type, cntlinux,cntaix ,cntlinux-cntaix diff from (
select a.OWNER,a.object_type,count(*) cntlinux from dba_objects a where a.owner ='FDM' group by a.OWNER,a.OBJECT_TYPE) c
,(select b.OWNER,b.object_type,count(*) cntaix from dba_objects b where b.owner ='FDM' group by b.OWNER,b.OBJECT_TYPE) d
where c.owner=d.owner and c.object_type=d.object_type order by c.owner,c.object_type
/ select c.OWNER,c.object_type, cntlinux,cntaix ,cntlinux-cntaix diff from (
select a.OWNER,a.object_type,count(*) cntlinux from dba_objects@t_s_link a where a.owner ='FDM' group by a.OWNER,a.OBJECT_TYPE) c
,(select b.OWNER,b.object_type,count(*) cntaix from dba_objects b where b.owner ='FDM' group by b.OWNER,b.OBJECT_TYPE) d
where c.owner=d.owner and c.object_type=d.object_type order by c.owner,c.object_type
/
4.6单一用户表分区对比
col object_type for a20
col object_name for a25
select object_name,object_type,CREATED,TIMESTAMP,TEMPORARY from dba_objects where owner ='JGDB' and object_type='TABLE PARTITION'; col object_type for a20
col object_name for a25
select object_name,object_type,CREATED,TIMESTAMP,TEMPORARY from dba_objects@t_s_link where owner ='JGDB' and object_type='TABLE PARTITION';
4.7单一用户表分区数量对比
select count(0) from dba_objects where owner ='JGDB' and object_type='TABLE PARTITION'; select count(0) from dba_objects@t_s_link where owner ='JGDB' and object_type='TABLE PARTITION';
4.8表分区详细对比
col object_name for a35
select c.object_name, cntlinux,cntaix ,cntlinux-cntaix diff from
(select count(0) cntaix,object_name from dba_objects where owner ='JGDB' and object_type='TABLE PARTITION' group by object_name) c,
(select count(0) cntlinux,object_name from dba_objects where owner ='JGDB' and object_type='TABLE PARTITION' group by object_name) d
where c.object_name=d.object_name(+) order by object_name; col object_name for a35
select c.object_name, cntlinux,cntaix ,cntlinux-cntaix diff from
(select count(0) cntaix,object_name from dba_objects@t_s_link where owner ='JGDB' and object_type='TABLE PARTITION' group by object_name) c,
(select count(0) cntlinux,object_name from dba_objects where owner ='JGDB' and object_type='TABLE PARTITION' group by object_name) d
where c.object_name=d.object_name(+) order by object_name;
4.9无效对象
select c.OWNER,'INVALID' ,linuxcnt ,aixcnt,linuxcnt-aixcnt diff from (select o.OWNER, count(*) linuxcnt from dba_objects o
where o.status='INVALID' and o.OWNER in ('DBSFWUSER','DVF','RIDP','FEX','CREDIT','ETL','TST','FDM','UPRR','JGDB','ACTIONUSER','DZDA','BKMONITOR','WKXTOAUSER','SENSORS','PUBLIC','OLAPSYS','SDM','ORACLE_OCM','AUDSYS','DVSYS','BP_QUERY','GSMADMIN_INTERN','AL','OJVMSYS','USE','GDM','APPQOSSYS','ORDDATA','BAK','SMARTBI','EXPDPUSER','REMOTE_SCHEDULE','R_AGENT')
group by o.OWNER
order by o.OWNER ) c,
(select o.OWNER, count(*) aixcnt from dba_objects o
where o.status='INVALID' and o.OWNER in ('DBSFWUSER','DVF','RIDP','FEX','CREDIT','ETL','TST','FDM','UPRR','JGDB','ACTIONUSER','DZDA','BKMONITOR','WKXTOAUSER','SENSORS','PUBLIC','OLAPSYS','SDM','ORACLE_OCM','AUDSYS','DVSYS','BP_QUERY','GSMADMIN_INTERN','AL','OJVMSYS','USE','GDM','APPQOSSYS','ORDDATA','BAK','SMARTBI','EXPDPUSER','REMOTE_SCHEDULE','R_AGENT')
group by o.OWNER
order by o.OWNER ) d
where c.owner=d.owner(+)
/ select c.OWNER,'INVALID' ,linuxcnt ,aixcnt,linuxcnt-aixcnt diff from (select o.OWNER, count(*) linuxcnt from dba_objects o
where o.status='INVALID' and o.OWNER in ('PICCSMIS','ODSUSER','ODSSMIS','PICCSMISREAD','VSMIS','DBAMONITOR','R7','FMIS_SMIS','FMIS_WRITEBACK','SMIS2MP','ECIF_SMIS','SUGGEST_SMIS','SMISCRM','XXX')
group by o.OWNER
order by o.OWNER ) c,
(select o.OWNER, count(*) aixcnt from dba_objects@t_s_link o
where o.status='INVALID' and o.OWNER in ('PICCSMIS','ODSUSER','ODSSMIS','PICCSMISREAD','VSMIS','DBAMONITOR','R7','FMIS_SMIS','FMIS_WRITEBACK','SMIS2MP','ECIF_SMIS','SUGGEST_SMIS','SMISCRM','XXX')
group by o.OWNER
order by o.OWNER ) d
where c.owner=d.owner(+)
/
4.10有效对象
select c.OWNER,'VALID' ,linuxcnt ,aixcnt,linuxcnt-aixcnt diff from (select o.OWNER, count(*) linuxcnt from dba_objects o
where o.status='VALID' and o.OWNER in ('PICCSMIS','ODSUSER','ODSSMIS','PICCSMISREAD','VSMIS','DBAMONITOR','R7','FMIS_SMIS','FMIS_WRITEBACK','SMIS2MP','ECIF_SMIS','SUGGEST_SMIS','SMISCRM','XXX')
group by o.OWNER
order by o.OWNER ) c,
(select o.OWNER, count(*) aixcnt from dba_objects o
where o.status='VALID' and o.OWNER in ('PICCSMIS','ODSUSER','ODSSMIS','PICCSMISREAD','VSMIS','DBAMONITOR','R7','FMIS_SMIS','FMIS_WRITEBACK','SMIS2MP','ECIF_SMIS','SUGGEST_SMIS','SMISCRM','XXX')
group by o.OWNER
order by o.OWNER ) d
where c.owner=d.owner
/ select c.OWNER,'VALID' ,linuxcnt ,aixcnt,linuxcnt-aixcnt diff from (select o.OWNER, count(*) linuxcnt from dba_objects o
where o.status='VALID' and o.OWNER in ('PICCSMIS','ODSUSER','ODSSMIS','PICCSMISREAD','VSMIS','DBAMONITOR','R7','FMIS_SMIS','FMIS_WRITEBACK','SMIS2MP','ECIF_SMIS','SUGGEST_SMIS','SMISCRM','XXX')
group by o.OWNER
order by o.OWNER ) c,
(select o.OWNER, count(*) aixcnt from dba_objects@t_s_link o
where o.status='VALID' and o.OWNER in ('PICCSMIS','ODSUSER','ODSSMIS','PICCSMISREAD','VSMIS','DBAMONITOR','R7','FMIS_SMIS','FMIS_WRITEBACK','SMIS2MP','ECIF_SMIS','SUGGEST_SMIS','SMISCRM','XXX')
group by o.OWNER
order by o.OWNER ) d
where c.owner=d.owner
/
4.11diff view
set pages 12222 lines 132
col OBJECT_TYPE for a15
col object_name for a33
select * from
(select object_name,object_type from dba_objects b where b.owner ='ODSSMIS' and object_type='VIEW'
minus
select object_name,object_type from dba_objects a where a.owner ='ODSSMIS' and object_type='VIEW') order by object_type,object_name
/ set pages 12222 lines 132
col OBJECT_TYPE for a15
col object_name for a33
select * from
(select object_name,object_type from dba_objects@t_s_link b where b.owner ='ODSSMIS' and object_type='VIEW'
minus
select object_name,object_type from dba_objects a where a.owner ='ODSSMIS' and object_type='VIEW') order by object_type,object_name
/
4.12用户索引
select index_name,table_name,owner from dba_indexes where table_owner in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC'); select index_name,table_name,owner from dba_indexes@t_s_link where table_owner in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC');
4.13用户对象权限,被赋予public用户的表
select * from dba_tab_privs where owner in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC') and grantee='PUBLIC'; select * from dba_tab_privs@t_s_link where owner in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC') and grantee='PUBLIC';
4.14用户权限
col owner format a10
col privilege format a10
select * from dba_sys_privs where grantee in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC') order by grantee;
select * from dba_tab_privs where grantee in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC') order by grantee;
select * from dba_role_privs where grantee in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC') order by grantee; col owner format a10
col privilege format a10
select * from dba_sys_privs@t_s_link where grantee in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC') order by grantee;
select * from dba_tab_privs@t_s_link where grantee in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC') order by grantee;
select * from dba_role_privs@t_s_link where grantee in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC') order by grantee;
4.15段类型统计
select segment_type,count(*) from dba_segments where owner='DEVELOP' group by segment_type;
select count(*) from dba_segments where owner='DEVELOP';
select count(*) from dba_constraints where owner='DEVELOP'; select segment_type,count(*) from dba_segments@t_s_link where owner='DEVELOP' group by segment_type;
select count(*) from dba_segments@t_s_link where owner='DEVELOP';
select count(*) from dba_constraints@t_s_link where owner='DEVELOP';
4.16约束统计
select constraint_type,count(*) from dba_constraints where owner='DEVELOP' group by CONSTRAINT_TYPE;
select STATUS,COUNT(*) from dba_constraints where owner='DEVELOP' group by status; select constraint_type,count(*) from dba_constraints@t_s_link where owner='DEVELOP' group by CONSTRAINT_TYPE;
select STATUS,COUNT(*) from dba_constraints@t_s_link where owner='DEVELOP' group by status;
5.db_link
col created format a10
col db_link format a25
select * from dba_db_links order by db_link; col created format a10
col db_link format a25
select * from dba_db_links@t_s_link order by db_link;
6.public的同义词
set linesize 1000
col SYNONYM_NAME format a40
col table_name format a40
select *
from dba_synonyms
where owner = 'PUBLIC'
and TABLE_OWNER in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC'); set linesize 1000
col SYNONYM_NAME format a40
col table_name format a40
select *
from dba_synonyms@t_s_link
where owner = 'PUBLIC'
and TABLE_OWNER in ('DEVELOP','DBUSER','HDCQRY','FINGER','DBQUERY','MCTC');
7.自动任务统计
select job,LOG_USER,LAST_DATE,NEXT_DATE,INTERVAL,FAILURES,BROKEN,WHAT from dba_jobs; select job,LOG_USER,LAST_DATE,NEXT_DATE,INTERVAL,FAILURES,BROKEN,WHAT from dba_jobs@t_s_link;
oracle数据对比--用户,索引,分区,dblink,同义词,视图的更多相关文章
- Oracle创建删除用户,角色,表空间,导入导出数据库命令总结(转载)
无意间看到一篇文章,觉得对于ORACLE的新手很实用,特转载,原文出处这里 说明:在创建数据库时输入的密码,是修改系统默认的密码,以system和sysman等系统默认身份登录时要输入的密码就是修改后 ...
- Oracle 分区表管理之组合分区(分区索引失效与性能比较)
整体结构如下: Oracle 分区表管理之组合分区(分区索引失效与性能比较) 虽然老早就使用了分区表,终于有时间写有关分区表的内容:不是所有的场景数据量变大需要用到分区表,一般单表数据超过2g可以考 ...
- 45.oracle表类型、数据拆分、表分区
不要做一些没有意义的事情,就比如说你要离职并不打算吃回头草,离职理由中完全没有必要说明“领导的水平太渣,人品太差”此类的原因,而是“个人原因”,当然实在不批准辞职另说. oracle表类型 表的类型分 ...
- 详解Oracle数据货场中三种优化:分区、维度和物化视图
转 xiewmang 新浪博客 本文主要介绍了Oracle数据货场中的三种优化:对分区的优化.维度优化和物化视图的优化,并给出了详细的优化代码,希望对您有所帮助. 我们在做数据库的项目时,对数据货场的 ...
- Oracle数据泵导入的时候创建索引是否会使用并行?
一.疑问,Oracle数据泵导入的时候创建索引是否会使用并行? 某客户需要使用数据泵进行迁移,客户咨询导入的时间能不能加快一点. 那么如何加快导入的速度呢? 多加一些并行,那么创建索引内部的索引并行度 ...
- oracle表分区、表分析及oracle数据泵文件导入导出开心版
1.先说oracle表分区是什么吧,这样吧我们来举个桃子,栗子太小,我们就不举了,我们来举个桃子. 你有500万份文件,你要把他存在磁盘上,好嘛,我们就一个文件夹,500万分文件在那儿杵着,我们想找到 ...
- oracle删除当前用户以及当前用户所有表、索引等操作
ORACLE删除当前用户下所有的表的方法 如果有删除用户的权限,则可以: drop user user_name cascade; 加了cascade就可以把用户连带的数据全部删掉.删除后再创建该用户 ...
- oracle表分区、表分析及oracle数据泵文件导入导出
1.先说oracle表分区是什么吧 你有500万份文件,你要把他存在磁盘上,好嘛,我们就一个文件夹,500万分文件在那儿杵着,我们想找到要的那个打开,嘿嘿,我们得找到什么时候. 这时候,有个人告诉你, ...
- Oracle数据库---序列、索引、同义词
--创建序列create sequence deptno_seqstart with 50increment by 10maxvalue 70cache 3; --为了方便演示,创建了一个和dept表 ...
- Oracle 表结构、索引以及分区信息查询
Oracle 表结构.索引以及分区信息查询 /* 获取表:*/ select table_name from user_tables; --当前用户的表 select table_name from ...
随机推荐
- vscode 远程服务器同步
1.下载 sftp 2. 在项目目录下新建sftp.json文件 3. 编辑sftp.json文件 { "name": "My Server", "h ...
- 搭建sftp服务器
sftp采用的是ssh加密隧道,安装性方面较ftp强,而且依赖的是系统自带的ssh服务,不像ftp还需要额外的进行安装 1. 创建sftp组 # groupadd sftp 创建完成之后使用ca ...
- linux 离线安装jdk
系统版本:centos7.8 | jdk版本:1.8 jdk版本:jdk-8u5-linux-x64.rpm 点击下载 提取码: ud1r 检查系统是否已经有JDK,输入如下命令查看是否系统中是否已安 ...
- Checkmarx
1.概述 CheckMarx:是以色列的一家高科技软件公司,也是世界上最著名的源代码安全扫描软件CheckmarxCxSuite的生产商. Checkmarx CxEnterprise(Checkma ...
- 图模导入原理之 SVG图形基础与图形导入
一.svg图形基础 PMS图形中,图形svg文件内容一般由两部分组成: 1.<defs>标签中定义的是图元信息,即各种不同设备不同状态的图元应该如何显示: 2.各种<XXXXXX_L ...
- 解决和根源:Unsolicited response received on idle HTTP channel starting with xxx
环境:golang,使用http client,服务器:iis +aspx.net动作:head请求或其他此问题见于各种请求情况.核心是,http在活动期间收到了非预期的信息.一开始我也很纳-闷,因为 ...
- manu check RAID GEM count and Fragment count of local FN>1
cat MANU_CHK.sh echo "input Chr" read C echo "input Start" read S echo "inp ...
- Python命令提示符:不是内部或外部命令,也不是可运行的程序或批处理文件
Python原装IDE(Integrated Development Environment)安装时,需要确认更新pip(什么是 pip ?pip 是 Python 中的标准库管理器.它允许你安装和管 ...
- centos7.6 挂载镜像配置本地yum源
镜像下载 http://mirrors.aliyun.com/centos-vault/7.6.1810/isos/x86_64/ 配置本地yum源 1.安装Centos后默认的Yum源如下 [roo ...
- Java学习文档
数在计算机中是以二进制形式表示的,分为有符号数和无符号数,原码.反码.补码都是有符号定点数的表示方法.一个有符号定点数的最高位为符号位,0是正,1是负(以8位整数为例),例如0000001 就是+1, ...