Running a Purge
A purge runs in the background as a queue of batches: one to plan the work, one per document type, one per module (inventory, then ledger), and one per history or system table to clean. Each batch works in short chunks that commit one by one, so the server can be restarted at any moment and the purge simply carries on. This page covers starting the run and following it on the Purge Monitor.
Before you press Run
Go through this list on the day of the run:
- The preparation is complete and the last Check shows no failure.
- The customer has agreed the dry run counts and every warning.
- Users are off the system, or know that it will be slow and that nothing dated in the purged range can be saved.
- Reports to compare afterwards are saved (see Before the run, save your comparison reports).
- A full backup of the main and archive databases was taken after the last change.
Starting the run
- On the Purge Configuration, clear Dry Run (preview only) and save.
- Open the Purge Monitor on the configuration. If the server was restarted since your last dry run, press Dry run again: Run purge stays disabled until there is one.
- Press Run purge. The dialog Run purge {0} for real — «تشغيل الحذف {0} فعليا» shows the cut-off, the companies, the archive database (or Documents are not archived), the documents that will be deleted, archived and marked with their counts, the transaction rows, the clean-up tables and any negative groups carried forward.
- Read the red line Deleted documents and transactions can not be restored except from a backup., tick I took a backup of the main and the archive databases after the last change, and type the configuration's code in the box Type {0} to confirm.
- Press Delete and run.
The server runs the whole pre-flight once more before it accepts, which takes a few minutes on a large database; the button shows that it is working and can not be pressed twice. If anything fails, the Pre-flight tab opens with The purge was not started and the reasons. If it passes, you see Purge for config {0} has been queued and will run in the background — «تمت جدولة الحذف لملف الإعدادات {0} وسيعمل في الخلفية», the status becomes Planning, and the run begins within seconds.
The start is recorded in the actions history of the configuration with the cut-off date. That entry is dated today, so it survives this purge and every later one.
The stages
- Plan. Creates one batch per document type and one per module. Takes seconds.
- Documents. One batch per document type, in turn: archive and delete, delete, or mark, in chunks of 2,000 documents. Every type with committed documents in the range is processed, also those you did not list (they are marked). The configuration status is Purging.
- Inventory. Creates the Purge Stock Receipt documents and waits until they are processed, aligns the cost engine's running totals with them, then deletes the quantity, reservation, cost and stock ages transactions of the range (copying them to the archive first when asked). Under FIFO it also moves the remaining layers under the roll-up receipts. It ends by rematching the stock ages of every item that got a roll-up line.
- Ledger. Creates the Purge Journal documents of every company and waits until they are posted, then deletes the ledger transactions, the dimension balances and the debt lines and matchings of the range, and rematches the debt ages of the affected customers and suppliers.
- Cleanup. Empties actions history, version history, user notifications and pending tasks up to the end of the cut-off day. The status is Cleaning up.
- Finished. The executed batches are removed and their summary is written to Last Run Log.
A stage starts only when the one before it has finished completely. Between two chunks the purge pauses a few seconds, so that users and other background work keep a share of the database.
Following it on the Purge Monitor
The Run tab of the Purge Monitor refreshes by itself.
Total progress (marked approximate) is the bar to watch. It lists the stages — Plan, Documents, Inventory, Ledger, Cleanup — each with its share of the run, a count ({0} of {1} document types, {0} of {1} documents, {0} of {1} steps, {0} of {1} batches) and its state. For the module stage in progress it also lists its steps (Steps of {0}), each ticked when done. The shares are rough on purpose: the bar never goes backwards, but a long step can hold it still for an hour.
Below it:
- a circle with the share of batches executed, {0} of {1} batches executed, {0} of {1} document types done, and live figures: Rows per second, Documents per second, Time left in this batch, Time left for documents (rough), Documents left (from the dry run) and Elapsed since the start;
- the Current batch card: its number, target (a document type, Inventory or Ledger, or a history table), phase, behaviour and status, with Attempts, Rows processed (a document counts several rows), Documents done, Last update and the Current step the server is working on;
- Failures, when a batch has an error (see When a Purge Fails);
- Batches by phase and status, a small matrix;
- the Batches grid, with filters by phase and status;
- Completed steps, every step marker written so far, with a search box;
- Request queues: unprocessed ledger and inventory requests, the roll-up documents and whether their requests are processed, the stock ages queues, the database files with their size and used space, and the SQL statements running right now (this last part needs the VIEW SERVER STATE permission on SQL Server).
The Log tab shows Last run log.
When the batch count stands still
The inventory and ledger stages are one batch each and can run for hours, so {0} of {1} batches executed can stay on the same number for a long time. Watch Total progress, the step list and Current step instead. The stock ages rematch at the end of the inventory stage is the usual long, quiet step.
The completed steps
These are the steps listed in Completed steps (and, for the module stages, ticked in Total progress):
| Stage | Steps, in order |
|---|---|
| Documents | Type done, once per document type (the Entity Type column names it) |
| Inventory | Roll-up stock receipts created, Quantity transactions purged, Reservation transactions purged, under FIFO FIFO cost matchings purged and Cost running totals aligned with the roll-up, then Cost transactions purged, Stock ages matchings purged, Roll-up stock ages created, Stock ages purged, and Queues rematched and batch closed |
| Ledger | Roll-up journals created, Ledger transactions purged, Dimension balances purged, Debt matchings purged, Debt ages purged, Unmatched manual debt lines purged, Manual debt lines purged, Roll-up journals posted to the ledger |
| Any | Cut-off date pinned, written when the run starts |
Steps that work per company are ticked once all companies are done.
How long it takes
The figures below come from test runs on copies of real customer databases (SQL Server, about 400 GB). Use them as an order of magnitude; your hardware and data decide.
| Stage | About 4.5 million documents in range | About 7 million documents in range | What drives it |
|---|---|---|---|
| Documents | 4 hours | 6 hours | Number of documents and their lines; 300 to 600 documents a second. Types with many approval cases or attachments are slower. |
| Inventory | 3 hours | 5 hours 20 minutes | Quantity and cost lines (2,500 to 3,500 quantity lines a second), FIFO layers and matchings, and the stock ages rematch (150 to 190 items a minute; about 2 hours for 15,000 items). |
| Ledger | 1 hour 30 minutes | 2 hours 30 minutes | Ledger lines (about 2,000 to 2,500 a second) and the size of the roll-up: one company with a wide variety of accounts and dimensions needed 104 journals and 45 minutes before the line deletion started. |
| Cleanup | 2 hours | 4 hours | Actions history and version history rows, about 2,500 a second (38 million rows took 4 hours). |
| Whole run | about 11 hours of work | 18 hours |
A database with half a million documents in range finishes in a few hours.
While it runs
- Nothing dated in the purged range can be saved, committed or deleted from the moment the run starts. Requests dated in the range wait instead of being processed.
- Stock ages and debt ages processing pause for new documents too, and catch up after the purge. The utilities that re-cost history from a date refuse to start, and the automatic repair of the cost running totals waits.
- Documents dated after the cut-off can be entered and are processed, but the database is under heavy load and some steps briefly hold the posting lock. Run the purge outside working hours: a weekend, a holiday, or nights for a year-by-year purge.
- A server restart does not stop the purge. When the server comes back, a purge in Planning, Purging or Cleaning up continues by itself from where it was; there is nothing to press. Tests killed the server in the middle of the documents, the roll-up receipts and the cost steps, and every time the purge resumed without losing or doubling anything.
- Only one purge runs at a time. A second configuration is refused while another one is active, and if two were ever queued, the younger waits until the older finishes.
One run or year by year
You can purge ten years in one run (cut-off at the end of the last year), or one year at a time with one configuration and one purge period per year, each cut-off later than the one before.
| One run for all years | Year by year | |
|---|---|---|
| Preparation | One purge period, closing entries up to the last year | A purge period, a configuration and the closing entries for each year |
| Duration | One long window (18 hours for 7 million documents) | Several shorter windows, each fitting in a night or a weekend |
| Roll-ups | One set of roll-up documents | One set per year; each later purge leaves the earlier roll-ups alone |
| Risk | One failure delays everything until it is resumed | A failure affects only that year's run |
A first purge at a customer is usually one run up to the last closed year. After that, a yearly purge after each year-end closing keeps every run small.
Messages you may see
| Message | Why | What to do |
|---|---|---|
| Purge configuration {0} is in dry run mode; clear Dry Run on the configuration to run it — «ملف إعدادات الحذف {0} في وضع التشغيل التجريبي، ألغِ اختيار التشغيل التجريبي في الملف لتشغيله» | Dry Run (preview only) is still ticked. | Clear it on the configuration and save. |
| The confirmation code does not match the purge configuration {0} — «كود التأكيد لا يطابق ملف إعدادات الحذف {0}» | The code typed in the dialog is wrong. | Type the code exactly. |
| The status of purge configuration {0} changed to {1}; reload the page — «تغيرت حالة ملف إعدادات الحذف {0} إلى {1}، أعد تحميل الصفحة» | Someone else started or resumed the purge meanwhile. | Reload the page. |
| Purge can not start: purge config {0} is still active (status: {1}) and purges run one at a time, oldest first - finish or resume config {0} first, then re-run this one — «لا يمكن بدء الحذف: ملف الحذف {0} ما زال نشطا (الحالة: {1}) وعمليات الحذف تعمل واحدة تلو الأخرى بدءا من الأقدم - أكمل أو استأنف الملف {0} أولا، ثم أعد تشغيل هذا الملف» | Another purge is running or failed. | Finish or resume it first. |
| Can not operate on this document because its fiscal period {0} is inside a purged range — «لا يمكن التعامل مع هذا المستند لأن فترته المالية {0} تقع ضمن نطاق تم حذف بياناته» | A user saved a document dated in the range. | Expected; date it after the cut-off if it is a new document. |
| You can not send the request of document {0} at date {1} because a data purge covers this date: its detail was rolled up into the purge period and the range stays protected after the purge finishes | A document's request would be dated in the range. English only. | Same as above. |