数据库迁移命令备忘
数据库迁移命令备忘NameValue查看表空间及位置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 1MAUTOEXTEND ON NEXT 10MMAXSIZE UNLIMITED LOGGINGEXTENT 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 contentsWidows下文件导入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 =yimpdp 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=yUnix下文件导入I:\reportData>impdp mdbadmin/mdbadmin@orcl directory =dump_report 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 tables=usp_contact先创建directory 路径备注:这个路径是指定dumpfile的相对路径1.create directory dump_data as '/home/itiltest/data';2.select * from dba_directories3.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.3dmp导入数据库后的物理存储空间大小——导入之后变小(待验证)查看表数据占用的物理存储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=itilrpdbexport ORACLE_BASE=/home/itiltest/itildbsexport PATH=$ORACLE_HOME/bin:$PATHexport 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$session3.alter system kill session '31,17'Dblink创建create database link ITILDB_LINKconnect to MDBADMINIDENTIFIED 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 bwhere (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 INTASret NUMBER;iDate DATE;tDate varchar2(30);BEGINif(length(strDate))>=18 thentDate:='YYYY-MM-DD HH24:MI:SS';elsif (length(strDate))>7 thentDate:='YYYY-MM-DD';elsetDate:='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_MVrefresh complete on demandasselect distinctw.object_id 变更ID,sec_to_date(t.open_date) 时间,get_per_site_name(w.ASSIGNEE) 单位,GET_PER_DEPT_NAME(w.ASSIGNEE) 部门,GET_易做图yst(w.ASSIGNEE) 经手人ID,GET_person(w.ASSIGNEE) 经手人,get_person(w.group_id) 经手组,w.ASSIGNEE ID,t.status 类型from chg t, wf wwhere t.id = w.object_idand t.status <> 'CL'普通视图的创建create or replace view cogno上一个:Oracle 10g表空间物理位置转移
下一个:ORACLE之表空间