主頁 > 知識庫 > oracle dba 應(yīng)該熟悉的命令

oracle dba 應(yīng)該熟悉的命令

熱門標(biāo)簽:地圖標(biāo)注原件 語音電話機器人缺點 百變地圖標(biāo)注 廣州市400電話辦理 宜賓外呼系統(tǒng)廠家 語音電話機器人營銷方案 修改高德地圖標(biāo)注 淮安自動外呼系統(tǒng)開發(fā) 南通防封外呼系統(tǒng)運營商
1 運行SQLPLUS工具
sqlplus

2 以O(shè)S的默認(rèn)身份連接
/ as sysdba

3 顯示當(dāng)前用戶名
show user

4 直接進(jìn)入SQLPLUS命令提示符
sqlplus /nolog

5 在命令提示符以O(shè)S身份連接
connect / as sysdba

6 以SYSTEM的身份連接
connect system/xxxxxxx@服務(wù)名

7 顯示當(dāng)然用戶有哪些表
select * from tab;

8 顯示有用戶名和帳戶的狀態(tài)
select username,account_status from dba_users;

9 將SCOTT帳號解鎖(加鎖)
alter user scott account unlock(lock);

10 以SCOTT的身份連接并且查看所屬表
connect scott/tiger
select * from tab;


11 查看EMP的表結(jié)構(gòu)及記錄內(nèi)容
desc emp
select empno,ename from emp;

12 以O(shè)S的身份登看SGA,共享池,CACHE的信息
connect / as sysdba
show sga
select name,value/1024/1024 from v$sga;
show parameter shared_pool_size
select value/1024/1024 from v$parameter where name ='shared_pool_size';
show parameter db_cache_size
select value/1024/1024 from v$parameter where name ='db_cache_size';

13 查看所有含有SIZE的信息
show parameter size
bitmap_merge_area_size integer 1048576
create_bitmap_area_size integer 8388608
db_16k_cache_size big integer 0
db_2k_cache_size big integer 0
db_32k_cache_size big integer 0
db_4k_cache_size big integer 0
db_8k_cache_size big integer 0
db_block_size integer 4096
db_cache_size big integer 33554432
db_keep_cache_size big integer 0
db_recycle_cache_size big integer 0

NAME TYPE VALUE
------------------------------------ ----------- -------------
global_context_pool_size string
hash_area_size integer 1048576
java_max_sessionspace_size integer 0
java_pool_size big integer 33554432
large_pool_size big integer 8388608
max_dump_file_size string UNLIMITED
object_cache_max_size_percent integer 10
object_cache_optimal_size integer 102400
olap_page_pool_size integer 33554432
oracle_trace_collection_size integer 5242880
parallel_execution_message_size integer 2148

NAME TYPE VALUE
------------------------------------ ----------- -------------
sga_max_size big integer 143727516
shared_pool_reserved_size big integer 2516582
shared_pool_size big integer 50331648
sort_area_retained_size integer 0
sort_area_size integer 524288
workarea_size_policy string AUTO


14 顯示SGA的信息
select * from v$sgastat;
POOL NAME BYTES
----------- -------------------------- ----------
fixed_sga 453532
buffer_cache 33554432
log_buffer 656384
shared pool subheap 46884
shared pool KGK heap 3756
shared pool KQR M PO 586792
shared pool KQR S PO 180232
shared pool KQR S SO 5128
shared pool sessions 410720
shared pool sql area 2144664
shared pool 1M buffer 2098176

POOL NAME BYTES
----------- -------------------------- ----------
shared pool KGLS heap 901756
shared pool parameters 8352
shared pool free memory 38687204
shared pool PL/SQL DIANA 420816
shared pool FileOpenBlock 695504
shared pool PL/SQL MPCODE 135692
shared pool library cache 2985576
shared pool miscellaneous 4889396
shared pool MTTR advisory 21164
shared pool PLS non-lib hp 2068
shared pool XDB Schema Cac 4966300

POOL NAME BYTES
----------- -------------------------- ----------
shared pool joxs heap init 4220
shared pool kgl simulator 563260
shared pool sim memory hea 44184
shared pool table definiti 1728
shared pool trigger defini 1896
shared pool trigger inform 1140
shared pool trigger source 448
shared pool type object de 69120
shared pool Checkpoint queue 282304
shared pool VIRTUAL CIRCUITS 265160
shared pool dictionary cache 1610880

POOL NAME BYTES
----------- -------------------------- ----------
shared pool KSXR receive buffers 1033000
shared pool character set object 323724
shared pool FileIdentificatonBlock 323292
shared pool message pool freequeue 834752
shared pool KSXR pending messages que 841036
shared pool event statistics per sess 1718360
shared pool fixed allocation callback 180
large pool free memory 8388608
java pool free memory 33554432

已選擇42行。

