Oracle數(shù)據(jù)庫的一些常用維護(hù)操作總結(jié)
我們知道,對數(shù)據(jù)庫的維護(hù)是數(shù)據(jù)庫保證數(shù)據(jù)庫安全穩(wěn)定運(yùn)行中必不可少的一個環(huán)節(jié)。本文我們總結(jié)了一些Oracle數(shù)據(jù)庫的一些常用的維護(hù)操作,包括一些常規(guī)的維護(hù)操作,一些系統(tǒng)的維護(hù)操作以及命名空間的維護(hù)操作等,接下來就讓我們來一起了解一下吧!
常規(guī):
Oracle在sqlplus命令行下,執(zhí)行完數(shù)據(jù)庫操作以后,需要跟上commit才能生效。
主要監(jiān)聽兩個端口,1521是數(shù)據(jù)庫連接端口,8080是服務(wù)器端口。
Oracle默認(rèn)安裝完畢,會自帶一個http服務(wù)器,以web的形式提供用戶管理界面,該服務(wù)器端口8080與tomcat的默認(rèn)端口一樣,是導(dǎo)致tomcat啟動不了的常見原因,我一般是修改tomcat的配置文件server.xml,把http1.1的端口改成8081。
系統(tǒng)維護(hù):
登錄
sqlplus username/password@addr [as sysdba,sysoper]
不寫地址默認(rèn)是localhost 不寫身份默認(rèn)是sysoper
查詢sid
select instance_name from v$instance
查詢數(shù)據(jù)庫版本
Select version FROM Product_component_version Where SUBSTR(PRODUCT,1,6)='Oracle';
查詢監(jiān)聽:lsnrctl status--在cmd下而不是sqlplus下
啟動監(jiān)聽:lsnrctl start--在cmd下而不是sqlplus下
停止監(jiān)聽:lsnrctl stop--在cmd下而不是sqlplus下
創(chuàng)建用戶
- create user weinianjie identified by "123" default tablespace sheep temporary tablespacetemp profile default;
- grant resource,connect,dba to weinianjie;
查詢當(dāng)前用戶
show user;
命名空間:
解釋:
百度百科原話:“ORACLE數(shù)據(jù)庫被劃分成稱作為表空間的邏輯區(qū)域——形成ORACLE數(shù)據(jù)庫的邏輯結(jié)構(gòu)。一個ORACLE數(shù)據(jù)庫能夠有一個或多個Oracle,而一個表空間則對應(yīng)著一個或多個物理的數(shù)據(jù)庫文件。表空間是ORACLE數(shù)據(jù)庫恢復(fù)的最小單位,容納著許多數(shù)據(jù)庫實(shí)體,如表、視圖、索引、聚簇、回退段和臨時(shí)段等。
每個ORACLE數(shù)據(jù)庫均有SYSTEM表空間,這是數(shù)據(jù)庫創(chuàng)建時(shí)自動創(chuàng)建的。SYSTEM表空間必須總要保持聯(lián)機(jī),因?yàn)槠浒鴶?shù)據(jù)庫運(yùn)行所要求的基本信息(關(guān)于整個數(shù)據(jù)庫的數(shù)據(jù)字典、聯(lián)機(jī)求助機(jī)制、所有回退段、臨時(shí)段和自舉段、所有的用戶數(shù)據(jù)庫實(shí)體、其它ORACLE軟件產(chǎn)品要求的表)。”
我的理解,表空間跟庫的概念差不多,一個表空間對應(yīng)一個或者多個物理文件,每個用戶屬于一個或多個表空間,其中有一個是默認(rèn)的。連接數(shù)據(jù)庫的時(shí)候不需要制定表空間,用戶創(chuàng)建的對象會在用戶默認(rèn)的表空間里存放著。
命名空間定義了一組對象類型,在命名空間里,對象的名字必須是唯一的,當(dāng)然,在不同的命名空間里,是可以使用相同的的名字的。
下面的對象類型共享同一個命名空間:
- ? Tables
- ? Views
- ? Sequences
- ? Private synonyms
- ? Stand-alone procedures
- ? Stand-alone stored functions
- ? Packages
- ? Materialized views
- ? User-defined types
創(chuàng)建數(shù)據(jù)表空間:create tablespace sheep datafile 'c:/sheep.dbf' size 20m autoextend on;
創(chuàng)建臨時(shí)表空間:create temporary tablespace sheep tempfile 'c:/sheep.dbf' size 20m autoextend on;
查詢空間:
- select tablespace_name from dba_tablespaces;
- select tablespace_name from user_tablespaces;
查詢表空間的物理情況:
- select * from dba_data_files where tablespace_name='SYSTEM';--這里一定要是全大寫的,哪怕你建空間的時(shí)候沒有使用大寫
- select * from dba_temp_files where tablespace_name='TEMP';--這里一定要是全大寫的,哪怕你建空間的時(shí)候沒有使用大寫
查詢表空間內(nèi)的表:
select table_name from dba_all_tables where tablespace_name='USERS';
表:
查詢當(dāng)前用戶空間的所有表:
select tname from tab
序列:
查詢當(dāng)前用戶空間的所有序列:
select squence_name from seq
創(chuàng)建序列:
create sequence user_seq minvalue 1 maxvalue 99999 start with 1 increment by 1 nocache nocycle
使用序列:
insert into user values(user_seq.nextval);
腳本:
- begin--必須以begin開頭。
- for column_ in (select * from tb1) loop
- insert into tb2 values(column_.field1);
- end loop;
- end;
java交互:
驅(qū)動名稱:oracle.jdbc.driver.OracleDriver
連接字符串:jdbc:oracle:thin:@localhost:1521:xe,其中***一個量是sid 。
關(guān)于Oracle數(shù)據(jù)庫的常用維護(hù)就介紹到這里,如果您想了解更多的關(guān)于Oracle數(shù)據(jù)庫的知識,可以看一下這里的文章:http://database.51cto.com/oracle/,相信一定可以帶給您收獲的。
【編輯推薦】






