AWS RDS Oracle DB remote connection

本文介绍了通过多种方式连接部署在AWS RDS上的Oracle数据库实例的过程。包括使用Oracle SQL Developer、SQL Plus进行连接的方法,以及从Windows和Linux环境中连接的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Created the Oracle EE on the AWS RDS, tried different methods to connect the created AWS RDS through internet.

1, install Oracle SQL developer, and SQL Plus on Windows, required JDK.
2, in RDS Security Groups, allow the inbound and outbound Oracle RDS TCP connection, port 1521
3, telnet to test the Endpoint and port 1521 is open and connectable, the format is "Telnet Endpoint(your end point string) 1521"
4, windows SQL plus command line to connect to the AWS RDS, the format as below, for windows Command line, should be without quotation mark ', and needs to change the user name, HOST is the endpoint string, SID is the database you created.

PROMPT>sqlplus mydbusr@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracledb.mydnsnameexample.rds.amazonaws.com)
(PORT=1521))(CONNECT_DATA=(SID=oracledb)))

after successful connection, the command line will display:
SQL*Plus: Release 11.2.0.1.0 Production on Tue May 17 12:59:07 2016

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

Enter password:

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options

SQL

5, Oracle SQL developer to connect AWS RDS Oracle EE in Windows
fill in the username, password, HostName (the Endpoint string), port (1521), SID (DB name), then click "test", it will test the connection, and "Connect" to Connect to the AWS RDS Oracle EE.

6, Connect AWS RDS Oracle EE from AWS EC2 Linux RHEL 7

Installed below three RPM,
oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

It is RPM file, for Ubuntu install, require to use alien to generate deb file,

sudo apt-get install alien
sudo alien oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
sudo alien oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
sudo alien oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
sudo dpkg -i ./oracle-instantclient12.1-basic_12.1.0.2.0-2_amd64.deb
sudo dpkg -i ./oracle-instantclient12.1-devel_12.1.0.2.0-2_amd64.deb
sudo dpkg -i ./oracle-instantclient12.1-sqlplus_12.1.0.2.0-2_amd64.deb

The installation folder is "/usr/lib/oracle/12.1/client64/lib/" and "/usr/lib/oracle/12.1/client64/bin/"
Remember to set the environment before use sqlplus command,
LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib/:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
PATH=/usr/lib/oracle/12.1/client64/bin:${PATH}
export PATH

Error encountered: sqlplus: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

Resolved it by install libaio,
sudo apt-get install libaio1 libaio-dev

The connection result is as below,

[root@ip-172-31-2-32 ec2-user]# sqlplus 'UserName@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=Endpoint string)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))'

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 18 01:52:28 2016

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

Enter password:

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options

SQL>

Reference link:
http://osric.com/chris/accidental-developer/2015/10/connecting-to-oracle-instance-in-aws-rds/
http://docs.aws.amazon.com/AmazonRDS/2012-01-15/UserGuide/USER_ConnectToOracleInstance.html
https://docs.oracle.com/database/121/SQPUG/apd.htm#SQPUG642
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
https://www.rootusers.com/how-to-enable-the-telnet-client-in-windows-10/
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html

<think>嗯,用户想了解数据库超时等待时长的设置方法和解决方案。首先,我需要回忆一下常见的数据库连接超时问题。通常,这可能涉及到连接池配置、数据库服务器设置,还有ORM框架的参数调整。比如,用户提到的MySQL和SQLAlchemy,这两个都是常见的技术栈。 用户提到的引用里有MySQL的autoConnect属性设置为true,这可能是指JDBC的autoReconnect参数?不过我记得MySQL的官方文档其实不建议设置这个参数,因为它可能会导致连接状态不一致的问题。所以需要提醒用户这一点,可能更好的方法是调整连接池的重连机制或者增加超时时间。 然后,关于SQLAlchemy的解决方案,用户引用了使用连接池的回收和预处理设置,比如pool_recycle和pool_pre_ping。这部分需要详细说明这些参数的作用,以及如何根据实际场景调整数值。比如pool_recycle应该小于数据库的wait_timeout,避免连接被服务器断开。 接下来,我需要考虑不同数据库的设置方法。比如MySQL的wait_timeout和interactive_timeout变量,PostgreSQL的idle_in_transaction_session_timeout,Oracle的sqlnet.expire_time,还有SQL Server的remote query timeout。每个数据库的配置方式不同,需要分别说明如何查看和修改这些参数,包括通过SQL命令或者配置文件调整。 另外,用户可能不仅想知道如何设置,还想了解为什么会出现超时,以及各种解决方案的适用场景。比如,连接池配置适用于应用层,而数据库参数调整是服务器端的。需要分点说明,让结构更清晰。 还要注意用户提到的“超时等待时长设置”,这可能包括连接超时、查询超时、空闲超时等不同类型。需要分别解释这些超时的含义和对应的设置方法。例如,JDBC的connectTimeout和socketTimeout,或者HikariCP的connectionTimeout属性。 最后,生成相关问题的时候,要覆盖用户可能进一步想知道的内容,比如具体数据库的配置步骤、连接池参数优化,或者如何检测超时原因。确保问题有针对性,帮助用户深入理解。</think># 数据库连接超时等待时长设置与解决方案 ## 一、核心解决方案 1. **数据库服务器端参数调整** - MySQL:修改`wait_timeout`和`interactive_timeout`参数 ```sql SET GLOBAL wait_timeout = 28800; -- 8小时 SET GLOBAL interactive_timeout = 28800; ``` 配置文件修改示例: ```ini [mysqld] wait_timeout = 28800 interactive_timeout = 28800 ``` - PostgreSQL:设置`idle_in_transaction_session_timeout`[^2] - Oracle:配置`sqlnet.expire_time`参数 2. **连接池配置优化** ```java // HikariCP示例 HikariConfig config = new HikariConfig(); config.setMaximumPoolSize(20); config.setConnectionTimeout(30000); // 30秒连接超时 config.setIdleTimeout(600000); // 10分钟空闲超时 ``` 3. **ORM框架设置** SQLAlchemy配置示例: ```python engine = create_engine( 'mysql+pymysql://user:pass@host/db', pool_recycle=3600, # 每小时回收连接 pool_pre_ping=True # 执行前检测连接有效性 ) ``` ## 二、具体场景解决方案 1. **JDBC连接超时** - 添加连接参数: ``` jdbc:mysql://host:3306/db?connectTimeout=5000&socketTimeout=60000 ``` - 注意:`autoReconnect=true`可能引发数据不一致问题[^1] 2. **分布式事务处理** ```xml <!-- Tomcat配置 --> <Resource name="jdbc/TestDB" validationQuery="SELECT 1" testOnBorrow="true" timeBetweenEvictionRunsMillis="30000" /> ``` 3. **云数据库特殊处理** - AWS RDS:调整参数组中的超时设置 - 阿里云:通过控制台修改连接保持策略 ## 三、检测与验证方法 1. 查看当前会话状态: ```sql SHOW PROCESSLIST; -- MySQL SELECT * FROM pg_stat_activity; -- PostgreSQL ``` 2. 监控工具推荐: - Prometheus + Grafana监控连接池指标 - MySQL Workbench性能仪表盘
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值