15 顯示PGA的信息
select * from v$pgastat;
NAME VALUE UNIT
---------------------------------------------------------------- ---------- ---------
aggregate PGA target parameter 16777216 bytes
aggregate PGA auto target 7640064 bytes
global memory bound 838656 bytes
total PGA inuse 8293376 bytes
total PGA allocated 13106176 bytes
maximum PGA allocated 22090752 bytes
total freeable PGA memory 0 bytes
PGA memory freed back to OS 0 bytes
total PGA used for auto workareas 0 bytes
maximum PGA used for auto workareas 4096 bytes
total PGA used for manual workareas 0 bytes

NAME VALUE UNIT
---------------------------------------------------------------- ---------- ---------
maximum PGA used for manual workareas 4096 bytes
over allocation count 0
bytes processed 8783872 bytes
extra bytes read/written 0 bytes
cache hit percentage 100 percent

已選擇16行。

17 在$ORACLE_HOME/sqlplus/admin/glogin.sql中加入環(huán)境變量,以后每次啟動生效
define _editor=vi
set line 2000


18 將當(dāng)前命令隨加到文件中
save c:a.sql append

19 將指定文件的命讀出緩沖區(qū)
get c:a.sql

20 執(zhí)行腳本語句
@ c:a.sql

21 將輸入保存到指定文件中
spool c:O.LOG
select * from v$sga;
spool off

22 設(shè)定行大小
set linesize 2000

23 設(shè)定頁大小
set pagesize 10

24 設(shè)定字符列格式
col ename format a30

25 設(shè)定數(shù)字列格式
col sal format 999,999.999

26 10G查看文件$ORACLE_HOME/install/protlist顯示端口
http://127.0.0.1:5560/isqlplus
9i查看文件$ORACLE_HOME/Apache/Apache/ports.ini顯示端口
http://127.0.0.1:7778/isqlplus
http://127.0.0.1:7778/isqlplusdba

27 啟動Oracle 9i監(jiān)聽程序
Oracle的監(jiān)聽程序主要是為客戶端的連接提供接口
$ lsnrctl start

28 關(guān)閉Oracle 9i監(jiān)聽程序
$ lsnrctl stop

29 啟動Oracle Web Server
$ cd $ORACLE_HOME/Apache/Apache/bin
$ ./startJServ.sh
/database/oracle/product/9i/Apache/Apache/bin/apachectl start: httpd started

30 關(guān)閉Oracle Web Server
$ cd $ORACLE_HOME/Apache/Apache/bin
$ ./stopJServ.sh
/database/oracle/product/9i/Apache/Apache/bin/apachectl stop: httpd stopped

31 啟動Oracle Web Server后默認(rèn)的端口號是7777
unix
cd $ORACLE_HOME/Apache/Apache/bin/
htpasswd $ORACLE_HOME/sqlplus/admin/iplusdba.pw admin
windows
cd D:oracleora92ApacheApachebin
htpasswd D:oracleora92/sqlplus/admin/iplusdba.pw admin
New password: *****
Re-type new password: *****
Adding password for user admin

32 pfile: $ORACLE_BASE/admin/實例名/Pfile
spfile: $ORACLE_HOME/dbs
監(jiān)聽器配置文件:listener.ora: $ORACLE_HOME/network/admin/
tnsnames.ora: $ORACLE_HOME/network/admin/

33 指定用戶的表空間
SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE USERNAME='用戶名'


34 當(dāng)前用戶
select user from dual;show user

35 當(dāng)前用戶的缺省表空間
SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE USERNAME=(select user from dual);

37 顯示正在使用的初始化參數(shù)文件
show parameter spfile

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string %ORACLE_HOME%DATABASESPFILE%
ORACLE_SID%.ORA
38 用SPfile轉(zhuǎn)Pfile
create pfile='c:init.ora' from spfile;
create pfile from spfile;
UNIX將生成在$ORACLE_HOME/dbs目錄下
WINDOWS將生成在$ORACLE_HOME/DATABASE目錄下

39 顯示cache的值
show parameter cache
前面兩個下劃線的是動態(tài)調(diào)整的參數(shù)
前面一個下劃線的是內(nèi)部參數(shù)

40 顯示正在使用的參數(shù)和文本參數(shù)值
select * from v$parameter;
select * from v$spparameter;

41 顯示動態(tài)性能視圖的結(jié)構(gòu)
desc v$parameter;
名稱
NUM
NAME
TYPE
VALUE
ISDEFAULT
ISSES_MODIFIABLE
ISSYS_MODIFIABLE
ISMODIFIED
ISADJUSTED
DESCRIPTION
UPDATE_COMMENT

42 有條件的顯示動態(tài)參數(shù)
select * from v$parameter where name like '%db_cache%';

43 修改參數(shù)語句
alter system set sga_max_size=256m scope=spfile; 寫入SPFILE,重啟生效
alter system set sga_max_size=256m scope=memory; 寫入內(nèi)存區(qū),立即生效
alter system set sga_max_size=256m scope=both; 即寫入內(nèi)存區(qū),又寫入SPFILE,默認(rèn)為BOTH.

44 動態(tài)調(diào)整large_pool_size的語句
alter system set large_pool_size=16M;

