Creating A Listener For the New DB
It's not a requirement to create a Listener before you create a database, but it's a good idea to do so. A Listener is a process which listens on a well-known port for requests from remote users seeking to connect to the Oracle database. Without one, therefore, you'd only ever be able to connect to the database whilst directly logged onto the server itself, which is obviously a bit of a show-stopper!
To create a Listener, we use the Network Configuration Assistant. To invoke the Assistant, just issue the command netca (should be in path) as the oracle user in a new terminal session. Press "Next" to accept the defaults. After a bit you will get to "Finish" which is where you want to finish.
netca
Creating a Database
First, find out the id of the oinstall group. You can find this from looking in System -> Admin -> Users and Groups -> Manage Groups. Alternatively, use:
cat /etc/group | grep oinstall
NB: The oinstall Group Id should be 1002 or similar. If the User/Group Applet is giving "0" then try double checking the Properties of the group. I've noticed that the Users/Groups Applet can be unreliable...
Then, as root, perform the following command. (NB: This can't be performed by sudo, you must be root)
echo "<dba_group_gid>" > /proc/sys/vm/hugetlb_shm_group
This allows the oinstall group access to hugetlbpages. Without this you will get error "ORA-27125: unable to create shared memory segment" when setting up the database.
Run the Database Configuration Assistant, or DBCA for short. You will need to be the Oracle user you set up earlier.
dbca
This is not a difficult thing to do: mostly, in our case, it involves clicking "Next" to walk through the wizard, accepting all defaults. You will be prompted when you actually need to enter something.
Just be sure to specify the correct database name (it should match what is set as your ORACLE_SID, but with a proper domain extension. By default the ORACLE_SID is orcl10, and can be found out by running the oraenv command in the oracle bin directory...
Use the password "oracle" for the password and write down the values it spits out at the end...!
NB: If you get a "ORA-12547- Lost Contact" error, make sure you have libaio1installed (sudo apt-get install libaio1)...
Well Done...!
If it all went well you now have an Oracle Db on your machine. Pat yourself on the back for getting this far and sticking with it. You still have a way to go before its all installed but go and have some tea to celebrate...! And then go on to Part 2...
Last Updated on Saturday, 16 January 2010 12:09
CREATE TABLESPACE test
DATAFILE 'c:/oracle/oradata/db/test01.dbf' SIZE 50M
UNIFORM SIZE 1M; #指定區(qū)尺寸為128k,如不指定,區(qū)尺寸默認(rèn)為64k
或
CREATE TABLESPACE test
DATAFILE 'c:/oracle/oradata/db/test01.dbf' SIZE 50M
MINIMUM EXTENT 50K EXTENT MANAGEMENT LOCAL
DEFAULT STORAGE (INITIAL 50K NEXT 50K MAXEXTENTS 100 PCTINCREASE 0);
可從dba_tablespaces中查看剛創(chuàng)建的表空間的信息
二、建立UNDO表空間
CREATE UNDO TABLESPACE test_undo
DATAFILE 'c:/oracle/oradata/db/test_undo.dbf' SIZE 50M
UNDO表空間的EXTENT是由本地管理的,而且在創(chuàng)建時(shí)的SQL語(yǔ)句中只能使用DATAFILE和EXTENT MANAGEMENT子句。
ORACLE規(guī)定在任何時(shí)刻只能將一個(gè)還原表空間賦予數(shù)據(jù)庫(kù),即在一個(gè)實(shí)例中可以有多個(gè)還原表空間存在,但只能有一個(gè)為活動(dòng)的。可以使用ALTER SYSTEM命令進(jìn)行還原表空間的切換。
SQL> ALTER SYSTEM SET UNDO_TABLESPACE = test_undo;
三、建立臨時(shí)表空間
CREATE TEMPORARY TABLESPACE test_temp
TEMPFILE '/oracle/oradata/db/test_temp.dbf' SIZE 50M
查看系統(tǒng)當(dāng)前默認(rèn)的臨時(shí)表空間
select * from dba_properties where property_name like 'DEFAULT%'
改變系統(tǒng)默認(rèn)臨時(shí)表空間
alter database default temporary tablespace test_temp;
四、改變表空間狀態(tài)
1.使表空間脫機(jī)
ALTER TABLESPACE test OFFLINE;
如果是意外刪除了數(shù)據(jù)文件,則必須帶有RECOVER選項(xiàng)
ALTER TABLESPACE game test FOR RECOVER;
2.使表空間聯(lián)機(jī)
ALTER TABLESPACE test ONLINE;
3.使數(shù)據(jù)文件脫機(jī)
ALTER DATABASE DATAFILE 3 OFFLINE;
4.使數(shù)據(jù)文件聯(lián)機(jī)
ALTER DATABASE DATAFILE 3 ONLINE;
5.使表空間只讀
ALTER TABLESPACE test READ ONLY;
6.使表空間可讀寫(xiě)
ALTER TABLESPACE test READ WRITE;
五、刪除表空間
DROP TABLESPACE test INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;
DROP TABLESPACE 表空間名 [INCLUDING CONTENTS [AND DATAFILES] [CASCADE CONSTRAINTS]]
1. INCLUDING CONTENTS 子句用來(lái)刪除段
2. AND DATAFILES 子句用來(lái)刪除數(shù)據(jù)文件
3. CASCADE CONSTRAINTS 子句用來(lái)刪除所有的引用完整性約束
六、擴(kuò)展表空間
首先查看表空間的名字和所屬文件
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
1.增加數(shù)據(jù)文件
ALTER TABLESPACE test
ADD DATAFILE '/oracle/oradata/db/test02.dbf' SIZE 1000M;
2.手動(dòng)增加數(shù)據(jù)文件尺寸
ALTER DATABASE DATAFILE 'c:/oracle/oradata/db/test01.dbf'
RESIZE 100M;
3.設(shè)定數(shù)據(jù)文件自動(dòng)擴(kuò)展
ALTER DATABASE DATAFILE 'c:/oracle/oradata/db/test01.dbf'
AUTOEXTEND ON NEXT 100M
MAXSIZE 200M;
設(shè)定后可從dba_tablespace中查看表空間信息,從v$datafile中查看對(duì)應(yīng)的數(shù)據(jù)文件信息
1、先查詢空閑空間
- select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
2、增加Oracle表空間
先查詢數(shù)據(jù)文件名稱、大小和路徑的信息,語(yǔ)句如下:
- select tablespace_name,file_id,bytes,file_name from dba_data_files;
3、修改文件大小語(yǔ)句如下
- alter database datafile
- '需要增加的數(shù)據(jù)文件路徑,即上面查詢出來(lái)的路徑
- 'resize 800M;
4、創(chuàng)建Oracle表空間
- create tablespace test
- datafile '/home/app/oracle/oradata/oracle8i/test01.dbf' size 8M
- autoextend on
- next 5M
- maxsize 10M;
- create tablespace sales
- datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
- autoextend on
- next 50M
- maxsize unlimited
- maxsize unlimited 是大小不受限制
- create tablespace sales
- datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
- autoextend on
- next 50M
- maxsize 1000M
- extent management local uniform;
- unform表示區(qū)的大小相同,默認(rèn)為1M
- create tablespace sales
- datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
- autoextend on
- next 50M
- maxsize 1000M
- extent management local uniform size 500K;
- unform size 500K表示區(qū)的大小相同,為500K
- create tablespace sales
- datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
- autoextend on
- next 50M
- maxsize 1000M
- extent management local autoallocate;
- autoallocate表示區(qū)的大小由隨表的大小自動(dòng)動(dòng)態(tài)改變,大表使用大區(qū)小表使用小區(qū)
- create tablespace sales
- datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
- autoextend on
- next 50M
- maxsize 1000M
- temporary;
- temporary創(chuàng)建字典管理臨時(shí)表空間
- create temporary tablespace sales
- tempfile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
- autoextend on
- next 50M
- maxsize 1000M
- 創(chuàng)建本地管理臨時(shí)表空間,如果是臨時(shí)表空間,所有語(yǔ)句中的datafile都換為tempfile
- 8i系統(tǒng)默認(rèn)創(chuàng)建字典管理臨時(shí)表空間,要?jiǎng)?chuàng)建本地管理臨時(shí)表空間要加temporary tablespace關(guān)鍵字
- 創(chuàng)建本地管理臨時(shí)表空間時(shí),不得使用atuoallocate參數(shù),系統(tǒng)默認(rèn)創(chuàng)建uniform管理方式
- 為表空間增加數(shù)據(jù)文件:
- alter tablespace sales add
- datafile '/home/app/oracle/oradata/oracle8i/sales02.dbf' size 800M
- autoextend on next 50M
- maxsize 1000M;
創(chuàng)建本地管理臨時(shí)Oracle表空間,如果是臨時(shí)表空間,所有語(yǔ)句中的datafile都換為tempfile8i系統(tǒng)默認(rèn)創(chuàng)建字典管理臨時(shí)表空 間,要?jiǎng)?chuàng)建本地管理臨時(shí)表空間要加temporary tablespace關(guān)鍵字創(chuàng)建本地管理臨時(shí)表空間時(shí),不得使用atuoallocate參數(shù),系統(tǒng)默認(rèn)創(chuàng)建uniform管理方式
為表空間增加數(shù)據(jù)文件:
- alter tablespace sales add
- datafile '/home/app/oracle/oradata/oracle8i/sales02.dbf' size 800M
- autoextend on next 50M
- maxsize 1000M;
5、更改自動(dòng)擴(kuò)展屬性:
- alter database datafile
- '/home/app/oracle/oradata/oracle8i/sales01.dbf',
- '/home/app/oracle/oradata/oracle8i/sales02.dbf'
- '/home/app/oracle/oradata/oracle8i/sales01.dbf
- autoextend off;
以上介紹創(chuàng)建Oracle表空間,在這里拿出來(lái)和大家分享一下,希望對(duì)大家有用。
重做日志redo log file是LGWR進(jìn)程從Oracle實(shí)例中的redo log buffer寫(xiě)入的,是循環(huán)利用的。就是說(shuō)一個(gè)redo log file(group) 寫(xiě)滿后,才寫(xiě)下一個(gè)。
歸檔日志archive log是當(dāng)數(shù)據(jù)庫(kù)運(yùn)行在歸檔模式下時(shí),一個(gè)redo log file(group)寫(xiě)滿后,由ARCn進(jìn)程將重做日志的內(nèi)容備份到歸檔日志文件下,然后這個(gè)redo log file(group)才能被下一次使用。
不管數(shù)據(jù)庫(kù)是否是歸檔模式,重做日志是肯定要寫(xiě)的。而只有數(shù)據(jù)庫(kù)在歸檔模式下,重做日志才會(huì)備份,形成歸檔日志。
歸檔日志結(jié)合全備份,用于數(shù)據(jù)庫(kù)出現(xiàn)問(wèn)題后的恢復(fù)使用。