導航:首頁 > 程序命令 > oracle基本命令

oracle基本命令

發布時間:2023-05-02 04:57:29

1. Oracle創建刪除導入導出命令行總結


說明:
在創建資料庫時輸入的密碼,是修改系統默認的密碼,以system和sysman等系統默認身份登錄時要輸入的密碼就是修改後的密碼(創建資料庫時輸入的密碼)
如果要創建游或新的用戶就必須以system或者sysman(這二者的許可權最大)的身份登錄後才可創建
創建用戶格式:create user 用戶名 identified by 密碼(例如:create user cht identified by cht;)
創建完成後,必須分配許可權,否則連不上資料庫和sqlplus。
因此要做:grant connect,resource,dba to cht;這樣資料庫就可以通過cht/cht連上了。那些select,update,delete,insert的許可權就不必分配了,因為每個用戶默認都有這些基本許可權。
命令行方式連接資料庫的方法:
開始==》運行==》cmd
方式一:
輸入sqlplus,回車
輸入用戶名: system,回車
輸入密碼: orcl,回車
方式二:
輸入sqlplus system/orcl@orcl,回車(system是用戶名,orcl是密碼,@後面的orcl是庫的名字)
(資料庫安裝完成後,有兩個系統級的用戶神激伍 :
1) system 默認密碼為 :manager
2) sys 默認密碼為 :change_on_install)
創建用戶前必須要先建好臨時表空間和數據表空間兩個表空間,否則用系統默認的表空間不好。
//創建臨時表空間
create temporary tablespace zfmi_temp tempfile 'D:oracleoradatazfmizfmi_temp.dbf' size 100m autoextend on next 32m maxsize 2048m extent management local;
說明:
1、zfmi_temp 表空間的名字
2、鉛春D:oracleoradatazfmi 存放資料庫文件的地方,一般是安裝資料庫後有控制文件,數據文件和日誌文件的文件夾,再加上要創建表空間的名字+dbf(數據文件)
3、100M 表空間的初始大小
4、32M 表空間自動增長的大小
5、2048M 表空間最大的大小
//創建數據表空間
create tablespace zfmi logging datafile 'D:oracleoradatazfmizfmi.dbf' size 100m autoextend on next 32m maxsize 2048m extent management local;
//創建用戶並指定表空間
create user zfmi identified by zfmi default tablespace zfmi temporary tablespace zfmi_temp;
//給用戶授予許可權
grant connect,resource dba to zfmi; (dba:指定所有許可權)
到這一步新建一個用戶的工作就完成了。
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//刪除用戶以及用戶所有的對象
drop user zfmi cascade;
//cascade參數是級聯刪除該用戶所有對象,經常遇到如用戶有對象而未加此參數則用戶刪不了的問題,所以習慣性的加此參數
//刪除表空間
前提:刪除表空間之前要確認該表空間沒有被其他用戶使用之後再做刪除
drop tablespace zfmi including contents and datafiles cascade onstraints;
//including contents 刪除表空間中的內容,如果刪除表空間之前表空間中有內容,而未加此參數,表空間刪不掉,所以習慣性的加此參數
//including datafiles 刪除表空間中的數據文件
//cascade constraints 同時刪除tablespace中表的外鍵參照
如果刪除表空間之前刪除了表空間文件,解決辦法:
如果在清除表空間之前,先刪除了表空間對應的數據文件,會造成資料庫無法正常啟動和關閉。
可使用如下方法恢復(此方法已經在oracle9i中驗證通過):
下面的過程中,filename是已經被刪除的數據文件,如果有多個,則需要多次執行;tablespace_name是相應的表空間的名稱。
$ sqlplus /nolog
SQL conn / as sysdba;
如果資料庫已經啟動,則需要先執行下面這行:
SQL shutdown abort
SQL startup mount
SQL alter database datafile 'filename' offline drop;
SQL alter database open;
SQL drop tablespace tablespace_name including contents;
導入導出命令:
Oracle數據導入導出imp/exp就相當於oracle數據還原與備份。exp命令可以把數據從遠程資料庫伺服器導出到本地的dmp文件, imp命令可以把dmp文件從本地導入到遠處的資料庫伺服器中。 利用這個功能可以構建兩個相同的資料庫,一個用來測試,一個用來正式使用。
下面介紹的是導入導出的實例。(注意:不用連接到SQL/plus,直接在DOS下就可以導出。)
數據導出:
1 將資料庫TEST完全導出,用戶名system 密碼manager 導出到D:chu.dmp中
exp system/manager@TEST file=d:chu.dmp full=y
2 將資料庫中system用戶與sys用戶的表導出
exp system/manager@TEST file=d:chu.dmp owner=(system,sys)
3 將資料庫中的表inner_notify、notify_staff_relat導出
exp aichannel/aichannel@TESTDB2 file= d:datanewsmgnt.dmp tables=(inner_notify,notify_staff_relat)
4 將資料庫中的表table1中的欄位filed1以"00"打頭的數據導出
exp system/manager@TEST file=d:chu.dmp tables=(table1) query=" where filed1 like ༼%'"
上面是常用的導出,對於壓縮,既用winzip把dmp文件可以很好的壓縮。
也可以在上面命令後面 加上 compress=y 來實現。
數據的導入
1 將D:chu.dmp 中的數據導入 TEST資料庫中。
imp system/manager@TEST file=d:chu.dmp
imp aichannel/aichannel@HUST full=y file=d:datanewsmgnt.dmp ignore=y
上面可能有點問題,因為有的表已經存在,然後它就報錯,對該表就不進行導入。
在後面加上 ignore=y 就可以了。
2 將d:chu.dmp中的表table1 導入
imp system/manager@TEST file=d:chu.dmp tables=(table1)
基本上上面的導入導出夠用了。不少情況要先是將表徹底刪除,然後導入。
注意:
操作者要有足夠的許可權,許可權不夠它會提示。
資料庫時可以連上的。可以用tnsping TEST 來獲得資料庫TEST能否連上。
附錄一:
給用戶增加導入數據許可權的操作
第一,啟動sql*puls
第二,以system/manager登陸
第三,create user 用戶名 IDENTIFIED BY 密碼 (如果已經創建過用戶,這步可以省略)
第四,GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW ,
DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,
DBA,CONNECT,RESOURCE,CREATE SESSION TO 用戶名字
第五, 運行-cmd-進入dmp文件所在的目錄,
imp userid=system/manager full=y file=*.dmp
或者 imp userid=system/manager full=y file=filename.dmp
執行示例:
F:WorkOracle_Databackupimp userid=test/test full=y file=inner_notify.dmp
屏幕顯示
Import: Release 8.1.7.0.0 - Proction on 星期四 2月 16 16:50:05 2006
(c) Copyright 2000 Oracle Corporation. All rights reserved.
連接到: Oracle8i Enterprise Edition Release 8.1.7.0.0 - Proction
With the Partitioning option
JServer Release 8.1.7.0.0 - Proction
經由常規路徑導出由EXPORT:V08.01.07創建的文件
已經完成ZHS16GBK字元集和ZHS16GBK NCHAR 字元集中的導入
導出伺服器使用UTF8 NCHAR 字元集 (可能的ncharset轉換)
. 正在將AICHANNEL的對象導入到 AICHANNEL
. . 正在導入表 "INNER_NOTIFY" 4行被導入
准備啟用約束條件
成功終止導入,但出現警告。
附錄二:
Oracle 不允許直接改變表的擁有者, 利用Export/Import可以達到這一目的。
先建立import9.par,
然後,使用時命令如下:imp parfile=/filepath/import9.par
例 import9.par 內容如下:
FROMUSER=TGPMS
TOUSER=TGPMS2 (註:把表的擁有者由FROMUSER改為TOUSER,FROMUSER和TOUSER的用戶可以不同)
ROWS=Y
INDEXES=Y
GRANTS=Y
CONSTRAINTS=Y
BUFFER=409600
file==/backup/ctgpc_20030623.dmp
log==/backup/import_20030623.log