45 當(dāng)前正在使用的SGA的大小
select sum(bytes)/1024/1024 from v$sgastat;

46 設(shè)置db_cache_size的大小保存在SPFILE
alter system set db_cache_size=128m scope=spfile;

47 設(shè)置shared_pool_size的大小保存在SPFILE中
alter system set shared_pool_size=80m scope=spfile;

48 顯示PGA的狀態(tài)
select * from v$pgastat;
show parameter pga
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target big integer 16777216

49 帶PFILE來啟動資料庫,?代表ORACLE的主目錄
startup pfile=?databaseinitmydb.ora

50 顯示當(dāng)前數(shù)據(jù)庫的狀態(tài),mount的狀態(tài)下就可以查看數(shù)據(jù)庫的狀態(tài)
select open_mode from v$database;

51 顯示當(dāng)前實例 nomount狀態(tài)下就可以查看實例
select * from v$instance;

52 顯示 background_dump_dest的路徑 ,
show parameter background_dump_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
background_dump_dest string D:oracleadminthwerpbdump

53 顯示當(dāng)有用戶的表
select * from user_tables;

54 顯示當(dāng)有用戶可以訪問表
select * from all_tables;

55 顯示用戶為SCOTT的表
select * from dba_tables where owner='SCOTT';

56 顯示所有用戶信息
select * from dba_users;

57 建立用戶并指定密碼
create user edpthw identified by edpthw;

58 給用戶授權(quán)
grant connect,resource to edpthw;

59 建立一個表
create table a(a int);

60 顯示數(shù)據(jù)字典中表名為USER開頭的表名
select table_name from dict where table_name like 'USER%';

61 在UNIX下oerr ora 錯誤號查看錯誤的幫助信息.

62 在unix 查看日志中有哪些錯誤
grep ORA alert_PROD.log|tail -10

63 顯示當(dāng)前實例
SELECT * FROM V$INSTANCE;

64 顯示當(dāng)前數(shù)據(jù)庫信息
SELECT * FROM V$DATABASE;

65 顯示當(dāng)前ORACLR資料的版本
SELECT * FROM V$VERSION;

66 顯示當(dāng)前的選項
SELECT * FROM V$OPTION;

67 顯示當(dāng)前實例的初始化參數(shù)
SELECT * FROM V$PARAMETER;

68 顯示數(shù)據(jù)文件
SELECT * FROM V$DATAFILE;

69 顯示日志文件
SELECT * FROM V$LOGFILE

70 顯示控制文件
SELECT * FROM V$CONTROLFILE;

71 顯示當(dāng)有有哪些會話
SELECT * FROM V$SESSION;

72 顯示當(dāng)前有哪些進(jìn)程
SELECT * FROM V$PROCESS;

73 顯示當(dāng)前后臺進(jìn)程
SELECT * FROM V$BGPROCESS;

74 顯示SGA的大小
SELECT * FROM V$SGA;

75 顯示SGA的統(tǒng)計數(shù)
SELECT * FROM V$SGASTAT;

76 顯示PGA的統(tǒng)計數(shù)
SELECT * FROM V$PGASTAT;

77 顯示有哪些控制文件
SHOW PARAMETER CONTROL_FILES;

78 增加一個控制文件一定要在NOMOUNT狀態(tài)下進(jìn)行.語句如下.
alter system set control_files='D:ORADATAMYDBCONTROL01.CTL',
'D:ORADATAMYDBCONTROL02.CTL',
'D:ORADATAMYDBCONTROL03.CTL',
'E:CONTROL04.CTL' SCOPE=SPFILE;

alter system set control_files='D:oracleoradatathwerpCONTROL01.CTL',
'D:oracleoradatathwerpCONTROL02.CTL',
'D:oracleoradatathwerpCONTROL03.CTL',
'D:oracleoradatathwerpCONTROL04.CTL' scope=spfile;

79 數(shù)據(jù)重新啟動
STARTUP FORCE

80 顯示當(dāng)前控制文件
SELECT * FROM V$CONTROLFILE;
SHOW PARAMETER CONTROL

81 刪除一個控制文件
alter system set control_files='D:ORADATAMYDBCONTROL01.CTL',
'D:ORADATAMYDBCONTROL02.CTL',
'D:ORADATAMYDBCONTROL03.CTL' SCOPE=SPFILE

82 顯示當(dāng)前使用的日志
SELECT * FROM V$LOG;

83 顯示實例的歸檔模式
ARCHIVE LOG LIST;

84 顯示重做日志文件
SELECT * FROM V$LOGFILE;

85 手工切換重做日志文件
ALTER SYSTEM SWITCH LOGFILE;

86 發(fā)出檢查點
ALTER SYSTEM CHECKPOINT;

87 顯示重做日期的歷史記錄
select * from v$log_history;

88 更改會語的日期格式
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

89 增加日志組
ALTER DATABASE ADD LOGFILE GROUP 4 ( 'D:ORADATAMYDBredo4.log') SIZE 10240K;

