Oracle手工建庫及配置監聽
一、關閉資料庫
二、修改SID
[[email protected]~]$ vi .bash_profile
exportORACLE_SID=powter
使其生效並驗證:
[[email protected]~]$ source .bash_profile
[[email protected]~]$ env |grep -i sid
ORACLE_SID=powter
三、建立目錄
[[email protected]]$ cd $ORACLE_BASE/admin/
[[email protected]]$ mkdir powter
[[email protected]
[[email protected]]$ pwd
/u01/app/oracle/admin/powter
[[email protected]]$ mkdir {a,b,c,u}dump
[[email protected]]$ cd $ORACLE_BASE/oradata
[[email protected]]$ pwd
/u01/app/oracle/oradata
[[email protected]]$ mkdir powter
到剛建立的powter目錄下建立3個目錄,模擬3個磁碟
[[email protected] oradata]$ cd powter/
[[email protected] powter]$ mkdirDisk{1,2,3}
四、新增圖形化介面資訊
修改/etc/oratab檔案,新增要建立資料庫的資訊,這樣在dbca中就可以看到此DB,並可以對此進行圖形介面管理。
[[email protected] powter]$ vi /etc/oratab
追加:
powter:/u01/app/oracle/product/10.2.0/db_1:N |
為了在終端可以開啟圖形介面,需要安裝“Xmanager”,並且進行以下修改
[[email protected]~]$ w
16:33:42 up 2 days, 12:38, 6 users, load average: 0.04, 0.05, 0.01
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
root pts/2 192.168.0.111 16:33 0.00s 0.02s 0.00s w
root :0 - 12:44 ?xdm? 29:45 0.24s /usr/bin/gnome-
root pts/3 192.168.0.111 12:44 2:54m 1.34s 1.09s rman
root pts/5 192.168.0.111 12:50 2:56m 0.08s 0.06s sqlplus as sy
root pts/6 192.168.0.111 15:54 2:18 5.19s 0.00s /bin/sh -f /u01
root pts/1 :0.0 16:07 25:41 0.02s 0.00s -bash
[[email protected]~]$ export DISPLAY=192.168.0.111:0.0
192.168.0.111屬於(已安裝Xmanager)客戶端的IP(我這裡是windows7中虛擬機器虛擬網絡卡的IP)
測試:
[[email protected] powter]$ dbca
可以看到,此時已經可以在dbca中看到powter資料庫了。
五、新增初始化檔案
[[email protected]~]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs/
[[email protected]]$ cat init.ora|grep -v ^#|grep -v ^$>initpowter.ora
[[email protected]]$ ls
hc_wolex.dat init.ora lkWOLEX snapcf_wolex.f
initdw.ora initpowter.ora orapwwolex spfilewolex.ora
[[email protected]]$ vi initpowter.ora
db_name=powter db_files = 80 db_file_multiblock_read_count = 8 shared_pool_size = 3500000 log_checkpoint_interval = 10000 processes = 50 parallel_max_servers = 5 max_dump_file_size = 10240 global_names = TRUE control_files = ( /u01/app/oracle/oradata/powter/Disk1/ctl01.ctl, /u01/app/oracle/oradata/powter/Disk2/ctl02.ctl, /u01/app/oracle/oradata/powter/Disk3/ctl03.ctl) sga_max_size=300M sga_target=300M undo_tablespace=undotbs undo_management=auto |
六、建立資料庫指令碼
(參見《Administrator'sGuide》第二章第7節“Step 7: Issue the CREATE DATABASEStatement”)
[or[email protected]~]$ cd $ORACLE_BASE
[[email protected]]$ gedit createdb_powter,sql
CREATE DATABASE powter USER SYS IDENTIFIED BY oracle USER SYSTEM IDENTIFIED BY oracle LOGFILE GROUP 1 ('/u01/app/oracle/oradata/powter/Disk1/redo01_01.log', '/u01/app/oracle/oradata/powter/Disk2/redo01_02.log') SIZE 100M, GROUP 2 ('/u01/app/oracle/oradata/powter/Disk1/redo02_01.log', '/u01/app/oracle/oradata/powter/Disk2/redo02_02.log') SIZE 100M, GROUP 3 ('/u01/app/oracle/oradata/powter/Disk1/redo03_01.log', '/u01/app/oracle/oradata/powter/Disk2/redo03_02.log') SIZE 100M MAXLOGFILES 200 MAXLOGMEMBERS 5 MAXLOGHISTORY 200 MAXDATAFILES 100 MAXINSTANCES 2 CHARACTER SET US7ASCII NATIONAL CHARACTER SET AL16UTF16 DATAFILE '/u01/app/oracle/oradata/powter/Disk1/system01.dbf' SIZE 325M REUSE EXTENT MANAGEMENT LOCAL SYSAUX DATAFILE '/u01/app/oracle/oradata/powter/Disk1/sysaux01.dbf' SIZE 325M REUSE DEFAULT TEMPORARY TABLESPACE tempts1 TEMPFILE '/u01/app/oracle/oradata/powter/Disk1/temp01.dbf' SIZE 20M REUSE UNDO TABLESPACE undotbs DATAFILE '/u01/app/oracle/oradata/powter/Disk1/undotbs01.dbf' SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED; |
執行指令碼:
[[email protected]~]$ cd $ORACLE_BASE
[[email protected]]$ sqlplus / as sysdba
此處順便建立spfile:
SQL>create spfile from pfile;
File created.
以nomount狀態啟動資料庫:
SQL>startup nomount
ORACLEinstance started.
Total SystemGlobal Area 314572800 bytes
FixedSize 2020480 bytes
VariableSize 67111808 bytes
DatabaseBuffers 243269632 bytes
RedoBuffers 2170880 bytes
SQL> !ls
admin createdb_powter,sql~ log_archive_area oraInventory
createdb_powter,sql flash_recovery_area oradata product
SQL>@createdb_powter.sql
Databasecreated.
檢視當前連線資料庫的例項名
SQL>select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
powter
檢視當前資料庫開啟狀態
SQL>select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
執行兩個指令碼,建立必要的檢視和過程、包等等。
[[email protected]]$ pwd
/u01/app/oracle/product/10.2.0/db_1/rdbms/admin
[[email protected]]$ sqlplus / as sysdba
SQL*Plus:Release 10.2.0.1.0 - Production on Thu Jul 19 21:25:30 2012
Copyright (c)1982, 2005, Oracle. All rights reserved.
Connected to:
OracleDatabase 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
SQL>@catalog.sql
……
PL/SQLprocedure successfully completed.
SQL>@catproc.sql
……
PL/SQLprocedure successfully completed.
七、建立SCOTT/TIGER練習使用者
跑utlsaml.sql指令碼,以建立SCOTT使用者
[[email protected]]$ pwd
/u01/app/oracle/product/10.2.0/db_1/rdbms/admin
[[email protected]]$ sqlplus / as sysdba
SQL*Plus:Release 10.2.0.1.0 - Production on Thu Jul 19 22:10:29 2012
Copyright (c)1982, 2005, Oracle. All rights reserved.
Connected to:
OracleDatabase 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
SQL> @utlsampl.sql
Disconnectedfrom Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bitProduction
With thePartitioning, OLAP and Data Mining options
修改SCOTT使用者的密碼以及將其解鎖
SQL> show user
USER is"SYS
SQL> alter user scott identified bytiger account unlock;
User altered.
以system使用者連線跑pupbld.sql指令碼
[[email protected]]$ pwd
/u01/app/oracle/product/10.2.0/db_1/sqlplus/admin
[[email protected]]$ sqlplus system/oracle
SQL*Plus:Release 10.2.0.1.0 - Production on Thu Jul 19 22:16:01 2012
Copyright (c)1982, 2005, Oracle. All rights reserved.
Connected to:
OracleDatabase 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
SQL> @pupbld.sql
……
● 另:也可以把另外一個數據庫中的SCOTT使用者匯入到其他資料庫中
資料庫open狀態下,
[[email protected]~]$ exp scott/tiger owner=scott file=scott.dmp
關閉當前資料庫,更改SID
SQL> shutdown immediate
Databaseclosed.
Databasedismounted.
ORACLEinstance shut down.
SQL> !
[[email protected]~]$ vi .bash_profile
exportORACLE_SID=wolex
[[email protected]~]$ source .bash_profile
[[email protected]~]$ !sql
sqlplus / assysdba
SQL*Plus:Release 10.2.0.1.0 - Production on Thu Jul 19 23:42:19 2012
Copyright (c)1982, 2005, Oracle. All rights reserved.
Connected to anidle instance.
SQL> startup
ORACLEinstance started.
Total SystemGlobal Area 314572800 bytes
FixedSize 2020480 bytes
VariableSize 121637760 bytes
DatabaseBuffers 188743680 bytes
RedoBuffers 2170880 bytes
Databasemounted.
Databaseopened.
檢視SID為wolex的資料庫中有多少個使用者
SQL> select username from all_users;
USERNAME
------------------------------------------------------------
DBSNMP
TSMSYS
DIP
OUTLN
SYSTEM
SYS
6 rowsselected.
匯入到當前(wolex)資料庫中:
SQL> !
[[email protected]~]$ imp scott/tiger file=scott.dmp
SQL> select username from all_users;
USERNAME
------------------------------------------------------------
SCOTT
DBSNMP
TSMSYS
DIP
OUTLN
SYSTEM
SYS
6 rowsselected.
嘗試連線SCOTT/TIGER:
SQL> conn scott/tiger
Connected.
SQL> show user
USER is"SCOTT"
如果是遠端匯入匯出的話,則不需要關閉任何一個數據庫,匯入匯出時加入SID(資料庫名?):
exp scott/[email protected] owner=scottfile=scott.dmp
imp scott/[email protected] file=scott.dmp
●
exppowter_test/[email protected]:1521/powter owner=powter_testfile=powter_test.dmp
在例項名為wolex的資料庫中建立powter_test並且賦予相應的許可權
$ imppowter_test/[email protected]:1521/wolex file=powter_test.dmp
八、模擬遠端登入資料庫
1、建立口令檔案
[[email protected]]$ pwd
/u01/app/oracle/product/10.2.0/db_1/dbs
[[email protected]]$ orapwd file=orapwpowter password=oracle
2、配置監聽
● 圖形化介面配置
(1)Oracle NetManager
[[email protected]]$ netmgr
(2)Oracle NetConfiguration Assistant
[[email protected]]$ netca
2、程式碼行配置
[[email protected]]$ pwd
/u01/app/oracle/product/10.2.0/db_1/network/admin
[[email protected]]$ vi listener.ora
在原來已經存在的listener監聽中新增powter資料庫(靜態註冊),再新增一個動態註冊監聽lsnr2
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = wolex) (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1) (SID_NAME = wolex) ) (SID_DESC = (GLOBAL_DBNAME = powter) (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1) (SID_NAME = powter) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.200)(PORT = 1521)) ) LSNR2 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.200)(PORT = 1522)) ) |
為listener監聽新增伺服器名(別名),lsnr2不新增
[[email protected]]$ vi tnsnames.ora
POWTER_ALIAS = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.200)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = powter) ) ) WOLEX_ALIAS = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.200)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = wolex) ) ) |
測試別名能否ping通:
[[email protected]]$ tnsping powter_alias
TNS Ping Utilityfor Linux: Version 10.2.0.1.0 - Production on 20-JUL-2012 01:41:50
Copyright (c)1997, 2005, Oracle. All rights reserved.
Used parameterfiles:
Used TNSNAMESadapter to resolve the alias
Attempting tocontact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.0.200)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = powter)))
OK (10 msec)
啟動監聽:
[[email protected]~]$ lsnrctl start
LSNRCTL forLinux: Version 10.2.0.1.0 - Production on 20-JUL-2012 01:37:33
Copyright (c)1991, 2005, Oracle. All rights reserved.
TNS-01106:Listener using listener name LISTENER has already been started
[[email protected]~]$ lsnrctl status
LSNRCTL forLinux: Version 10.2.0.1.0 - Production on 20-JUL-2012 01:37:40
Copyright (c)1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.200)(PORT=1521)))
STATUS of theLISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version10.2.0.1.0 - Production
Start Date 20-JUL-2012 01:09:40
Uptime 0 days 0 hr. 27 min. 59 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
ListenerParameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener LogFile /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
ListeningEndpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.200)(PORT=1521)))
ServicesSummary...
Service"powter" has 2 instance(s).
Instance "powter", status UNKNOWN,has 1 handler(s) for this service...
Instance "powter", status READY, has 1 handler(s)for this service...
Service"powter_XPT" has 1 instance(s).
Instance "powter", status READY,has 1 handler(s) for this service...
Service"wolex" has 2 instance(s).
Instance "wolex", status UNKNOWN,has 1 handler(s) for this service...
Instance "wolex", status READY, has1 handler(s) for this service...
Service"wolexXDB" has 1 instance(s).
Instance "wolex", status READY, has1 handler(s) for this service...
Service"wolex_XPT" has 1 instance(s).
Instance "wolex", status READY, has1 handler(s) for this service...
The commandcompleted successfully
通過IP和埠號和例項名模擬遠端連線
[[email protected]]$ sqlplus sys/oracle@192.168.0.200:1521/powteras sysdba
SQL*Plus:Release 10.2.0.1.0 - Production on Fri Jul 20 01:28:28 2012
Copyright (c)1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
通過別名簡化連線
SQL> !
[[email protected]]$ cd
[[email protected]~]$ sqlplus sys/oracle@powter_alias as sysdba
SQL*Plus:Release 10.2.0.1.0 - Production on Fri Jul 20 01:30:12 2012
Copyright (c)1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
SQL>
開啟lsnr2監聽
[[email protected]~]$ lsnrctl start lsnr2
[[email protected]~]$ lsnrctl status lsnr2
LSNRCTL forLinux: Version 10.2.0.1.0 - Production on 20-JUL-2012 01:43:47
Copyright (c)1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.200)(PORT=1522)))
STATUS of theLISTENER
------------------------
Alias lsnr2
Version TNSLSNR for Linux: Version10.2.0.1.0 - Production
Start Date 20-JUL-2012 01:43:34
Uptime 0 days 0 hr. 0 min. 12 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
ListenerParameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener LogFile /u01/app/oracle/product/10.2.0/db_1/network/log/lsnr2.log
ListeningEndpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.200)(PORT=1522)))
The listener supports no services
The commandcompleted successfully
將資料庫中的預設埠號設定為lsnr2的埠號,然後動態註冊
SQL>show parameter local_
NAME TYPE VALUE
------------------------------ ------------------------------------
local_listener string
SQL>alter system set local_listener="(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.0.200)(PORT = 1522))" scope=memory;
Systemaltered.
SQL>show parameter local_
NAME TYPE VALUE
------------------------------ ------------------------------------
local_listener string (ADDRESS= (PROTOCOL = TCP)(HOST
=192.168.0.200)(PORT = 1522))
SQL>alter system register;
System altered.
[[email protected]]$ lsnrctl status lsnr2
LSNRCTL forLinux: Version 10.2.0.1.0 - Production on 20-JUL-2012 01:57:07
Copyright (c)1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.200)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias lsnr2
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 20-JUL-2012 01:43:34
Uptime 0 days 0 hr. 13 min. 32 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/lsnr2.log
Listening EndpointsSummary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.200)(PORT=1522)))
ServicesSummary...
Service"powter" has 1 instance(s).
Instance "powter", status READY, has 1 handler(s)for this service...
Service"powter_XPT" has 1 instance(s).
Instance "powter", status READY,has 1 handler(s) for this service...
The commandcompleted successfully
九、小技巧
1、在SQL>中使用vi編輯
(1)、
[[email protected]~]$ vi .bash_profile
export EDITOR=vi
[[email protected]~]$ source .bash_profile
SQL>edit
Wrote file afiedt.buf
以上方法並沒有完全像vi環境一樣?不知道是否因為資料庫型別(事務DB、資料倉庫等)不同?
(2)、修改登入引數
[[email protected]~]$ cd $ORACLE_HOME/sqlplus/admin/
在glogin.sql檔案中追加:
[[email protected]]$ vi glogin.sql
DEFINE _EDITOR =vi
儲存退出即可,以上修改後,在sqlplus中輸入ed(it)即可進入vi編輯器修改上一條SQL語句。
(3)、在SQL*Plus中臨時修改:
SQL>define _editor=/bin/vi
2、檢視所有68個系統變數值
SQL>show all
3、列出上一條快取的SQL語句
● l
● list
● ;
4、改變終端提示符:
SQL>show all
┇
sqlprompt "SQL> "
┇
SQL> setsqlprompt "[email protected]> "
5、對上一條快取的SQL語句進行部分修改
● c[hange]
6、執行上一條快取的SQL語句
● /
7、修改系統變數,並在所有會話中生效
[[email protected]]$ pwd
/u01/app/oracle/product/10.2.0/db_1/sqlplus/admin
[[email protected]]$ vi glogin.sql
例如追加:
set linesize 120 set pagesize 30 col[umn]ename for[mat] a10 |
8、通過錯誤程式碼檢視資訊
[[email protected]~]$ oerr ora 04031
04031, 00000,"unable to allocate %s bytes of shared memory(\"%s\",\"%s\",\"%s\",\"%s\")"
// *Cause: More shared memory is needed than wasallocated in the shared
// pool.
// *Action: Ifthe shared pool is out of memory, either use the
// dbms_shared_pool package to pin largepackages,
// reduce your use of shared memory, orincrease the amount of
// available shared memory by increasingthe value of the
// INIT.ORA parameters"shared_pool_reserved_size" and
// "shared_pool_size".
// If the large pool is out of memory,increase the INIT.ORA
// parameter"large_pool_size".
9、連線sql developer
(1)配置密碼檔案?
(2)啟動監聽
(3)關閉Linux的防火牆
[[email protected]~]# /sbin/iptables -F
十、兩個SID連線兩個DB
SID為powter的例項啟動powter資料庫:
[[email protected]~]$ echo $ORACLE_SID
powter
[[email protected]~]$ sqlplus / as sysdba
SQL*Plus:Release 10.2.0.1.0 - Production on Fri Aug 10 08:47:11 2012
Copyright (c)1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
SQL> selectinstance_name from v$instance;
INSTANCE_NAME
--------------------------------
powter
SID為wolex的例項啟動wolex_db資料庫:
[[email protected]~]$ export ORACLE_SID=wolex
[[email protected]~]$ echo $ORACLE_SID
wolex
[[email protected]~]$ sqlplus / as sysdba
SQL*Plus:Release 10.2.0.1.0 - Production on Fri Aug 10 08:49:13 2012
Copyright (c)1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
SQL> selectinstance_name from v$instance;
INSTANCE_NAME
----------------
wolex