Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
Gary McNair needed to reload a table atomically in unlogged databases without transactions. Paul Watson suggested loading a new table then renaming old and new (and indexes); Henri Cujass suggested synonyms. Garcia Benjamin warned renaming with open cursors gives error 710 and suggested MERGE; Henri said AUTO_REPREPARE or reoptimization helps. Gary planned to try MERGE and synonyms.
Auto-generated by Claude from the posts below — may be imperfect; read the full thread.
Gary McNair — source: IBM Community (ConnectedCommunity.org) Informix forum
Hi Informix Group,
We have been using IDS for 15 years or so, but our DB's have always been unlogged/raw. No transactions.
We now have a need to reload a table atomically. By "reload" I mean clear all records from the table and load it fresh from a .dat file. By "atomically" I mean the change occuring without other concurrent processes seeing the table in an intermediate state (empty or missing records).
Obviously using a transaction would be one way of doing this, but like I said we have never enabled logging on the DB in the past, and would prefer not to have to change a lot of existing INSERT/UPDATE/DELETE code to begin/end transactions.
I thought about using an EXCLUSIVE LOCK during the reload, but I believe that with a raw table other processes will ignore the lock when SELECTing, so they will see the table in an intermediate state.
I also thought about preparing another table with the new data and then quickly renaming the 2 tables (current to old and then new to current), but there would be a small window of time where there would be no table.
Can anybody see a clever way of doing this without transactions?
Thanks,
Rob
------------------------------
Gary McNair
------------------------------
#Informix
↪ replying to Gary McNair
Paul Watson — source: IBM Community (ConnectedCommunity.org) Informix forum
Load into new_table;
Rename table to old_table;
Rename new_table to table;
That as close to instant as you can get, the rename part anyway
Don't forget to rename the indices
Cheers
Paul
↪ replying to Gary McNair
Henri Cujass — source: IBM Community (ConnectedCommunity.org) Informix forum
Hi Rob,
play with synonym ( drop / create ) if it's faster as the two "rename table" you need for the switch to a table copy.
Regards
Henri
------------------------------
Henri Cujass
leolo IT, CTO
Germany
------------------------------
↪ replying to Gary McNair
Garcia Benjamin — source: IBM Community (ConnectedCommunity.org) Informix forum
Hi,
Be carefully, renaming a table with "open cursors" on it will fire "informix errors" :
SQL statement error number -710.
Table () has been dropped, altered or renamed.
Regards
------------------------------
Garcia Benjamin
------------------------------
↪ replying to Gary McNair
Garcia Benjamin — source: IBM Community (ConnectedCommunity.org) Informix forum
Hi,
depending on the numbers of records and a unique logical key you can maybe load new data on another table a use MERGE to sync the original table ...
Regards
------------------------------
Garcia Benjamin
------------------------------
↪ replying to Garcia Benjamin
Henri Cujass — source: IBM Community (ConnectedCommunity.org) Informix forum
Hi Garcia,
it's depend from AUTO_REPREPARE. You can use the open cursor "with reoptimization" in this case.
Regards
Henri
------------------------------
Henri Cujass
leolo IT, CTO
Germany
------------------------------
↪ replying to Garcia Benjamin
Gary McNair — source: IBM Community (ConnectedCommunity.org) Informix forum
Hi Garcia,
I was not aware of this MERGE statement. It looks good for syncing, I will give it a try.
Thanks,
Rob
------------------------------
Gary McNair
------------------------------
↪ replying to Henri Cujass
Gary McNair — source: IBM Community (ConnectedCommunity.org) Informix forum
Thanks Henri for the suggestion of using synonyms and AUTO_REPREPARE, I will keep it in mind.
------------------------------
Gary McNair
------------------------------
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.