92 刪除日志組
ALTER DATABASE DROP LOGFILE GROUP 4 ;


90 增加日志組成員
ALTER DATABASE ADD LOGFILE MEMBER 'D:ORADATAMYDBredo11.log' TO GROUP 1;

91 刪除日志組成員
ALTER DATABASE DROP LOGFILE MEMBER 'D:ORADATAMYDBredo14.log' ;


92 顯示系統(tǒng)表空間
select * from dba_tablespaces;

93 顯示系統(tǒng)表空間所擁有的文件
select * from dba_data_files;

94 顯示系統(tǒng)臨時表空間
select * from dba_temp_files;

95 顯示表空間的已被使用多少
select tablespace_name,sum(bytes)/1024/1024 m
from dba_data_files group by tablespace_name;

96 顯示表空間還有多少沒有使用
select tablespace_name,
sum(bytes)/1024/1024 m
from dba_free_space group by tablespace_name;

97 創(chuàng)建表空間
10G CREATE BIGFILE TABLESPACE "MYTBS1" DATAFILE 'D:ORADATAMYDBmytbs_01.dbf' SIZE 100M LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;
9I CREATE TABLESPACE "MYTBS1" DATAFILE 'D:oracleORADATAthwerpmytbs_01.dbf' SIZE 100M LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;
CREATE SMALLFILE TABLESPACE "MYTBS1" DATAFILE 'D:ORADATAMYDBmytbs_01.dbf' SIZE 100M , 'D:ORADATAMYDBmytbs02.dbf' SIZE 100M LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

98 在指字表空間里建表
create table t1 (a int) tablespace mytbs1;

99 在指字表空間里建索引
create index t1_ind on t1(a) tablespace mytbs1;

100 在指定表空間里增加數(shù)據(jù)文件
ALTER TABLESPACE "MYTBS1" ADD DATAFILE 'D:ORADATAMYDBmytbs03.dbf' SIZE 100M

100 修改表空間的大小
ALTER DATABASE DATAFILE 'D:ORADATAMYDBMYTBS_01.DBF' RESIZE 200M

101 表空間改文件的自動擴展
ALTER DATABASE DATAFILE 'D:ORADATAMYDBMYTBS03.DBF' AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED

102 刪除表空間和表空間所屬文件
drop tablespace mytbs1 including contents and datafiles;

103 建立臨時表空間
CREATE SMALLFILE TEMPORARY TABLESPACE "MYTEMP" TEMPFILE 'D:oracleORADATAthwerpmytemp01.dbf' SIZE 200M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M
CREATE TEMPORARY TABLESPACE "MYTEMP" TEMPFILE 'D:oracleORADATAthwerpmytemp01.dbf' SIZE 200M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M

104 更改用戶的臨時表空間
ALTER USER "GARY" TEMPORARY TABLESPACE "MYTEMP"

105 設(shè)置成默認(rèn)的表空間
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE "MYTEMP"

106 創(chuàng)建臨時表空間組
ALTER TABLESPACE MYTEMP TABLESPACE GROUP MYTEMP_GROUP
ALTER TABLESPACE TEMP TABLESPACE GROUP MYTEMP_GROUP

107 創(chuàng)建重做表空間
CREATE UNDO TABLESPACE "MYUNDO" DATAFILE 'D:ORADATAMYDBmyundo01.dbf' SIZE 200M

108 顯示重做參數(shù)
show parameter undo

109 回滾段的使用情況
select * from dba_rollback_segs;

110 更改重做表空間
alter system set undo_tablespace=myundo;

111 建立一個表
create table a tablespace users as select * from dba_objects;

112 插入一些記錄
insert into a select * from a;

113 有條件查詢表名放在哪個表空間
select * from dba_tables where table_name='A' and owner='SYS';

114 有條件查詢段名放在哪個表空間
select * from dba_segments where segment_name='A' and owner='SYS';

115 查詢有哪些段類型
select distinct segment_type from dba_segments;

116 查詢段和表空間的對應(yīng)關(guān)系
select * from dba_extents where segment_name='A' and owner='SYS';

117 建立一個16K表空間
CREATE TABLESPACE "MYTBS3" DATAFILE 'D:oracleORADATAthwerpmytbs3.dbf' SIZE 100M LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO BLOCKSIZE 16384;

118 指字參數(shù)建立表
create table b (a int,b varchar2(10)) tablespace users INITRANS 2 PCTFREE 5;

119 顯示當(dāng)前所使用的塊大小
show parameter block_size;

120 釋放表的高水位的空間
alter table a deallocate unused;

121 高水位前移.速度快
truncate table a;

122 分配空間給表
alter table a allocate extent (datafile 'D:ORADATAMYDBusers01.dbf' size 1m);

123 指定參數(shù)建立表
create table C (a int) tablespace system pctfree 10 pctused 60 storage(freelists 2);
CREATE TABLE "SYS"."D" ( "A" VARCHAR2(10)) TABLESPACE "SYSTEM" PCTFREE 5 PCTUSED 60 INITRANS 2 MAXTRANS 100 STORAGE ( FREELISTS 2)
124 生成一個測試表
create table a tablespace users as select * from dba_objects;

125 查看表行的物理地址
select rowid form a;

126 用包的命令查看表行的物理地址
select DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID),DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID),DBMS_ROWID.ROWID_ROW_NUMBER(ROWID) FROM A

127 建立表索引
CREATE INDEX A_IND ON A(OBJECT_NAME) TABLESPACE MYTBS2;

128 查看表的索引
SELECt * FROM DBA_INDEXES WHERE TABLE_NAME='A';
SELECT * FROM DBA_SEGMENTS WHERE SEGMENT_NAME='A_IND';

129 移動重組表空間
ALTER TABLE A MOVE TABLESPACE USERS;

130 重建表索引
ALTER INDEX A_IND REBUILD;

131 設(shè)置行可以內(nèi)部移動屬性
ALTER TABLE A ENABLE ROW MOVEMENT;

132 在原地進(jìn)行行的移動
ALTER TABLE A SHRINK SPACE;

133 查看表所存儲的信息
SELECT BYTES FORM DBA_SEGMENTS WHERE SEGMENT_NAME='A';
SELECT OWNER,SEGMENT_NAME,BYTES FROM DBA_SEGMENTS WHERE SEGMENT_NAME='A';

134 截取表
TRUNCATE TABLE A;

135 刪除表
DROP TABLE A CASCADE CONSTRAINTS;

136 顯示垃圾桶(10G才有)
show recyclebin
SELECT * FROM DBA_RECYCLEBIN;
SELECT * FROM USER_RECYCLEBIN;

137 恢復(fù)已刪除的表
flashback table a to before drop;

138 恢復(fù)較早已前的已刪除的表
flashback table "BIN$hWrBq1irS0COp10n22NZJg==$0" to before drop rename to a1;

139 查詢指定表的索引
select * from dba_indexs where table_name='A';

140 清除垃圾桶
PURGE RECYCLEBIN;
PURGE DBA_RECYCLEBIN;

141 刪除表并清除垃圾桶(10G)
DROP TABLE A PURGE;

142 刪除表的列
ALTER TABLE A DROP COLUMN COMMENTS CASCAGE CONSTRAINTES CHECKPOINT 1000;


143 重命名列
ALTER TABLE A RENAME COLUMN HIRE_DATE TO START_DATE;

144 標(biāo)記不可使用的列
ALTER TABLE A SET UNUSED COLUMN COMMENTS CASCADE CONSTRAINTS;

145 刪除不再使用的的列
ALTER TABLE A DROP UNUSED COLUMNS CHECKPOINT 10000;

146 繼續(xù)列的刪除操作
ALTER TABLE A DROP COLUMNS CONTINUE CHECKPOINT 10000;

147 增加表的主索引
ALTER TABLE A ADD PRIMARY KEY (OBJECT_ID);

148 刪除表的主索引
ALTER TABLE A DROP PRIMARY KEY;

149 索引表的主索引并指定索引所使用的表空間
ALTER TABLE A ADD PRIMARY KEY (OBJECT_ID) USING INDEX TABLESPACE USERS;

150 建立一個普通索引
CREATE INDEX A_NAME_IND ON A(OWNER,OBJECT_NAME);

151 建立一個函數(shù)索引
SELECT /*+ INDEX(A A_NAME2_IND) */ * FROM A WHERE UPPER(OBJECT_NAME)='A';

152 建立一個位圖索引
CREATE BITMAP INDEX A_NAME_BT ON A(OWNER);

153 查詢數(shù)據(jù)庫的信息
SELECT /*+ INDEX(A A_NAME_BT) */ * FROM A WHERE OWNER='SYS' OR OWNER='SYSTEM';
SELECT /*+ FULL(A) */ * FROM A WHERE OWNER='SYS' OR OWNER='SYSTEM';

154 生成一個腳本來建立索引重整
SELECT 'ALTER INDEX '||INDEX_NAME||' COALESCE;' FROM DBA_INDEXES WHERE TABLE_NAME='A' AND OWNER='SYS'
SELECT 'ALTER INDEX '||INDEX_NAME||' REBUILD ONLINE;' FROM DBA_INDEXES WHERE TABLE_NAME='A' AND OWNER='SYS'

155 顯示所有用戶的信息
SELECT * FROM DBA_USERS;

156 顯示當(dāng)前數(shù)據(jù)庫的用戶
SELECT USERNAME,ACCOUNT_STATUS,DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE FROM DBA_USERS;

160 建立一個新用戶
create user edpthw identified by "123456"
default tablespace users
temporary tablespace temp
quota unlimited on users
quota 10m on mytbs2;

161 查詢限額信息
select * from dba_ts_quotas;
select * from user_ts_quotas;

162 用戶改密碼
alter user edpthw identified by edpthw;

163 鎖用戶
alter user edpthw account lock;