2. OracleRAC日常基本維護命令

所有實例和服務的狀態

$ srvctl status database d orcl

Instance orcl is running on node linux

Instance orcl is running on node linux

單個實例的狀態禪扒

$ srvctl status instance d orcl i orcl

Instance orcl is running on node linux

在資料庫全局命名服務的狀態

$ srvctl status service d orcl s orcltest

Service orcltest is running on instance(s) orcl orcl

特定節點上節點應用程序的狀態

$ srvctl status nodeapps n linux

VIP is running on node: linux

GSD is running on node: linux

源蔽Listener is running on node: linux

ONS daemon is running on node: linux

ASM 實例的狀態

$ srvctl status a *** n linux

ASM instance +ASM is running on node linux

列出配置的所有資料庫

$ srvctl config database

orcl

顯示 RAC 資料庫的配置

$ srvctl config database d orcl

linux orcl /u /app/oracle/proct/ /db_

linux orcl /u /app/oracle/proct/ /db_

顯示指定集群資料庫的所有服務

$ srvctl config service d orcl

orcltest PREF: orcl orcl AVAIL:

顯示節點應用程序的配置 —(VIP GSD ONS 監聽器)

$ srvctl config nodeapps n linux a g s l

VIP exists : /linux vip/ / /eth :eth

