oracle笔记2

五、  Using Data Dictionary and Dynamic Performance Views

   1、数据字典的表

      dictionary,all_object,dba_object,

oracle笔记2_第1张图片


oracle笔记2_第2张图片


select * from v$controlfile;



oracle笔记2_第3张图片


select dbid,name from v$database;

select instance_name from v$instance;

 

 

六、Maintaining the Control File

 

1、Add Spfile control file

  (1)  alter system set control_files='/home/oracle/oradata/TS/control01.ctl','/home/oracle/oradata/TS/control02.ctl',
                                                   '/home/oracle/oradata/TS/control03.ctl','/home/oracle/oradata/TS/control04.ctl'
                                                    scope = spfile;

  (2) shutdown  immediate;

  (3) cp control01.ctl control04.ctl

  (4) startup;

 

v$parameter,     v$controlfile,    v$controlfile_record_section

 

2、Advanced Topic

    Creating New Control Files

    Backing up Control Files


3、转储控制文件内容:

SQL> alter system set events 'immediate trace name controlf level 10';


System altered.


SQL> show parameter user_d


NAME                                 TYPE       VALUE
------------------------------------ ---------- ------------------------------
user_dump_dest                       string     /u1/oracle/admin/orcl/udump
SQL> 

查看/u1/oracle/admin/orcl/udump日志文件




或者-----------------------------------------------------------------------------------------------------------


SQL> oradebug setmypid
Statement processed.
SQL> select spid from v$process where addr=(select paddr from v$session                            
  2  where sid=(select sid from v$mystat where rownum=1));


SPID
------------
6026


SQL> oradebug dump controlf 3
Statement processed.
SQL> !vi  /u1/oracle/admin/orcl/udump/orcl_ora_6026.trc



-------------------11g可以这样查找-------------------------------------------------------

select value from v$diag_info where name ='Default Trace File';




4、备份控制文件

alter database backup controlfile to '/u01/home/control2011.bak';

或者

alter database bakcup controlfile to trace as '/u01/home/backctl.txt';

或者rman备份

backup current controlfile;

backup database include current controlfile;



 

 

 

 

 七、Maintaining Online Redo Log Files
        
v$log、v$logfile、v$log_history


1、Force Log switched & CK
select group#,thread#,sequence#,status from v$log;
alter system switch logfile;
select group#,thread#,sequence#,status from v$log;

2、Checkpoints can be forced by:
--Setting FAST_START_MTTR_TARGET parameter
 alter system set fast_start_mttr_target=600 scope=both;
--ALTER SYSTEM CHECKPOINT command
 alter system checkpoint;
3、Adding Redo Files Groups
alter database add logfile group 4
('/db01/redo04.log') size 5M


alter database add logfile member
'/db02/redo04.log' to group 4

select * from v$logfile;


4、删除日志文件
--删除日志文件的组成员
alter database drop logfile member '/db02/redo04.log';
--删除组
alter database drop logfile group 4;
select * from v$logfile;



5、Relocate & Rename
(1) ALTER DATABASE RENAME FILE command
-Shut down the database
-Copy the online redo log files to the new Location
-Place the database in Mount mode
-Execute the command
alter database rename file '/db01/redo03.log' 
to '/db01/redo03.rdo';
-Open database for normal operation
alter database open;


(2)Add new members and drop old members.


6、Clear Redo Files
(1) --alter database clear logfile command can be userd to 
   --reinitialize an online redo log file.
alter database clear logfile group 2;
(2)--Use the unarchived keyword to avoid archiving the 
  --corrupted online redo log file.
alter database clear unarchived logfile group 2;

7、--检查数据是否为archive模式
select archiver from v$instance;
select log_mode from v$database;






八、 Managing Tablespace & Data Files


1、--创建表空间
select * from v$tablespace;
select file_name,tablespace_name from dba_data_files;

create tablespace pual datafile
'/db01/pual01.dbf' size 20m;




2、
select tablespace_name,contents,extent_management from dba_tablespaces;
select * from database_properties;

create temporary tablespace mytemp
tempfile '/db01/mytemp01.dbf' size 10m
extent management local;


alter database default temporary tablespace mytemp;

3、Read-Only Tablespaces
alter tablespace userdata read_only;
alter tablespace TS1 read write;


4、Taking a Tablespace Offline
alter tablespace TS1 offline;
alter tablespace TS1 online;


5、Resizing a Tablespace
select a.tablespace_name,a.bytes/1024/1024 bytes_used, 
b.largest/1024/1024 largest, 
round(((a.bytes-b.bytes)/a.bytes)*100,2) percent_used
from 
(select tablespace_name,sum(bytes) bytes from dba_data_files 
group by tablespace_name ) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest 
from dba_free_space 
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
order by ((a.bytes - b.bytes) / a.bytes) desc