164 使密碼過期,迫使改下一次進(jìn)入改密碼
alter user edpthw password expire;

165 取消限額
alter user edpthw quota unlimited on mytbs2;

166 刪除用戶
drop user hmtong cascade;

167 授權(quán)用戶
grant create session,create table,create view to edpthw;

168 分別授權(quán)
GRANT CREATE ANY TABLE TO "hmtong"
GRANT CREATE TABLE TO "hmtong"
GRANT DROP ANY TABLE TO "hmtong"
GRANT SELECT ANY TABLE TO "hmtong"

169 折消授權(quán)
REVOKE UNLIMITED TABLESPACE FROM "hmtong"

170 對象授權(quán)
GRANT SELECT ON "hmtong"."A" TO "edpthw"

171 折消對象授權(quán)
REVOKE SELECT ON "hmtong"."A" FROM "edpthw"

172 取消進(jìn)入系統(tǒng)直接用默認(rèn)密碼,而一定要自己輸入密碼才可以進(jìn)入
unix $ORACLE_HOMENETWORKADMINSQLNET.ORA
windows D:oracleproduct10.1.0Db_1NETWORKADMINSQLNET.ORA
SQLNET.AUTHENTICATION_SERVICES= (NTS,NONE)
修改$ORACLE_HOME/network/admin/sqlnet.ora文件
  將原有的:SQLNET.AUTHENTICATION_SERVICES= (NTS)
  改為:SQLNET.AUTHENTICATION_SERVICES= (NONE)
  或者直接注釋:#SQLNET.AUTHENTICATION_SERVICES= (NTS)

173 查詢Pwfile中存放的用戶信息
select * from v$pwfile_users;

174 授權(quán)sysdba給指定用戶
grant sysdba to hmtong;

175 取消指定用戶的sysdba權(quán)限
revoke sysdba from hmtong;

176 修改系統(tǒng)的授權(quán)的屬性
alter system set remote_login_passwordfile=exclusive; 能sysdba登錄,能授權(quán)
alter system set remote_login_passwordfile=shared scope=spfile; 只能sysdba登錄,不能授權(quán)
alter system set remote_login_passwordfile=NONE; 取消

177 重建口令文件
orapwd file=PWDmydb.ora password=itpub

178 創(chuàng)建一個用戶
create user hmtong identified by abcdefg;

179 授權(quán)連接給指定用戶
GRANT "CONNECT" TO "hmtong";
GRANT UNLIMITED TABLESPACE,CONNECT,RESOURCE TO HMTONG;

180 創(chuàng)建表
create table t1(a int);
create table t2(a int);

181 查看系統(tǒng)特權(quán)
select * from user_sys_privs;

182 查看對象特權(quán)
select * from user_tab_privs;

183 查看被授予的角色
select * from user_role_privs;

184 查看角色的有什么權(quán)限
select * from role_sys_privs;

185 查看角色的有哪些表
select * from role_tab_privs;

186 查看當(dāng)前會話的權(quán)限
select * from session_privs;

187 監(jiān)聽器的狀態(tài)
lsnrctl start
$ORACLE_HOME/network/admin/listener.ora

188 監(jiān)聽器的啟動和關(guān)閉
lsnrctl start [名字]
lsnrctl stop [名字]

189 監(jiān)聽器的狀態(tài)和服務(wù)信息
lsnrctl stat
lsnrctl service

190 配置監(jiān)聽器的工具
netca
netmgr

192 動態(tài)注冊監(jiān)聽器
alter system register;

193 配置監(jiān)聽器的兩個參數(shù)
show parameter local_listener
show parameter remote_listener

194 追加設(shè)置一個服務(wù)名,服務(wù)名可以多個對應(yīng)一個實例
alter system set service_names=mydb,appdb

195 客戶連接配置文件
$ORACLE_HOME/network/admin/tnsname.ora

196 檢查指定的監(jiān)聽器是否存在
TNSPING MYDB


197 將SQLNET.ORA配置好就可以connect system/testdb1@192.168.100.80:1521/testdb1方式連接
SQLNET.AUTHENTICATION_SERVICES= (NTS,NONE)
NAMES.DIRECTORY_PATH= (TNSNAMES,EZCONNECT)

198 快速重啟資料庫
shutdown immediate

199 將資料庫開啟到mount的狀態(tài)
startup mount

200 顯示數(shù)據(jù)庫的歸檔還是非歸檔模式
archive log list
數(shù)據(jù)庫日志模式 存檔模式
自動存檔 禁用
存檔終點 D:oracleora92RDBMS
最早的概要日志序列 64
下一個存檔日志序列 69
當(dāng)前日志序列 69

201 在數(shù)據(jù)庫mount的狀態(tài)下更改數(shù)據(jù)庫的歸檔模式
alter database archivelog; 歸檔
alter database noarchivelog; 非歸檔

202 打開數(shù)據(jù)庫
alter database open;

203 查看歸檔的路徑的
SQL> show parameter log_archive_dest_x

