MAX_IDLE_TIME & IDLE_TIME oracle
Posted DBA更进一步:不再安分的时代
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MAX_IDLE_TIME & IDLE_TIME oracle相关的知识,希望对你有一定的参考价值。
https://docs.oracle.com/en/database/oracle/oracle-database/12.2/refrn/MAX_IDLE_TIME.html#GUID-9E26A81D-D99E-4EA8-88DE-77AF68482A20
1.179 MAX_IDLE_TIME
MAX_IDLE_TIME
specifies the maximum number of minutes that a session can be idle. After that point, the session is automatically terminated.
Property | Description |
---|---|
Parameter type |
Integer |
Default value |
0 |
Modifiable |
|
Modifiable in a PDB |
Yes |
Range of values |
0 to the maximum integer. The value of 0 indicates that there is no limit. |
Basic |
No |
Oracle RAC |
Different instances can use different values. |
https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/CREATE-PROFILE.html#GUID-ABC7AE4D-64A8-4EA9-857D-BEF7300B64C3
IDLE_TIME
ALTER PROFILE app_user LIMIT IDLE_TIME DEFAULT;
Oracle Database enforces resource limits in the following ways:
-
If a user exceeds the
CONNECT_TIME
orIDLE_TIME
session resource limit, then the database rolls back the current transaction and ends the session. When the user process next issues a call, the database returns an error. -
If a user attempts to perform an operation that exceeds the limit for other session resources, then the database aborts the operation, rolls back the current statement, and immediately returns an error. The user can then commit or roll back the current transaction, and must then end the session.
-
If a user attempts to perform an operation that exceeds the limit for a single call, then the database aborts the operation, rolls back the current statement, and returns an error, leaving the current transaction intact.
torndb
torndb是tornado框架封装使用MySQLdb,十分方便。
class Connection(object): def __init__(self, host, database, user=None, password=None, max_idle_time=7 * 3600, connect_timeout=0, time_zone="+0:00", charset = "utf8", sql_mode="TRADITIONAL"): self.host = host self.database = database self.max_idle_time = float(max_idle_time)
参数
在这里,可以学到几种参数的传输
*;一个星号代表的是tuple,元组
**;双星号代表的是字典
还有一种user=None,是为了防止没有这个参数
初始化
host:主机号
database:数据库名
user=None
password=None
charset:utf-8 编码
time_zone:时区
max_idle_time:待了解
connect_timeout
sql_mode:
self.host = host self.database = database self.max_idle_time = float(max_idle_time)
max_idle_time:不知道他的作用
args = dict(conv=CONVERSIONS, use_unicode=True, charset=charset, db=database, init_command=(‘SET time_zone = "%s"‘ % time_zone), connect_timeout=connect_timeout, sql_mode=sql_mode)
使用dict()生成一个字典:他的作用现在也不知道
if user is not None: args["user"] = user if password is not None: args["passwd"] = password
如果用户,密码存在,就加到args字典中去
# We accept a path to a MySQL socket file or a host(:port) string if "/" in host: args["unix_socket"] = host else: self.socket = None pair = host.split(":") if len(pair) == 2: args["host"] = pair[0] args["port"] = int(pair[1]) else: args["host"] = host args["port"] = 3306
“/”和“\”
windows下是\,linux和unix下是/
self._db = None self._db_args = args self._last_use_time = time.time()
self._last_use_time = time.time()
算的是1970年1月1日至今的时间秒数
self._db = None:置为空,这个是MySQLdb连接的db
try: self.reconnect() except Exception: logging.error("Cannot connect to MySQL on %s", self.host, exc_info=True)
reconnect
这里调用self.reconnect()方法,那就看看他是干嘛的
def reconnect(self): """Closes the existing database connection and re-opens it.""" self.close() self._db = MySQLdb.connect(**self._db_args) self._db.autocommit(True)
关闭存在的数据库连接,然后重新连接他
self._db = MySQLdb.connect(**self._db_args) MySQLdb的连接
self._db.autocommit(True)
autocommit属性设置为True:这样设置的作用是自动提交
close 关闭数据库的连接
def close(self): """Closes this database connection.""" if getattr(self, "_db", None) is not None: self._db.close() self._db = None
获取对象(自己本身)的“_db”属性是不是None,不是的话,就关闭,并且置为None
def __del__(self): self.close()
python 类的__del__方法
__del__方法
当一个类实例删除时被调用
def query(self, query, *parameters, **kwparameters): """Returns a row list for the given query and parameters.""" cursor = self._cursor() try: self._execute(cursor, query, parameters, kwparameters) if cursor.description: column_names = [d[0] for d in cursor.description] return [Row(itertools.izip(column_names, row)) for row in cursor] return None finally: cursor.close()
_cursor方法:cursor的意思是数据库中的游标,一种查询方法
def _cursor(self): self._ensure_connected() return self._db.cursor()
以上是关于MAX_IDLE_TIME & IDLE_TIME oracle的主要内容,如果未能解决你的问题,请参考以下文章
局域网内连接服务端oracle数据库,用数据库工具例如(obj9 ,plsql)连接一定时间就断开了,怎么保持连接?
[4G&5G专题-92]:流程 - 4G LTE 终端在RRC IDLE空闲状态下的小区选择与小区重选
[4G&5G专题-90]:流程 - 4G LTE 终端在RRC IDLE状态下的行为