GSD exists

雹襲州ONS daemon exists

Listener exists

顯示 ASM 實例的配置

$ srvctl config a *** n linux

+ASM /u /app/oracle/proct/ /db_

集群中所有正在運行的實例

SELECT

inst_id

instance_number inst_no

instance_name inst_name

parallel

status

database_status db_status

active_state state

host_name host

FROM gv$instance

ORDER BY inst_id;

INST_ID INST_NO INST_NAME PAR STATUS DB_STATUS STATE HOST

orcl YES OPEN ACTIVE NORMAL rac

orcl YES OPEN ACTIVE NORMAL rac

位於磁碟組中的所有數據文件

select name from v$datafile

union

select member from v$logfile

union

select name from v$controlfile

union

select name from v$tempfile;

NAME

+FLASH_RECOVERY_AREA/orcl/controlfile/current

+FLASH_RECOVERY_AREA/orcl/onlinelog/group_

+FLASH_RECOVERY_AREA/orcl/onlinelog/group_

+FLASH_RECOVERY_AREA/orcl/onlinelog/group_

+FLASH_RECOVERY_AREA/orcl/onlinelog/group_

+ORCL_DATA /orcl/controlfile/current

+ORCL_DATA /orcl/datafile/example

+ORCL_DATA /orcl/datafile/indx

+ORCL_DATA /orcl/datafile/sysaux

+ORCL_DATA /orcl/datafile/system

+ORCL_DATA /orcl/datafile/undotbs

+ORCL_DATA /orcl/datafile/undotbs

+ORCL_DATA /orcl/datafile/undotbs

+ORCL_DATA /orcl/datafile/undotbs

+ORCL_DATA /orcl/datafile/users

+ORCL_DATA /orcl/datafile/users

+ORCL_DATA /orcl/onlinelog/group_

+ORCL_DATA /orcl/onlinelog/group_

+ORCL_DATA /orcl/onlinelog/group_

+ORCL_DATA /orcl/onlinelog/group_

+ORCL_DATA /orcl/tempfile/temp

rows selected

屬於 ORCL_DATA 磁碟組的所有 ASM 磁碟

SELECT path

FROM v$a *** _disk

WHERE group_number IN (select group_number

from v$a *** _diskgroup

where name = ORCL_DATA );

PATH

ORCL:VOL

ORCL:VOL

啟動/停止RAC集群

確保是以 oracle UNIX 用戶登錄的 我們將從rac 節點運行所有命令

# su – oracle

$ hostname

Rac

停止 Oracle RAC g 環境

第一步是停止 Oracle 實例 當此實例(和相關服務)關閉後 關閉 ASM 實例 最後 關閉節點應用程序(虛擬IP GSD TNS 監聽器和 ONS)

$ export ORACLE_SID=orcl

$ emctl stop dbconsole

$ srvctl stop instance d orcl i orcl

$ srvctl stop a *** n rac

$ srvctl stop nodeapps –n rac

啟動 Oracle RAC g 環境

第一步是啟動節點應用程序(虛擬 IP GSD TNS 監聽器和 ONS) 當成功啟動節點應用程序後 啟動 ASM 實例 最後 啟動 Oracle 實例(和相關服務)以及企業管理器資料庫控制台

$ export ORACLE_SID=orcl

$ srvctl start nodeapps n rac

$ srvctl start a *** n rac

$ srvctl start instance d orcl i orcl