204 動態(tài)的配置歸檔路徑在兩個不同的目錄下同時歸檔
alter system set log_archive_dest_1='location=e:archive';
alter system set log_archive_dest_2='location=d:archive';

205 切換系統(tǒng)的下一個日志文件
alter system switch logfile; (10G就會產(chǎn)生歸檔文件)

206 定義自動歸檔
alter system set log_archive_start=true scope=spfile; (9i)(10G不用設(shè))

207 查看數(shù)據(jù)庫的歸檔的信息
select * from v$log;

208 查看曾經(jīng)做過哪些歸檔及路徑
select * from v$archived_log;

209 查看有哪還沒有做歸檔的信息
select * from v$archive;

210 設(shè)置歸檔路徑2暫時不歸檔和啟用歸檔
alter system set log_archive_dest_state_2=defer;
alter system set log_archive_dest_state_2=enable;

211 查看最少路徑歸檔數(shù)目的參數(shù)
show parameter log_archive_min_succeed_dest

212 查看歸檔路徑的文件名格式參數(shù)
show parameter log_archive_format

213 查改歸檔文件名的格式
alter system set log_archive_format='mydb_%s_%r_%t.log' scope=spfile;

214 顯示出快速恢復(fù)區(qū)的大小和路徑
show parameter db_recovery_file_dest
show parameter db_recovery_file_dest_size

215 更改歸檔路徑到到快速恢復(fù)區(qū)
alter system set log_archive_dest_1='location=use_db_recovery_file_dest';

216 更改快速恢復(fù)區(qū)的路徑
alter system set db_recovery_file_dest='e:recover';

217 查看快速恢復(fù)區(qū)的使用情況
select * from v$recovery_file_dest;

218 更改快速恢復(fù)區(qū)的大小
alter system set db_recovery_file_dest_size=10g;
219 查看數(shù)據(jù)庫的歸檔模式
select log_mode from v$database;
archive log list

220 查看歸檔文件的歸檔路徑
show parameter log_archive_dest
select * from v$archive_dest;

221 查看歸檔文件
select * from v$archive;

222 查看曾經(jīng)歸檔過的記錄
select * from v$archived_log;

223 啟動在線備份表空間
alter tablespace users begin backup;

224 查詢指定表空間的文件路徑
select file_name from dba_data_files where tablespace_name='USERS';

225 在SQL狀態(tài)上暫時離開返回到SHELL
host ocopy user*.dbf e:backup

226 結(jié)束生成備份表空間
alter tablespace users end backup;

227 備份數(shù)據(jù)庫的控制文件
alter database backup controlfile to 'e:backupcontrol01.ctl';

228 生成創(chuàng)建控制文件的腳本
alter database backup controlfile to trace as 'e:backupcontrol01.sql';

229 查詢哪個文件需要恢復(fù)
select * from v$recover_file;

230 查詢指定文件號的詳細(xì)信息
select * from v$datafile where file#=6;

231 查詢有哪些需要歸檔
select * from v$recovery_log;

232 恢復(fù)指字的數(shù)據(jù)文件
recover datafile 6;

233 創(chuàng)建一個例子表
create table a11 tablespace mytbs3 as select * from dba_objects;

233 查詢有沒有指定的文件
select * from dba_extents where file_id=6;

224 自動找到歸檔日志恢復(fù)相應(yīng)數(shù)據(jù)文件
recover AUTOMATIC datafile 6;

225 將一個表空間設(shè)置成不可用
ALTER TABLESPACE USERS OFFLINE IMMEDIATE

226 恢復(fù)指定表空間
RECOVER TABLESPACE USERS;

227 將指定的表文件設(shè)置成不可用
ALTER DATABASE DATAFILE 6 OFFLINE;

228 將指定的表文件設(shè)置成在線
ALTER DATABASE DATAFILE 6 ONLINE;

229 創(chuàng)建一個測試表
CREATE TABLE TEST (A DATE);

230 插入當(dāng)前系統(tǒng)日期
INSERT INTO TEST VALUES(SYSDATE);

231 查詢TEST的值
SELECT * FROM TEST;

232 在注冊表里的設(shè)置日期格式
NLS_DATE_FORMAT=YYYY-MM-DD HH24:MI:SS

233 恢復(fù)到指定的時間點
RECOVER DATABASE UNTIL TIME '2006-11-26 10:49:43';

234 打開資料庫并重置重做日志
alter database open resetlogs;

235 恢復(fù)控制文件
RECOVER DATABASE using backup controlfile UNTIL cancel;

236 追加臨時表空間
alter tablespace temp add tempfile 'd:oradatamydbtemp01.dbf' size 10m reuse;

237 Rman的連接
connect target /

238 顯示要備份的數(shù)據(jù)庫文件
report schema;

239 在RMAN的指定位置來備份文件
run {
allocate channel ch1 type disk format 'e:rman%U.bak' maxpiecesize=2g;
backup database;
}

240 在RMAN的顯示威者默認(rèn)設(shè)置
show all;

backup database;

