数据库名称 : PROD1

update employees set salary = salary + 1000 where LAST_NAME = ‘Bell’;

select LAST_NAME, salary from employees where LAST_NAME=‘Bell’; (结果为5000)

另一个用户查看 :

export ORACLE_SID=PROD1

sqlplus / as sysdba

conn hr/hr

show user;

select LAST_NAME, salary from employees where LAST_NAME = ‘Bell’; (结果仍为4000, 上一个用户没有提交commit)

DBWn不管用户有没有提交都将DB Buffer Cashe 中的数据写入数据文件中,老数据从undo(前镜像)中提取.

当有数据修改时,一条redo record纪录 (1. undo 中保存前镜像,2. 5000 —> 6000)

归档日志 :日志被复写之前的拷贝

两个磁盘保证冗余,日志组1(两份redo log1,日志组2(两份redo log 2),磁盘2 保存和磁盘1一样的日志,防止一个磁盘发生损坏。

alter database add logfile(‘ … ‘) size 100M;

uname -a : 查内核

ps -ef | grep PROD1 : 查看进程

startup nomount : 启动实例

create pfile from spfile : 将二进制文件转化成文本文件,放在同一目录下

注:spfile时二进制文件

alter database mount; : 打开控制文件 (参数文件记录控制文件位置)

select* from v$instance;

select * from v$rablespace;

select * from v$log;

注:v$是oracle软件启动以后保存在内存中的结构信息(视图).

select * from dba_tables; (报错,数据库没有打开)

alter database open; : 打开数据库

select * from dba_objects; : 查表

nomount spfile pfile

mount control file

open database

startup : 代替以上三个步骤命令

startup mount —> alter database open

startup nomount —> alter database mount

数据库块头纪录着块中行数据是否提交

表(段segment)

列 (块block)

行(区extent)

eg :

insert into emp values (1, 2, 3);

delete emp where salary < 5000;

高水位线 :数据块从下往上插入数据,最上面数据所在位置(除块头),若删除了部分纪录(salary < 5000), 高水位线不会下降,空出的位置被打上标记表明纪录被删除

eg :

update emp set salary = salary + 100 where salary < 5000;

行迁移 :当某一条纪录被update后内容过多时无法容纳,将其做上标记表明其被迁移到其他块或该块的其他位置。

行连接 :一个块无法容纳一行数据,两个块共放一条纪录

@?/rdbms/admin/awrpt  : 执行awrpt脚本文件

host

pwd

commit不能移动数据块

高水位线 (历史最高水位线):在全表扫描时起作用,表示要扫描到的位置

默认8个块(表中行列较差的次方)叫一个区

管理块 (表头前8个块):用于管理

high water mark高水位线 :纪录数据插入到的位置

数据清理项目 :

生产库上已经有多张表比较大, 经历了5年的时间,有的表已经涨大到上亿行纪录,没有使用分区表,需要将今年意外的数据全部转存到历史表中,并对表进行整理。

考虑因素 :

1. 是否可以停止业务,停机时间叫时间窗口

1.1. 可以停止业务,清除数据 :

drop : 连同表的定义一起删除(之后不能rollback)

drop table EMP;

delete : 删除表中的数据,并不删除表的定义(之后可以rollback)

delete emp where 一年前的数据

truncate : 即删除数据,不删除表的定义,又将高水位线移动到第一个块(表开头后的)(之后不能rollback)

将本年的数据查询处建立一个新表,之后删除旧表,之后将表改名

eg :

export ORACLE_SID=PROD1;

conn hr/hr

commit;

desc employees;

create table EMP as select * from employees;

desc EMP

select * from EMP;

drop table EMP;

create table EMP as select * from employees where 0=1;

desc EMP;

select * from EMP;

insert into EMP select * from employees;

insert into EMP select * from employees;

insert into EMP select * from employees;

insert into EMP select * from employees;

insert into EMP select * from employees;

insert into EMP select * from employees;

insert into EMP select * from employees;

insert into EMP select * from employees;

/ : 运行上一个命令

drop table EMP;

集合操作(快)

select COUNT(*) from EMP;

delete EMP;

truncate table EMP;

insert into EMP select * from employees;

commit;

insert into EMP select * from  employees;

/

/

/

/

select COUNT(*) from EMP;

create table EMP_BK as select * from EMP where salary < 6000;

select count(*) from EMP_BK;

sekect count(*) from EMP;

create table EMP_TEMP as select * from EMP where salary >= 6000;

select count(*) from EMP;

truncate table EMP;

drop table EMP;

select count(*) from EMP;

alter table EMP_TEMP rename to EMP; : 将EMP_TEMP表重命名为EMP

select count(*) from EMP where salary >= 6000;

select count(*) from EMP where salary < 6000;

select count(*) from EMP_BK;

alter table EMP move; : 收缩水位线

注 :此做法会引起大量IO, 生成大量日志

2. 不可以停止业务,没有时间窗口

2.1. delete

2.2.

alter table table_name shrink :收缩表段

实质上是构造一个新表,必须启动行纪录转移仅适用于堆表

不能实现收缩的表 :群集表,具有LONG类型列的表,LOB段,

段收缩是在线的,索引在段收缩期间维护,不要求额外的磁盘空间

选项 :

cascade :缩小表及其索引,

alter table table_name enable row movement;

vi script_12.sql

vi monitor_table.sql

@monitor_table.sql

set serveroutput on

host

exec show_space(‘EMP’, ‘HR’);

show parameter block;

conn hr/hr

drop table EMP;

alter system switch logfile;

create table EMP as select * from employees;

insert into EMP select * from employees;

commit;

insert into EMP select * from employees;

/

/

/

/

/

/

commit;

select count(*) from EMP;

col setment_name format a20

select segment_name, bytes/1024/1024, blocks from user_segments where segment_name =‘EMP’;

select table_name, blocks, empty_blocks from user _tables where table_nam =‘EMP’;

analyze table emp compute statistics;

select table_name, blocks, empty_blocks from user _tables where table_nam =‘EMP’;

drop table EMP_BK;

create table EMP_BK as select * from EMP where salary < 6000;

select count(*) from EMP_BK;

conn sys/oracle as sysdba

set serveroutput on;

exec show_space(‘EMP’,’HR’);

conn hr/hr;

delete EMP where salary < 6000;

commit;

conn sys/oracle as sysdba

set serveroutput on;

exec show_space(‘EMP’, ‘HR’);

conn hr/hr

alter table emp enable row mvement;

alter table emp shrink space;

conn sys/oracle as sysdba;

set serveroutput on;

exec show_space(‘EMP’, ‘HR’);

数据清理需要考量的一些东西

enmo_day_04的更多相关文章

随机推荐

  1. Android Studio的git功能的使用

    初次使用AS自带的git工具的配置 初次使用AS自带的git工具需要设置一些配置,如果你已配置过,可跳过该部分内容. 首先你需要下载git,然后打开AS的git设置,路径如下,选择你安装在你电脑上的g ...

  2. 【转】PowerShell入门(七):管道——在命令行上编程

    转至:http://www.cnblogs.com/ceachy/archive/2013/02/22/PowerShell_Pipeline.html 管道对于Shell来说是个化腐朽为神奇的东西, ...

  3. 初识Python第三天(二)

    2.2 OrderedDict有序字典 import collections dic = collections.OrderedDict() dic['k1'] = 'v1' dic['k2'] = ...

  4. Python之反射

    一.引言 有时候我们会碰到类似这样的需求,就是想要执行类的某个方法,或者需要对对象的某个参数赋值,而方法名或参数名已经包装在类中并不能去顶,需要通过参数传递字符串的形式输入.在这样的情况你会选择什么样 ...

  5. String s ; 和 String s = null ; 和 String s = "" ; 的却别

    String s ;该语句表示只是声明了一个引用变量,但是并没有初始化引用,所以对变量s的任何操作(除了初始化赋值外) 都将引发异常. String s=null; 表示未申请任何内存资源,即此语句表 ...

  6. log4j日志不输出MyBatis SQL脚本?

    日志输出级别调成debug,然并卵? 试试加下这个包. <dependency> <groupId>org.slf4j</groupId> <artifact ...

  7. Script循环语句 的相关知识跟练习

    循环语句有两种问题类型:穷举和迭代 穷举: 在不知道什么情况下才是我们需要的结果的时候,只能让它一个一个的都执行一遍 迭代:在现有的条件下,根据规律,不断求解中间情况,最终推选出结果 两个关键词 br ...

  8. [转]C#中调用资源管理器(Explorer.exe)打开指定文件夹 + 并选中指定文件 + 调用(系统默认的播放类)软件(如WMP)打开(播放歌曲等)文件

    原文:http://www.crifan.com/csharp_call_explorer_to_open_destinate_folder_and_select_specific_file/ C#中 ...

  9. 富文本常用封装(NSAttributedString浅析)

    最近经常遇到关于富文本的一些需求,特此封装了几个最常用的API分享给大家,但授之以鱼不如授之以渔,接下来会顺便谈谈NSAttributedString,确保你读了本篇文章能够自己封装关于富文本的API ...

  10. jquery.validate使用 - 2

    jQuery.validate.js API说明 参考http://ideabean.javaeye.comPlugin methods Name Type validate( options ) R ...