$ emctl start dbconsole

使用 SRVCTL 啟動/停止所有實例

啟動/停止所有實例及其啟用的服務 我只是覺得有意思就把此步驟作為關閉所有實例的一種方法加進來了!

$ srvctl start database d orcl

lishixin/Article/program/Oracle/201311/16967

3. 干貨-Oracle里的常用命令

本文轉自:51Testing軟體測試網。(http://www.51testing.com/html/27/n-7827.html)

      第一章:日誌管理

1.forcing log switches

sql> alter system switch logfile;

2.forcing checkpoints

sql> alter system checkpoint;

3.adding online redo log groups

sql> alter database add logfile [group 4]

sql> ('/disk3/log4a.rdo','/disk4/log4b.rdo') size 1m;

4.adding online redo log members

sql> alter database add logfile member

sql> '/disk3/log1b.rdo' to group 1,

sql> '/disk4/log2b.rdo' to group 2;

5.changes the name of the online redo logfile

sql> alter database rename file 'c:/oracle/oradata/oradb/redo01.log'

sql> to 'c:/oracle/oradata/redo01.log';

6.drop online redo log groups

sql> alter database drop logfile group 3;

7.drop online redo log members

sql> alter database drop logfile member 'c:/oracle/oradata/redo01.log';

8.clearing online redo log files

sql> alter database clear [unarchived] logfile 'c:/oracle/log2a.rdo';

9.using logminer analyzing redo logfiles

a. in the init.ora specify utl_file_dir = ' '

b. sql> execute dbms_logmnr_d.build('oradb.ora','c:\oracle\oradb\log');

c. sql> execute dbms_logmnr_add_logfile('c:\oracle\oradata\oradb\redo01.log',

sql> dbms_logmnr.new);

d. sql> execute dbms_logmnr.add_logfile('c:\oracle\oradata\oradb\redo02.log',

sql> dbms_logmnr.addfile);

e. sql> execute dbms_logmnr.start_logmnr(dictfilename=>'c:\oracle\oradb\log\oradb.ora');

f. sql> select * from v$logmnr_contents(v$logmnr_dictionary,v$logmnr_parameters

sql> v$logmnr_logs);

g. sql> execute dbms_logmnr.end_logmnr;

第二章:表空間管理

1.create tablespaces

sql> create tablespace tablespace_name datafile 'c:\oracle\oradata\file1.dbf' size 100m,

sql> 'c:\oracle\oradata\file2.dbf' size 100m minimum extent 550k [logging/nologging]

sql> default storage (initial 500k next 500k maxextents 500 pctinccease 0)

sql> [online/offline] [permanent/temporary] [extent_management_clause]

2.locally managed tablespace

sql> create tablespace user_data datafile 'c:\oracle\oradata\user_data01.dbf'

sql> size 500m extent management local uniform size 10m;

3.temporary tablespace

sql> create temporary tablespace temp tempfile 'c:\oracle\oradata\temp01.dbf'

sql> size 500m extent management local uniform size 10m;

4.change the storage setting

sql> alter tablespace app_data minimum extent 2m;

sql> alter tablespace app_data default storage(initial 2m next 2m maxextents 999);

5.taking tablespace offline or online

sql> alter tablespace app_data offline;

sql> alter tablespace app_data online;

6.read_only tablespace

sql> alter tablespace app_data read only|write;

7.droping tablespace

sql> drop tablespace app_data including contents;

8.enableing automatic extension of data files

sql> alter tablespace app_data add datafile 'c:\oracle\oradata\app_data01.dbf' size 200m

sql> autoextend on next 10m maxsize 500m;

9.change the size fo data files manually

sql> alter database datafile 'c:\oracle\oradata\app_data.dbf' resize 200m;

10.Moving data files: alter tablespace

sql> alter tablespace app_data rename datafile 'c:\oracle\oradata\app_data.dbf'

sql> to 'c:\oracle\app_data.dbf';

11.moving data files:alter database

sql> alter database rename file 'c:\oracle\oradata\app_data.dbf'

sql> to 'c:\oracle\app_data.dbf';

第三章:表

1.create a table

sql> create table table_name (column datatype,column datatype]....)

sql> tablespace tablespace_name [pctfree integer] [pctused integer]

