enmo_day_04
数据库名称 : 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的更多相关文章
随机推荐
- AppleWatch___学习笔记(三)iPhone和Apple Watch上的数据同步
WatchKit App类似于之前iOS 8上新推出的App Extension(应用扩展),比如Today Extension(今天扩展)和Share Extension(分享扩展).只要你对iOS ...
- ios项目总结一:开发中常用的设计模式
一.单例设计模式 1.应用场景: 程序运行期间,在内存中只有一个实例存在,主要用于资源共享,对硬件的访问等等 2.优点: 跨模块,解耦合,使用简单 3.敏捷原则: 单一职责原则 4.SDK实例: UI ...
- ifconfig
虚拟机启动后发现ifconfig命令下,没有打印ip .用ifconfig eth0 up命令开启下网卡. #ifconfig eth0 up .更改eth0配置: #vi/etc/sysconfig ...
- [充电]多线程无锁编程--原子计数操作:__sync_fetch_and_add等12个操作
转自:http://blog.csdn.net/minCrazy/article/details/40791795 多线程间计数操作.共享状态或者统计相关时间次数,这些都需要在多线程之间共享变量和修改 ...
- Java 泛型和通配符解惑
转自:http://www.linuxidc.com/Linux/2013-10/90928.htm T 有类型 ? 未知类型 一.通配符的上界 既然知道List<Cat>并不是Lis ...
- [Scrapy] Mac安装Scrapy
Mac安装Scrapy Mac版本 10.11 El Captain. 前一段想在Mac上用Scrapy,各种问题.有一个不错的工具:Anaconda. 安装Anaconda 下载地址 我还是下pyt ...
- python matplotlib 中文显示参数设置
python matplotlib 中文显示参数设置 方法一:每次编写代码时进行参数设置 #coding:utf-8import matplotlib.pyplot as pltplt.rcParam ...
- iOS 编码规范
Coding Guidelines for Cocoa https://developer.apple.com/library/prerelease/content/documentation/Coc ...
- EVA资料
[史上最全EVA资料+原画+画集+设定集][共2266P=3.56GB] <ignore_js_op> <ignore_js_op> <ignore_js_op> ...
- GPIO相关知识
参考资料: 1. 维基百科GPIO 2. GPIO博客资料(一) 3. MMIO和PMIO 知识点: ● GPIO是General-purpose input/output的缩写,是一个在集成电路上的 ...