IT忍者神龜之Oracle DBA常用查詢吐血列舉,oracledba

來源:互聯網
上載者:User

IT忍者神龜之Oracle DBA常用查詢吐血列舉,oracledba

–1. 查詢系統所有對象
select owner, object_name, object_type, created, last_ddl_time, timestamp, status
from dba_objects
where owner=upper('scott')

–2. 查看系統所有表
select owner, table_name, tablespace_name from dba_tables

–3. 查看所有使用者的表
select owner, table_name, tablespace_name from all_tables

–4. 查看目前使用者表
select table_name, tablespace_name from user_tables

–5. 查看使用者表索引
select t.*,i.index_type from user_ind_columns t, user_indexes i where
t.index_name = i.index_name and t.table_name = i.table_name
and t.table_name = 要查詢的表

–6. 查看主鍵
select cu.* from user_cons_columns cu, user_constraints au
where cu.constraint_name = au.constraint_name
and au.constraint_type = upper('p') and au.table_name = 要查詢的表

–7. 查看唯一性限制式
select column_name from user_cons_columns cu, user_constraints au
where cu.constraint_name = au.constraint_name and au.constraint_type =  upper('u')
and au.table_name = 要查詢的表

–8. 查看外鍵
select * from user_constraints c where c.constraint_type = 'r' and c.table_name = 要查詢的表
select * from user_cons_columns cl where cl.constraint_name = 外鍵名稱
select * from user_cons_columns cl where cl.constraint_name = 外鍵參考資料表的鍵名

–9. 查看錶的列屬性
select t.*,c.comments
from user_tab_columns t, user_col_comments c
where t.table_name = c.table_name and t.column_name = c.column_name and t.table_name = 要查詢的表

–10. 查看所有資料表空間
select tablespace_name from dba_data_files group by tablespace_name

############################################
–1. 查看oracle最大串連數
sql>show parameter processes    #最大串連數

–2. 修改最大串連數
sql>alter system set processes=value scope=spfile
–重啟資料庫
sql>shutdown force
sql>start force

–3. 查看當前串連數
sql>select * from v$session where username is not null

–4. 查看不同使用者的串連數
sql>select username,count(username) from v$session where username is not null group by username #查看指定使用者的串連數

–5. 查看活動的串連數
sql>select count(*) from v$session where status='active' #查看並發串連數

–6. 查看指定程式的串連數
sql>select count(*) from v$session where program='jdbc thin client' #查看jdbc串連oracle的數目

–7. 查看資料庫安裝執行個體(dba許可權)
sql>select * from v$instance

–8. 查看運行執行個體名
sql>show parameter instance_name

–9. 查看資料庫名
sql>show parameter db_name

–10. 查看資料庫網域名稱
sql>show parameter db_domain

–11. 查看資料庫服務名
sql>show parameter service_names

–12. 查看全域資料庫名
sql>show parameter global

–13. 查看錶空間使用率

