当前位置:操作系统 > Unix/Linux >>

数据库迁移命令备忘

数据库迁移命令备忘
 
Name
Value
查看表空间及位置
select a.tablespace_name ,b.file_name,a.block_size,a.block_size,b.bytes/1024/1024 "Sum MB" from dba_tablespaces a,dba_data_files b where a.tablespace_name=b.tablespace_name;
 
 
 
创建表空间及指定位置
CREATE SMALLFILE TABLESPACE "MDB_TEST"
DATAFILE '/home/itiltest/itildbs/oradata/ITILRPDB/MDB_DATESPACE3'
SIZE 1M
AUTOEXTEND ON NEXT 10M
MAXSIZE UNLIMITED LOGGING
EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO DEFAULT NOCOMPRESS
改变表空间的数据文件位置
1.alter tablespace MDB_DATA offline;
2.alter database rename file '/home/oracle/app/oracle11g/dbs/homeitiltestitildbsoradataITILRPDBMDB_INDEXSPACE' to /home/itiltest/itildbs/oradata/ITILRPDB/homeitiltestitildbsoradataITILRPDBMDB_INDEXSPACE'
3.alter tablespace MDB_DATA online;
备注:运行未成功正在查找原因
删除表空间
Drop  tablesapce xxx
备注:如果有内容的话使用 Drop tablespace xxx including contents
Widows下文件导入
C:\Users\zhangxuegang>imp mdbadmin/mdbadmin@orcl file=i:\reportData\(
d1.dmp,d2.dmp,d3.dmp,d4
.dmp,d5.dmp,d6.dmp,d7.dmp,d8.dmp,d9.dmp,d10.dmp,d11.dmp,d12.dmp,d13.dmp,d14.dmp,
d15.dmp
) tables=ca_contact ignore =y
 
 
impdp mdbadmin/password@mdb directory =dump_data dumpfile=d1.dmp,d2.dmp,d3.dmp,d4.dmp,d5.dmp,d6.dmp,d7.dmp,d8.dmp,d9.dmp,d10.dmp,d11.dmp,d12.dmp,d13.dmp,d14.dmp,d15.dmp full=y
Unix下文件导入
I:\reportData>impdp mdbadmin/mdbadmin@orcl directory =dump_report dumpfile=d1.d
mp,d2.dmp,d3.dmp,d4.dmp,d5.dmp,d6.dmp,d7.dmp,d8.dmp,d9.dmp,d10.dmp,d11.dmp,d12.d
mp,d13.dmp,d14.dmp,d15.dmp tables=usp_contact
先创建directory 路径
备注:这个路径是指定dumpfile的相对路径
1.create directory dump_data as '/home/itiltest/data';
2.select * from dba_directories
3.grant read, write on directory dump_data to mdbadmin;
由于进行全库迁移使用expdp方式导出全库,即指定full=y,但是在其他机器上导入时,由于expdp全库导出时已经自带建立表空间的脚本,而新机器盘符与原来不一样,无法创建表空间,如何在导入之前指定表空间的位置呢。比如原来是"I:\oracle\product\test" 而新机器就没有I盘,如何手动指定到"E:\oracle"文件夹下
impdp scott/tiger FULL=y directory=dumpo dumpfile=full.dmp  REMAP_DATAFILE='I:\oracle\product\test\test.dbf':'E:\oracle\product\test\test.dbf'
解决clob字段不能直接用dblink取的问题
错误的名称:dblink无法使用从远程表选择的lob定位器的问题
 
zhangxuegang 于 2013/3/15 10:59 修改
 
解决方法:1.可以先创建临时表,然后把远程的blob字段的表克隆到临时表中,然后进行链接操作
代码:
Create global temporary table qtggxx_temp as select  titie ,content ,create_date,ref_id from qtggxx@test_link;
                       2.同过dblink创建视图查看远程数据
Create or replace view qtggxx as select "title",(select p.cotent from qtggxx_temp p where p.ref_id=ref_id )as content,"create_date","ref_id","source_ref_url"
,"bm_id" from qtggxx@test_link
 
 
只导入表结构
expdb u1/u1@orcl directory=xxx content = metadata_only  dumpfile =xxx.dmp schemas =xx logfule =u1.log
文件导入导出的大小比例
dmp文件——dmp.gz的压缩比例为1——5.3
dmp导入数据库后的物理存储空间大小——导入之后变小(待验证)
查看表数据占用的物理存储
select segment_name,segment_type,bytes/1024/1024 from user_segments where segment_name='COGNOS_CHG_T';
Aix导入之前设置环境
export ORACLE_HOME=/home/oracle/app/oracle11g/
export ORACLE_SID=itilrpdb
export ORACLE_BASE=/home/itiltest/itildbs
export PATH=$ORACLE_HOME/bin:$PATH
export PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin:/home/oracle/app/oracle11g/bin
删除用户,及删掉使用的进程
1.drop user mdbadmin cascade;
2.select username ,sid,serial# from v$session
3.alter  system kill session '31,17'
Dblink创建
create database link ITILDB_LINK
  connect to MDBADMIN
  IDENTIFIED BY "ca1234"
  using '(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 128.64.96.76)(PORT = 1522))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = mdb)
    )
  )';
 
查看 oracle内存使用情况
select a.sid,b.name,a.value from v$sesstat a,v$statname b
where (b.name like '%uga%' or b.name like '%pga%') and a.statistic# = b.statistic#
order by sid
函数的创建
CREATE OR REPLACE FUNCTION "DATE_TO_SEC" (strDate IN CHAR)
--将日期型转换为整型秒
        RETURN INT
AS
        ret NUMBER;
        iDate DATE;
        tDate varchar2(30);
BEGIN
 
        if(length(strDate))>=18 then
         tDate:='YYYY-MM-DD HH24:MI:SS';
        elsif (length(strDate))>7 then
         tDate:='YYYY-MM-DD';
        else
         tDate:='YYYY-MM';
        end if;
        iDate:=TO_DATE(strDate,tDate);
        ret := (iDate-TO_DATE('1970-1-1 8:0:0','YYYY-MM-DD HH24:MI:SS'))*(24*60*60);
RETURN ret;
END ;
物化视图的创建
create materialized view COGNOS_AL_CJS_MV
refresh complete on demand
as
select    distinct
          w.object_id                     变更ID,
          sec_to_date(t.open_date)        时间,
          get_per_site_name(w.ASSIGNEE)   单位,
          GET_PER_DEPT_NAME(w.ASSIGNEE)   部门,
          GET_analyst(w.ASSIGNEE)         经手人ID,
          GET_person(w.ASSIGNEE)          经手人,
          get_person(w.group_id)          经手组,
          w.ASSIGNEE                      ID,
          t.status                        类型
     from chg t, wf w
     where t.id = w.object_id
     and t.status <> 'CL'
普通视图的创建
create or replace view cogno
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,