snippetModerate
How do I find my current SCN?
Viewed 0 times
findscncurrenthow
Problem
Given any version of Oracle:
- How do I find my current SCN?
- What is the maximum possible SCN?
Solution
Current SCN
Oracle 9i:
Oracle 10g and above:
SCN Limits
SCN has a hard limit imposed by its format and a soft limit imposed artificially by Oracle, as described here. I've quoted the relevant portions below (emphasis added).
Hard Limit
The architects of Oracle's flagship database application must have
been well aware the SCN needed to be a massive integer. It is: a
48-bit number (281,474,976,710,656). It would take eons for an Oracle
database to eclipse that number of transactions and cause problems --
or so you might think.
Soft Limit
The soft limit derives from a very simple calculation anchored to a
point in time 24 years ago: Take the number of seconds since 00:00:00
01/01/1988 and multiply that figure by 16,384. If the current SCN
value is below that, then all is well and processing continues as
normal. To put this in simple terms, the calculation assumes that a
database running constantly since 01/01/1988, processing 16,384
transactions per second, cannot exist in reality.
SCN Limit Check
This script (Oracle 10g and above) will check how much of the hard and soft limits you have exhausted. Thanks to Rob for calling out the soft limit.
Oracle 9i:
SELECT dbms_flashback.get_system_change_number as current_scn
FROM DUAL;Oracle 10g and above:
SELECT current_scn
FROM V$DATABASE;SCN Limits
SCN has a hard limit imposed by its format and a soft limit imposed artificially by Oracle, as described here. I've quoted the relevant portions below (emphasis added).
Hard Limit
The architects of Oracle's flagship database application must have
been well aware the SCN needed to be a massive integer. It is: a
48-bit number (281,474,976,710,656). It would take eons for an Oracle
database to eclipse that number of transactions and cause problems --
or so you might think.
Soft Limit
The soft limit derives from a very simple calculation anchored to a
point in time 24 years ago: Take the number of seconds since 00:00:00
01/01/1988 and multiply that figure by 16,384. If the current SCN
value is below that, then all is well and processing continues as
normal. To put this in simple terms, the calculation assumes that a
database running constantly since 01/01/1988, processing 16,384
transactions per second, cannot exist in reality.
SCN Limit Check
This script (Oracle 10g and above) will check how much of the hard and soft limits you have exhausted. Thanks to Rob for calling out the soft limit.
WITH limits AS (
SELECT
current_scn
--, dbms_flashback.get_system_change_number as current_scn -- Oracle 9i
, (SYSDATE - TO_DATE('1988-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')) * 24*60*60 * 16384
AS SCN_soft_limit
, 281474976710656 AS SCN_hard_limit
FROM V$DATABASE
)
SELECT
current_scn
, current_scn/scn_soft_limit*100 AS pct_soft_limit_exhausted
, scn_soft_limit
, current_scn/scn_hard_limit*100 AS pct_hard_limit_exhausted
, scn_hard_limit
FROM limits;Code Snippets
SELECT dbms_flashback.get_system_change_number as current_scn
FROM DUAL;SELECT current_scn
FROM V$DATABASE;WITH limits AS (
SELECT
current_scn
--, dbms_flashback.get_system_change_number as current_scn -- Oracle 9i
, (SYSDATE - TO_DATE('1988-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')) * 24*60*60 * 16384
AS SCN_soft_limit
, 281474976710656 AS SCN_hard_limit
FROM V$DATABASE
)
SELECT
current_scn
, current_scn/scn_soft_limit*100 AS pct_soft_limit_exhausted
, scn_soft_limit
, current_scn/scn_hard_limit*100 AS pct_hard_limit_exhausted
, scn_hard_limit
FROM limits;Context
StackExchange Database Administrators Q#11405, answer score: 17
Revisions (0)
No revisions yet.