If the number of CDRs stored in the Enswitch database becomes excessive, performance may suffer. Billing may take a long time to run, and the call history report may be slow. This can be cured by deleting or archiving old CDRs.
Warning: Do not delete or archive CDRs until you are certain that they are no longer needed for billing. Doing so may cause incorrect invoices to be produced.
Deleting CDRs
If old CDRs are no longer required, they can be deleted. To do this, add an entry similar to the following to /etc/crontab:
09 3 * * * enswitch /opt/enswitch/current/bin/cdrs_delete 366
This deletes CDRs older than 366 days every night at 3:09am. cdrs_delete deletes both archived (see below) and unarchived CDRs, plus their auxiliary data in the cdrcosts, cdrcost_taxes, and notes tables.
Archiving CDRs locally
If old CDRs are still required, for example for regulatory compliance, they can be archived within the Enswitch database. This improves the performance of billing and the call history report, but still makes the archived CDRs available to the system owner. To do this, change the "Table containing archived CDRs" configuration setting to "cdrs_archive", then add an entry similar to the following to /etc/crontab:
39 3 * * * enswitch /opt/enswitch/current/bin/cdrs_archive 90
This archives CDRs older than 90 days every night at 3:39am. This can be done in conjunction with deleting CDRs, so (for example), CDRs could be archived after 90 days, then deleted after 366 days.
Archived CDRs are moved from the cdrs to the cdrs_archive table within the Enswitch database. This improves performance by reducing the size of the indexes on the cdrs table, making the searches done by billing and the call history report faster. Note that auxiliary tables cdrcosts, cdrcost_taxes, and notes are not touched as these are only ever accessed by primary key, so moving data out of them does not speed up access to them.
Archived CDRs are hidden from all users by default. It is possible to allow some roles to access them by granting the "Read archived data" role permission. This should be done with caution because it reduces the performance gains made by archiving, and should normally be limited to the system owner role.
Archiving CDRs remotely
As an alternative to archiving CDRs locally as above, CDRs (and the corresponding data from auxiliary tables cdrcosts, cdrcost_taxes, and notes) can be moved to a remote database on another machine. THIS IS NOT SUPPORTED, AND NOT RECOMMENDED. IF YOU DO THIS, YOU ARE RESPONSIBLE FOR CONFIGURING AND MANAGING THE REMOTE MACHINE. YOU WILL NEED TO MERGE ANY SCHEMA CHANGES MADE BY FUTURE ENSWITCH UPGRADES. If you're sure you want to do this, the steps are:
- Contact Enswitch support and let them know you're doing this. They will disown any responsibility for what you're doing.
- Take a backup of the Enswitch database.
- If you've archived any CDRs locally, move them back to the cdrs table.
- Create the remote database, with the cdrs, cdrcosts, cdrcost_taxes, and notes tables. These tables must have exactly the same schemas as the Enswitch database. Note that if future versions of Enswitch change these schemas, you must manually change the remote database.
- Create a database user for the new database, and give them access to the above tables.
- Create "delete/cdrs/archive", "insert/cdrs/archive", and "select/cdrs/archive" handlers in /etc/enswitch/databases.ini.
- Change the "Table containing archived CDRs" configuration setting to "cdrs".
- Restart the web server.
- Create a crontab entry, similar to the local archiving above, but for "/opt/enswitch/current/bin/cdrs_archive_remote".
- Run "/opt/enswitch/current/bin/cdrs_archive_remote <days>" manually.
- Check that the data in both databases is as you expect.
- Optionally, configure cdrs_delete as above.
- Enable the "Read archived data" permission for any roles that may access archived CDRs. This should be done with caution because it reduces the performance gains made by archiving, and should normally be limited to the system owner role.