在使用ADG进行读写分离的时候,备库偶尔会报无法连接,而且无法连接的用户具有随机性。经检查发现主库上面有个trigger用于屏蔽dblink,而判断条件与audsid有关。由于备库是只读的,所以所有登录的用户使用同一个audsid号(4294967295),因此造成了trigger判断错误。那么audsid到底是做什么的呢?
AUDSID
AUDSID由SYS.AUDSES$这个SEQUENCE产生,当有一个新的会话产生,其AUDSID的值即为这个SEQUENCE的NEXTVAL。
Oracle 10g之前,在会话为’CONNECT INTERNAL’ 或为oracle进程是Oracle后台进程这两种情况的时候,AUDSID的值为0。’CONNECT INTERNAL’即指以AS SYSDBA和AS SYSOPER连接的会话。
10g及之后,AUDSID在’CONNECT INTERNAL’ 时为UB4MAX(4294967295), 在Oracle后台进程连接时为0。具体如下:
If AUDSID=0, then就是 Oracle后台进程产生的一个会话。 If AUDSID=4294967295,
then说明是sys用户产生的一个会话。 If 0<AUDSID<4294967295,then说明是普通用户产生的一个会话。AUDSID在后台存储为8位16进制
4294967295=>FFFFFFFF,在v$session中字段长度为10,其最大值由SYS.AUDSES$决定。
AUDSID由SYS.AUDSES$这个SEQUENCE(即序列,这种数据库对象)产生, 由desc SYS.AUDSES$提示证明他是个SEQUENCE(即序列,这种数据库对象)。
Sessionsconnecting to an Oracle database have a number of identifiers
assigned to themwhich can be found in the V$SESSION dynamic view.
–当session 连接到Oracle 数据库时,会分配一个标识号,这个标识号可以从v$session 这个视图里查询。
One of theseidentifiers is V$SESSION.AUDSID. Thisidentifier is
particularly useful because it can also be obtained by a sessionusing
the SQL function USERENV(‘SESSIONID’). In this way, a session can find
its own session-related information.
–其中一个标识符就是v$session.audsid. 这个标识符非常有用,因为它也可以用SQL 函数USERENV(‘SESSIONID’)来获取,这样,session 就可以发现其关联的信息。
SQL> select userenv('SESSIONID') from dual;
USERENV('SESSIONID')
--------------------
13591
--查看当前的Auditingsession id
This AuditingSession ID is determined when the user connects to the
database and is aconstant value for the duration of the session.
–AUDID 决定用户是什么时候连接到数据库的,在session 活动期间,该值是不变的。
The value thatis assigned to AUDSID is taken from a sequence in the
Oracle Data Dictionary,the sequence SYS.AUDSES$. When AUDSID
isassigned to a new session the SYS.AUDSES$ sequence is incremented
using NEXTVALand the new value is assigned to the session.
–那么session 分配的AUDSID 值是从SYS.AUDSES$序列中获取的,当分配时,SYS.AUDSES$会使用nextval 增加,然后赋值给session。
However, not allsessions get an AUDSID: Sessions connecting as
‘internal’ do not increment theSYS.AUDSES$ sequence and the value of
their AUDSID is 0.
–但是,不是所有的session 都可以获取到AUDSID值。 用internal连接时,就不会增加SYS.AUDSES$序列,其对应session 的AUDSID 值是0.
---查询下一个序列值
SQL>select AUDSES$.nextval from dual;
---查询当前序列值
SQL>select AUDSES$.currval from dual;