๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
ORACLE/ADMIN

[Oracle] ์˜ค๋ผํด ์ ‘์† tnsnames.ora ์„ค์ • Easy Connect, ๋กœ์ปฌ ์ด๋ฆ„ ์ง€์ • ๋ฐฉ์‹

by ๐ŸŒปโ™š 2020. 7. 11.

์˜ค๋ผํด ์ ‘์† ๋ฐฉ๋ฒ•

์ด์ „ ๊ธ€์—์„œ Listener์™€ ๊ด€๋ จ๋œ ์‹ค์Šต์„ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Oracle ์ ‘์† ๋ฐฉ๋ฒ• ์ค‘์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” Easy Connect์™€ ๋กœ์ปฌ ์ด๋ฆ„ ์ง€์ • ๋ฐฉ์‹์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

์‹ค์Šต ํ™˜๊ฒฝ

OS : OEL 5.4
DB : Oracle 12.1.0.2
SID: newdb, PROD(1๊ฐœ ์„œ๋ฒ„์•ˆ 2๊ฐœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค)
hostname : host01
listener ์‚ฌ์ „ ๊ตฌ์ถ• ์™„๋ฃŒ 1521ํฌํŠธ ์‚ฌ์šฉ

 

 

Easy Connect ๋ฐฉ์‹

๊ฐ€์žฅ ์‰ฝ๊ฒŒ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ํ•„์š”ํ•œ ์ •๋ณด๋“ค์„ ๋‚˜์—ดํ•ด์„œ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

[oracle@host01 ~]$ sqlplus system/oracle@host01:1521/PROD

sqlplus๋ฅผ ์ด์šฉํ•ด์„œ ์ ‘์†ํ–ˆ์Šต๋‹ˆ๋‹ค. <๊ณ„์ •>/<๋น„๋ฐ€๋ฒˆํ˜ธ>@<ํ˜ธ์ŠคํŠธ๋ช… ํ˜น์€ IP>:<๋ฆฌ์Šค๋„ˆ ํฌํŠธ>/<์„œ๋น„์Šค ๋ช…> ํ˜•ํƒœ๋กœ ์—ฐ๊ฒฐํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

SYSTEM@host01:1521/PROD> show parameter db_name

PROD ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘์†ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

 

์„œ๋น„์Šค๋ช… ๋ณ€๊ฒฝ ๋ฐ ์ ‘์†

SYS@PROD> show parameter service_names

์ตœ์ดˆ์— ์„ค์ •๋˜๋Š” ์„œ๋น„์Šค๋ช…์€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ค์น˜ ์‹œ ์ง€์ •ํ•˜๋Š” DB Name๊ณผ Domain Name์˜ ์กฐํ•ฉ์œผ๋กœ ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค. ์„œ๋น„์Šค๋ช…์€ ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ๋งŒ๋“ค์–ด ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด ์„œ๋น„์Šค๋ช…์„ ํ•˜๋‚˜ ์ถ”๊ฐ€ํ•˜๊ณ  Easy Connect ๋ฐฉ์‹์œผ๋กœ ์ ‘์†์„ ๋‹ค์‹œ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

SYSTEM@host01:1521/PROD> alter system set service_names = 'PROD', 'ABC';
SYSTEM@host01:1521/PROD> conn system/oracle@host01:1521/abc
Connected.
SYSTEM@host01:1521/abc> show parameter db_name

์ƒˆ๋กœ์šด ์„œ๋น„์Šค๋ช…์œผ๋กœ ์ ‘์†ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

 

๋กœ์ปฌ ์ด๋ฆ„ ์ง€์ • ๋ฐฉ์‹ tnsname.ora ์‚ฌ์šฉ

Easy Connect ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ด์„œ ์ ‘์†ํ•˜๋ ค๋ฉด ๋งค๋ฒˆ ํ˜ธ์ŠคํŠธ๋ช…, ๋ฆฌ์Šค๋„ˆ ํฌํŠธ, ์„œ๋น„์Šค๋ช…์„ ์ž…๋ ฅํ•ด์•ผ ์ ‘์†์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ถˆํŽธํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๋Ÿฌํ•œ ์ •๋ณด๋“ค์„ ๋ฏธ๋ฆฌ tnsnames.ora ํŒŒ์ผ์— alias๋กœ ๋งŒ๋“ค์–ด ๊ด€๋ฆฌํ•˜๊ณ  ํ•ด๋‹น ๋ณ„์นญ์„ ์ด์šฉํ•ด์„œ ๋Œ€์‹  ์ ‘์†ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‹ค์ œ๋กœ ํ˜„์žฅ์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. tnsnames.ora ํŒŒ์ผ์€ ์ง์ ‘ ์ƒ์„ฑํ•˜์—ฌ ๋งŒ๋“ค์–ด๋„ ๊ฐ€๋Šฅํ•˜๊ณ  Oracle Net Manager์™€ Oracle Net Configuration Assistant๋ฅผ ์‚ฌ์šฉํ•ด์„œ๋„ ์ƒ์„ฑ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

 

