zoukankan      html  css  js  c++  java
  • Oracle清理大表,降水位

    背景:一张表的清理机制存在问题,导致该表的数据一直在增加,该表水位已很高,需要对该表的数据进行清理并降水位。

    1.1 迁移前准备

    步骤一、新建表 p_transaction_bak。

    oracle@linux-nxv6:~/orcale > sqlplus test/test

    SQL> create table p_transaction_bak
    as
    select * from p_transaction where 1 = 0;
    SQL> alter table p_transaction_bak modify OPERATIONDATE DEFAULT sysdate;
    SQL> alter table p_transaction_bak modify INVALID DEFAULT 0;

    步骤二、有需要的有效数据插入新表中。

    SQL> alter session enable parallel dml;

    insert /*+ append parallel(p,8) */ into p_transaction_bak p select /*+ parallel(n,8) */ * from p_transaction n
    where to_char(n.operationdate, 'yyyy-mm-dd') between
    to_char(to_date('2016-06-27', 'yyyy-mm-dd'), 'yyyy-mm-dd') and
    to_char(to_date('2016-07-04', 'yyyy-mm-dd'), 'yyyy-mm-dd');

    commit;

    步骤三、为新表 p_transaction

    table创建主键和索引
    SQL> create unique index PK_PO_TRANSACTION_NEW on p_transaction_bak(STREAMINGID) tablespace portaloneindx parallel 8 online;
    SQL> alter table p_transaction_bak add constraint PK_PO_TRANSACTION_NEW primary key (STREAMINGID);
    SQL> alter index PK_PO_TRANSACTION_NEW noparallel;
    SQL> create index ix_transaction_operationdate on p_transaction_bak(operationdate) tablespace portaloneindx parallel 8 online;
    SQL> alter index ix_transaction_operationdate noparallel;

    ----End

    1.2 执行数据迁移

    步骤一、停应用

    步骤二、以SYSDBA用户登录数据库。

    oracle@linux-nxv6:~/orcale > sqlplus / as sysdba

    步骤三、检查数据表空间和索引表空间使用率。

    SQL>select total.tablespace_name,
    round(total.MB, 2) as Total_MB,
    round(total.MB - free.MB, 2) as Used_MB,
    round((1 - free.MB / total.MB) * 100, 2) || '%' as Used_Pct
    from (select tablespace_name, sum(bytes) / 1024 / 1024 as MB
    from dba_free_space
    group by tablespace_name) free,
    (select tablespace_name, sum(bytes) / 1024 / 1024 as MB
    from dba_data_files
    group by tablespace_name) total
    where free.tablespace_name = total.tablespace_name;

    步骤四、并行将数据插入新表。

    SQL> alter session enable parallel dml;

    insert /*+ append parallel(p,8) */ into p_transaction_bak p select /*+ parallel(n,8) */ * from p_transaction n
    where to_char(n.operationdate, 'yyyy-mm-dd') =
    to_char(to_date('2016-07-05', 'yyyy-mm-dd'), 'yyyy-mm-dd');

    commit;

    步骤五、备份旧表。

    SQL> rename p_transaction to p_transaction_old;

    步骤六、重命名新表。

    SQL> rename p_transaction_bak to p_transaction;

    ----End

    1.3 回滚以上操作 oracle@linux-nxv6:~/ orcale > sqlplus test/test

    SQL>rename p_transaction to p_transaction_new;
    SQL>rename p_transaction_old to p_transaction;
    SQL>truncate table p_transaction_new;
    SQL>drop table p_transaction_new;

    ----End

  • 相关阅读:
    让 vscode 作为 SpringBoot,Java,Maven,甚至于 JavaScript,C,C++,Python,Php等多语言的开发工具吧!
    MySQL 连接错误集锦
    前端开发工具库:包含事件委托,动画处理,以及大部分常用的前端工具
    初探 Node.js 框架:eggjs (环境搭配篇)
    如何快速搭建一个 Node.JS 项目并进入开发?
    关于 JavaSrcipt 前端开发的建议:模块化开发
    Spring-Session 会话共享 -> 基于 Redis 集群,内附各大错误合集,包括配置,类寻找不到、连接错误等
    Java Email 邮件发送
    CSS 显示或隐藏子元素
    Ubuntu美化及配置,常见问题解决方案(仿 Mac 风格)
  • 原文地址:https://www.cnblogs.com/zihanxing/p/6852695.html
Copyright © 2011-2022 走看看