Chinaunix首页 | 论坛 | 博客
  • 博客访问: 447255
  • 博文数量: 135
  • 博客积分: 4177
  • 博客等级: 上校
  • 技术积分: 1145
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-13 17:16
文章分类

全部博文(135)

文章存档

2011年(5)

2010年(4)

2009年(26)

2008年(25)

2007年(29)

2006年(42)

2005年(4)

分类: Oracle

2006-04-24 17:33:09

P4上安装8.17oracle时需用要进行如下的动作:

如在p4的机器上安装首先要将安装盘拷到硬盘,然后删除或更名symcjit.dll文件

DESC显示表结构

DESC  user_table( 代词不是语句)

Desc 用于获取关于数据库对象的信息。对一张表或者视图使用此命令可以显示有哪些列、数据类型。

使用脚本文件

1、  可以用save 保存当前语句到脚本文件;

2、  可以用‘get 文件名’ 将脚本文件调入当前缓存;

3、  可以用’@文件名’来运行一个脚本文件。

四、附命令列表:

假设当前执行命令为:select * from tab;
 
(a)ppend     添加文本到缓冲区当前行尾    a  order by tname 结果:select * from tab order by tname;
                                      (注:a后面跟2个空格)
(c)hange/old/new 在当前行用新的文本替换旧的文本 c/*/tname     结果:select tname from tab;
(c)hange/text  从当前行删除文本        c/tab       结果:select tname from ;
del       删除当前行
del n      删除第n行
(i)nput 文本   在当前行之后添加一行
(l)ist      显示缓冲区中所有行
(l)ist n     显示缓冲区中第 n 行
(l)ist m n    显示缓冲区中 m 到 n 行
run       执行当前缓冲区的命令
/        执行当前缓冲区的命令
r        执行当前缓冲区的命令
@文件名     运行调入内存的sql文件,如:
 
SQL> edit s<回车>
如果下不存在s.sql文件,则系统自动生成s.sql文件,
在其中输入“select * from tab;”,存盘退出。
 
SQL> @s<回车>
系统会自动查询当前用户下的所有表、视图、同义词。
 
@@文件名     在.sql文件中调用令一个.sql文件时使用
 
save 文件名   将缓冲区的命令以文件方式存盘,缺省文件扩展名为.sql
get 文件名    调入存盘的sql文件
start 文件名   运行调入内存的sql文件
 
spool 文件名   把这之后的各种操作及执行结果“假脱机”即存盘到磁盘文件上,默认文件扩展名为.lst
spool      显示当前的“假脱机”状态
spool off    停止输出
 
例:
SQL> spool a
SQL> spool
正假脱机到 A.LST
SQL> spool off
SQL> spool
当前无假脱机
 
exit       退出SQL*PLUS
desc 表名    显示表的结构
 user    显示当前连接用户
show error    显示错误
show all     显示所有68个系统变量值
edit       打开默认编辑器,Windows系统中默认是notepad.exe,把缓冲区中最后一条SQL语句调入afiedt.buf文件中进行编辑
edit 文件名   把当前目录中指定的.sql文件调入编辑器进行编辑
 
clear screen   清空当前屏幕显示

 

Recover datafile ‘d:\oracleoradata\fox\user01.dbf(数据库恢愎动作)

Rollback

Alter session set nls_language=American;

Data---c\y\m\d\h\m\s(世纪\年\月\日\小时\分\秒)

Oracle 9i Document可查SQL*Plus的数据资料.

Disconnect断开它们之间的连接

 

SYSTEM         (系统表空间,存放表空间名称\所含数据文件等管理信息)

UNDOTBS        (回滚表空间,存放数据恢愎信息)

CWMLITE      

DRSYS          

EXAMPLE        

INDX           

TEMP           

TOOLS          

USERS          

 

Database

    Control files

       Datafiles

       Redo log files

       Parameter files

       Password files

       Archived log files

 

启动一个用户进程:       sqlplusw /nolog

                                   conn kong/kxf_001

                                   conn sys/change_on_install@database as sysdba

                                   shutdown immediate(关闭数据库)

                                   startup nomount;(intance的启动)

                                   alter database mount;(control file启动)

                                   alter database open;(数据物理文件的校验)

                                   show sga;(显示内存的结构信息)

                                   set wrap off

                                   set linesize 200

                                   select * from v$bgprocess(name 显示后台进程名)

                                   a     where paddr<>’00’(在一段添加上去之后用run执行)

select * from v$bgprocess where paddr<>’00’(显示必须的后台进程)

select * from v$controlfile;(显示controlfile文件)

select * from v$logfile;(显示日志文件)

show parameter shared

show parameter db_cache

show log_cache

alter session set nls_language=American

alter system set db_cache_size=64m;(改变缓存的大小)

c /64/20/(查找上面的替换文式)

input 添加字段在数据库的下一栏

alter system set share_pool_size=64;

show parameter db;

                                   E:\oracle\admin\foxconn\pfile\init.ora(初始参数文件的重要;)

                                   Alter system set db_cache_advice=on;

                                   Archive log list(归档模式显示)

                                   Clea scre(清屏命令)

PMON           process monitor(rolling back the transaction)

DBWn            database writer (database buffer cache -------datafiles)

LGWR           log writer (log buffer cache -----logfile) first writer log

CKPT            check point(header所需周期性的同步信息)

SMON           system monitor

RECO            distributed recovery

Oracle的用户进程并不可直接操作实例与

       Control file应该起到的实际位置是在interancedatabase中间

Logical structure

       Table spaces

       Segments

       Extents

       Blocks

 

.Getting started with the oracle server

特权用户:启动和关闭数据库;

       sys: owner of the database data dictionary

       system: owner of additional internal tables and views used by oracle tools

 

Oracle universal installer(oui)

                           #./runinstaller for unix system

                            orapwd

                            select * from v$pwfile_users;

                            sqlplus(有两种一种是图形介面一个是字符介面)

Oracle database configuration assistant(dbca)   直接可以键于dbca 可运行

Password file

Sql*plus

Oracle enterprise manager

User System and sys user 拥有着不同的权限方式;

Authentication methods for database administrators(对管理员的审核方式,对口令文件的审核,)

Syssystemdatabase本身的用户ID,数据库没有启动时,用户ID当然是不能生效的;当然了对验证用户连接也是不可以的;这就需要特权用户;

              一种是:OS的安全性来完成

              另一种是口令文件:

Windows 下实现口令文件的审核

       Create os user id                                               --创建用户ID

       Create os group-ora_dba,ora_fox_dba                   --命名的规则也是一定的.

                                                               --系统会默认一个ora_dba的东西

                              Ora_oper,ora_fox_oper           --组的名字很特别而且是一定的

       Add os user id to to ora_dba group                           --把用户ID放置到那个组中

 

Edit sqlnet.ora Sqlnet.authentication_services=(nts)   --OS验证

存放地点为:oracle_home\ora90\network\admin\sqlnet.ora

      

口令文件的改:

口令文件的存放地点为: E:\oracle\ora90\database\PWDSID.ora (选将其删除)

orapwd file=e:\oracle\ora90\database\pwdfox.ora password=chinaunix entries=10;(只对sys用户起作用);

改变了口令之后数据库需要重新启动;

grant sysdba to username;

初始参数文件中:remote_login_passwordfile = exclusive(初始参数文件中的些参数可以授予更多的人有系统管理员的权限) 初始参数文件!init.ora

select * from v$pwfile_users;

password

1)      orapwd /oradim

2)      edit init parameter

3)      grant sysdba to kong(怎么创建一个用户)

4)      revoke sysdba from kong

oracle enterprise manager(OEM)

 

sysman/oem_temp/admin

 

 

.managing an oracle instance

       alter system set timed_statistics=false scope=memory/spfile/both; 只是把系统参数改到内存中/重启也可以保持/改到两者都可以;

       desc v$system_parameter(显示可以改变的参数文件)

       select name,isses_modifiable from v$system_parameter where issus_modifiable=’true’

       alter session set timed_statistics=false;

       select name,issys_modifiable from v$system_parameter where issys_modifiable<>’false’

       immediate/deferred的区别

       create spfile=’d:\oracle\oracle90\database\spfile.ora’ from pfile;

       create pfile=’d:\initbck.ora’ from spfile;

初始参数文件

                     system parameter file—spfilesid,spfile(sid为数据库的Id)

                     存放位置为:E:\oracle\ora90\database\SPFILEFOXCONN.ORA不可直接使用修改文本的方式进行此文本的修改

                     init parameter file—initsid.ora

              explicit显示参数(两者之间有何联系,如果没有定义显示的值,会默认隐式的值)

              implicit隐式参数(都有一个缺省值)

spfilesid.ora(可以保存到下一次的启动)----spfile.ora---initsid.ora(参数的利用顺序比较重要)

oracle managed files

              SQL> show  parameter db_create;

                     Alter system set db_create_file_dest=’d:\oracle\oradb’ (指定路径的重要)

                     Create tablespace test1;(表空间默认为100M)

                     Alter database add logfile group 6;

                     Drop tablespace test1;

                     Alter database drop logfile group 6;(删除日志文件)

                     Create tablespace test1

                     Datafile ‘d:\oracle\oradb\test1.dbf’ size 2m(以前的方式)

                     Create tablespace test1

                     Datafile ‘d:\oracle\oradb\test1.dbf’ reuse(重新建立)

                     Drop tablespace test1

                     Includeing contents and datafiles;(连表空间物理文件一起册除)

 

Nomount 读初始参数文件定位到我们的其它的控制参数

                     Online数据创建(background_dump_dest=E:\oracle\admin\foxconn\bdump\ foxconnALRT.LOG如果没有此文件,oracle会自动创建;

Mount select * from v$tablesspaces;

              Database 的结构信息还不能读到; 用户信息也是读不到的;

Startup [nonount|mount|open]

       Pfile=

       Restrict(限制绘画,限制有特权的用户访问,其它的用户不具有此权限)

       Recovery

       Force(忽略,强制重新启动)

Startup force pfile=d:\oracle\admin\fox\pfile\init.ora mount

Alter database open read only;(只能查询不能修改)

Online/offline

Alter systemenable restricted session;

Grant restricted session to kkk;

Alter system disable restricted session;

Shutdown

                     Normal

                     Transactional

                     Immediate

                     Abort      要清楚这几者之间的区别

      

.Creating a database

              oracle安装过程中会自动创建一个database.

              须要条件为:

1.       特权用户(审核方式)

by the operating system(操作系统审核)

using password file(口令文件审核)

2.       创建oracle的两种方式;

UNIX平台下的设定.

ORACLE_BASE oracle第一级安装的子目录;

ORACLE_HOME oracle管理文件所在的路径;

ORACLE_SID

ORACLE_NLS33 字符集的远择问题

PATH

LD_LIBRARY_PATH       文件库所在路径;

Setenv oracle_home=………………….(oracle设置的方式)

 

a)        oracle database configuration assistant(dbca)

相对来说是比较简单;dbca oracle 8i以前的版本是没有的.

b)        the create database command

创建数据库所需资料:

1.       intance dbname的名字..

2.       字符集.

3.       启动实例,并且把系统启动在nomount的状态下才可以;

4.       create database

5.       运行一些脚本来完成后期的创建过程.

 

   Windows平台与unix平台不一样就是windows平台首先要创建实例.

nomount才可以创建database

命令提示符:set oracle_sid=foxconn

oradim –NEW –sid FOXCONN –INTPWD admin –pfile d:\oracle\ora90\database\initfoxconn.ora 此路径为此路径比较好;(此参数会直接调节到服务一栏中);创建完之后服务一栏已启动;

准备初始参数文件,以及文件所在的路径;

copy E:\oracle\ora90\admin\sample\ E:\oracle\admin\foxconn

change E:\oracle\admin\fox\pfile\ init.ora

       db_name=foxconn(db_name要跟sid号一样)

       control_files=(‘d:\oracle\oradata\foxconn\control01.ctl’, ‘d:\oracle\oradata\foxconn\control02.ctl’, ‘d:\oracle\oradata\foxconn\control03.ctl’)

至少做两个多功放在不同的harddisk下面,防止hardisk出现问题

       db_block_size=8192

       sqlplusw /nolog

       conn sys/admin as sysdba

       create spfile from pfile;

              E:\oracle\ora90\database\initfoxconn.ora

                     Ifile更改

                     Text_enable=true注释掉

Create database foxconn

Maxlogfiles 10

Maxdatafiles 1024

Maxinstances 2

Datafile ‘d:\oracle\oradata\foxconn\system01.dbf’ size 50m

       Logfile

       Group 1 ‘d:\oracle\oradata\foxconn\redo01.ora’,

       Group 2 ‘d:\oracle\oradata\foxconn\redo02.ora’;

3.       operation system environment

on unix,set the following environment variables;

oracle_base: E:\oracle

oracle_home: E:\oracle\ora90

oracle_sid

ora_nls33(字符集的选择)

path

ld_library_path

on windows

4.       using the database configuration assistant

the database configuration assistant allows you to:

create a database

configure database options

delete a database

manage templates

windows平台底下的事例,模型:E:\oracle\ora90\admin\sampleE:\oracle\admin\foxconn模型的结构是一样的;

.Data dictionary contents and usage

       (数据库的结构信息),想象的物理存在!

select * from dba_users;(查找所有的用户id)  

       select * from dba_objects;

       desc dictionary;(显示数据字典视图)

       desc v$fixed_table

E:\oracle\ora90\rdbms\admin\sql.bsq(command的作用)

       Dynamic performance tables(内存表,动态性能表)

       Data dictionary

1.       Base tables(read only \created with create database)

2.       Data dictionary views

.Maintaining the control File

       记录database结构信息. 控制文件是连接Database和实例的桥梁;

       在启动数据库在mount状态下时会去读控制文件;

       而且在数据库操作的过程当中,控制文件也是必须做的.

       只能与一个database相关联.要做多功.

explain the uses of the control file(控制文件的用途)

       List the contents of the control file

Multiplex and manage the control file(建议控制文件做多功,而且放在不同的物理harddisk)

       Manage the control file with oracle managed files

       Obtain control file information

       The control file is a binary file that defines the current state of the physical database…

       那些信息来自控制文件?

       select * from v$database;(database的相关信息)

       select * from v$tablespace;(表空间的相关信息)

       select * from v$logfile;(日志文件的相关信息)

       select * from v$log;(重做日志的顺序号)         SEQUENCE#

       select * from v$backup(那些文件进入到了备份状态)

       alter tablespace users begin backup; ORA-01123: 无法启动联机备份;未启用介质恢复

       select * from v$archived_log;(那些是归一档的日志文件)

       alter tablespace users end backup;(停止备份的工作)

       show parameter spfile

       select * from parameter where name like ‘control%’;

Multiplexing the control file using spfile

       run

alter system set control_files=

'E:\ORACLE\ORADATA\FOXCONN\CONTROL01.CTL',

'E:\ORACLE\ORADATA\FOXCONN\CONTROL02.CTL',

'E:\ORACLE\ORADATA\FOXCONN\CONTROL03.CTL',

'E:\ORACLE\ORADATA\FOXCONN\CONTROL01.CTL'

scope=both;

关闭数据库并重启,copy and rename

alter database backup controlfile to ‘c:\control.bak’/trace(备份controlfile)

.maintaining Redo log files

    在线日志文件,归档日志文件.指把在线的日志文件备份下来叫做归档日志文件;

    conn sys/change_on_install@foxconn as sysdba

    conn sys/change_on_install as sysdba(指定数据库和不指定数据库之间有些不同但我不知道这是为什么? SQL> archive log list(查询的归档方式)

ORA-01507: ??????

在查询归档模式时会出现这样的问题;下一种方式则不会;

    alter system archive log start;(归档模式开始备份)

    alter system switch logfile;(日志文件交换)

    alter system checkpoint;(手工强制完成checkpoint)

mttr- mean time to recovery;

FAST_START_MTTR_TARGET;(反过来限制数据库的频率;)

Show parameter fast;

Show parameter log_checkpoint(控制同步所发生的频率)

Select * from v$log;(查看日志有多个少组,以及其它一些数据)

Alter database add logfile group 4

d:\oracle\oradata\foxconn\redo04.ora size 10m;(添加一个日志组,后面一行可以多加几个member;不同组可以是不同大小,同组大小一定要一样)

alter database add logfile member

d:\oracle\oradata\fox\redo04a.ora to group 4 (组已建立大小,但member不用再会有大小的概念);

alter database drop logfile group 4;(册除日志组,只对控制文件进行了册除,os文件没有进行任何动作;)限制条件:

restricted:-----current log group;

               active log group;

              no archived log group

              at least one member per group

alter database drop logfile member d:\oracle\oradata\foxconn\redo04a.ora;

(册除日志,日志组中的最后一个日志是无法删除的,无法删除最后一个日志组成员;)

clear logfilereinit log file

alter database clear logfile group 2;(清空日志组)

alter database clear unarchived logfile group 5;(清空没有归档的日志组,做完此件事情之后一定要做full db backup.因为日志出现了断点)

alter database rename file d:\oracle\oradata\foxconn\redo05.ora

to d:\oracle\oradata\foxconn\redo05a.ora;(日志改名)

move or rename logfileos level

alter database rename file xxx to xxx

 

show parameter db_create

alter system set db_create_online_log_dest_1=d:\oracle\oralog;

alter database add logfile group 6;

建立logfile group 默认在group6目录为d:\oracle\oralog\大小为100M;这是oracle使用OMF自动派生出来的文件使用相同的大小.

alter database drop logfile group 4;(OMF方式会对OS文件也进行删除)

 

v$log--        log group information

           status current/active/inactive/unused

v$logfile--    statusblankin use

               stale-imcomplete

 

Archived redo log files

        Two advantages exist to archiving

           recovery : a database backup, together with online

           And archived redo log files can guarantee recovery

           Of all committed transactions.

           Backup:can be performed while the database is open.

           by default a database is created in noarchivelog mode.

 

Archivelog--------noarchivelog

1.    shutdown clearly

2.    startup mount

3.    alter database archivelog/noarchivelog

4.    alter database open;

5.    full db backup;(重要,因为模式改变了)

archive log start (自动归档启用)

select * from v$archived_log;(动太归档日志文件)

show parameter log_archive;

redo日志主要的作用是帮助恢愎做了一半的进程

在线日志文件建议做多功.日志可以用来恢愎你的数据.

Redo log files are organized into groups.

groups and member一个group里面有member,多个member可以对应不同的hardisk

 

数据分析(logmnr—1) set directory

                init.ora文件中utl_file_dir=d:\oracle\admin\fox\cddump此项指定临时文件存放处.  2)restartup

                3)create directory file

                  desc dbms_logmnr

                4)add log file

                       dbms_logmnt.add_logfile

                      dbms_logmnt.removefile

                5)start logmnr

                      dbms_logmnt.start_logmnr

                6)v$logmnr_content—sqlredo/sqlundo

    execute dbms_logmnr_d.build(‘foxdict.ora’,’d:\oracle\admin\fox\cdump’);

execute dbms_logmnr.start_logmnr(dictfilename=>’d:\oracle\admin\fox\cdump\foxdict.ora’);

.Managing Tablespaces and Data files

    表空间与数据文件

database---tablespaces: logical area

segment---specific logical structure occupied space collection

            建立一个所占有空间的一个集合;某一个逻辑结构所占用的集合;

        table/index/temp/rollback(oracle数据环境中只有这四类重要)

extent(分区)---allocte 段是通过分区大小拿到的.

Black(块)---use&store unit是oracle使用和存储单位;

8的整数位;分区绝对是块的整数倍;

alter tablespace users

offine normal/immediate/temporary/recovery(tablespace offine的几种不同的方式\后面三种有可能出现表空间不同步,就会要一个恢愎的动作)

select * from v$tablespace;--(查找表空间)

select * from v$datafile; --(查找数据文件)

select t1.name,t2.name

from v$tablespace t1,v$datafile t2 --(原来我不知道t1跟t2的意思)

where t1.ts#=t2.ts#;     (查找对应的数据库物理文件,它们之间是通过表空间的号连接在一起的;)

利用此查到UNIX下192.168.0.15下的运行方式如下:

NAME

NAME

SYSTEM

/u02/oradata/ora/system01.dbf

TOOLS

/u02/oradata/ora/tools01.dbf

RBS

/u02/oradata/ora/rbs01.dbf

TEMP

/u02/oradata/ora/temp01.dbf

USERS

/u02/oradata/ora/users01.dbf

INDX

/u02/oradata/ora/indx01.dbf

OMS_DATA

/u02/oradata/ora/OMS_DATA.dbf

OMS_INDEX

/u02/oradata/ora/OMS_INDEX.dbf

OMS_LAR_DATA

/u02/oradata/ora/OMS_LAR_DATA.dbf

OMS_LAR_INDEX

/u02/oradata/ora/OMS_LAR_INDEX.dbf

SARM_DATA

/u02/oradata/ora/SARM_DATA.dbf

SARM_INDEX

/u02/oradata/ora/SARM_INDEX.dbf

TEMP_TS

/u02/oradata/ora/TEMP_TS.dbf

ASAP_DATA

/u02/oradata/ora/ASAP_DATA.dbf

ASAP_INDEX

/u02/oradata/ora/ASAP_INDEX.dbf

 

    alter tablespace users

    add datafile ‘d:\oracle\oradata\fox\user02.dbf’ size 10m

    (增加一个文件的表空间)

   

 

    system tables (每个数据库里面都有一个系统表空间)

    select * from dba_rollback_segs;(系统回滚段的存放,放置于系统回滚段)

    alter user kong

    quota 10m on user;(限制user表空间的容量为10M)

    create tablespace xxx [datafile ‘xxx’]---omf

    [size XXX---kb,mb]

    [extent management local/dictionary]

    [default storage(xxx)]----initial/next/pctincrease/min extents/

系统表空间

用户表空间

 

create tablespace kong  --建立表空间

datafile ‘d:\oracle\oradata\fox\kong.dfb’ size 5m

exetent management dictionary

default storage (

initial 100k

next 100k

next 100k

pctincrease 10)

    offline    (字典管理的存储参数)

 

create tablespace kong1

datafile ‘d:\oracle\oradata\fox\kong1.dbf’ size 5m

extent management local autoallocate;

uniform size 1m;

(本地管理,不能像上面的那样)

 

      

        locally managed tablespaces:

        Dictionary-managed tablespaces:

 

    Alter tablespace kong

    Minimum extent 10;(最小分区数)

 

Rollback的使用情况.

 

Show parameter undo;(回滚段方式的显示)

Create undo tablespace undo1

    Database ‘/u01/oracdata/undo101.dbf’ size 40m;

Can only use the datafile and extent

Management

Create temporary tablespace kong4

Tempfile ‘d:\oracle\oradata\fox\kong4.ora’ size 5m

Extent management local;

(临时表空间,临时表空间不能存放永久的数据对象且不能被离线,与系统表空间的争用)

 

alter database default temporary tablespace kong4

指定缺省的临时表空间

 

alter tablespace userdata offline;

1.create table tt1

    (id int)

    tablespace kong;

2.input including contents

3.drop tablespace kong1(OS文件未被删除)

    including contents and datafiles;

 

alter database datafile ‘d:\oracle\oradata\fox\kong4.dbf’

autoexetnd on;(此为设定自动扩张属性)

resize 50m;(此为扩张数据文件)

alter tablespace kong

add datafile ‘d:\oracle\oradata\fox\konga.dbf’

size 10m;

添加一个新的文件给它;

alter tablespace kong

rename file ‘d:\oracle\oradata\fox\konga.dbf’

to ‘d:\oracle\oradata\fox\kong01.dbf’

 

对系统表空间进行改名须启动到mount状态下:

alter database rename

    file ‘/u01/oradata/sys01.dbf’

    to ‘/u03/oradata/sys01.dbf’;

 

omf

alter system set db_create_file_dest=’d:\oracle\oralog’;

create tablespace omftb;

drop tablespace omftb;(删除表以及他所带的os文件)

 

select * from dba_tablespaces;

select * from v$tablespace;

select * from v$datafile;

select * from dba_data_file;(表空间的相关信息)

.storage structure and relationships

    database ----tablespace----segment----extent---oracle black

    table             常规表

    partition table        优化大数据量的表

    cluster              

    index

type of segments----index-organized table

                  index partition

                  undo segment

                   temporary segment

                  lob segment

                   nested table

                   bootstrap segment(不需要管理)

 

    create table kong.test1

    (id int)

    tablespace kong

    storage(initial 100k

    next 100k);             创建表时指定它的存储参数,存储参数优先级高;

 

    create tablespace kong1

    datafile ‘d:\oracle\oradata\fox\kong1’ size 10m

    create table kong.test11

    (id int)

    tablespace kong1;

 

    create table kong.test11

    (id int)

    tablespace kong1

    storage(initial 100k

   next 100k)    初始分配表空间

 

    alter table kong.test12

    allocate extent (size 1m datafile ‘d:\oracle\oradata\fox\kong.dbf’);

    段可以跨文件但不可以跨表空间;

 

    drop table kong.test12;

    truncate table kong.test11;(此两项为空间开始放)

 

    alter table kong.authors

    deallocate unused;(释放没有用到表的空间)

 

    input keep 0

 

    oracle中使用内存也是以使用块大小为单位;

    create tablespace kong2

    datafile ‘d:\oracle\oradata\oemrep\kong2.dbf’ size 10m

    blocksize 8k;

    出现如下的错误:表空间块大小 8192 与配置的块大小不匹配

    show parameter db;

    db_block_size                        integer     4096

 

    alter system set db_cache_size=10m;

    (指定好内存区域)

    alter system set db_8K_cache_size=8k再执行上行的命令就会没有问题了;

 

 

TOP DOWN  与bouttomu up的区别;

事务初始值------初始值        initrans

               最大值     maxtrans

               空间预留    pctused

 

    select * from dba_tablespaces;(所有的表空间)

    select * from dba_segments;(所有的段)

    select * from dba_extents;(数据库中所有的区间)

    desc dba_extents;

    select sum(bytes) from dba_extents

    where owner=’kong’ and segment_name=’authors’

    计算authors表所占用的字节数;

    select * from dba_data_files

    select * from dba_free_space

.Undo data

    undo取代以前的Rollback

    show parameter undo;

    select * from dba_rollback_segs;

    create undo tablespace undotbs1

    datafile 'e:\oracle\oradata\oemrep\undotbs1.dbf' size 10m;

    alter system set undo_tablespace=undotbs1;

    (自定义回滚段的数据库)

    alter tablespace undotbs1

    add datafile 'e:\oracle\oradata\oemrep\undotbs1a.dbf' size 10m

    (此表空间不能被离线与撤消.)

    drop tablespace undotbs1

    including contents and datafiles;

    删除表空间和它所带的文件;

    create rollback segment rbs1

    tablespace undotbs;(创建回滚段)

    select * from dba_rollback_segs

    alter system set undo_suppress_errors=true;

    初始参数文件:init.ora

    undo_management=AUTO

    undo_tablespace=UNDOTBS修改undow参数文件

undo_management                      string      AUTO(自动管理)

undo segment function

1.    transaction rollback

2.    read consistency

    分不同的用户,只要没有做确认的动作,你们做的操作就不能体现在其它用户的数据姐    中.

3.    tracsaction recovery

    undo_suppress_errors                 boolean     FALSE

    此值为false在缺省情况下会报错;

UNDO_retention 回闪(默认为900秒.就是持续为900),提交之后不能回滚.不能回滚,但有回闪;回闪只能看,但不能恢愎.oracle是不能够后悔.

    Desc dbms_flashback

    Desc dbms_flashback.enable_at_time(’26-jan-04:12:17 pm’)

    Alter session set nls_language=American;(可找到此时间之后的数据)

    Execute dbms_flashback.disable;

Select end_time,begin_time,undoblks from v$undostat;

Select * from dba_rollbak_segs;

            V$rollname

            V$rollstat

            V$undostat

            V$session

            V$transaction

手动

show parameter undo

show parameter rollback

十一Managing Tables

 管理表的空间分配;管理表而不是实现这张表;

restricted 限制

 

create table test1

 (id int)

 tablespace users;(常规表regular table)

                   partitioned table

                   index-organized table

                   cluster(群集表)

Data type----User defined

         ----Build in(内建)

                         Scalar(标量)---nchar(unicate)

                         Collection(集合)

                         Relationship(关系)

create table test2

(lname char(2000))

tablespace users

 

create table test2

(lname varchar(4000))

tablespace users

 

NUMBER(P,S)精度;刻度

Create table salary

(id int,salary number(5,2))

tablespace users;(最大长度为5位,小数位可以保留2位)

create table test2

(itime date)

tablespace users

 

lob----large object

blog—图象

clog—文本

nclog

bfile---实际方式的指针的方式.是以文件的方式保存在os中;

long ---4G

long raw---2G

ROWID---行ID

        标识确定我们维一的一行放在那里;行ID是缺省存在的.

        分为扩展行ID:extended ROWID Format

        限制行ID:Restricted ROWID Format

select rowid from kong.authors;

看到的是64进制的总共字符串是18位的.(rowid—length=18, base 64 string)

            10bytes,80bits

            object#--32bits, 6

            rfile#--10bits,3

            block#--22bits,6

            row#--16bits,3

           base 64—A-Z,a-z,0-9,/,+

desc dbms_rowid

select rowid,dbms_rowid,rowid_to_restricted(rowid)

from kong.authors;

select rowid,dbms_rowid.rowid_block_number(rowid),dbms_rowid.rowid_row_number(rowid) from kong.authors;

Structure of a Row

Row header

Column length    (255type,栏位的值块定是一个字节或第三个字节)

Column Value

 

Create table test2

(id int,

lname varchar2(20) not null,

fname varchar(20) constraint ck_1 check(fname like ‘k%),

empdate date default sysdate)

tablespace users;

 

create global temporary table xxx (临时表)

on commit delete rows(提交关删除.)

as

select * from kong.authors;

 

create global temporary table xxx   (临时表)

on commit preserve rows(保持相关行)

as

select * from kong.authors;

临时不需要回滚,同步等动作;

 

create table test3

(id int)

tablespace users

storage(initial 100k

next 100k

pctincrease 0

minextents 1

maxextents 10)

pctfree 10

pctused 40

 

alter table hr.employees

pctfree 30

pctused 50

storage(next 500k

minexetnts 2

maxextents 100)

 

alter table kong.authors

allocate extent(size 1m datafile ‘d:\oracle\oradata\system01.dbf’);

 

high water mark(高水印),就是随着表扩张而到过的位置;

alter table kong.authors

deallocate unnsed;(保持没有用到的空间)

 

alter table kong.authors

deallocate unnsed keep 2m;(在高水印上保持2M的空间)

 

alter table kong.authors

move tablespace indx;将表move到表空间indx

 

create index testindex1

on kong.authors(au_lname)

tablespace users;创建索引表

索引在完成move之后,索引是不可用的;索引将来进行重建;

alter index testindex1

rebuild;(重建索引)

 

truncate table kong.authors;

清空表.清空表的同时放空间;

 

drop table kong.authors

cascade constraint;丢弃表

 

alter table kong.sales

drop column qty;

 

alter table kong.sales

set unused column stor_id;(设定此栏位不能用)

 

alter table kong.sales

drop unused columns;(删除设定成不能用的栏位)

 

DBA_TABLE

Select * from dba_tables where owner=’kong’(查到kong有多少表)

 

Select * from dba_objects where owner=’kong’

增加表的column

alter table tablename add columnname

insert into table …… values ……

update tablename

set column=value, column=values;

 

delect tablename 只是删除表里的values并不会删除表,删除表的命令是什么呢?

 

十二Manager indexes

索引是独立于表的独立存在的结构:是除了表之之外唯一可以申请空羊的物理结构;

index –independentn physical

        pointer—book catalog

               --ponit to table data—rowid

      --speed query/overload data update

      --oltp(在线交易): less indexes(越少越好)

      --olap(数据仓库): more indexes(越多越好)

      --B-tree— nonleaf/leaf( or 查询比较低效)

              (平衡二杈树)

root—branch---leaf—pointer---table

pointer 组成如下:

                 index entry header

                 key column length

                 key column value    (此二项为内容提要)

                 rowid               (此为页号)

 

 

Bitmap Index

        取值唯一性相对来说比较低,建议使用位图索引.

 

Create index testindex1

On kong.orders(orderid)

Tablespace users            (不做声明是B树结构索引的表)

 

Create bitmap imdex testbit1

On sales(qty)

Tablespace users;   (建立位图索引表)

 

创建索引不能使用PCTUSER…

create index testindex2

on stores(stor_name)

tablespace users

pctfree 20

pctused 40

storage(

initial 100k

next 100k);

 

Creating Indexes:Guidelines

         Balance query and DML needs

         Place in separate tablespace

         Use uniform extent sizes:Multiples of five blocks

         Or MINIMUM EXTENT size for tablespace

         Consider Nologging for large indexes

         INITRANS should generally be higher on indexes

         Than on the corresponding tables.

 

create index testindex2

on stores(stor_name)

tablespace users

pctfree 20

pctused 40

storage(

initial 100k

next 100k);

nologging;

 

show parameter create_bitmap_area_size

(加速建立位图索引的,缺省情况下是8MB)

 

create index testindex3

on orders(ordered)

reverse;反转索引

 

alter index testindex3

pctfree 20

storage(

next 200k

pctincrease 20);

 

十三.maintaining Data integrity

alter table suthors

add constraint pk_1 primary key(au_id);

 

alter table authors

add constraint uk_1 nuique(au_lname,au_fname);唯一约束

 

alter table stores

add constraint pk_sales primary key(stor_id);

alter table sales

add constraink fk_sales foreign key(stor_id) references stores(stor_id);

 

 

 

 

十五 Managing Users

create user testuser1

identified by kxf_001;

 

grant connect,create table to testuser1;(没有表空间,

权限的管理,资源的管理;

 

alter user testuser1

account lock;              锁定帐号

 

如果不指定表空间,系统会默认系统的表空间;

account locking

default tablespace

temporary tablespace

tablespace quotas

resource limits

direct privileges

role privileges

 

审核

    DB/OS/ALL

 

Alter user testuser1

Quota 10m on users;有表空间也有了使用表空间的使用限额.

 

Database Schema 就是数据对象的有者;是owner的集合

                Tables

                Triggers

                Constraints

                Indexes

                Views

                Sequences

                Stored program units

                Synonyms

                User-defined data types

                Database links

 

Desc dba_users

 

Select username,default_tablespace from dba_users

Where username=’kong’;(查看kong用户缺省的表空间)

 

Alter user kong profile default;

 

用户的验证方式: 口令验证(DB):

                外部(OS):

                全局(GLOBOL):

 

Create user aaron

Identified by kxf_001

Default tablespace data

Temporary tablespace temp

Quota 15m on data

Password expire;

 

Alter database default temporary tablespace temp;

 

Create user ops$kong

Identified externally

Default tablespace users

Temporary tablespace temp

Quota 10m on users;    (OS的验证)

 

指定限额

alter user testuser2

quota 5m on users;

临时表限额不必要,回滚表不能有限额;

 

drop user arron;

(不能删除已连接的用户,

drop user testuser1 cascade (删除用户信息,包含它所在的数据对象)

 

select * from dba_users;(查看表有多少用户ID)

 

desc dba_ts_quotas(每一用户的空间限额)

 

select * from dba_ts_quotas

where username=’kong’;

 

阅读(1804) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~