sql> [initrans integer] [maxtrans integer]

sql> storage(initial 200k next 200k pctincrease 0 maxextents 50)

sql> [logging|nologging] [cache|nocache]

2. an existing table

sql> create table table_name [logging|nologging] as subquery

3.create temporary table

sql> create global temporary table xay_temp as select * from xay;

on commit preserve rows/on commit delete rows

4.pctfree = (average row size - initial row size) *100 /average row size

pctused = 100-pctfree- (average row size*100/available data space)

5.change storage and block utilization parameter

sql> alter table table_name pctfree=30 pctused=50 storage(next 500k

sql> minextents 2 maxextents 100);

6.manually allocating extents

sql> alter table table_name allocate extent(size 500k datafile 'c:/oracle/data.dbf');

7.move tablespace

sql> alter table employee move tablespace users;

8.deallocate of unused space

sql> alter table table_name deallocate unused [keep integer]

9.truncate a table

sql> truncate table table_name;

10.drop a table

sql> drop table table_name [cascade constraints];

11.drop a column

sql> alter table table_name drop column comments cascade constraints checkpoint 1000;

alter table table_name drop columns continue;

12.mark a column as unused

sql> alter table table_name set unused column comments cascade constraints;

alter table table_name drop unused columns checkpoint 1000;

alter table orders drop columns continue checkpoint 1000

data_dictionary : dba_unused_col_tabs

第四章:索引

1.creating function-based indexes

sql> create index summit.item_quantity on summit.item(quantity-quantity_shipped);

2.create a B-tree index

sql> create [unique] index index_name on table_name(column,.. asc/desc) tablespace

sql> tablespace_name [pctfree integer] [initrans integer] [maxtrans integer]

sql> [logging | nologging] [nosort] storage(initial 200k next 200k pctincrease 0

sql> maxextents 50);

3.pctfree(index)=(maximum number of rows-initial number of rows)*

100/maximum number of rows

4.creating reverse key indexes

sql> create unique index xay_id on xay(a) reverse pctfree 30 storage(initial 200k

sql> next 200k pctincrease 0 maxextents 50) tablespace indx;

5.create bitmap index

sql> create bitmap index xay_id on xay(a) pctfree 30 storage( initial 200k next 200k

sql> pctincrease 0 maxextents 50) tablespace indx;

6.change storage parameter of index

sql> alter index xay_id storage (next 400k maxextents 100);

7.allocating index space

sql> alter index xay_id allocate extent(size 200k datafile 'c:/oracle/index.dbf');

8.alter index xay_id deallocate unused;

第五章:約束

1.define constraints as immediate or deferred

sql> alter session set constraint[s] = immediate/deferred/default;

set constraint[s] constraint_name/all immediate/deferred;

2. sql> drop table table_name cascade constraints

sql> drop tablespace tablespace_name including contents cascade constraints

3. define constraints while create a table

sql> create table xay(id number(7) constraint xay_id primary key deferrable

sql> using index storage(initial 100k next 100k) tablespace indx);

primary key/unique/references table(column)/check

4.enable constraints

sql> alter table xay enable novalidate constraint xay_id;

5.enable constraints

sql> alter table xay enable validate constraint xay_id;

第六章:LOAD數據

1.loading data using direct_load insert

sql> insert /*+append */ into emp nologging

sql> select * from emp_old;

2.parallel direct-load insert

sql> alter session enable parallel dml;

sql> insert /*+parallel(emp,2) */ into emp nologging

sql> select * from emp_old;

3.using sql*loader

sql> sqlldr scott/tiger \

sql> control = ulcase6.ctl \

sql> log = ulcase6.log direct=true

第七章:reorganizing data

1.using expoty

$exp scott/tiger tables(dept,emp) file=c:\emp.dmp log=exp.log compress=n direct=y

2.using import

$imp scott/tiger tables(dept,emp) file=emp.dmp log=imp.log ignore=y

3.transporting a tablespace

sql>alter tablespace sales_ts read only;

$exp sys/.. file=xay.dmp transport_tablespace=y tablespace=sales_ts

triggers=n constraints=n

$ datafile

$imp sys/.. file=xay.dmp transport_tablespace=y datafiles=(/disk1/sles01.dbf,/disk2

/sles02.dbf)

