oracle 表迁移方法 (一)

在生产系统中,因业务需求,56张表中清空54张表数据,另外两张表数据保留,数据量大约10G左右:
1.大部分人想法就是expdp/impdp,的确是这样,哈哈

2.rman

3.以下方法,move

虚拟机单表模拟如下:
[[email protected] ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Nov 3 18:40:16 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf

创建表空间
SQL> create tablespace dahao datafile ‘/u01/app/oracle/oradata/orcl/dahao01.dbf‘ size 100m;

Tablespace created.

创建用户
SQL> create user dahao identified by dahao default tablespace dahao;

User created.

授权
SQL> grant dba to dahao;

Grant succeeded.

SQL> conn dahao/dahao
Connected.

SQL> show user
USER is "DAHAO"

创建测试表
SQL> create table dahao as select * from scott.emp;

Table created.

查看索引
SQL> select index_name from user_indexes;

no rows selected

创建索引
SQL> create index index_empno on dahao(empno) tablespace users;

Index created.

查看索引
SQL> select index_name from user_indexes;

INDEX_NAME
------------------------------
INDEX_EMPNO

创建表move的表空间
SQL> create tablespace yoon datafile ‘/u01/app/oracle/oradata/orcl/yoon01.dbf‘ size 100m;

Tablespace created.

将表设置只读模式
SQL> alter table dahao.dahao read only;

Table altered.

迁移表对应表空间
SQL> alter table dahao.dahao move tablespace yoon;

Table altered.

修改用户默认表空间
SQL> alter user dahao identified by dahao default tablespace yoon;

User altered.

查看表状态
SQL> select TABLE_NAME,TABLESPACE_NAME,READ_ONLY from dba_tables where owner=‘DAHAO‘ and table_name=‘DAHAO‘;

TABLE_NAME                     TABLESPACE_NAME                REA
------------------------------ ------------------------------ ---
DAHAO                          YOON                           YES

SQL> show user
USER is "DAHAO"

SQL> select index_name from user_indexes;

INDEX_NAME
------------------------------
INDEX_EMPNO

查看索引状态,失效
SQL> select INDEX_NAME,TABLE_OWNER,TABLE_NAME,STATUS from user_indexes where index_name=‘INDEX_EMPNO‘;

INDEX_NAME                     TABLE_OWNER                    TABLE_NAME                     STATUS
------------------------------ ------------------------------ ------------------------------ --------
INDEX_EMPNO                    DAHAO                          DAHAO                          UNUSABLE

重建索引
SQL> alter index index_empno rebuild tablespace users;

Index altered.

查看用户默认表空间
SQL> select username,default_tablespace from dba_users;
DAHAO                          YOON

将表设置读写模式
SQL> alter table dahao read write;

Table altered.

查看表状态
SQL> select TABLE_NAME,TABLESPACE_NAME,READ_ONLY from dba_tables where owner=‘DAHAO‘ and table_name=‘DAHAO‘;

TABLE_NAME                     TABLESPACE_NAME                REA
------------------------------ ------------------------------ ---
DAHAO                          YOON                           NO

时间: 2024-08-01 23:39:35

oracle 表迁移方法 (一)的相关文章

oracle下导出某用户所有表的方法

scott/tiger是用户名和密码,handson是导出的实例名 按用户方式导出数据(owner当中写的是用户名) exp scott/[email protected] file=scott_back owner=scott 按表方式导出数据(talbes当中写的是全部表的名称) exp scott/[email protected] tables=(emp, dept) file=scott_back_tab 按表空间方式导出数据(tablespaces当中写的是表空间名称) exp sy

SQL创建Oracle表空间、用户以及给用户赋权的方法

//创建表空间 Create tablespace examination//创建表空间examination datafile 'c:\Oracle\zhangwei\examination.dbf'//与表空间关联的文件存放位置(要预先手动建好文件夹) size 100m//文件初始大小,千万不要写成mb(这里以下可略) autoextend on//文件大小可自动拓展 next 30m//每次拓展30m maxsize unlimited//不限制文件大小的上限 logging//生成对于

oracle 表空间tablespace_name 文件满了,扩充方法

当然:还是建议在简历表空间时就让其自动扩充的,代码如下:(注意倒数三行) create tablespace prmms_log   logging    datafile 'C:\app\Administrator\product\11.2.0\dbhome_1\database\prmms_log.dbf'   size 50m   autoextend on    next 50m maxsize 20480m   extent management local; 好吧,假如你和博主一样给

Oracle 11G R2 用exp无法导出空表解决方法

四.  Oracle 10g以后增加了expdp和impdp工具,用此工具也可以导出空的表 oracleexpdp/impdp 用法详解 1)  创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建. createdirectory db_bak as 'd:\test\dump'; 2)  查看管理理员目录(同时查看操作系统是否存在,因为Oracle并不关心该目录是否存在,如果不存在,则出错) select * fromdba_directories; 3)  给s

Oracle 11gR2 用exp无法导出空表解决方法

Oracle 11gR2 用exp无法导出空表解决方法 在11gR2中有个新特性,当表无数据时,不分配segment以节省空间,Oracle 当然在执行export导出时,空表则无法导出,但是还是有解决办法的: 解决方法: 一.insert一行,再rollback就产生segment了. 该方法是在在空表中插入数据,再删除,则产生segment.导出时则可导出空表. 二.设置deferred_segment_creation参数 该参数值默认是TRUE,当改为FALSE时,无无是空表还是非空表,

oracle表空间迁移

1.创建一个新的表空间 newspaces (原来的表空间oldspaces) 2.从原来的表空间里面导出数据(test.dmp),然后在新的表空间里面导入之前导出的数据(test.dmp),选择从用户到用户的方式导入 3.执行下面这个SQL: select 'alter table ' ||table_name || ' move tablespace 目标表空间名称;' from user_all_tables 将结果集导出,然后在导出的文件里面把查询拼接的SQL全部复制到plsql里面执行

Oracle表空间文件迁移

set ORACLE_SID = ORCL; sqlplus /nolog connect sys/1234 as sysdba; alter tablespace tablespace_name offline; alter database rename file '......\tablespace_name.dbf' to '......\tablespace_name.dbf'; alter tablespace tablespace_name online; recover data

数据库 SQL Server 到 MySQL 迁移方法总结

最近接手一起老项目数据库 SQL Server 到 MySQL 的迁移.因此迁移前进行了一些调查和总结.下面是一些 SQL Server 到 MySQL 的迁移方法. 1. 使用 SQLyog 迁移 具体方法可以参加:http://www.cnblogs.com/gaizai/p/3237907.html 优点:该迁移方法很简单,灵活,迁移时,可以进行字段的修改,比如在sql server中原来是datetime,然后迁移到mysql时你可以配置成timestamp: 成功率很高: 缺点:迁移很

Oracle数据迁移至MySQL

ORACLE DB: 11.2.0.3.0 MYSQL DB: 5.5.14 因项目需求,需要将ORACLE生产中数据迁移至MYSQL数据库中作为初始数据,方法有如下几种: 1.ORACLE OGG 2.通过手动编写select “insert into”脚本 3.工具,本次我就是使用了工具(sqluldr2),工具下载地址可以到www.anysql.net去下载 使用方法:将sqluldr2.bin工具上传到oracle的bin目录下,[[email protected] bin]# chow