1.修改數據庫名
1.查看oracle實例名
2.shutdown immediate
3.lsnrctl stop $ORACLE_SID#----------windows下關閉使用oracle服務
4.修改 /etc/oratab 的$ORACLE_SID#------------windows沒有
5.修改用戶環境變量.bashprofile #------------windows沒有
6.linux下$ORACLE_HOME/dbs 修改有關$ORACLE_SID的文件名
windows下$ORACLE_HOME/database 修改有關$ORACLE_SID的文件名
7.重新生成密碼文件,啟動數據庫
liunx:orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=5 force=y
windows:
在一個cmd運行oracle %ORACLE_ORCL%
在另一個cmd運行
set ORACLE_HOME=E:appcswggodproduct11.2.0dbhome_1database
set ORACLE_ORCL=orcl
orapwd file=%ORACLE_HOME%/ORACLE_HOME/dbs/orapw%ORACLE_SID% password=oracle entries=5 force=y
startup
#-------------------1.選擇orcl實例
[oracle@h1 ~]$ sqlplus "/as SYSDBA"
SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 12 03:07:58 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
#-------------2.查看實例
SQL> select * from v$thread;
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
orcl
#-----------------3.關機
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
#-------------4.關閉監聽
[oracle@h1 ~]$ lsnrctl stop orcl
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 12-NOV-2012 03:20:11
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.5.130)(PORT=1522)))
The command completed successfully
#--------------5.修改/etc/oratab
[oracle@h1 ~]$ su root
Password:
[root@h1 oracle]# vi /etc/oratab
#------------orcl 修改為bitc
bitc:/app/oracle/product/11.2.0/dbhome_2:N
test:/app/oracle/product/11.2.0/dbhome_2:N
"/etc/oratab" 24L, 764C written
[root@h1 oracle]#
#-----------------6.修改.bash_profile並生效
[root@h1 oracle]# su oracle
[oracle@h1 ~]$ pwd
/home/oracle
[oracle@h1 ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_BASE=/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_2
export ORACLE_SID=bitc
export PATH=$ORACLE_HOME/bin:.:$PATH
".bash_profile" 16L, 323C written
[oracle@h1 ~]$ . .bash_profile
[oracle@h1 ~]$ echo $ORACLE_SID
bitc
#---------------------7.修改配置文件名
[oracle@h1 ~]$ cd $ORACLE_HOME/dbs
[oracle@h1 dbs]$ ls -al
total 56
drwxr-xr-x. 2 oracle oinstall 4096 Nov 12 03:18 .
drwxr-xr-x. 76 oracle oinstall 4096 Nov 10 00:52 ..
-rw-rw----. 1 oracle oinstall 1544 Nov 10 00:40 hc_DBUA0.dat
-rw-rw----. 1 oracle oinstall 1544 Nov 12 03:18 hc_orcl.dat
-rw-rw----. 1 oracle oinstall 1544 Nov 12 03:03 hc_test.dat
-rw-r--r--. 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r-----. 1 oracle oinstall 1906 Nov 9 23:35 initorcl.ora
-rw-r-----. 1 oracle oinstall 24 Nov 3 07:13 lkORCL
-rw-r-----. 1 oracle oinstall 24 Nov 10 00:45 lkTEST
-rw-r-----. 1 oracle oinstall 1536 Nov 10 06:40 orapworcl
-rw-r-----. 1 oracle oinstall 1536 Nov 10 04:23 orapwtest
-rw-r-----. 1 oracle oinstall 2560 Nov 12 03:04 spfileorcl.ora
-rw-r-----. 1 oracle oinstall 2560 Nov 9 23:05 spfileorcl.ora.bak
-rw-r-----. 1 oracle oinstall 3584 Nov 12 03:03 spfiletest.ora
[oracle@h1 dbs]$ chmod 777 *
[oracle@h1 dbs]$ mv hc_orcl.dat hc_bitc.dat
[oracle@h1 dbs]$ mv lkORCL lkBITC
[oracle@h1 dbs]$ mv orapworcl orapwbitc
[oracle@h1 dbs]$ mv spfileorcl.ora spfilebitc.ora
[oracle@h1 dbs]$
[oracle@h1 dbs]$ ls
hc_bitc.dat init.ora lkTEST spfilebitc.ora
hc_DBUA0.dat initorcl.ora orapwbitc spfileorcl.ora.bak
hc_test.dat lkBITC orapwtest spfiletest.ora
#-----------------8.生成密碼文件
[oracle@h1 dbs]$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=5 force=y
#---------------9.啟動數據庫
[oracle@h1 dbs]$ echo $ORACLE_SID
bitc
[oracle@h1 dbs]$ sqlplus "/as SYSDBA"
SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 12 03:35:11 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.
Total System Global Area 501059584 bytes
Fixed Size 2214736 bytes
Variable Size 318768304 bytes
Database Buffers 176160768 bytes
Redo Buffers 3915776 bytes
Database mounted.
Database opened.
SQL> exit
2.數據庫更名後,配置靜態監聽
[oracle@h1 dbs]$ netmgr
#-------------------1.配置監聽文件
配置遠程namespace:
驗證:
#----------------2.修改靜態監聽參數
SQL> show parameter listener;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
listener_networks string
local_listener string BITC
remote_listener string
SQL> alter system set local_listener="BITC";
System altered.
SQL> alter system register;
System altered.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
#----------------------------3.啟動實例監聽
[oracle@h1 dbs]$ lsnrctl start BITC
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 12-NOV-2012 05:01:08
Copyright (c) 1991, 2009, Oracle. All rights reserved.
TNS-01106: Listener using listener name orcl has already been started
[oracle@h1 dbs]$ lsnrctl status BITC
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 12-NOV-2012 05:01:16
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.5.130)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias orcl
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 12-NOV-2012 04:48:54#啟動日期
Uptime 0 days 0 hr. 12 min. 22 sec#正常運行時間
Trace Level off #跟蹤級別
Security ON: Local OS Authentication#安全性
SNMP OFF
Listener Parameter File /app/oracle/product/11.2.0/dbhome_2/network/admin/listener.ora#監聽程序參數文件
Listener Log File /app/oracle/diag/tnslsnr/h1/orcl/alert/log.xml#監聽程序日志文件
Listening Endpoints Summary... #監聽端點摘要
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.5.130)(PORT=1522)))
Services Summary... #服務摘要
Service "bitc" has 1 instance(s).
Instance "bitc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "bitc", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "bitc", status READY, has 1 handler(s) for this service...
The command completed successfully
#-----------------------------------------------#
動態監聽默認1521,多個實例只能共享這個端口;
在netmgr中配置namespace,所有實例的主機名和端口必須完全一致,否則一實例可能堵塞其他實例監聽
注在64位oracle配置32位oracle的遠程listener可能因為版本問題失敗
3.Materialized View同步
#---------------------------------------在TEST上
select * from dba_db_links;
#---------------------host 已變成BITC,不是ORCL,db_link失效
SQL> alter public database link conn_orcl connect to u01 identified by abc;
alter public database link conn_orcl connect to u01 identified by abc
ORA-32598: user names cannot be changed in ALTER DATABASE LINK command
SQL> drop public database link conn_orcl;
Database link dropped
SQL> create public database link CONN_BITC connect to u01 identified by abc using 'BITC';
Database link created
#---------------------------------------在BITC上
SQL> conn system/manager
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as system
SQL> grant dba to u01;
Grant succeeded
SQL> conn u01/abc
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as u01
SQL> create table t1(id int primary key,name varchar(30));
Table created
SQL> create materialized view log on t1;
Materialized view log created
#---------------------------------------在TEST上,建立物化視圖,由於ORCL數據未錄入,
#------------t1_mv無數據
SQL> select * from U01.t1@CONN_BITC;
ID NAME
--------------------------------------- ------------------------------
#-----------------按主鍵建同步
SQL> create materialized view t1_mv refresh fast start with sysdate next sysdate+1/1440
2 with primary key as select * from u01.t1@conn_bitc;
Materialized view created
SQL> select * from t1_mv;
ID NAME
--------------------------------------- ------------------------------
#---------------------------------------在BITC上,插入數據提交
SQL> insert into t1 values(1,'chal');
1 row inserted
SQL> commit;
Commit complete
#---------------------------------------在TEST上,每一分鐘同步,t1_mv未到同步時間,數據未同步
SQL> select * from t1_mv;
ID NAME
--------------------------------------- ------------------------------
#---------------------------------------在TEST上,經過每一分鐘,t1_mv到同步時間,數據由ORCL同步到TEST
SQL> select * from t1_mv;
ID NAME
--------------------------------------- ------------------------------
1 chal
#--------------------------------------------#
#---------------------------------------在BITC上
SQL> show user
User is "u01"
SQL> create table stu (id int,name varchar(30));
Table created
#------------------log日志建立必須有主鍵
SQL> create materialized view log on stu;
create materialized view log on stu
ORA-12014: table 'STU' does not contain a primary key constraint
#---------------------------------------在TEST上
#-----------------按ROWID建同步
SQL> create materialized view stu_mv refresh force start with sysdate next
2 sysdate+1/1440 with rowid as select * from u01.stu@CONN_BITC;
Materialized view created
#---------------------------------------在BITC上
SQL> insert into stu values(1,'TOM');
1 row inserted
SQL> commit;
Commit complete
#---------------------------------------在TEST上
SQL> select * from stu_mv;
ID NAME
--------------------------------------- ------------------------------
1 TOM
#---------------------4.快照同步
#------------------------------------------有主鍵----------------------------------------------#
#---------------------------------------在BITC上
SQL> show user
User is "u01"
SQL> create table test1(id int primary key,name varchar(30));
Table created
SQL> create snapshot log on test1;
Materialized view log created
SQL> insert all into test1 values(1,'egg') into test1 values(2,'apple')
2 select * from dual;
2 rows inserted
SQL> commit;
Commit complete
SQL>
#---------------------------------------在TEST上
SQL> create snapshot sn_test1 as select * from u01.test1@CONN_BITC;
Materialized view created
SQL> alter snapshot sn_test1 refresh fast start with sysdate next sysdate+1/1440
2 with primary key;
Materialized view altered
#--------------擁有主鍵,復制是增量的
SQL> select * from sn_test1;
ID NAME
--------------------------------------- ------------------------------
1 egg
2 apple
SQL>
#---------------------------------------在BITC上
SQL> insert into test1 values(3,'fish');
1 row inserted
SQL> commit;
Commit complete
#---------------------------------------在TEST上
SQL> select * from sn_test1;
ID NAME
--------------------------------------- ------------------------------
1 egg
2 apple
SQL> /
ID NAME
--------------------------------------- ------------------------------
1 egg
2 apple
SQL> /
ID NAME
--------------------------------------- ------------------------------
1 egg
2 apple
3 fish
#------------------------------------------無主鍵----------------------------------------------#
#---------------------------------------在BITC上
SQL> create table test2(id int,name varchar(30));
Table created
SQL> insert into test2 values(1,'beef');
1 row inserted
SQL> commit;
Commit complete
#---------------------------------------在TEST上
SQL> create snapshot sn_test2 refresh complete start with sysdate
2 next sysdate+1/1440 with rowid as select * from u01.test2@conn_bitc;
Materialized view created
#-------------------complete,無增量刷新
SQL> select * from sn_test2;
ID NAME
--------------------------------------- ------------------------------
1 beef
#------------snapshot與備份區別------------------------#
熱備份
熱備份是在數據庫運行的情況下,采用archivelog mode方式備份數據庫的方法。所以,如果你有昨天夜裡的一個冷備份而且又有今天的熱備份文件,在發生問題時,就可以利用這些資料恢復更多的信息。熱備份要求數據庫在Archivelog方式下操作,並需要大量的檔案空間。一旦數據庫運行在archivelog狀態下,就可以做備份了。熱備份的命令文件由三部分組成:
1.數據文件一個表空間一個表空間的備份:
(1)設置表空間為備份狀態;
(2)備份表空間的數據文件;
(3)回復表空間為正常狀態。
2.備份歸檔log文件:
(1)臨時停止歸檔進程;
(2)log下那些在archive rede log目標目錄中的文件;
(3)重新啟動archive進程;
(4)備份歸檔的redo log文件。
3.用alter database bachup controlfile命令來備份控制文件:
熱備份的優點是:
1.可在表空間或數據庫文件級備份,備份的時間短。
2.備份時數據庫仍可使用。
3.可達到秒級恢復(恢復到某一時間點上)。
4.可對幾乎所有數據庫實體做恢復。
5.恢復是快速的,在大多數情況下愛數據庫仍工作時恢復。
熱備份的不足是:
1.不能出錯,否則後果嚴重;
2. 若熱備份不成功,所得結果不可用於時間點的恢復;
3. 因難於維護,所以要特別仔細小心,不允許“以失敗告終”。
5.全局數據庫名,數據庫服務名
#-------------1.數據庫名DB_NAME
方法一:select name from v$database;
方法二:show parameter db
方法三:查看參數文件
#-------------2.數據庫實例名
實例名也被寫入參數文件中,該參數為instance_name,在winnt平台中,實例名同時也被寫入注冊表。
在一般情況下,數據庫名和實例名是一對一的關系,但如果在oracle並行服務器架構(即oracle實時應用集群)中,數據庫名和實例名是一對多的關系(HA)。
方法一:select instance_name from v$instance;
方法二:show parameter instance
方法三:在參數文件中查詢。
數據庫實例名與ORACLE_SID
雖然兩者都表是oracle實例,但兩者是有區別的。instance_name是oracle數據庫參數。而ORACLE_SID是操作系統的環境變量。ORACLD_SID用於與操作系統交互,也就是說,從操作系統的角度訪問實例名,必須通過ORACLE_SID。在winnt不台,ORACLE_SID還需存在於注冊表中。
但ORACLE_SID必須與instance_name的值一致,否則,你將會收到一個錯誤,在unix平台,是“ORACLE not available”,在winnt平台,是“TNS:協議適配器錯誤”。數據庫實例名與網絡連接
數據庫實例名除了與操作系統交互外,還用於網絡連接的oracle服務器標識。當你配置oracle主機連接串的時候,就需要指定實例名。當然8i以後版本的網絡組件要求使用的是服務名SERVICE_NAME。
#-------------3.數據庫域名
數據庫域名在存在於參數文件中,他的參數是db_domain.查詢數據庫域名
方法一:select value from v$parameter where name = 'db_domain';
方法二:show parameter domain
方法三:在參數文件中查詢
#-------------4.數據庫服務名
從oracle9i版本開始,引入了一個新的參數,即數據庫服務名。參數名是SERVICE_NAME。
如果數據庫有域名,則數據庫服務名就是全局數據庫名;否則,數據庫服務名與數據庫名相同。查詢數據庫服務名
方法一:select value from v$parameter where name = 'service_name';
方法二:show parameter service_name
#-------------5.全局數據庫名=數據庫名+數據庫域名