sql> alter tablespace sales_ts read write;

4.checking transport set

sql> DBMS_tts.transport_set_check(ts_list =>'sales_ts' ..,incl_constraints=>true);

在表transport_set_violations 中查看

sql> dbms_tts.isselfcontained 為true 是, 表示自包含

第八章:managing password security and resources

1.controlling account lock and password

sql> alter user juncky identified by oracle account unlock;

2.user_provided password function

sql> function_name(userid in varchar2(30),password in varchar2(30),

old_password in varchar2(30)) return boolean

3.create a profile : password setting

sql> create profile grace_5 limit failed_login_attempts 3

sql> password_lock_time unlimited password_life_time 30

sql>password_reuse_time 30 password_verify_function verify_function

sql> password_grace_time 5;

4.altering a profile

sql> alter profile default failed_login_attempts 3

sql> password_life_time 60 password_grace_time 10;

5.drop a profile

sql> drop profile grace_5 [cascade];

6.create a profile : resource limit

sql> create profile developer_prof limit sessions_per_user 2

sql> cpu_per_session 10000 idle_time 60 connect_time 480;

7. view => resource_cost : alter resource cost

dba_Users,dba_profiles

8. enable resource limits

sql> alter system set resource_limit=true;

第九章:Managing users

1.create a user: database authentication

sql> create user juncky identified by oracle default tablespace users

sql> temporary tablespace temp quota 10m on data password expire

sql> [account lock|unlock] [profile profilename|default];

2.change user quota on tablespace

sql> alter user juncky quota 0 on users;

3.drop a user

sql> drop user juncky [cascade];

4. monitor user

view: dba_users , dba_ts_quotas

第十章:managing privileges

1.system privileges: view => system_privilege_map ,dba_sys_privs,session_privs

2.grant system privilege

sql> grant create session,create table to managers;

sql> grant create session to scott with admin option;

with admin option can grant or revoke privilege from any user or role;

3.sysdba and sysoper privileges:

sysoper: startup,shutdown,alter database open|mount,alter database backup controlfile,

alter tablespace begin/end backup,recover database

alter database archivelog,restricted session

sysdba: sysoper privileges with admin option,create database,recover database until

4.password file members: view:=> v$pwfile_users

5.O7_dictionary_accessibility =true restriction access to view or tables in other schema

6.revoke system privilege

sql> revoke create table from karen;

sql> revoke create session from scott;

7.grant object privilege

sql> grant execute on dbms_pipe to public;

sql> grant update(first_name,salary) on employee to karen with grant option;

8.display object privilege : view => dba_tab_privs, dba_col_privs

9.revoke object privilege

sql> revoke execute on dbms_pipe from scott [cascade constraints];

10.audit record view :=> sys.aud$

11. protecting the audit trail

sql> audit delete on sys.aud$ by access;

12.statement auditing

sql> audit user;

13.privilege auditing

sql> audit select any table by summit by access;

14.schema object auditing

sql> audit lock on summit.employee by access whenever successful;

15.view audit option : view=> all_def_audit_opts,dba_stmt_audit_opts,

dba_priv_audit_opts,dba_obj_audit_opts

16.view audit result: view=> dba_audit_trail,dba_audit_exists,dba_audit_object,

dba_audit_session,dba_audit_statement

第十一章: manager role

1.create roles

sql> create role sales_clerk;

sql> create role hr_clerk identified by bonus;

sql> create role hr_manager identified externally;

2.modify role

sql> alter role sales_clerk identified by commission;

sql> alter role hr_clerk identified externally;

sql> alter role hr_manager not identified;

3.assigning roles

sql> grant sales_clerk to scott;

sql> grant hr_clerk to hr_manager;

sql> grant hr_manager to scott with admin option;

4.establish default role

sql> alter user scott default role hr_clerk,sales_clerk;

sql> alter user scott default role all;

sql> alter user scott default role all except hr_clerk;

sql> alter user scott default role none;

5.enable and disable roles

sql> set role hr_clerk;

sql> set role sales_clerk identified by commission;

sql> set role all except sales_clerk;

sql> set role none;

6.remove role from user

sql> revoke sales_clerk from scott;

sql> revoke hr_manager from public;

7.remove role

sql> drop role hr_manager;

8.display role information

