{"id":1243,"date":"2015-10-16T19:04:39","date_gmt":"2015-10-17T00:04:39","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1243"},"modified":"2024-02-04T13:13:45","modified_gmt":"2024-02-04T18:13:45","slug":"connecting-to-oracle-instance-in-aws-rds","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2015\/10\/connecting-to-oracle-instance-in-aws-rds\/","title":{"rendered":"Connecting to Oracle instance in AWS RDS"},"content":{"rendered":"<p>I inherited a development Oracle instance in Amazon Web Services&#8217;s Relational Database Service (AWS RDS) from a former colleague. I wanted to know what was in the database, and for that, I had to connect to it. I decided the most straightforward way would be with the simplest tool: SQL*Plus.<br \/>\n<!--more--><\/p>\n<p>First, I spun up a Debian server in the AWS EC2 (Elastic Compute Cloud) service. Then I installed 2 packages from the <a href=\"http:\/\/www.oracle.com\/technetwork\/topics\/linuxx86-64soft-092277.html\">Oracle Instant Client for Linux<\/a> (AKA instaclient):<\/p>\n<ul>\n<li>Instant Client Package &#8211; Basic<\/li>\n<li>Instant Client Package &#8211; SQL*Plus<\/li>\n<\/ul>\n<p>These come packaged as RPMs, so I had to use <code>alien<\/code> to install it. The <a href=\"https:\/\/help.ubuntu.com\/community\/Oracle%20Instant%20Client\">Ubuntu documentation on installing the Oracle Instant Client<\/a> was helpful.<\/p>\n<p>Then I tried my connection string:<br \/>\n<code>sqlplus adminuser\/t0u6h*pa55w0rd\/\/really.long.aws.string:1521<\/p>\n<p>ERROR:<br \/>\nORA-12170: TNS:Connect timeout occurred<\/code><\/p>\n<p>OK, that meant that the IP address of my EC2 instance was not authorized in the security group for the database. I added the IP address via the AWS web interface.<\/p>\n<p><code>sqlplus adminuser\/t0u6h*pa55w0rd\/\/really.long.aws.string:1521<\/p>\n<p>ERROR:<br \/>\nORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA<\/code><\/p>\n<p>OK, I do need to provide a service name, don&#8217;t I? I tacked on the DB Name listed in the AWS web interface:<\/p>\n<p><code>sqlplus adminuser\/t0u6h*pa55w0rd\/\/really.long.aws.string:1521\/devdb<\/p>\n<p>ERROR:<br \/>\nORA-12514: TNS:listener does not currently know of service requested in connect descriptor<\/code><\/p>\n<p>If I&#8217;m not mistaken, TNS service names are defined in the tnsnames.ora file, and really&#8230;I&#8217;ve always found tnsnames.ora to be more trouble than it&#8217;s worth. I tried a different route instead by using just a connect string, as suggested by AWS&#8217;s <a href=\"http:\/\/docs.aws.amazon.com\/AmazonRDS\/latest\/UserGuide\/USER_ConnectToOracleInstance.html\">Connecting to a DB Instance Running the Oracle Database Engine<\/a>.<\/p>\n<p><code>sqlplus 'adminuser@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=really.long.aws.string)(PORT=1521))(CONNECT_DATA=(SID=devdb)))'<\/p>\n<p>ERROR:<br \/>\nORA-21561: OID generation failed<\/code><\/p>\n<p>A new error message is still progress, right?<\/p>\n<p>I assumed the error meant the specified SID was incorrect. I had read in the AWS documentation somewhere that &#8220;the value for the Oracle SID will be the name of the DB instance&#8217;s database that you specified when you created the DB instance, not the name of the DB instance.&#8221; Since I had not created the DB instance, I was afraid I might never connect. However, that did not turn out to be the problem.<\/p>\n<p>Several sites suggested that the fix for &#8220;ORA-21561: OID generation failed&#8221; is to make sure that the <code>hostname<\/code> and the <code>\/etc\/hosts<\/code> entry for the machine match. Most of the posts online described people who were trying to connect to an Oracle DB on the the localhost machine. I figured that this suggestion was for the server-side and was therefore not relevant in my case. Besides, Oracle was running as a service and I had no access to the underlying server machine.  However, it turns out that the hostname and hosts entry mismatch makes a difference for the <em>client<\/em> machine as well.<\/p>\n<p><code># hostname<br \/>\nip-NNN-NNN-NNN-NNN<\/p>\n<p># head -1 \/etc\/hosts<br \/>\n127.0.0.1       localhost<\/code><\/p>\n<p>I updated the entry in <code>\/etc\/hosts<\/code> to:<br \/>\n<code>127.0.0.1       ip-NNN-NNN-NNN-NNN localhost<\/code><\/p>\n<p>And then it worked!<\/p>\n<p><code>sqlplus 'adminuser@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=really.long.aws.string)(PORT=1521))(CONNECT_DATA=(SID=devdb)))'<\/p>\n<p>Enter password:<\/p>\n<p>Connected to:<br \/>\nOracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production<br \/>\nWith the Partitioning, Oracle Label Security, OLAP, Data Mining,<br \/>\nOracle Database Vault and Real Application Testing options<\/p>\n<p>SQL&gt;<\/code><\/p>\n<p>I realized that just because I could connect to it from my Linux machine would not help my colleagues who might want to access it from Windows. I installed the Oracle instant client (Basic + SQL*Plus) for Windows and tried connecting. It wouldn&#8217;t connect at all. I tried to test the connection:<\/p>\n<p><code>telnet really.long.aws.string 1521<br \/>\n'telnet' is not recognized as an internal or external command, operable program or batch file.<\/code><\/p>\n<p>Oh, Windows&#8211;why isn&#8217;t telnet installed by default? I enabled telnet via the <em>Turn Windows features on or off<\/em> option in the Control Panel.<\/p>\n<p><code>telnet really.long.aws.string 1521<br \/>\nConnecting To really.long.aws.string...Could not open connection to the host, on port 1521: Connect failed<\/code><\/p>\n<p>Right! I had added the IP address of the Linux machine, but I needed to add the IP address of the Windows machine to the AWS security group. After that, I could connect via telnet. I tried the connect string again:<\/p>\n<p><code>sqlplus 'adminuser@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=really.long.aws.string)(PORT=1521))(CONNECT_DATA=(SID=devdb)))'<\/p>\n<p>ERROR<br \/>\nORA-12560: TNS:protocol adapter error<\/code><\/p>\n<p>That error, as it turned out, indicated that sqlplus on Windows did not like the quoted connection string:<\/p>\n<p><code>C:\\oracle\\instant_client_12_1&gt;sqlplus adminuser@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=really.long.aws.string)(PORT=1521))(CONNECT_DATA=(SID=devdb)))<br \/>\nSQL*Plus: Release 12.1.0.2.0 Production on Fri Oct 16 19:44:19 2015<\/p>\n<p>Copyright (c) 1982, 2014, Oracle.  All rights reserved.<\/p>\n<p>Enter password:<\/p>\n<p>Connected to:<br \/>\nOracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production<br \/>\nWith the Partitioning, Oracle Label Security, OLAP, Data Mining,<br \/>\nOracle Database Vault and Real Application Testing options<\/p>\n<p>SQL&gt;<\/code><\/p>\n<p>It worked! Everything seemed quite straightforward once I&#8217;d made all the obvious mistakes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A database isn&#8217;t very useful if you can&#8217;t connect to it. I describe my steps and mis-steps connecting to an Oracle database running as an AWS RDS instance using SQL*Plus on Linux and Windows.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[575,282],"tags":[363,278,274,364,368],"class_list":["post-1243","post","type-post","status-publish","format-standard","hentry","category-aws","category-oracle-2","tag-aws","tag-database","tag-oracle","tag-rds","tag-sqlplus"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1243"}],"version-history":[{"count":15,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1243\/revisions"}],"predecessor-version":[{"id":1351,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1243\/revisions\/1351"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}