Pages

Sunday, April 22, 2018

Golden Gate Extract is in Abended state because of OGG-01496 Failed to open target trail file

==========================
General
==========================
The issue: One of the Oracle GG (Golden Gate) EXTRACT  processes is in ABENDED status

>%cd /software/ogg/1212
/software/ogg/1212/>% ./ggsci
info all

EXTRACT     RUNNING     EXT_S_04    00:00:06      00:00:06    
EXTRACT     RUNNING     EXT_S_05    00:00:05      00:00:01    
EXTRACT     RUNNING     EXT_S_06    00:00:06      00:00:06    
EXTRACT     ABENDED     EXT_S_07    00:00:06      144:13:03   
EXTRACT     RUNNING     EXT_S_09    00:00:05      00:00:01    
EXTRACT     RUNNING     EXT_S_10    00:00:06      00:00:06    
EXTRACT     RUNNING     EXT_S_11    00:00:05      00:00:01    
EXTRACT     RUNNING     EXT_S_12    00:00:05      00:00:01    
EXTRACT     RUNNING     EXT_S_13    00:00:06      00:00:06  

==========================
Investigation and resolution
==========================
/software/ogg/1212/>% ./ggsci
VIEW REPORT EXT_S_07
...
...
Database Version:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

Database Language and Character Set:
NLS_LANGUAGE     = "AMERICAN" 
NLS_TERRITORY    = "AMERICA" 
NLS_CHARACTERSET = "AL32UTF8" 

2018-04-22 06:59:58  INFO    OGG-02089  Source redo compatibility version is: 11.2.0.4.

2018-04-22 06:59:59  WARNING OGG-02045  Database does not have streams_pool_size initialization parameter configured.

2018-04-22 07:00:00  INFO    OGG-02068  Integrated capture successfully attached to logmining server OGG$CAP_EXT_S_07 using OGGCapt
ure API.

2018-04-22 07:00:00  INFO    OGG-02086  Integrated Dictionary will be used.

Source Context :
  SourceModule            : [er.recovery]
  SourceID                : [/scratch/aime1/adestore/views/aime1_adc4150472/oggcore/OpenSys/src/app/er/recovery.c]
  SourceFunction          : [RECOVERY_initialize]
  SourceLine              : [1862]
  ThreadBacktrace         : [11] elements
                          : [/software/ogg/1212/libgglog.so(CMessageContext::AddThreadContext()+0x1e) [0x7f3ad7f15dee]]
                          : [/software/ogg/1212/libgglog.so(CMessageFactory::CreateMessage(CSourceContext*, unsigned int, ...)+0x31
c) [0x7f3ad7f12c2c]]
                          : [/software/ogg/1212/libgglog.so(_MSG_ERR_RECOVERY_OPEN_FAILED(CSourceContext*, char const*, int, CMessa
geFactory::MessageDisposition)+0x3c) [0x7f3ad7eef8fc]]
                          : [/software/ogg/1212/extract(RECOVERY_initialize()+0x3e6) [0x5623f6]]
                          : [/software/ogg/1212/extract(extract_main(int, char**)+0x34b) [0x5b0a1b]]
                          : [/software/ogg/1212/extract(ggs::gglib::MultiThreading::MainThread::ExecMain()+0x4f) [0x68743f]]
                          : [/software/ogg/1212/extract(ggs::gglib::MultiThreading::Thread::RunThread(ggs::gglib::MultiThreading::T
hread::ThreadArgs*)+0x104) [0x687694]]
                          : [/software/ogg/1212/extract(ggs::gglib::MultiThreading::MainThread::Run(int, char**)+0x8b) [0x68785b]]
                          : [/software/ogg/1212/extract(main+0x3f) [0x5b047f]]
                          : [/lib64/libc.so.6(__libc_start_main+0xfd) [0x3998c1ed1d]]
                          : [/software/ogg/1212/extract() [0x51dc59]]

2018-04-22 07:00:00  ERROR   OGG-01496  Failed to open target trail file /software/ogg/1212/dirdat/07/out/es000436, at RBA 35310590
.

2018-04-22 07:00:00  ERROR   OGG-01668  PROCESS ABENDING.

GGSCI (esp-tel-2-dbu-2) 1> ALTER EXT_I_07 ETROLLOVER