view: =>dba_roles,dba_role_privs,role_role_privs,dba_sys_privs,

role_sys_privs,role_tab_privs,session_roles

第十二章: BACKUP and RECOVERY

1. v$sga,v$instance,v$process,v$bgprocess,v$database,v$datafile,v$sgastat

2. Rman need set dbwr_IO_slaves or backup_tape_IO_slaves and large_pool_size

3. Monitoring Parallel Rollback

> v$fast_start_servers , v$fast_start_transactions

4.perform a closed database backup (noarchivelog)

> shutdown immediate

> cp files /backup/

> startup

5.restore to a different location

> connect system/manager as sysdba

> startup mount

> alter database rename file '/disk1/../user.dbf' to '/disk2/../user.dbf';

> alter database open;

6.recover syntax

--recover a mounted database

>recover database;

>recover datafile '/disk1/data/df2.dbf';

>alter database recover database;

--recover an opened database

>recover tablespace user_data;

>recover datafile 2;

>alter database recover datafile 2;

7.how to apply redo log files automatically

>set autorecovery on

>recover automatic datafile 4;

8.complete recovery:

--method 1(mounted databae)

> c:\backup\user.dbf c:\oradata\user.dbf

>startup mount

>recover datafile 'c:\oradata\user.dbf;

>alter database open;

--method 2(opened database,initially opened,not system or rollback datafile)

> c:\backup\user.dbf c:\oradata\user.dbf (alter tablespace offline)

>recover datafile 'c:\oradata\user.dbf' or

>recover tablespace user_data;

>alter database datafile 'c:\oradata\user.dbf' online or

>alter tablespace user_data online;

--method 3(opened database,initially closed not system or rollback datafile)

>startup mount

>alter database datafile 'c:\oradata\user.dbf' offline;

>alter database open

> c:\backup\user.dbf d:\oradata\user.dbf

>alter database rename file 'c:\oradata\user.dbf' to 'd:\oradata\user.dbf'

>recover datafile 'e:\oradata\user.dbf' or recover tablespace user_data;

>alter tablespace user_data online;

--method 4(loss of data file with no backup and have all archive log)

>alter tablespace user_data offline immediate;

>alter database create datafile 'd:\oradata\user.dbf' as 'c:\oradata\user.dbf''

>recover tablespace user_data;

>alter tablespace user_data online

5.perform an open database backup

> alter tablespace user_data begin backup;

> files /backup/

> alter database datafile '/c:/../data.dbf' end backup;

> alter system switch logfile;

6.backup a control file

> alter database backup controlfile to 'control1.bkp';

> alter database backup controlfile to trace;

7.recovery (noarchivelog mode)

> shutdown abort

> cp files

> startup

8.recovery of file in backup mode

>alter database datafile 2 end backup;

9.clearing redo log file

>alter database clear unarchived logfile group 1;

>alter database clear unarchived logfile group 1 unrecoverable datafile;

10.redo log recovery

>alter database add logfile group 3 'c:\oradata\redo03.log' size 1000k;

>alter database drop logfile group 1;

>alter database open;

or >cp c:\oradata\redo02.log' c:\oradata\redo01.log

>alter database clear logfile 'c:\oradata\log01.log';

閱讀全文

與oracle基本命令相關的資料

熱點內容
cad命令縮小 瀏覽:152
linux發展史 瀏覽:627
伺服器選用什麼CPU比較好 瀏覽:334
明星怎麼宣傳安卓 瀏覽:953
8255晶元編程 瀏覽:65
java文件bat運行 瀏覽:747
java常見筆試 瀏覽:529
360程序員模式 瀏覽:363
AQS演算法的查詢樹構造 瀏覽:329
小豬微信營銷源碼 瀏覽:12
阿里雲伺服器能連接列印機嗎 瀏覽:175
命令行參考 瀏覽:281
怎麼初步認識編程 瀏覽:208
為什麼程序員都喜歡谷歌 瀏覽:891
壓縮性骨拆能自愈嗎 瀏覽:277
安卓怎麼設置游戲畫面 瀏覽:114
k線上寫字源碼 瀏覽:457
單擊按鈕保存資料源碼 瀏覽:354
華為gt加密卡 瀏覽:213
河北超融合伺服器廠家雲主機 瀏覽:894