alter tablespace TS1 add datafile
'/db01/ts12.dbf' size 200M
autoextend on next 10m maxsize 2000M


select file_name,tablespace_name,autoextensible from dba_data_files;


alter database '/db01/ts11.dbf'
autoextend on next 10M maxsize 100M;


alter database datafile '/db01/ts11.dbf'
resize 2000M;

--临时表空间
select * from dba_temp_files;




6、Methods for Moving DF
--先把表空间offline
alter tablespace TS1 offline;
-- 然后拷贝数据到目标目录,
alter tablespace TS1 rename 
datafile '/db01/ts11.dbf'
to '/db02/ts11.dbf'


--先把数据库shutdown 然后拷贝数据到目标目录,
--再startup mount
alter database rename file '/db02/ts11.dbf' 
to '/db01/ts11.dbf'
--最后
alter database open;


7、Dropping Tablespaces
drop table TS1 
including contents and datafiles;


8、Tablespace Information
dba_tablespaces
v$tablespace
dba_data_files
v$datafile
dba_temp_files
v$tempfile








九、 Storage Structure & Relationships

--set autot off(查看执行情况)

--set autot on

1、
select tablespace_name ,block_size from dba_tablespaces;

2、Configuring ASSM
create tablespace data02
datafile '/db01/data11.dbf' size 5M
extent management local uniform size 6K
segment space management auto;


3、Manual Data Block Mgmt
select * from user_objects;
select segment_name from user_segment
s;



4、Getting Storage Information

DBA_EXTENDS

DBA_SEGMENTS

DBA_TABLESPACES

DBA_DATA_FILES

DBA_FREE_SPACE

select segment_name,segment_type from user_segments;


十、Managing Undo Data


--查看表所属系统的块

select ename,sal,dbms_rowid.rowid_block_number(rowid) block#,
dbms_rowid.rowid_relative_fno(rowid) as file#
from emp
where empno  = 7839



--更改uodo表空间

alter system set undo_tablespace=undotbs2;

select addr,used_ublk from v$transaction;

select end_time,begin_time,undoblks from v$undostat;


###决定undo表空间大小

--一秒钟最高峰需要多少块

select max(undoblks/((end_time-begin_time)*24*3600)) maxundo from v$undostat;

select sum(undoblks) / sum((end_time-begin_time)*24*3600) from v$undostat;--平均块

--系统需要undo空间

show parameter undo_retention

show parameter db_block_size

所需空间=undo_retention*db_block_size*maxundo


--

DBA_SEGMENTS

DBA_ROLLBACK_SEGS

select segment_name,tablespace_name from dba_rollback_segs;

V$ROLLNAME

V$ROLLSTAT

V$UNDOSTAT

V$SESSION

V$TRANSACTION


select * from v$rollname;


查看用户实务产生使用的undo段:

select s.sid, s.serial#, s.username, r.name, t.cr_get, t.phy_io, t.used_ublk,
       t.noundo, s.program
from   v$rollname r, v$transaction t, v$session s
where  t.addr = s.taddr and t.xidusn = r.usn
order  by t.cr_get, phy_io





SQL> delete emp;


14 rows deleted.


SQL> commit;


Commit complete.


SQL> select * from emp as of timestamp sysdate-1/1440;


no rows selected


SQL> /


no rows selected


SQL> select * from emp as of timestamp sysdate - 2/1440;


     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        900                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1700        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1350        500         30
      7566 JONES      MANAGER         7839 02-APR-81       3075                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1350       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2950                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2550                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3100                    20
      7839 KING       PRESIDENT            17-NOV-81       5100                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1600          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1200                    20
      7900 JAMES      CLERK           7698 03-DEC-81       1050                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3100                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1400                    10


14 rows selected.


SQL> insert into emp select * from emp as of timestamp sysdate - 2/1440;


14 rows created.


SQL> commit;


Commit complete.


SQL> select * from emp;


     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        900                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1700        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1350        500         30
      7566 JONES      MANAGER         7839 02-APR-81       3075                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1350       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2950                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2550                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3100                    20
      7839 KING       PRESIDENT            17-NOV-81       5100                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1600          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1200                    20
      7900 JAMES      CLERK           7698 03-DEC-81       1050                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3100                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1400                    10


14 rows selected.






undo表空间恢复:

1)系统中是否存在其他的undo  如果是则修改为其他undo, 把损坏的脱机, 启动数据库到open, 删除损坏的表空间并建立新的

2)系统中没有其他的undo表空间, 使用隐参让我们undo脱机, 打开数据库,删除undo  建立undo







十一、sysaux

select * from v$sysaux_occupants







你可能感兴趣的:(oracle笔记2)