2018-04-22 08:00:46  INFO    OGG-01520  Rollover performed.  For each affected output trail of Version 10 or higher format, after starting the source extract, issue ALTER EXTSEQNO for that trail's reader (either pump EXTRACT or REPLICAT) to move the reader's scan to the new trail file;  it will not happen automatically.
EXTRACT altered.

GGSCI (esp-tel-2-dbu-2) 2> INFO EXT_I_07

EXTRACT    EXT_I_07  Initialized   2018-04-22 07:06   Status ABENDED
Checkpoint Lag       144:05:34 (updated 00:01:03 ago)
Log Read Checkpoint  Oracle Integrated Redo Logs
                     2018-04-16 07:55:12
                     SCN 3.2337132669 (15222034557)


GGSCI (esp-tel-2-dbu-2) 3> START EXTRACT EXT_I_07

Sending START request to MANAGER ...
EXTRACT EXT_I_07 starting


GGSCI (esp-tel-2-dbu-2) 4> INFO EXT_I_07

EXTRACT    EXT_I_07  Last Started 2018-04-22 08:02   Status RUNNING
Checkpoint Lag       144:06:58 (updated 00:00:06 ago)
Process ID           12870
Log Read Checkpoint  Oracle Integrated Redo Logs
                     2018-04-16 07:55:12
                     SCN 3.2337132669 (15222034557)



====================================================
What is the cause for "OGG-01496 Failed to open target trail file"?
====================================================
If existing extract output trail file was purged, it would cause the extract process to encounter this error.

By default, Extract Process writes EOF to trail file and the downstream Pump or Replicat process expect to see an EOF before switching to a next file.

The problem, is that Extract Process cannot write EOF to the current file because is was 
deleted or corrupted, and we need manually switch to next sequence file.

The solution is to use ETROLLOVER command and restart the EXTRACT.

====================================================
ETROLLOVER
====================================================
ETROLLOVER causes the extract to increment to the next trail file in the trail sequence when it restarts.


For example, if the current file is ET000002, the current file will be ET000003 when Extract restarts. 

A trail can be incremented from 000001 through 999999, and then the sequence numbering starts over at 000000.

Tuesday, April 17, 2018

Golden Gate Introduction

=========================
General
=========================
Useful reference for Oracle Golden Gate.




=========================
Short reference
=========================





Golden Gate has these Processes:
Extract
AKA CAPTURE Process
The Extract process is the extraction (capture) data from source system.
Extract runs on the source system.
Extract can be either Initial Load or Ongoing.

For Initial Load, Extract extracts (captures) a current, static set of data directly from their source objects, i.e. from Tables.

For Ongoing, Extract captures DML and DDL operations after the initial synchronization has taken place, i.e. from Database recovery logs or transaction logs (such as the Oracle redo logs or SQL/MX audit trails). 


Replicat

AKA APPLY Process
The Replicat process is Running on the Target Database.
The Goldengate Replicat process duty is to apply the changes to Target Database.

It reads the data from a file known an EXTTRAIL file which contains data changes made on the source. 

In addition, Replicat also posts its exact location of the trail file while processing records. 
This is used for recovery from crashes, allowing it to start from the exact point where it left off, without any data loss.



=========================
How to check OGG version:
=========================

When running ggcgi versions command, the version displayed is actually the version of the database. 
OGG version, is displayed in the header of login info.

/software/ogg/1212/ggcgi
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.0.0 17185003 OGGCORE_12.1.2.0.0_PLATFORMS_130924.1316_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Sep 25 2013 00:31:13
Operating system character set identified as UTF-8.


Copyright (C) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
 GGSCI (my_server) 1> versions
Operating System:
Linux
Version #1 SMP Sun Nov 10 22:19:54 EST 2013, Release 2.6.32-431.el6.x86_64
Node: esp-tel-1-dbu-2
Machine: x86_64

Database:
ERROR: Not logged into database, use DBLOGIN.

GGSCI (esp-tel-1-dbu-2) 3> DBLOGIN userid ogg  password oggpass
Successfully logged into database.

GGSCI (esp-tel-1-dbu-2) 4> VERSIONS
Operating System:
Linux
Version #1 SMP Sun Nov 10 22:19:54 EST 2013, Release 2.6.32-431.el6.x86_64
Node: esp-tel-1-dbu-2
Machine: x86_64

Database:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 - Production

NLSRTL Version 11.2.0.4.0 - Production

=========================
Golden Gate CLI Command Summary:
=========================
/software/ogg/1212/ggcgi

