分区表需要数据备份吗oracle,Oracle 分区表数据的导入与导出(1)
--****************************
-- 导入导出 Oracle 分区表数据
--****************************
导入导入Oracle 分区表数据是Oracle DBA 经常完成的任务之一。分区表的导入导出同样普通表的导入导出方式,只不过导入导出需要考
虑到分区的特殊性,如分区索引,将分区迁移到普通表,或使用原始分区表导入到新的分区表。下面将描述使用imp/exp,impdp/expdp导入导出
分区表数据。
有关分区表的特性请参考:
有关导入导出工具请参考:
有关导入导出的官方文档请参考:
一、分区级别的导入导出
可以导出一个或多个分区,也可以导出所有分区(即整个表)。
可以导入所有分区(即整个表),一个或多个分区以及子分区。
对于已经存在数据的表,使用imp导入时需要使用参数IGNORE=y,而使用impdp,加table_exists_action=append | replace 参数。
二、创建演示环境
1.查看当前数据库的版本
SQL> select * from v$version where rownum < 2;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
2.创建一个分区表
SQL> alter session set nls_date_format='yyyy-mm-dd';
SQL> CREATE TABLE tb_pt (
sal_date DATE NOT NULL,
sal_id NUMBER NOT NULL,
sal_row NUMBER(12) NOT NULL)
partition by range(sal_date)
(
partition sal_11 values less than(to_date('2012-01-01','YYYY-MM-DD')) ,
partition sal_12 values less than(to_date('2013-01-01','YYYY-MM-DD')) ,
partition sal_13 values less than(to_date('2014-01-01','YYYY-MM-DD')) ,
partition sal_14 values less than(to_date('2015-01-01','YYYY-MM-DD')) ,
partition sal_15 values less than(to_date('2016-01-01','YYYY-MM-DD')) ,
partition sal_16 values less than(to_date('2017-01-01','YYYY-MM-DD')) ,
partition sal_other values less than (maxvalue)
) nologging;
3.创建一个唯一索引
CREATE UNIQUE INDEX tb_pt_ind1
ON tb_pt(sal_date) nologging;
4.为分区表生成数据
SQL> INSERT INTO tb_pt
SELECT TRUNC(SYSDATE)+ROWNUM, dbms_random.random, ROWNUM
FROM dual
CONNECT BY LEVEL<=5000;
SQL> commit;
SQL> select count(1) from tb_pt partition(sal_11);
COUNT(1)
----------
300
SQL> select count(1) from tb_pt partition(sal_other);
COUNT(1)
----------
2873
SQL> select * from tb_pt partition(sal_12) where rownum < 3;
SAL_DATE SAL_ID SAL_ROW
--------- ---------- ----------
01-JAN-12 -1.356E+09 301
02-JAN-12 -761530183 302
三、使用exp/imp导出导入分区表数据
1.导出整个分区表
[oracle@node1 ~]$ exp scott/tiger file='/u02/dmp/tb_pt.dmp' log='/u02/dmp/tb_pt.log' tables=tb_pt
Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:52:18 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing o
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses ZHS16GBK character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table TB_PT
. . exporting partition SAL_11 300 rows exported
. . exporting partition SAL_12 366 rows exported
. . exporting partition SAL_13 365 rows exported
. . exporting partition SAL_14 365 rows exported
. . exporting partition SAL_15 365 rows exported
. . exporting partition SAL_16 366 rows exported
. . exporting partition SAL_OTHER 2873 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
[oracle@node1 ~]$ oerr exp 00091
00091, 00000, "Exporting questionable statistics."
// *Cause: Export was able export statistics, but the statistics may not be
// usuable. The statistics are questionable because one or more of
// the following happened during export: a row error occurred, client
// character set or NCHARSET does not match with the server, a query
// clause was specified on export, only certain partitions or
// subpartitions were exported, or a fatal error occurred while
// processing a table.
// *Action: To export non-questionable statistics, change the client character
// set or NCHARSET to match the server, export with no query clause,
// export complete tables. If desired, import parameters can be
// supplied so that only non-questionable statistics will be imported,
// and all questionable statistics will be recalculated.
在上面的导出中出现了错误提示,即EXP-00091,该错误表明exp工具所在的环境变量中的NLS_LANG与DB中的NLS_CHARACTERSET不一致
尽管该错误对最终的数据并无影响,但调整该参数来避免异常还是有必要的。因此需要将其设置为一致即可解决上述的错误提示。
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK
[oracle@node1 ~]$ export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
经过上述设置之后再次导出正常,过程略。
2.导出单个分区
[oracle@node1 ~]$ exp scott/tiger file='/u02/dmp/tb_pt_sal_16.dmp' log='/u02/dmp/tb_pt_sal_16.log' tables=tb_pt:sal_16
Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:52:38 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing o
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table TB_PT
. . exporting partition SAL_16 366 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings
在上面的导出过程中再次出现了统计信息错误的情况,因此采取了对该对象收集统计信息,但并不能解决该错误,但在exp命令行中增
加statistics=none即可,如下:
[oracle@node1 ~]$ exp scott/tiger file='/u02/dmp/tb_pt_sal_16.dmp' log='/u02/dmp/tb_pt_sal_16.log' /
> tables=tb_pt:sal_16 statistics=none
如果要导出多个分区,则在tables参数中增加分区数。如:tables=(tb_pt:sal_15,tb_pt:sal_16)
3.使用imp工具生成创建分区表的DDL语句
[oracle@node1 ~]$ imp scott/tiger tables=tb_pt indexfile='/u02/dmp/cr_tb_pt.sql' /
> file='/u02/dmp/tb_pt.dmp' ignore=y
Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:54:38 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing o
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
. . skipping partition "TB_PT":"SAL_11"
. . skipping partition "TB_PT":"SAL_12"
. . skipping partition "TB_PT":"SAL_13"
. . skipping partition "TB_PT":"SAL_14"
. . skipping partition "TB_PT":"SAL_15"
. . skipping partition "TB_PT":"SAL_16"
. . skipping partition "TB_PT":"SAL_OTHER"
Import terminated successfully without warnings.
4.导入单个分区(使用先前备份的单个分区导入文件)
SQL> alter table tb_pt truncate partition sal_16; --导入前先将分区实现truncate
Table truncated.
SQL> select count(1) from tb_pt partition(sal_16);
COUNT(1)
----------
0
SQL> ho imp scott/tiger tables=tb_pt:sal_16 file='/u02/dmp/tb_pt_sal_16.dmp' ignore=y
Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:55:39 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing o
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
. importing SCOTT's objects into SCOTT
. importing SCOTT's objects into SCOTT
. . importing partition "TB_PT":"SAL_16"
IMP-00058: ORACLE error 1502 encountered
ORA-01502: index 'SCOTT.TB_PT_IND1' or partition of such index is in unusable state
Import terminated successfully with warnings.
收到了ORA-01502错误,下面查看索引的状态,并对其重建索引后再执行导入
SQL> select index_name ,status from dba_indexes where table_name='TB_PT'; --查看索引的状态
INDEX_NAME STATUS
------------------------------ --------
TB_PT_IND1 UNUSABLE
SQL> alter index TB_PT_IND1 rebuild online; --重建索引
Index altered.
SQL> ho imp scott/tiger tables=tb_pt:sal_16 file='/u02/dmp/tb_pt_sal_16.dmp' ignore=y --再次导入成功
Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:56:15 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing o
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
. importing SCOTT's objects into SCOTT
. importing SCOTT's objects into SCOTT
. . importing partition "TB_PT":"SAL_16" 366 rows imported
Import terminated successfully without warnings.
SQL> select count(*) from tb_pt partition(sal_16);
COUNT(*)
----------
366
分区表需要数据备份吗oracle,Oracle 分区表数据的导入与导出(1)相关推荐
- Oracle数据库:oracle数据表格dmp,sql,pde格式导入与导出,视图、序列、索引等对象的导出,oracle完结,后续开启mysql的学习
Oracle数据库:oracle数据表格dmp,sql,pde格式导入与导出,视图.序列.索引等对象的导出,oracle完结,后续开启mysql的学习 2022找工作是学历.能力和运气的超强结合体,遇 ...
- mysql数据备份在哪里_mysql之数据备份与恢复
本文内容: 复制文件法 利用mysqldump 利用select into outfile 其它(列举但不介绍) 首发日期:2018-04-19 有些时候,在备份之前要先做flush tables , ...
- 小米4c刷机包Linux,MIUI【双开应用】数据备份(android通用,分身数据)
本帖最后由 jonhy_love 于 2018-3-31 09:57 编辑 miui发帖子一直是审核不过,发在这了. 0 前言现在手机配置都高了,Android新版本也都支持手机分身和应用双开(分身) ...
- 数据备份_这5种数据备份方式你全都了解吗?
数据备份显然是一份枯燥而又乏味的工作,企业每日花费大量成本却只是进行着数据的覆盖,显得浪费又无意义.这种想法是许多中小型企业主都会有的,但有过数据丢失经历的站长都会将备份看做是与吸引流量同等重要的事. ...
- serv-u 数据备份_如何使用用户数据脚本在EC2实例上安装Apache Web Server
serv-u 数据备份 你好朋友, 在本教程中,我们将看到如何使用用户数据脚本在EC2实例上安装Apache Web Server. 在我以前的教程之一中,我已经解释了如何使用AWS控制台启动EC2实 ...
- 云呐数据备份|什么是结构化数据
什么是结构化数据,非结构化数据 结构化数据,简单来说就是数据库.结合到典型场景中更容易理解,比如企业ERP.财务系统:医疗HIS数据库:政府行政审批: 其他核心数据库等.这些应用需要哪些存储方案呢?基 ...
- 数据备份 linux,linux下的数据备份
制定备份策略 将原始设备转储到文件,或从文件恢复原始设备 执行部分备份和手工备份 检验备份文件的完整性 从备份部分地或完全恢复文件系统 完善的备份是系统管理的必要部分,但是决定对什么进行备份以及何时和 ...
- Ambari2.7.0 + HDP3.1.4.0安装,hdfs数据备份和恢复,hive数据备份和恢复,hbase数据备份和恢复,常见错误总结,Ambari卸载,hadoop-ha,hive和ES整合
目录 1 Ambari + HDP离线安装 1.1 介绍 1.1.1 Ambari介绍 1.1.2 HDP 1.1.3 HDP-UTILS 1.2 登录ambari官网地址 1.3 Ambari和HD ...
- Oracle数据库的数据备份
目录 一.理解数据备份 1.1.数据库的数据备份含义: 1.2.备份数据的目的: 二.数据备份的类型: 2.1. 完全备份(Full Backup): Ⅰ.优点: Ⅱ.缺点: 2.2. 增量备份(In ...
- oracle数据备份 full,oracle数据库备份 full
通过exp命令对Oracle数据库进行备份操作(提供两种情况的备份:备份本地,备份远程的数据库) 通过exp命令可以对Oracle数据库进行备份操作,其命令含义是:exp 用户名/密码@数据库所在ip ...
最新文章
- 从 Gzip 压缩 SVG 说起 — 论如何减小资源文件的大小
- 中石油训练赛 - Cafebazaar’s Chess Tournament(FFT)
- Today's my MDX...
- vue中的slot插槽
- heartbeat V2实现MySQL+NFS高可用
- Eclipse2019开发javaweb应用的配置(解决eclipse中没有Server配置选项和没有Dynamic Web Project项目类型)
- 【PDF转换 编辑】 推荐几个好用的pdf相关的网址和软件
- 公众号迁移开通留言功能
- 易灵思FPGA-报告总结篇
- bestcoder#22NPY and girls
- 怎样删除服务器内磁盘阵列信息,如何管理你的磁盘阵列
- Python 教程视频汇总
- python经典编程题分别取个位十位百位
- Windows7UltimateSP1x64安装及一些设置
- OpenCV中threshold自动阈值,类似matlab中的graythresh
- 线搜索中的Armijo-Goldstein准则及Wolfe-Powell准则
- 互联网思维方式(一)
- 【数学建模论文】数学模型分析红楼梦作者
- butter中文意思_butterfly是什么意思_butterfly的翻译_音标_读音_用法_例句_爱词霸在线词典...
- Apache Kafka实战读书笔记(推荐指数:☆☆☆☆☆)
热门文章
- 本地 MarkDown 怎么部署到服务器上?教你使用 Docsify 搭建个人博客
- Redis实战(八):面试常问:击穿,穿透,雪崩,分布式锁,API(jedis,luttce,springboot:low/high level)
- Linux中source命令的用法:修改环境变量之后立即生效
- Linux运行脚本忽略警告,ShellCheck - 显示Shell脚本的警告和建议的工具
- 乱序图片 极验_极验验证吴渊:传统图片验证方式已经无效了!
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
- 缓存之EHCache(二)
- spark读取文件源码分析-3
- 通俗易懂,Maven依赖pom中的scope详解
- 【双百解法】剑指 Offer 11. 旋转数组的最小数字