241 配置缺省的路徑
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'E:RMAN%U.BAK' MAXPIECESIZE 2G;

242 清除缺省配置
CONFIGURE CHANNEL DEVICE type DISK clear;

243 配置并行數(shù)
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;

244 配置自動備份控制文件
CONFIGURE CONTROLFILE AUTOBACKUP on;

245 配置有益度
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

246 配置可以恢復(fù)到7天內(nèi)的保留窗口
CONFIGURE RETENTION POLICY TO recovery window of 7;

247 備份表空間
backup tablespace users;

248 備份數(shù)據(jù)文件
backup datafile 6;

249 備份前一天的重做日志
backup archivelog until time 'sysdate-1';

250 備份SP文件
backup spfile;

251 備份當(dāng)前的控制文件
backup current controlfile;

252 列出所有的備份集
list backupset ;

253 列出所有的匯總備份集
list backupset summary;

254 列出具體的備份信息
list backupset 16

255 刪除備份集13
delete backupset 13;

256 不提示刪除所有的備份集
delete noprompt backupset;

257 凡是USERS的備份都刪除
delete backup of tablespace users;

258 列出哪些不需要的備份集
report obsolete ;

259 邊備份邊壓縮數(shù)據(jù)庫
backup as compressed backupset database;

260 增量備份時的0級備份一個表空間
backup incremental level 0 tablespace users;

261 2級備份累積備份
backup incremental level 2 cumulative tablespace users;

262 刪除指定日期的歸檔日志
DELETE ARCHIVELOG UNTIL TIME 'SYSDATE-1/24';


263 在RMAN恢復(fù)指定表空間
RUN {
SQL 'ALTER TABLESPACE USERS OFFLINE IMMEDIATE';
RESTORE TABLESPACE USERS;
RECOVER TABLESPACE USERS;
SQL 'ALTER TABLESPACE USERS ONLINE';
}

264 在RMAN的恢復(fù)控制文件
STARTUP NOMOUNT
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
RESTORE DATABASE VALIDATE;
RECOVER DATABASE ;
ALTER DATABASE OPEN RESETLOGS;

265 查詢數(shù)據(jù)庫的字符集
select * from database_properties where property_name like 'NLS_CHA%';
NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK

266 導(dǎo)出數(shù)據(jù)到一個文件中
exp userid=system/oracle file=full.dmp full=y
exp userid=system/oracle file=full1.dmp,full2.dmp,full3.dmp filesize=2g full=y direct=y log=full.log feedback=10000

267 導(dǎo)出指定用戶的表
exp userid=system/oracle file=gary.dmp owner=gary,wei direct=y log=gary
exp userid=system/oracle file=gary.dmp owner=gary direct=y log=gary.log

268 導(dǎo)出指定表
exp userid=system/oracle file=gary_a.dmp tables=gary.a direct=y log=gary

269 導(dǎo)出指定表
exp userid=system/oracle file=gary_a1.dmp tables=gary.a query='where owner=''GARY''' log=gary.LOG

270 查看導(dǎo)出的幫助信息
exp -help

271 刪除gary的用戶
drop user gary cascade;

272 重建用戶GARY
CREATE USER "GARY" PROFILE "DEFAULT" IDENTIFIED BY "GARY" ACCOUNT UNLOCK

273 授權(quán)用戶GARY
GRANT UNLIMITED TABLESPACE,CONNECT,RESOURCE TO "GARY";

274 導(dǎo)入用戶GARY的數(shù)據(jù)
imp userid=system/oracle fromuser=gary touser=gary show=y
imp userid=system/oracle fromuser=gary touser=gary file=full.dmp log=imp.log
imp userid=system/oracle fromuser=gary touser=wei file=gary.dmp log=imp.log

275 查詢狀態(tài)
select object_name,object_type,owner from dba_objects where status='INVALID';

EXEC UTL_RECOMP.RECOMP_PARALLEL

276 建立對象,允許可以用這個目錄來導(dǎo)入導(dǎo)出
create directory mydir as 'e:expdata';

277 授權(quán)用戶的權(quán)限
grant read,write on directory mydir to gary;

278 導(dǎo)出數(shù)據(jù)
expdp userid=gary/gary dumpfile=gary directory=mydir PARALLEL=2 schemas=gary job_name=gary_job
expdp userid=gary/gary attach=gary_job

268 查詢?nèi)蝿?wù)
SELECT * FROM V$DATAPUMP_JOB;

269 導(dǎo)入數(shù)據(jù)
impdp userid=system/oracle dumpfile=gary directory=mydir job_name=gary_job

標(biāo)簽:池州 南平 股票投資 襄陽 嘉峪關(guān) 聊城 通化 南平

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《oracle dba 應(yīng)該熟悉的命令》,本文關(guān)鍵詞  oracle,dba,應(yīng)該,熟悉,的,命令,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《oracle dba 應(yīng)該熟悉的命令》相關(guān)的同類信息!
  • 本頁收集關(guān)于oracle dba 應(yīng)該熟悉的命令的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章