{{tag>[cli oracle database sql sqlplus config]}} ====== SQL*Plus configuration ====== SQL*Plus의 Oracle Net connection file, environment variable와 startup profile을 구성하는 방법이다. ===== Summary ===== * Oracle Net service name은 일반적으로 ''tnsnames.ora''에 정의하고 ''TNS_ADMIN''으로 config directory를 지정한다. * SQL*Plus는 site profile ''glogin.sql''을 먼저, user profile ''login.sql''을 나중에 처리한다. * profile script는 connection 때 자동 실행될 수 있으므로 credential과 destructive SQL을 넣지 않는다. ===== File Locations ===== ^ File ^ Purpose ^ Typical location ^ | ''tnsnames.ora'' | net service name과 connect descriptor mapping | ''$ORACLE_HOME/network/admin'' 또는 ''$TNS_ADMIN'' | | ''sqlnet.ora'' | Oracle Net client naming, authentication, encryption 등 | ''$ORACLE_HOME/network/admin'' 또는 ''$TNS_ADMIN'' | | ''glogin.sql'' | site-wide SQL*Plus profile | ''$ORACLE_HOME/sqlplus/admin/glogin.sql'' | | ''login.sql'' | user 또는 project SQL*Plus profile | current directory 또는 ''SQLPATH'' search path | Instant Client에서는 installation directory 아래 ''network/admin''을 사용하거나 별도 directory를 만들고 ''TNS_ADMIN''을 지정할 수 있다. 정확한 default path는 platform과 installation method에 따라 다르다. ===== Oracle Net Service Names ===== ==== tnsnames.ora ==== APPDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = db.example.com)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = appsvc.example.com) ) ) export TNS_ADMIN=/etc/oracle/network/admin sqlplus app_user@APPDB ''tnsnames.ora''에는 password를 저장하지 않는다. file permission으로 변경 주체를 제한하고 hostname, service name과 TLS 관련 설정 변경을 review한다. ==== Easy Connect ==== 단순한 TCP connection에는 ''tnsnames.ora'' 없이 Easy Connect string을 사용할 수 있다. sqlplus app_user@"db.example.com:1521/appsvc.example.com" Easy Connect와 ''tnsnames.ora'' 모두에서 password를 생략하면 SQL*Plus가 안전한 password prompt를 표시한다. ===== Environment Variables ===== * ''TNS_ADMIN'': ''tnsnames.ora'', ''sqlnet.ora'' 등 Oracle Net config directory * ''TWO_TASK'' (Unix): command에 connect identifier가 없을 때 사용할 default identifier * ''LOCAL'' (Windows): ''TWO_TASK''에 대응하는 default identifier * ''SQLPATH'': ''login.sql''과 SQL script를 찾는 추가 search path * ''ORACLE_PATH'' (Unix): SQL script search path에 쓰이는 legacy/Unix 환경 변수 * ''NLS_LANG'': client language, territory와 character set. database character set을 바꾸는 설정이 아님 * ''ORA_PLUS_AUTOEXEC'': implicit profile script 처리 mode. ''ENABLE'', ''RESTRICT'', ''DISABLE'' export TNS_ADMIN=/etc/oracle/network/admin export TWO_TASK=APPDB sqlplus app_user ===== SQL*Plus Profiles ===== ==== login.sql ==== interactive readability에 필요한 formatting만 두고 application script가 profile default에 의존하지 않게 한다. SET PAGESIZE 100 SET LINESIZE 200 SET TAB OFF SET TRIMSPOOL ON SET SQLPROMPT '_USER@_CONNECT_IDENTIFIER> ' * ''glogin.sql''은 site-wide default를 제공한다. * ''login.sql''은 user 또는 project override를 제공한다. * SQL*Plus start와 successful ''CONNECT'' 뒤에 profile이 다시 처리될 수 있다. * batch script는 필요한 ''SET'' 값을 script 안에 명시해 profile 차이로 인한 output 변화를 줄인다. profile에 password, wallet secret, production connection string, ''DROP'', ''ALTER SYSTEM'', ''HOST'' 같은 privileged 또는 destructive action을 넣지 않는다. repository에서 받은 ''login.sql''도 자동 실행 전에 검토한다. ==== Automatic Profile Execution ==== 최신 SQL*Plus의 ''ORA_PLUS_AUTOEXEC''는 implicit profile 실행을 제어한다. * ''ENABLE'': legacy behavior로 profile을 자동 실행 * ''RESTRICT'': profile은 실행하지만 선택된 command와 statement를 제한 * ''DISABLE'': implicit profile 실행 중지 export ORA_PLUS_AUTOEXEC=RESTRICT sqlplus app_user@APPDB 명시적으로 ''START'', ''@'', ''@@''로 실행한 script까지 이 변수가 제한하는 것은 아니다. ===== Precedence and Validation ===== - ''TNS_ADMIN''을 설정했다면 해당 directory의 Oracle Net file을 먼저 확인한다. - SQL*Plus start 또는 ''CONNECT'' 성공 뒤 ''glogin.sql''이 먼저, ''login.sql''이 다음으로 처리된다. - ''login.sql''의 설정이 같은 SQL*Plus variable에 대한 site default를 override할 수 있다. - batch script 안에서 다시 지정한 ''SET'' 값은 이후 실행에 적용된다. # password는 prompt에서 입력 sqlplus -L app_user@APPDB SQL> SHOW USER SQL> SHOW ALL SQL> SELECT SYS_CONTEXT('USERENV', 'SERVICE_NAME') FROM dual; ===== Troubleshooting ===== * ''ORA-12154'': 실제 ''TNS_ADMIN'' 값, filename 대소문자, alias와 ''tnsnames.ora'' parenthesis를 확인한다. * 예상하지 않은 formatting이나 command 실행: ''glogin.sql'', current/search path의 ''login.sql'', ''ORA_PLUS_AUTOEXEC''를 확인한다. * 다른 database에 연결됨: ''TWO_TASK'' 또는 Windows ''LOCAL''이 설정되었는지 확인한다. * script를 찾지 못함: current directory, ''SQLPATH'', nested script의 ''@@'' 기준 directory를 확인한다. * 문자 깨짐: terminal locale과 ''NLS_LANG''을 확인하되 검증 없이 임의 character set으로 변환하지 않는다. ===== See Also ===== * [[sql_plus:ko|SQL*Plus]] * [[https://docs.oracle.com/en/database/oracle/oracle-database/26/sqpug/configuring-SQL-Plus.html|Configuring SQL*Plus]] * [[https://docs.oracle.com/en/database/oracle/oracle-database/26/netag/|Oracle Database Net Services Administrator's Guide]] ===== History ===== * codex:: 2026-08-13 Added Oracle Net files, environment variables, profile precedence, validation, and secure configuration guidance. {{indexmenu>.#1|js}}