Oracle database is a very popular relational database, but during use, we often encounter the problem of database connection timeout. This problem may cause a series of troubles such as data transmission interruption and performance degradation. So, how to set the timeout in Oracle database? This article will introduce you to the specific method.
1. Principle of timeout setting
In Oracle, the timeout period is implemented through SQLnet read and write timeout parameters. SQLnet is a network component of Oracle Database that provides support for communication between clients and servers. When executing a timeout, the client issues a request. When the server does not respond, the client waits for the specified time. If the waiting time exceeds the specified timeout, the connection will be disconnected.
Normally, there are two types of Oracle timeout settings:
1. Session-level timeout
Session-level timeout is effective for a single session, through the ALTER SESSION command to set.
2.SQLNET level timeout
SQLNET level timeout is valid for all sessions of the entire SQLNET connection and is set by modifying the SQLNET.ORA file. SQLNET.ORA is Oracle's network configuration file, in which SQLNET-level parameters can be defined.
You can choose the appropriate timeout setting method according to the actual situation.
2. Session-level timeout setting
In Oracle, you can use the ALTER SESSION command to set the session-level timeout. The syntax is as follows:
ALTER SESSION SET SQL_TRACE = TRUE | FALSE;
Among them, SQL_TRACE = TRUE means enabling tracking mode. In this mode, Oracle database will record the execution of all SQL statements. .
ALTER SESSION SET SQL_TRACE = FALSE;
SQL_TRACE = FALSE means disabling tracing mode.
You can set the TIMED_STATISTICS parameter to true when SQL_TRACE = TRUE to enable the output of statistical information in tracking mode, as shown below:
ALTER SESSION SET TIMED_STATISTICS = TRUE;
For session-level timeouts, this can be achieved by setting the SQLNET.ALLOWED_LOGON_VERSION parameter to 10 or higher.
SQLNET.ALLOWED_LOGON_VERSION is a SQLNET.ORA parameter that defines which Oracle database versions can be authenticated. For example, when allowing Oracle 10g for authentication, you can set this parameter:
SQLNET.ALLOWED_LOGON_VERSION_CLIENT = 10
This will allow clients connected to the Oracle 10g database to connect.
3. SQLNET level timeout setting
SQLNET level timeout is based on the parameter setting of the SQLNET.ORA file. The SQLNET.ORA file is usually located in a specific directory on the Oracle client or server.
In the SQLNET.ORA file, you can control the SQLNET level timeout by setting two parameters, namely SQLNET.INBOUND_CONNECT_TIMEOUT and SQLNET.OUTBOUND_CONNECT_TIMEOUT.
SQLNET.INBOUND_CONNECT_TIMEOUT is a parameter on the server side, used to control the time when the server accepts client sessions.
SQLNET.OUTBOUND_CONNECT_TIMEOUT is a parameter of the client, used to control the time when the client connects to the server.
By setting these two parameters, you can prevent long-term connections between the client and the server, thereby avoiding wasting too much time and resources on the connection.
Add the following parameters in the SQLNET.ORA file to set SQLNET.INBOUND_CONNECT_TIMEOUT:
INBOUND_CONNECT_TIMEOUT_LISTENER = 120
Set the timeout for the server to accept client sessions to 120 seconds.
Add the following parameters in the SQLNET.ORA file to set SQLNET.OUTBOUND_CONNECT_TIMEOUT:
SQLNET.OUTBOUND_CONNECT_TIMEOUT=10
Set the timeout for the client to connect to the Oracle server to 10 Second.
It should be noted that when modifying parameters by modifying the SQLNET.ORA file, you need to restart the Oracle database or Oracle listener to make the parameters take effect.
4. How to verify whether the timeout setting takes effect
After you complete the setting of the Oracle timeout time, how to verify whether it takes effect? This can be verified through Oracle's v$session dynamic view or by tracing SQL statements.
- Verification through v$session view
You can view the current session of the user through the following SQL statement:
SELECT * FROM v$session WHERE sid = '&sid';
The &sid here is the SID of the current user, which can be obtained through the following SQL statement:
SELECT sid, serial# FROM v$session WHERE username = '&username' ;
After finding the specified SESSION, you can query the CONNECT_TIME and IDLE_TIME parameters of the SESSION to determine whether it is effective.
- Trace SQL statements
If you need to trace the SQL statements of the Oracle database, you can set the TRACEFILE_IDENTIFIER parameter of SESSION and use the Oracle Trace tool to trace the SQL statements. It should be noted here that you need SYSDBA or SYSOPER permissions to perform tracking operations.
You can verify whether the Oracle timeout settings are valid through the above two methods. If the settings are found to be invalid, you can troubleshoot by checking whether the SQLNET.ORA file is configured completely and correctly.
Summarize
In the Oracle database, since long-term connections will affect system performance and other factors, the connections need to be controlled. Through the ALTER SESSION command and the settings of the SQLNET.ORA file introduced in this article, you can set the timeout for the Oracle database. Of course, in actual use, it is necessary to choose the appropriate timeout setting method according to different environments and actual needs.
Note: This article refers to many excellent materials. If there is any infringement, please contact us to delete it.
The above is the detailed content of How to set timeout in Oracle database. For more information, please follow other related articles on the PHP Chinese website!

Oracle's product ecosystem includes databases, middleware and cloud services. 1. OracleDatabase is its core product, supporting efficient data storage and management. 2. Middleware such as OracleWebLogicServer connects to different systems. 3. OracleCloud provides a complete set of cloud computing solutions.

MySQL and Oracle each have advantages in performance, scalability, and security. 1) Performance: MySQL is suitable for read operations and high concurrency, and Oracle is good at complex queries and big data processing. 2) Scalability: MySQL extends through master-slave replication and sharding, and Oracle uses RAC to provide high availability and load balancing. 3) Security: MySQL provides fine-grained permission control, while Oracle has more comprehensive security functions and automation tools.

Oracle is called the "Powerhouse" of database management because of its high performance, reliability and security. 1. Oracle is a relational database management system that supports multiple operating systems. 2. It provides a powerful data management platform with scalability, security and high availability. 3. Oracle's working principles include data storage, query processing and transaction management, and supports performance optimization technologies such as indexing, partitioning and caching. 4. Examples of usage include creating tables, inserting data, and writing stored procedures. 5. Performance optimization strategies include index optimization, partition table, cache management and query optimization.

Oracleoffersacomprehensivesuiteofproductsandservicesincludingdatabasemanagement,cloudcomputing,enterprisesoftware,andhardwaresolutions.1)OracleDatabasesupportsvariousdatamodelswithefficientmanagementfeatures.2)OracleCloudInfrastructure(OCI)providesro

The development history of Oracle software from database to cloud computing includes: 1. Originated in 1977, it initially focused on relational database management system (RDBMS), and quickly became the first choice for enterprise-level applications; 2. Expand to middleware, development tools and ERP systems to form a complete set of enterprise solutions; 3. Oracle database supports SQL, providing high performance and scalability, suitable for small to large enterprise systems; 4. The rise of cloud computing services further expands Oracle's product line to meet all aspects of enterprise IT needs.

MySQL and Oracle selection should be based on cost, performance, complexity and functional requirements: 1. MySQL is suitable for projects with limited budgets, is simple to install, and is suitable for small to medium-sized applications. 2. Oracle is suitable for large enterprises and performs excellently in handling large-scale data and high concurrent requests, but is costly and complex in configuration.

Oracle helps businesses achieve digital transformation and data management through its products and services. 1) Oracle provides a comprehensive product portfolio, including database management systems, ERP and CRM systems, helping enterprises automate and optimize business processes. 2) Oracle's ERP systems such as E-BusinessSuite and FusionApplications realize end-to-end business process automation, improve efficiency and reduce costs, but have high implementation and maintenance costs. 3) OracleDatabase provides high concurrency and high availability data processing, but has high licensing costs. 4) Performance optimization and best practices include the rational use of indexing and partitioning technology, regular database maintenance and compliance with coding specifications.

Steps to delete the failed database after Oracle failed to build a library: Use sys username to connect to the target instance. Use DROP DATABASE to delete the database. Query v$database to confirm that the database has been deleted.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function