Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: HANA identity column issues after system restart

$
0
0

Hi Juste / Lars ,

 

We have faced the second issue (rename table with primary key and identity)for a production customer system. And the issue was resolved by performing a permanent workaround (own) as I mentioned below.

 

Basically the table didn't have a primary key and identity earlier. Later the identity along with PK was added to one column by creating a temp table with identity and PK  (e.g table1_tmp) and then the records were inserted into the tmp table excluding the PK column. Later the original table(table1)  was dropped and table table1_tmp was renamed to table1. After few weeks when the HANA DB was restarted , we faced this error : invalid sequence: RESET BY query is invalid.

 

After investigation and thorough testing , came to a conclusion that the issue is due to missing / in-appropriate sequence.please note that the system sequence _sys_sequence_xxxxx was originally created for table table1_tmp when you created the identity. And once you renamed the table , it seems only table name mapping is being changed for table to table1 which is in memory. If you open a sequence definition you will still see it as : select max(identity_column)+1 from table1_tmp.

 

So , after restart it tries to find the table table1_tmp in db which it could not find and throws this error.looks to be a bug but could not find any solution or fix anywhere.

 

So there are 2 workaround for this issue :

A. Temporary workaround till next db restart but quick.

B. Permanent workaround - will take some time as shown below.

 

 

A. Temporary workaround :

 

1. select max(identity_column) from table1. lets say if the value is 1000.

2. Create a table1_tmp table again but identity column with clause (START WITH 1000 increment by 1)

3. insert into table1_tmp select col1,col2....(excluding identity_column) from table1 where identity_column=1000.

 

(in this way the last value in temp table will be same as table1) and again the sequence mapping will be restored.

4. you can now drop the table1_tmp table.

5. start the normal insert in table1 and it works , the next value inserted should be 1001

 

B. Permanent workaround :

 

1. note down the max identity row value from table1 (e.g. its 1000)

2. take a binary export of table on OS.

3. backup the create.sql file somewhere else.

4. now edit the create.sql file and put the clause : (START WITH 1001 increment by 1)

5. import the table back into db. ( you may choose the backup the table in db by rename table (e.g. rename table table1 to table1_back) if its highly crucial until the import is successful and you are confirm that the issue is resolved , then you can drop the backup table.)

6. start the normal insert into the table1 table excluding the identity column.

 

in my case , the table disk size was 125GB and table is on node with 2 TB RAM in a scale out so the export took ~20 mins and import ~25 mins.

 

In this way you have created the own system generated "sequence" for table table1 (select max(identity_column)+1 from table1) and there is no mapping involved hence db restart will not raise this error.

 

tested this on 85.0 and 85.02 and implemented on 85.0 prod.

 

Regards,

Ganesh Sawale.


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>