6.6 connstrユーティリティを使用した接続文字列の表示
Oracle Database接続文字列コマンドライン・ユーティリティ(connstr)を実行すると、すべての使用可能なネットワーク・サービス名のOracle Database接続文字列を表示できます。
これらの文字列をクライアント・アプリケーションまたはツール(SQL*Plus、Python、JDBC Thinなど)で使用してOracle Databaseにすばやく接続することも、ローカル・ネーミング・メソッドで使用するためにこれらのサービス名エントリを
tnsnames.oraファイルに書き込むこともできます。
connstrスクリプトは、デフォルトのインストールに含まれています。このユーティリティは、使用可能なシステム構成に基づいて、単一のOracleソフトウェア・インストールの接続文字列を表示します。
ノート:
このユーティリティは、単一インスタンスまたはOracle Database Freeのインストールに適しています。それよりも複雑な構成のOracle Real Application Clusters (Oracle RAC)やOracle Data Guardなどには適していません。これはリスナー制御ユーティリティ(lsnrctl)に依存しているため、Oracle Databaseとリスナーをホストしているコンピュータでこのユーティリティを実行する必要があります。ただし、表示される接続文字列は、サポートされているすべてのクライアント・システムで使用できます。
例6-1 簡易接続形式でのconnstrユーティリティの出力例
Using Listener: LISTENER with Oracle Home: /app/oracle/product/23ai/dbhome_1
Service Name: sales.us.example.com
Connection String: sales-server:1521/sales.us.example.com
Connection strings can be used to connect to the specified service name.
For SQL*Plus you can use:
SQL> connect username@sales-server:1522/sales.us.example.com
For Python you can use:
connection = cx_Oracle.connect(user="username", password="password",
dsn="sales-server:1521/sales.us.example.com")
For JDBC Thin you can use:
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@sales-server:1521/sales.us.example.com");
ods.setUser("username"); ods.setPassword("password");
Connection conn = ods.getConnection();
Write connect strings to tnsnames.ora (Y/N)? (Default: N): y
関連トピック