12345678910111213141516171819202122232425262728293031 -- (1)select dbf.tablespace_name,       dbf.totalspace"總量(m)",       dbf.totalblocksas "總塊數",       dfs.freespace"剩餘總量(m)",       dfs.freeblocks"剩餘塊數",       (dfs.freespace / dbf.totalspace) * 100 as "空閑比例"  from (select t.tablespace_name,               sum(t.bytes) / 1024 / 1024 totalspace,               sum(t.blocks) totalblocks          from dba_data_files t         group by t.tablespace_name) dbf,       (select tt.tablespace_name,               sum(tt.bytes) / 1024 / 1024 freespace,               sum(tt.blocks) freeblocks          from dba_free_space tt         group by tt.tablespace_name) dfs where trim(dbf.tablespace_name) = trim(dfs.tablespace_name)-- (2)select t.name "tablespace name",       free_space,       (total_space - free_space) used_space,       total_space  from (select tablespace_name,sum(bytes / 1024 / 1024) free_space          from sys.dba_free_space         group by tablespace_name)free,       (select b.name,sum(bytes / 1024 / 1024) total_space          from sys.v_$datafile a, sys.v_$tablespace b         where a.ts# = b.ts#         group by b.name) t where free.tablespace_name = t.name

oracle DBA 培訓

對於oracle DBA的培訓幾點看法如下:
1、首先我不贊成oracle初學者去自己摸索,因為這樣往往會如盲人摸象,會有一些錯誤oracle概念。oracle DBA的培訓有人說,我會SQL,是指會查詢oracle資料。DBA說,你要是這麼說的話,只怕oracle資料也有查錯的機會。
2、要想學好ORACLE選一個好DBA培訓學校很重要,選一個好老師更重要。記住明師出高徒,是明白的明。不是有名的名,所以,你需要的是明師,能夠讓你明白的人。發現oracle明師的方法,只有一個辦法就是跟老師交流,看看培訓老師對所交的課程有沒有一個DBA總體概念,還有一個對DBA教材是否熟悉。

我09年在CUUG上的oracle DBA就業培訓班。去之前我從沒接觸過資料庫,當時只是想學門高技術C++或oracle,現在看來選擇是對的。我也曾有和你一樣的疑問,擔心跟不上。其實oracle並不是那麼高不可攀,只要你想學就一定能跟得上,CUUG的DBA就業培訓班都是從0基礎開始的教,進度也比較慢,不會拉著你走。剛開始教oracle基礎、SQL等不需要什麼基礎的,聽誰說學SQL要基礎嗎?你把這些前期的基礎學好了,後面的也就不擔心不會了。但學oracle確得是理科專業,對電腦有興趣的,也不能是電腦盲啊。其實自己肯努力再差的基礎都跟得上,我也是過來人啊。
至於CUUG的oracle DBA就業培訓班學完後能否就業?這個真的是深有感觸啊。我培訓的時候,班上27人,培訓完後26個都順利找到工作,還有一個當時學的很慢,就留下來繼續實踐了2個月後也找到了工作。培訓後期是做項目,這個非常有用,找工作面試的感覺。自己是工作過幾年的人。
 
Oracle DBA面試題

列舉幾個比較容易被問到的問題。(來自cuug)

1. 解釋冷備份和熱備份的不同點以及各自的優點

解答:熱備份針對歸檔模式的資料庫,在資料庫仍舊處於工作狀態時進行備份。而冷備份指在資料庫關閉後,進行備份,適用於所有模式的資料庫。熱備份的優點在於當備份時,資料庫仍舊可以被使用並且可以將資料庫恢複到任意一個時間點。冷備份的優點在於它的備份和恢複操作相當簡單,並且由於冷備份的資料庫可以工作在非歸檔模式下,資料庫效能會比歸檔模式稍好。(因為不必將archive log寫入硬碟)

2. 你必須利用備份恢複資料庫,但是你沒有控制檔案,該如何解決問題呢?

解答:重建控制檔案,用帶backup control file 子句的recover 命令恢複資料庫。

3. 如何轉換init.ora到spfile?

解答:使用create spfile from pfile 命令
.
4. 解釋data block , extent 和 segment的區別(這裡建議用英文術語)

解答:data block是資料庫中最小的邏輯儲存單元。當資料庫的對象需要更多的實體儲存體空間時,連續的data block就組成了extent . 一個資料庫物件擁有的所有extents被稱為該對象的segment.

5. 給出兩個檢查表結構的方法

解答:1、DESCRIBE命令
2、DBMS_METADATA.GET_DDL 包
6. 怎樣查看資料庫引擎的報錯

解答:alert log.

7. 比較truncate和delete 命令

解答:兩者都可以用來刪除表中所有的記錄。區別在於:truncate是DDL操作,它移動HWK,不需要 rollback segment .而Delete是DML操作, 需要rollback segment 且花費較長時間.

8. 使用索引的理由

解答:快速存取表中的data block

9. 給出在STAR SCHEMA中的兩種表及它們分別含有的資料

解答:Fact tables 和dimension tables. fact table 包含大量的主要的資訊而 dimension tables 存放對fact table 某些屬性描述的
資訊

10. FACT Table上需要建立何種索引?

解答:位元影像索引(bitmap index)

11. 給出兩種相關約束?

解答:主鍵和外鍵

12. 如何在不影響子表的前提下,重建一個母表

解答:子表的外鍵強制失效,重建母表,啟用外鍵

13. 解釋歸檔和非歸檔模式之間的不同和它們各自的優缺點

解答:歸檔模式是指你可以備份所有的資料庫 transactions並恢複到任意一個時間點。非歸檔模式則相反,不能恢複到任意一個時間點。
但是非歸檔模式可以帶來資料庫效能上的少許提高

14. 如何建立一個備份控制檔案?

解答:Alter database backup control file to trace.

15. 給出資料庫正常啟動所經曆的幾種狀態 ?

解答:
STARTUP NOMOUNT – 資料庫執行個體啟動
STARTUP MOUNT - 資料庫裝載
STARTUP OPEN – 資料庫開啟

16. 哪個column可以用來區別V$視圖和GV$視圖?

解答: INST_ID 指明叢集環境中具體的某個instan......餘下全文>>
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.