Programming Languages on Power

Power Programming Languages

IBM Power, including the AIX, IBM i, and Linux operating systems, support a wide range of programming languages, catering to both traditional enterprise applications and modern development needs.


#Power


#Servers
#Programminglanguages
 View Only
Expand all | Collapse all

How do I address SQL7008 error with reason 9

  • 1.  How do I address SQL7008 error with reason 9

    Posted 10/11/24 12:50 PM
    Edited by Patrick Conner 10/11/24 03:15 PM

    I'm helping a coworker that received the following message when trying to insert a record:

    2024-10-11 05:39:04,959 ERROR o.h.e.j.s.SqlExceptionHelper [ForkJoinPool.commonPool-worker-1] [SQL7008] SQROLEINFO in SQAATYPE9 not valid for operation. Cause . . . . . : The reason code is 9.

    9 -- Index is currently held or is not valid.

    Do one of the following based on the reason code: 1 -- blah blah... 9 -- Use the EDTRBDAP command to change the sequence of the access path from HELD to 1-99 or * OPN, or rebuild or delete the unique index or constraint.

    I tried using EDTRGDAP, but the file in question doesn't show in the list.

    I investigated the indexes using ACS and found the primary key constraint shows 'No' in the valid column. The 'current key values' shows -1 which I thought is odd, but I don't know if it is related.

    Any suggestions on how to handle SQL7008 error with reason code 9?



    ------------------------------
    Patrick Conner
    ------------------------------


    #SQL


  • 2.  RE: How do I address SQL7008 error with reason 9

    Posted 10/11/24 05:05 PM

    To resolve this issue I dropped the primary key and added it back which I'm guessing is the standard way to 'rebuild' a primary key constraint. At first the constraint could not be added due to a duplicate key value on two rows. Once I cleaned up the data, I was able to add the constraint. I'm curios as to how a duplicate key was allowed while the constraint was in place. Does a duplicate key slip past the primary key occasionally?



    ------------------------------
    Patrick Conner
    ------------------------------



  • 3.  RE: How do I address SQL7008 error with reason 9

    Posted 10/14/24 09:47 PM
    Edited by Satid S 10/14/24 09:49 PM

    Dear Patrick

    >>>> Does a duplicate key slip past the primary key occasionally? <<<<

    I wonder if this is a known bug? Or a quirk in its operation when encountering some rare situation?    The latter point reminds me of the early days when I began my career with AS/400 in early 1990s and I found in a few customer cases data corruption errors when reading data from physical files with Query/400 which made me wonder why my customers wrote corrupted data or was it physical disk issue?    I encountered an enlightening moment a few years later reading a published article by a member of DB2 expert team from IBM Rochester that DDS-created PF DOES NOT do data validation at write time but does it at read time while SQL-created table does data validation at write time and this difference is a cause of possible write of corrupt data into DDS-created PF for some situations. 



    ------------------------------
    Satid S
    ------------------------------



  • 4.  RE: How do I address SQL7008 error with reason 9

    Posted 10/15/24 08:34 AM

    Interesting... I thought validation time (before/after) was determined by the language used. I understood that RPG validates data when retrieving records and SQL validates when outputting rows. But I digress. 

    The situation still makes no sense because I know DDS unique keys are honored as well as DDL primary keys. Focusing on the primary key which was the constraint that was violated, I assume I have to consider the duplicate a glitch and just move on.



    ------------------------------
    Patrick Conner
    ------------------------------



  • 5.  RE: How do I address SQL7008 error with reason 9
    Best Answer

    Posted 10/15/24 10:20 AM

    The DDS validation is limited to decimal data validation.  Unique keys are always enforced on SQL & non-SQL interfaces.

    I'd say in general that the situation you describe primarily happens in rare defect situations.  There's a VLOG that gets written by Db2 when this happens to try to capture the root cause of the index invalidation.



    ------------------------------
    Kent Milligan
    ------------------------------



  • 6.  RE: How do I address SQL7008 error with reason 9

    Posted 10/15/24 09:12 PM
    Edited by Satid S 10/15/24 09:15 PM
      |   view attached

    Dear Patrick

    I attach herewith the article I mentioned in case you are curious. IIRC, the article was published in NEWS3X/400 magazine (or was it when the magazine changed its name to iSeries Magazine? I do not remember exactly) if you recognize the name. 



    ------------------------------
    Satid S
    ------------------------------



  • 7.  RE: How do I address SQL7008 error with reason 9

    Posted 10/16/24 08:27 AM

    Thanks Satid. I'm always willing to learn.



    ------------------------------
    Patrick Conner
    ------------------------------



  • 8.  RE: How do I address SQL7008 error with reason 9

    Posted 10/23/24 09:11 AM

    I discovered that the invalidation reason does get logged and can be retrieved:

    select system_index_name, system_table_name, system_table_partition, index_type, accpth_type, create_timestamp, last_build_timestamp, last_invalidation_timestamp, last_invalidation_reason_code, last_invalidation_reason_type, index_held, maintenance, recovery, index_valid, unique, partitioned

      from qsys2.SYSPARTITIONINDEXES x

      where system_table_schema = 'MYSCHEMA'  and system_table_name ='MYTABLE'

      order by system_table_schema, system_table_name, system_table_partition, system_index_name



    ------------------------------
    Kent Milligan
    ------------------------------



  • 9.  RE: How do I address SQL7008 error with reason 9

    Posted 11/22/24 12:33 PM

    thanks Kent



    ------------------------------
    Patrick Conner
    ------------------------------



  • 10.  RE: How do I address SQL7008 error with reason 9

    Posted 10/15/24 09:52 AM
    Edited by Robert Berendt 01/08/25 03:55 PM

    Are you sure that it ever had the primary key constraint?  You remarked that it said No on the primary key constraint.  It is possible to create a pf with a key but it not be declared unique.  I know of one software company who does not key their PFs, and doesn't enforce unique on their LFs.  Instead, they choose to enforce this all via code.  After doing some migrations and mergers it's quite easy to duplicate rows in that situation.

    I can slip a duplicate key in this:

    R ABR                                          
      MYKEY         11A         ALIAS(I_AM_THE_KEY)
      MYDATA        10A         ALIAS(I_AM_DATA)   
    K MYKEY                                        

    but not this:

                                UNIQUE             
    R ABR                                          
      MYKEY         11A         ALIAS(I_AM_THE_KEY)
      MYDATA        10A         ALIAS(I_AM_DATA)   

    K MYKEY                          

    Satid is right about the  DDS not checking at write time.  I have published samples of how to cram invalid data into numerics in DDS that DDL would stop cold.  It's really simple and no advanced bit twiddling needed.           



    ------------------------------
    Robert Berendt IBMChampion
    Business Systems Analyst, Lead
    Dekko
    Fort Wayne
    ------------------------------



  • 11.  RE: How do I address SQL7008 error with reason 9

    Posted 10/23/24 04:19 PM
    Edited by Rich Malloy 10/23/24 04:44 PM

    Hi Patrick. I can tell you from some personal and mostly 'recent' experience this can definitely happen if the table/access path encounters just the 'right amount of damage' to it. Once the AP is damaged and the constraint is invalid  - the wild wild west can occur for sure.  And of course, once you find this out, finding and removing the duplicates is a lot of fun as well. In my case, it was a result of a system crash , after the recovery of that event - it took us a good couple of weeks to proactively identify all tables/constraints that ended up having an issue and then of course, finding all the records in the tables that were "duplicates" based on the key of the table. I will also tell you that the recovery wasn't always the same - using IBM's favorite answer to most any question.. "It Depends"..... Glad the extent of your issue was isolated/limited ...!


    As FYI - this was a doc IBM pointed me to using in order to help resolve my issues. Note - I think this doc is a little misleading and needs to be updated some but it was largely accurate and very helpful. 

    https://www.ibm.com/support/pages/index-check-tool-ibm-i-71-and-higher-releases

    ------------------------------
    Rich Malloy
    ------------------------------



  • 12.  RE: How do I address SQL7008 error with reason 9

    Posted 11/25/24 04:08 AM

    Patrick, 

    To add to the wealth of information that the others have posted (and out of personal experience) something that might also explain the anomaly. 

    It is possible to have constraints defined but that are not active, some might disable them for some reason unknown. 

    It's likely that a constraint was enabled at some stage but with no data checking (possibly also for a slight minute or two when a process wrote the records). 

    We found out the hard way with a role swap that ended up having inconsistencies due to the constraint differences, developers enabled to constraints but turned off the actual data checks from that. this somewhat I am not sure why the database engineers enable that functionality when it comes to Data Integrity. 

    Our solution was that we had to go through each constraint , disable -> reenable WITH data check in ACS and fix data as it errors out. 


    Perhaps something to look at as well in your environment. 



    ------------------------------
    Marius le Roux
    Owner
    MLR Consulting
    ------------------------------



  • 13.  RE: How do I address SQL7008 error with reason 9

    Posted 11/25/24 09:05 AM
    Edited by Robert Berendt 01/08/25 03:55 PM

    https://www.ibm.com/docs/en/i/7.5?topic=views-syscst

    select *
    from qsys2.syscst
    where ENABLED = 'NO'
    ;



    ------------------------------
    Robert Berendt IBMChampion
    Business Systems Analyst, Lead
    Dekko
    Fort Wayne
    ------------------------------