6
11

More than 5 years have passed since last update.

Oracleに接続する際の忘備録

Last updated at Posted at 2017-12-29

久しぶりにCentOSに構築したOracleに接続しようおもたら、前に出会ったようなエラーとなって何回も調べるの面倒なんで忘備録としてメモ

sqlplus xxx/xxx@xxx
SQL*Plus: Release 11.2.0.1.0 Production on 土 12月 30 00:52:30 2017

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

ERROR:
ORA-12541: TNS: リスナーがありません

毎度のことながらまだまだDBの知識たりんなあ、、、とか前もこのエラーでたなあとか思いつつ
とりあえずlistenerの状態確認

[oracle@dbserver admin]$ lsnrctl status LISTENER

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-12月-2017 01:23:55

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))に接続中
TNS-12541: TNS: リスナーがありません。
 TNS-12560: TNS: プロトコル・アダプタ・エラー
  TNS-00511: リスナーがありません。
   Linux Error: 111: Connection refused

リスナーがありません。さっきと一緒やないか。リスナー起動してみるか。

[oracle@dbserver admin]$ lsnrctl start LISTENER

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-12月-2017 01:28:23

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

/usr/oracle/app/product/11.2.0/dbhome_1/bin/tnslsnrを起動しています。お待ちください...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
システム・パラメータ・ファイルは/usr/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.oraです。
ログ・メッセージを/usr/oracle/app/diag/tnslsnr/dbserver/listener/alert/log.xmlに書き込みました。
リスニングしています: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))に接続中
リスナーのステータス
------------------------
別名                      LISTENER
バージョン                TNSLSNR for Linux: Version 11.2.0.1.0 - Production
開始日                    30-12月-2017 01:28:23
稼働時間                  0 日 0 時間 0 分 0 秒
トレース・レベル          off
セキュリティ              ON: Local OS Authentication
SNMP                      OFF
パラメータ・ファイル      /usr/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora
ログ・ファイル            /usr/oracle/app/diag/tnslsnr/dbserver/listener/alert/log.xml
リスニング・エンドポイントのサマリー...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
リスナーはサービスをサポートしていません。
コマンドは正常に終了しました。

うまく起動できた、、、か???
ステータスもう一度見てみる

[oracle@dbserver admin]$ lsnrctl status LISTENER

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-12月-2017 01:28:51

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))に接続中
リスナーのステータス
------------------------
別名                      LISTENER
バージョン                TNSLSNR for Linux: Version 11.2.0.1.0 - Production
開始日                    30-12月-2017 01:28:23
稼働時間                  0 日 0 時間 0 分 27 秒
トレース・レベル          off
セキュリティ              ON: Local OS Authentication
SNMP                      OFF
パラメータ・ファイル      /usr/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora
ログ・ファイル            /usr/oracle/app/diag/tnslsnr/dbserver/listener/alert/log.xml
リスニング・エンドポイントのサマリー...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
リスナーはサービスをサポートしていません。
コマンドは正常に終了しました。

稼働は始まってそう。ならもっかい接続してみようか。

[oracle@dbserver admin]$ sqlplus xxx/xxx@xxx as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 土 12月 30 01:29:05 2017

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

ERROR:
ORA-12514: TNS:
リスナーは接続記述子でリクエストされたサービスを現在認識していません

別のエラーが。。。つらい。
connectionで確認してみると別のエラーを確認できた。

[oracle@dbserver admin]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on 土 12月 30 01:32:35 2017

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

SQL> conn / as sysdba
ERROR:
ORA-12162: TNS: 指定されたNetサービス名は正しくありません。

調べてみると環境変数足りないかも
https://blogs.yahoo.co.jp/ramusesu701/63129112.html

自分の環境だと、SIDの環境変数を設定できていなかったので、Oracleユーザのbashrcに環境変数を設定する。

export ORACLE_SID=xxx

変更後はsourceコマンドで反映

source .bashrc

接続できてアイドルインスタンスだったので、startupして無事起動

[oracle@dbserver admin]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 土 12月 30 01:38:40 2017

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

アイドル・インスタンスに接続しました。

SQL> startup
ORACLEインスタンスが起動しました。

Total System Global Area 1603411968 bytes
Fixed Size                  2213776 bytes
Variable Size            1224738928 bytes
Database Buffers          369098752 bytes
Redo Buffers                7360512 bytes
データベースがマウントされました。
データベースがオープンされました。

おわり

6
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
11