GGSCI Command Summary:


Object:          Command:
SUBDIRS          CREATE
ER               INFO, KILL, LAG, SEND, STATUS, START, STATS, STOP
EXTRACT          ADD, ALTER, CLEANUP, DELETE, INFO, KILL, LAG, SEND,
                 START, STATS, STATUS, STOP
EXTTRAIL         ADD, ALTER, DELETE, INFO
GGSEVT           VIEW
MANAGER          INFO, REFRESH, SEND, START, STOP, STATUS
MARKER           INFO
PARAMS           EDIT, VIEW
REPLICAT         ADD, ALTER, CLEANUP, DELETE, INFO, KILL, LAG,                        SEND, START, STATS, STATUS, STOP
REPORT           VIEW
RMTTRAIL         ADD, ALTER, DELETE, INFO
TRACETABLE       ADD, DELETE, INFO
TRANDATA         ADD, DELETE, INFO

CHECKPOINTTABLE  ADD, DELETE, CLEANUP, INFO

Usage example:
status extract EXT_01
stop extract EXT_01


Reference to commands


=========================
Golden Gate CLI
=========================
To see open Golden Gate CLI:
su - oracle

cd $OGG_HOME
./ggsci

=========================
See Info about Extract:
=========================

GGSCI (my_server) 2> INFO EXTRACT DPM_I_03

EXTRACT    DPM_I_03  Last Started 2016-12-12 15:08   Status ABENDED
Checkpoint Lag       00:00:00 (updated 00:22:07 ago)
Log Read Checkpoint  File /software/ogg/1212/dirdat/03/out/ei000000
                     First Record  RBA 0

INFO EXTRACT DPM_I_03 SHOWCH
INFO EXTRACT DPM_I_03 DETAIL
GGSCI (my_server) 4> INFO EXTRACT DPM_I_03 DETAIL

EXTRACT    DPM_I_03  Last Started 2016-12-12 15:11   Status ABENDED
Checkpoint Lag       00:00:00 (updated 00:24:35 ago)
Log Read Checkpoint  File /software/ogg/1212/dirdat/03/out/ei000000
                     First Record  RBA 0

  Target Extract Trails:

  Trail Name                                       Seqno        RBA     Max MB Trail Type

  /software/ogg/1212/dirdat/03/in/ei                   0          0        100 EXTTRAIL

  Extract Source                          Begin             End
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record
  /software/ogg/1212/dirdat/03/out/ei000000  * Initialized *   First Record


Current directory    /software/ogg/1212

Report file          /software/ogg/1212/dirrpt/DPM_I_03.rpt
Parameter file       /software/ogg/1212/dirprm/dpm_i_03.prm
Checkpoint file      /software/ogg/1212/dirchk/DPM_I_03.cpe
Process file         /software/ogg/1212/dirpcs/DPM_I_03.pce
Error log            /software/ogg/1212/ggserr.log


=========================
Data Dictionary
=========================


DBA_CAPTURE
- capture_name (OGG$CAP_EXT_I_03)
- status (ENABLED/DISABLED)
- client_name (EXT_I_03)
- client_status (ATTACHED/DETACHED)


DBA_CAPTURE_PARAMETERS
~70 paramaters per each capture_name (OGG$CAP_EXT_I_03)


DBA_CAPTURE_EXTRA_ATTRIBUTES


~5 additional parameters per each capture_name (OGG$CAP_EXT_I_03)


DBA_CAPTURE_PREPARED_DATABASE

The smallest timestamp when the local database was prepared for instantiation.


DBA_CAPTURE_PREPARED_SCHEMAS

A list of SCHEMA and their smallest scn and timestamp

DBA_CAPTURE_PREPARED_TABLES
A list of SCHEMA.TABLE and their smallest scn and timestamp


DBA_HIST_STREAMS_CAPTURE

History runs, each entry for one snap_id.


V$STREAMS_CAPTURE
Session related information (sid, serial#) for OGG capture_name.



=========================
Golden gate health checks
=========================
What to check:

- Extract parameter files from $OGG_HOME/dirprm/<extract name>.prm

- *.rpt files from $OGG_HOME/dirrpt/<extract name>.rpt)

- ggserr.log: GoldenGate Error Log

- Oracle GoldenGate healthcheck report for your database release.
  This is extracted by following technote:
GoldenGate Integrated Capture and Integrated Replicat Healthcheck Script (Doc ID 1448324.1)

- "Output of the Oracle GoldenGate OS Info Script" 
- in case of a core file, stack_xxx.txt" containing the stack trace from the failing process


=========================
Golden gate spool output
=========================

Golden Gate does not have spool option.
To spool output to a file, need to use Linux script command.

script /to/some/path/my_log.log
ggsci
OGGSCI >info extract *. detail
OGGSCI >exit

exit


=========================
Golden gate Parameter files
=========================

Parameter files are located under /software/ogg/1212/dirprm/

oracle@my_server:/software/ogg/1212/dirprm>% less ext_p_15.prm
EXTRACT ext_p_15

setenv (ORACLE_SID="igt")
setenv (ORACLE_HOME="/software/oracle/112")
setenv (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")                     

USERID ogg, PASSWORD AACAAAAAAAAAAAIAZEDCPHICXGPEQCED ENCRYPTKEY DEFAULT

EXTTRAIL /software/ogg/1212/dirdat/15/out/ep

CACHEMGR CACHESIZE 256M

-- Bi-direction replication
TRANLOGOPTIONS EXCLUDEUSER ogg
TRANLOGOPTIONS INTEGRATEDPARAMS (MAX_SGA_SIZE 256)

include ./dirprm/PROVtables_15.inc


oracle@my_server:/software/ogg/1212/dirprm>% less ext_i_15.prm
EXTRACT ext_i_15

setenv (ORACLE_SID="igt")
setenv (ORACLE_HOME="/software/oracle/112")
setenv (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")

USERID ogg, PASSWORD AACAAAAAAAAAAAIAZEDCPHICXGPEQCED ENCRYPTKEY DEFAULT

EXTTRAIL /software/ogg/1212/dirdat/15/out/ei

CACHEMGR CACHESIZE 256M

-- Bi-direction replication
TRANLOGOPTIONS EXCLUDEUSER ogg
TRANLOGOPTIONS INTEGRATEDPARAMS (MAX_SGA_SIZE 256)
--TRANLOGOPTIONS EXCLUDETAG 0180

include ./dirprm/SFItables_15.inc


oracle@esp-tel-1-dbu-2:/software/ogg/1212/dirprm>% less dpm_i_15.prm 
EXTRACT dpm_i_15

setenv (ORACLE_SID="igt")
setenv (ORACLE_HOME="/software/oracle/112")
setenv (NLS_LANG = "AMERICAN_AMERICA.AL32UTF8")

USERID ogg, PASSWORD AACAAAAAAAAAAAIAZEDCPHICXGPEQCED ENCRYPTKEY DEFAULT

RMTHOST esp-tel-2-ora-1, MGRPORT 7809, TCPBUFSIZE 100000
RMTTRAIL /software/ogg/1212/dirdat/15/in/ei
PASSTHRU

TABLE USER_A.*; 
dpm_i_15.prm (END) 

=================
rep_X_99.prm
=================
oracle@esp-tel-1-dbu-2:/software/ogg/1212/dirprm>% less rep_p_12.prm 
REPLICAT rep_p_12

setenv (ORACLE_SID="igt")
setenv (ORACLE_HOME="/software/oracle/112")
setenv (NLS_LANG = "AMERICAN_AMERICA.AL32UTF8")

ASSUMETARGETDEFS
USERID ogg, PASSWORD AACAAAAAAAAAAAIAZEDCPHICXGPEQCED ENCRYPTKEY DEFAULT

REPERROR (-1, IGNORE)

CACHEMGR CACHESIZE 256M

DISCARDFILE /software/ogg/1212/dirdat/12/in/disc12p.txt, append,

include ./dirprm/mapPROVtables_12.inc 

To reload mgr.prm without restart to ggsci
GGSCI (qanfv-1-dbs-1b) 2> view param mgr

PORT 7809
SYSLOG NONE

AUTOSTART EXTRACT *
AUTOSTART REPLICAT *
AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 2, RESETMINUTES 60
AUTORESTART REPLICAT *, RETRIES 5, WAITMINUTES 2, RESETMINUTES 60

DOWNREPORTMINUTES 5
LAGCRITICALMINUTES 5

purgeoldextracts /software/ogg/191/dirdat/01/in/*, USECHECKPOINTS, MINKEEPHOURS
3
purgeoldextracts /software/ogg/191/dirdat/01/out/*, USECHECKPOINTS, MINKEEPHOURS
 4


GGSCI (qanfv-1-dbs-1b) 3> refresh mgr

Sending REFRESH request to MANAGER ...
Mgr Params Updated


Oracle Support: Oracle GoldenGate Subdirectories
Burlson: GoldenGate directory structure tips
Start, Stop, Report, Altering Extract 


dirdat is Huge (400Gb)
$OGG_HOME/ is 100% full 

The reason is $OGG_HOME/dirdat/01/in/ and $OGG_HOME/dirdat/01/out/ got huge and old es<SEQ> files.

SEND MANAGER PURGEOLDEXTRACTS does not work.

After manually deleting old files (more than 1 month old, the REPLICAT processes are in ABENDED state.

Now do STOP EXTRACT XXX and CLEANUP EXTRACT XXX
Use CLEANUP EXTRACT to delete run history for the specified Extract group. The cleanup keeps the last run record intact so that Extract can resume processing from where it left off. Before using this command, stop Extract by issuing the STOP EXTRACT command.

Oracle GoldenGate error log 

ggserr.log


=========================
Golden Gate File Structure
=========================


Use the GGSCI SHOW command to display the instance directory structure.

GGSCI (esp-tel-1-dbu-2) 1> show

Parameter settings:

SET SUBDIRS    ON
SET DEBUG      OFF

Current directory: /software/ogg/1212

Using subdirectories for all process files

Editor:  vi

Reports (.rpt)                 /software/ogg/1212/dirrpt
Parameters (.prm)              /software/ogg/1212/dirprm
Replicat Checkpoints (.cpr)    /software/ogg/1212/dirchk
Extract Checkpoints (.cpe)     /software/ogg/1212/dirchk
Process Status (.pcs)          /software/ogg/1212/dirpcs
SQL Scripts (.sql)             /software/ogg/1212/dirsql
Database Definitions (.def)    /software/ogg/1212/dirdef
Dump files (.dmp)              /software/ogg/1212/dirdmp
Masterkey wallet files (.wlt)  /software/ogg/1212/dirwlt
Credential store files (.crd)  /software/ogg/1212/dircrd


dirprm directory
This directory is the default location for parameter files associated with group names. 
When an object created such as extract, data pump extract and replicat, a parameter file is looked at for the group name. 
Using non-default location is referenced by the parameter PARAMS <parameter file>.  Regardless of the parameter file location, the parameter file name and the group name must match.

dirrpt directory
This directory is the default location for reports and discarded records. 
Whenever a process ABENDED, a report file is created on this directory. 
The report file indicates the reasons for failure, and if the failure is database related, it also indicate the Oracle error code. 
Using non-default location is referenced by the parameter REPORT <report file>.

The Goldengate dirchk directory
This directory is for storing extract, data pump and replicat checkpoint files. 
Depending on the object type, a file is created using the group name with proper a relevant extension. 
For extract process, the checkpoint file name is <group name>.cpe. 
For replicat process, the checkpoint file name is <group name>.cpr.

dirpcs directory
This directory stores Oracle GoldenGate process identifier (PID). 
It's the PID assigned by the operating system to running program, which is associated with an Oracle GoldenGate process. 
To obtain more details, use the operating system command ps -edf | grep <group name>. 

dirsql directory
This directory is default location to store SQL Script used by Oracle GoldenGate.

dirdef directory
This directory is used to store definition files. 
Definition files are required when the source and the target tables are not identical. 
Mostly used for heterogeneous environment when mapping tables across dissimilar platforms.

dirdmp directory
Golden Gate process dump files

Below command delete dmp files older than 30 days:
find /software/ogg/1212/dirdmp/ -type f -name "*.dmp" -mtime +30 -exec rm {} \;


dirdat directory
This directory is used to start trail files. 
The trail files are identified by a two character prefix, followed by 6 digits. 
An extract or replicat processes trail files are designated by the parameter EXTTRAIL followed by the trial file location and name. 
For example, EXTTRAIL ./dirdat/sa.

dirtmp directory
This directory is the default location for Oracle GoldenGate temporary files due to capturing large transactions that goes beyond default cache size used by the extract process. 
The location and size is controlled by the CACHEMGR sub-parameters CACHESIZE, CACHEDIRECTORY and CACHEPAGEOUTSIZE. 
Also, it's always recommended to dedicate a directory location to host the temporary files, avoiding contention with other type of files.

=========================
References
=========================
Introduction

Nice Tutorial

GoldenGate Reference for Oracle GoldenGate for Windows and UNIX

Administering Oracle GoldenGate for Windows and UNIX

Oracle GoldenGate - Basic Configuration

Monday, April 16, 2018

Sequences by Example

==========================
Create Sequence
==========================
CREATE SEQUENCE my_sequence
       INCREMENT BY 1
       START WITH 1
       NOMAXVALUE
       NOCYCLE
       CACHE 10;


==========================
Fetch Sequence Next Value
==========================
SELECT my_sequence.NEXTVAL FROM DUAL;
1

==========================
See Sequence Current Number
==========================
SELECT my_sequence.CURRVAL FROM DUAL;
1

==========================
Set Sequence increment
==========================
ALTER SEQUENCE my_sequence INCREMENT BY 20
SELECT my_sequence.NEXTVAL FROM DUAL;
21

==========================
Set Sequence to New Init Value
==========================
ALTER SEQUENCE my_sequence  START WITH 101
ORA-02283: cannot alter starting sequence number

The solution it to advance sequence to N-1 number manually.
ALTER SEQUENCE my_sequence  INCREMENT BY 20
SELECT my_sequence.CURRVAL FROM DUAL;
22

ALTER SEQUENCE my_sequence  INCREMENT BY 77
SELECT my_sequence.NEXTVAL FROM DUAL;
99

ALTER SEQUENCE my_sequence  INCREMENT BY 1
100

ALTER SEQUENCE my_sequence  INCREMENT BY -99
SELECT my_sequence.NEXTVAL FROM DUAL;
1

What is advancing the sequence too low?

ALTER SEQUENCE my_sequence  INCREMENT BY -99999
SELECT my_sequence.NEXTVAL FROM DUAL;
ORA-08004: sequence MY_SEQUENCE.NEXTVAL goes below MINVALUE and cannot be instantiated

==========================
Handle MAXVALUE option
==========================
Without CYCLE Option.
DROP SEQUENCE my_sequence;
CREATE SEQUENCE my_sequence
       INCREMENT BY 1
       START WITH 1
       MAXVALUE 5
       NOCYCLE
       NOCACHE;



SELECT my_sequence.NEXTVAL FROM DUAL;

1
SELECT my_sequence.NEXTVAL FROM DUAL;
2
SELECT my_sequence.NEXTVAL FROM DUAL;
3
SELECT my_sequence.NEXTVAL FROM DUAL;
4
SELECT my_sequence.NEXTVAL FROM DUAL;
5
SELECT my_sequence.NEXTVAL FROM DUAL; 
ORA-08004: sequence MY_SEQUENCE.NEXTVAL exceeds MAXVALUE and cannot be instantiated

ALTER SEQUENCE my_sequence  INCREMENT BY -4
SELECT my_sequence.NEXTVAL FROM DUAL;
1

Or, increase MAXVALUE
ALTER SEQUENCE my_sequence MAXVALUE 20;

With CYCLE Option.
DROP SEQUENCE my_sequence;
CREATE SEQUENCE my_sequence
       INCREMENT BY 1
       START WITH 1
       MAXVALUE 5
       CYCLE
       NOCACHE;

SELECT my_sequence.NEXTVAL FROM DUAL;
1
SELECT my_sequence.NEXTVAL FROM DUAL;
2
SELECT my_sequence.NEXTVAL FROM DUAL;
3
SELECT my_sequence.NEXTVAL FROM DUAL;
4
SELECT my_sequence.NEXTVAL FROM DUAL;
5
SELECT my_sequence.NEXTVAL FROM DUAL;  
1

==========================
Invalid Options
==========================
 - Create sequence NOMAXVALUE + CYCLE

CREATE SEQUENCE my_sequence
       INCREMENT BY 1
       START WITH 1
       NOMAXVALUE
       CYCLE
       NOCACHE

ORA-04015: ascending sequences that CYCLE must specify MAXVALUE


==========================
Invalid Options
==========================
SELECT * FROM USER_SEQUENCES WHERE sequence_name = 'MY_SEQUENCE';

SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY CYCLE_FLAG ORDER_FLAG CACHE_SIZE LAST_NUMBER
------------- --------- --------- ------------ ---------- ---------- ---------- -----------
MY_SEQUENCE                             1         20            1 Y          N                   0           1