In a daily routine, I need to drop and do a bulk load of a database.
The problem is that I have a WebApp relying on that database. So I can't drop the database just like this.
What would be a good way to tackle this problem ?
|
In a daily routine, I need to drop and do a bulk load of a database. The problem is that I have a WebApp relying on that database. So I can't drop the database just like this. What would be a good way to tackle this problem ? |
|||||
|
|
Well, this is straightforward in most databases. While your app is running, from your loading job:
While steps 1-3 are running, the app will see the "old" version of the data and can continue as normal. The instant step 4 completes, the app will see the new data as soon as it runs the next query. |
|||
|
|
Do you need to drop and reload the database? In a case like yours, I would look at a way to synchronize the database with the reference set (the data you are loading). An alternative approach would be to have two databases. Load a different one each day. Configure the webapp so that you can swap databases on the fly. |
|||
|
|
|
Truncate the tables, then bulk load the data. If needed lock the web app from the table before truncating the table. |
|||
|
|
|
this depends on how the dependency trees are. If you have lots of dependend objects on the table[s] where you load the data in, best is not to change the object, the table because lots of invalidations will take place. truncate table gets rid of the data very fast but won't work when referential constraints are in place. It also won't work when the app is running because of locking issues. Best for the application will be a normal delete/insert sequence. Not the fastest option but it is best for availabillity and has the least problems with locking. Other options can be partition exchange loading. Constraints can be problematic and take a lot of time to validate. Never ever drop a table just to get rid of the data. A table is to be considered as application infrastructure and should allways be available, because the application will throw lots of errors to your users. |
|||
|
|
|
|||||||||||||
|
|
i load the new data in a temporary table. this way, i have to lock only the rows, that i need to update. Afterwards i delete missing rows and insert new rows.
this works at least for postgresql. for oracle i use the following:
when i have impossible values, i may use NVL instead:
|
|||
|
|