zoukankan      html  css  js  c++  java
  • 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’);

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

  • 相关阅读:
    silverlight click 事件委托是 RoutedEventHandler
    silverlight 2 系统对话框
    CSLA.Net 3.0.5 项目管理示例 UI ProjectEdit.aspx
    委托和事件 委托
    Visual Studio 项目模板、文件模板、代码段和环境设置
    C# 打好基础图文详解
    Hession 基础应用
    ADO.NET Entity Framework 概述
    CSLA.Net 3.0.5 项目管理示例 业务基类 Project.cs
    关于使用 Visual Studio 开发环境收费的问题,博友们谁有经验分享一下。
  • 原文地址:https://www.cnblogs.com/jilili/p/4691488.html
Copyright © 2011-2022 走看看