Oracle Net Manager ์‚ฌ์šฉ

[oracle@host01 ~]$ netmgr

Oracle Net Manager๋ฅผ ์‹คํ–‰ํ•œ ํ›„, Service Naming์„ ์„ ํƒํ•˜๊ณ  ์ขŒ์ธก "+" ๊ธฐํ˜ธ๋ฅผ ๋ˆŒ๋Ÿฌ ์ ‘์† ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ์ž…๋ ฅ๋ž€์— ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ๋ณ„์นญ์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. abc๋กœ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

TCP/IP ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

ํ˜ธ์ŠคํŠธ ๋ช…๊ณผ ์—ฐ๊ฒฐํ•  ๋ฆฌ์Šค๋„ˆ์˜ ํฌํŠธ๋ฅผ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค.

 

์—ฐ๊ฒฐํ•  ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์„œ๋น„์Šค๋ช…์„ ์ž…๋ ฅํ•ด์ค๋‹ˆ๋‹ค. Connection Type์—์„œ๋Š” Shared Server ํ˜น์€ Dedicated Server๋กœ ๋‚˜๋ˆ ์„œ ์ ‘์†ํ•˜๋Š” ์˜ต์…˜์„ ์„ ํƒํ•  ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค. Database Default๋กœ ์ง€์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

ํ…Œ์ŠคํŠธ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ฒŒ ๋˜๋ฉด scott๊ณ„์ •์œผ๋กœ ํ™•์ธํ•˜๋Š” ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค. ํ…Œ์ŠคํŠธ ํ•˜์ง€์•Š๊ณ  ์ง„ํ–‰ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

์„ค์ •์„ ๋ชจ๋‘ ์™„๋ฃŒํ–ˆ์œผ๋‹ˆ ์ขŒ์ธก ์ƒ๋‹จ์— File - Save Network Configuration์œผ๋กœ ์ €์žฅํ•˜๊ณ  ๋น ์ ธ๋‚˜์˜ต๋‹ˆ๋‹ค.

 

[oracle@host01 ~]$ cd $ORACLE_HOME/network/admin
[oracle@host01 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.1.0.2/dbhome/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ABC =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host01)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PROD)
    )
  )

tnsnames.ora ํŒŒ์ผ์„ ์—ด์–ด๋ณด๋‹ˆ ABC๋ผ๋Š” ๋ณ„์นญ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ ‘์†์ •๋ณด๊ฐ€ ๊ธฐ์žฌ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ํ•ด๋‹น ๋ณ„์นญ์œผ๋กœ ์ ‘์†์ด ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธํ•ด๋ณด๊ณ˜์Šต๋‹ˆ๋‹ค.

 

 

[oracle@host01 admin]$ sqlplus system/oracle@abc

 

 

Oracle Net Configuration Assistant ์‚ฌ์šฉ

[oracle@host01 ~]$ netca

Local Net Service Name configuration์„ ํ†ตํ•ด tnsnames.oraํŒŒ์ผ์— alias๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Add ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

 

์ ‘์†ํ•  ์„œ๋น„์Šค ๋ช…์นญ์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 

TCP ํ†ต์‹  ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

 

ํ˜ธ์ŠคํŠธ๋ช…๊ณผ ์‚ฌ์šฉํ•  ๋ฆฌ์Šค๋„ˆ์˜ ํฌํŠธ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

 

ํ…Œ์ŠคํŠธ๋Š” ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.

 

๋ณ„์นญ์„ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค.

 

์ถ”๊ฐ€ ์ž‘์—…์€ ์—†์œผ๋ฏ€๋กœ NO ์„ ํƒ ํ›„ Next

 

์ถ”๊ฐ€๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ tnsnames.ora ํŒŒ์ผ์„ ๋‹ค์‹œ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

[oracle@host01 ~]$ cd $ORACLE_HOME/network/admin
[oracle@host01 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.1.0.2/dbhome/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

EFG =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host01)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PROD)
    )
  )

ABC =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host01)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PROD)
    )
  )

์ง€์ •ํ•œ EFG ์„œ๋น„์Šค ๋ช…์ด ์ถ”๊ฐ€๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ ‘์†๋„ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

[oracle@host01 admin]$ sqlplus system/oracle@efg

์ ‘์† ์™„๋ฃŒ๋˜์—ˆ๊ณ  tnsnames.ora ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ด์„œ ์˜ค๋ผํด์— ์ ‘์†ํ•˜๋Š” ์‹ค์Šต์„ ํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

 

๋Œ“๊ธ€