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; #指定區尺寸為128k,如不指定,區尺寸默認為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中查看剛創建的表空間的信息
二、建立UNDO表空間
CREATE UNDO TABLESPACE test_undo
DATAFILE 'c:/oracle/oradata/db/test_undo.dbf' SIZE 50M
UNDO表空間的EXTENT是由本地管理的,而且在創建時的SQL語句中只能使用DATAFILE和EXTENT MANAGEMENT子句。
ORACLE規定在任何時刻只能將一個還原表空間賦予數據庫,即在一個實例中可以有多個還原表空間存在,但只能有一個為活動的。可以使用ALTER SYSTEM命令進行還原表空間的切換。
SQL> ALTER SYSTEM SET UNDO_TABLESPACE = test_undo;
三、建立臨時表空間
CREATE TEMPORARY TABLESPACE test_temp
TEMPFILE '/oracle/oradata/db/test_temp.dbf' SIZE 50M
查看系統當前默認的臨時表空間
select * from dba_properties where property_name like 'DEFAULT%'
改變系統默認臨時表空間
alter database default temporary tablespace test_temp;
四、改變表空間狀態
1.使表空間脫機
ALTER TABLESPACE test OFFLINE;
如果是意外刪除了數據文件,則必須帶有RECOVER選項
ALTER TABLESPACE game test FOR RECOVER;
2.使表空間聯機
ALTER TABLESPACE test ONLINE;
3.使數據文件脫機
ALTER DATABASE DATAFILE 3 OFFLINE;
4.使數據文件聯機
ALTER DATABASE DATAFILE 3 ONLINE;
5.使表空間只讀
ALTER TABLESPACE test READ ONLY;
6.使表空間可讀寫
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 子句用來刪除段
2. AND DATAFILES 子句用來刪除數據文件
3. CASCADE CONSTRAINTS 子句用來刪除所有的引用完整性約束
六、擴展表空間
首先查看表空間的名字和所屬文件
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
1.增加數據文件
ALTER TABLESPACE test
ADD DATAFILE '/oracle/oradata/db/test02.dbf' SIZE 1000M;
2.手動增加數據文件尺寸
ALTER DATABASE DATAFILE 'c:/oracle/oradata/db/test01.dbf'
RESIZE 100M;
3.設定數據文件自動擴展
ALTER DATABASE DATAFILE 'c:/oracle/oradata/db/test01.dbf'
AUTOEXTEND ON NEXT 100M
MAXSIZE 200M;
設定后可從dba_tablespace中查看表空間信息,從v$datafile中查看對應的數據文件信息
1、先查詢空閑空間
- select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
2、增加Oracle表空間
先查詢數據文件名稱、大小和路徑的信息,語句如下:
- select tablespace_name,file_id,bytes,file_name from dba_data_files;
3、修改文件大小語句如下
- alter database datafile
- '需要增加的數據文件路徑,即上面查詢出來的路徑
- 'resize 800M;
4、創建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表示區的大小相同,默認為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表示區的大小相同,為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表示區的大小由隨表的大小自動動態改變,大表使用大區小表使用小區
- create tablespace sales
- datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
- autoextend on
- next 50M
- maxsize 1000M
- temporary;
- temporary創建字典管理臨時表空間
- create temporary tablespace sales
- tempfile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
- autoextend on
- next 50M
- maxsize 1000M
- 創建本地管理臨時表空間,如果是臨時表空間,所有語句中的datafile都換為tempfile
- 8i系統默認創建字典管理臨時表空間,要創建本地管理臨時表空間要加temporary tablespace關鍵字
- 創建本地管理臨時表空間時,不得使用atuoallocate參數,系統默認創建uniform管理方式
- 為表空間增加數據文件:
- alter tablespace sales add
- datafile '/home/app/oracle/oradata/oracle8i/sales02.dbf' size 800M
- autoextend on next 50M
- maxsize 1000M;
創建本地管理臨時Oracle表空間,如果是臨時表空間,所有語句中的datafile都換為tempfile8i系統默認創建字典管理臨時表空 間,要創建本地管理臨時表空間要加temporary tablespace關鍵字創建本地管理臨時表空間時,不得使用atuoallocate參數,系統默認創建uniform管理方式
為表空間增加數據文件:
- alter tablespace sales add
- datafile '/home/app/oracle/oradata/oracle8i/sales02.dbf' size 800M
- autoextend on next 50M
- maxsize 1000M;
5、更改自動擴展屬性:
- 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;
以上介紹創建Oracle表空間,在這里拿出來和大家分享一下,希望對大家有用。
重做日志redo log file是LGWR進程從Oracle實例中的redo log buffer寫入的,是循環利用的。就是說一個redo log file(group) 寫滿后,才寫下一個。
歸檔日志archive log是當數據庫運行在歸檔模式下時,一個redo log file(group)寫滿后,由ARCn進程將重做日志的內容備份到歸檔日志文件下,然后這個redo log file(group)才能被下一次使用。
不管數據庫是否是歸檔模式,重做日志是肯定要寫的。而只有數據庫在歸檔模式下,重做日志才會備份,形成歸檔日志。
歸檔日志結合全備份,用于數據庫出現問題后的恢復使用。