Oracle 服務名/實例名,Service_name 和Sid的區別


Service_name 和Sid的區別

Service_name:該參數是由oracle8i引進的。在8i以前,使用SID來表示標識數據庫的一個實例,但是在Oracle的並行環境中,
1、一個數據庫對應多個實例:
 這樣就需要多個網絡服務名,設置繁瑣。為了方便並行環境中的設置,引進了Service_name參數,該參數對應一個數據庫,而不是一個實例,
而且該參數有許多其它的好處。該參數的缺省值為Db_name. Db_domain,即等於Global_name。 sid是數據庫實例的名字,每個實例各不相同。
2、一個數據庫可以對應多個Service_name
以便實現更靈活的配置。該參數與SID沒有直接關系,即不必Service name 必須與SID一樣。
 
        

一、SID
    是用來標識這個數據庫內部每個實例的名字(一個數據庫可以有多個實例(如RAC))

給程序開發連接用,比如連接串: jdbc:oracle:thin:@//10.121.51.22:1521:sidname   
//注意是:sidname,不是/sidname // linux下登錄演示
[root@shdb02 ~]# su - oracle
//輸出當前默認的實例sid
[oracle@shdb02 ~]$ echo $ORACLE_SID  
htsby2
//設置當前要登錄的實例sid
[oracle@shdb02 ~]$ export ORACLE_SID=fpm2
//輸出當前的實例sid
[oracle@shdb02 ~]$ echo $ORACLE_SID
fpm2
[oracle@shdb02 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 14 11:05:37 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
//查詢當前實例的數據庫(數據庫對應多個實例)
SQL> select name from v$database;
NAME
---------
FPM
//查詢當前登錄的實例sid
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
fpm2
//查詢實例的相關參數
SQL> show parameter instance

NAME    TYPE    VALUE
------------------------------------ ----------- ------------------------------
active_instance_count    integer
cluster_database_instances    integer    2
instance_groups string
instance_name    string    fpm2
instance_number integer    2
instance_type    string    RDBMS
open_links_per_instance integer    4
parallel_instance_group string
parallel_server_instances    integer    2

  二、SERVICE_NAME
      是這個數據庫對外的名稱,外面的人要想連接我這個數據庫,你就在客戶端的連接串里寫上service_name。

一般給客戶端pl/sql用,舉例: username@10.128.51.22:1521/fpm
//注意是 /fpm 而不是:fpm
//實例驗證
[root@shdb02 ~]# su - oracle
[oracle@shdb02 ~]$ export ORACLE_SID=fpm2  //fpm2是實例sid
[oracle@shdb02 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 10 22:43:36 2022
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

//查詢該實例的數據庫名,數據庫和實例是一對多的關系,也就是1個數據庫對應多個實例。

SQL> select name from v$database; NAME --------- FPM

//查看當前的實例sid
 SQL> select instance_name from v$instance;  
 INSTANCE_NAME
 ----------------
 fpm2
 //查詢當前的數據庫服務名
 SQL> show parameter service_name;  

 NAME TYPE VALUE
 ------------------------------------ ----------- ------------------------------
 service_names    string    fpm

 

 三、 Java JDBC Thin Driver 連接 Oracle有三種方法:

1、格式一: JDBC 使用服務名 ServiceName:  jdbc:oracle:thin:@//<host>:<port>/<service_name> 
Example: jdbc:oracle:thin:@//192.168.2.1:1521:my_service_name 
注意這里的格式,@后面有//, 這是與使用SID的主要區別。 
這種格式是Oracle 推薦的格式,因為對於oracle集群來說,每個節點的SID 是不一樣的,但是SERVICE_NAME 確可以包含所有節點。 
 
2、格式二: JDBC 使用實例 SID:  jdbc:oracle:thin:@<host>:<port>:<SID> 
例子:jdbc:oracle:thin:@//10.121.51.22:1521:my_sid 
 
格式三:Oracle JDBC 使用 TNSName: 
jdbc:oracle:thin:@<TNSName> 
Example: jdbc:oracle:thin:@tna
特別要注意 /和:的問題,對於1和2來說

查詢數據庫名:

[root@shdb02 ~]# su - oracle
[oracle@shdb02 ~]$ export ORACLE_SID=fpm2  //fpm2是實例名
[oracle@shdb02 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 10 22:43:36 2022
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
//查詢該實例的數據庫名,數據庫和實例是一對多的關系,也就是1個數據庫對應多個實例。
SQL> select name from v$database; NAME --------- FPM
SQL> select instance_name from v$instance;  
 INSTANCE_NAME
 ----------------
 fpm2
//查詢當前的數據庫服務名 
 SQL> show parameter service_name;   

 NAME TYPE VALUE
 ------------------------------------ ----------- ------------------------------
 service_names    string    fpm

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM