我们可以通过Oracle视图v$session来查看当前数据库中的所有会话信息,其中该视图有一列为status标志会话状态,Oracle官方文档对这
我们可以通过Oracle视图v$session来查看当前数据库中的所有会话信息,其中该视图有一列为status标志会话状态,Oracle官方文档对这一列定义如下
STATUS
VARCHAR2(8) Status of the session:ACTIVE - Session currently executing
INACTIVE
KILLED - Session marked to be killed
CACHED - Session temporarily cached for use by Oracle*XA
SNIPED - Session inactive, waiting on the client
通过我们遇到的都是ACTIVE,INACTIVE,KILLED三种状态
1、active 会话处于活动状态,当前session正在执行sql语句
2、inactive会话处于不活动状态,,sql语句已经执行完毕,但是由于某种原因,会话和后台进程没有释放,通过我们在sqlplus中退出和类似plsql developer工具log out或者直接退出,都是直接关闭会话,而不是将会话置于inactive状态,下面以sqlplus命令为例
[oracle@oracle11g ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu May 23 23:09:30 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select count(*) from v$process;
COUNT(*)
----------
30
SQL>
开启另一会话窗口,查询会话数量
SQL>select count(*) from v$session;
查询结果是27个会话
我们退出之前的会话
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@oracle11g ~]$
再次查询会话数量,结果是26。说明会话已经释放。而通常情况下inactive会话比较多的情况下是我们采用jboss,weblogic之类的中间件,建立连接池,而连接使用完毕之后并未释放连接,仍然将连接放回到连接池的情况。
我本机上采用weblogic连接池,连接到oracle,设置初始连接数量是5,我们通过查询
SQL> set linesize 150
SQL> select s.SID,s.SERIAL#,s.OSUSER,s.USERNAME,s.STATUS,s.PROGRAM from v$session s where s.STATUS='INACTIVE' and s.USERNAME='TEST';
SID SERIAL# OSUSER USERNAME STATUS PROGRAM
---------- ---------- ------------------------------ ------------------------------ -------- ------------------------------------------------
16 64 Administrator TEST INACTIVE JDBC Connect Client
21 28 Administrator TEST INACTIVE JDBC Connect Client
141 164 Administrator TEST INACTIVE JDBC Connect Client
142 93 Administrator TEST INACTIVE JDBC Connect Client
145 30 Administrator TEST INACTIVE JDBC Connect Client
由于会话的创建和释放都需要耗费一定的资源,应用端往往会通过连接池来缓存会话。如果inactive会话过多,不建议直接kill session,毕竟应用的稳定性是第一位的,可以考虑调整应用连接池的数量,或者考虑增加processes的数量。
3、killed处于此状态的会话,被标注为删除,表示出现了错误,正在回滚
当然,也是占用系统资源的。还有一点就是,killed的状态一般会持续较长时间,而且用windows下的工具pl/sql developer来kill掉,是不管用的,要用命令:alter system kill session 'sid,serial#' ; 可以通过此方式来解除死锁。

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

MySQL is an efficient relational database management system suitable for storing and managing data. Its advantages include high-performance queries, flexible transaction processing and rich data types. In practical applications, MySQL is often used in e-commerce platforms, social networks and content management systems, but attention should be paid to performance optimization, data security and scalability.

The relationship between SQL and MySQL is the relationship between standard languages and specific implementations. 1.SQL is a standard language used to manage and operate relational databases, allowing data addition, deletion, modification and query. 2.MySQL is a specific database management system that uses SQL as its operating language and provides efficient data storage and management.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor