Operations

VICIdial database maintenance: archive, optimize, schedule

The VICIdial scripts that keep the live tables small, what each one deletes or locks, the archive script's defaults, and when to run them safely.

By Published 7 min read
Database cylinders and a calendar on a dark blue grid

To the point

A VICIdial database stays healthy through a handful of scripts that cron runs for you, plus one you have to add yourself.

  • Hourly and nightly scripts clear short-lived rows, fix agent time records and run OPTIMIZE on the busiest tables.
  • ADMIN_archive_log_tables.pl copies call and agent logs into _archive tables and deletes the old rows from the live ones. It is commented out in VICIdial's recommended crontab, it keeps two years unless you say otherwise, and it can lock the dialer for hours.
  • Run anything that locks tables outside your calling hours, in the server's own time zone.

Why a VICIdial database grows

Every call writes rows. vicidial_log gets one per outbound call, call_log one per channel, and vicidial_agent_log one per agent event. Carrier, dial, closer and recording logs add more. On the build we measured, these log tables are MyISAM and append-heavy: inserts stay cheap until deletes leave holes in the table files.

None of these rows expire on their own. That is what database maintenance in VICIdial is for: keep the live tables small, keep the history in archive tables, and compact the files after deletes.

The scripts VICIdial already runs

A server built by Trustane installs VICIdial's recommended maintenance crontab; the nightly reset and optimize run at the times VICIdial's install guide gives. Compare it with crontab -l on your own server.

WhenScriptWhat it does
Every hour at :11AST_flush_DBqueue.pl -qDeletes vicidial_manager rows older than an hour (the default --seconds=3600) and runs OPTIMIZE on the tables VICIdial uses most
Every hour at :33, and at 00:50 with --last-24hoursAST_cleanup_agent_log.plFixes agent time records that were written out of order, so pause and talk time add up
Daily at 00:25AST_DB_dead_cb_purge.pl --purge-non-cb -qDeletes callback rows that are finished: inactive, or whose lead is no longer in a callback status. Each is copied to vicidial_callbacks_archive first
Daily at 01:02AST_reset_mysql_vars.plClears this server's live rows: logged-in agents, calls in progress and conference seats
Daily at 01:03AST_DB_optimize.plRuns OPTIMIZE TABLE on 20 tables, among them vicidial_list, vicidial_log, call_log, vicidial_agent_log and vicidial_hopper
VICIdial database jobs on a Trustane-built server: five scheduled by cron, the log archive script not scheduled

Two of these scripts carry warnings in their own source. AST_flush_DBqueue.pl should run on one server only, so in a cluster it belongs on the database server's crontab and nowhere else. AST_reset_mysql_vars.pl says not to run it while the server has active calls. That is why its daily time matters more than it looks: see the section on timing below.

The archive script: ADMIN_archive_log_tables.pl

This is the script that keeps the live log tables small. VICIdial's recommended crontab carries it as a commented-out line, so it does not run until someone turns it on. For each log table it handles, it:

  1. copies every row into the matching _archive table (INSERT IGNORE INTO vicidial_log_archive SELECT * FROM vicidial_log),
  2. deletes the rows in the live table older than the cutoff, but only if the copy raised no error,
  3. runs OPTIMIZE on the live table and on the archive table.

At the very end of a full run it records the cutoff in system_settings as oldest_logs_date.

The archive tables are created with the same columns as the originals (CREATE TABLE vicidial_log_archive LIKE vicidial_log), so the history is still in the database (which grows by the archive copy), just out of the tables the dialer and the agent screen touch. It also deletes old server_performance rows without archiving them.

Its defaults

  • Two years kept. With no option, the cutoff is 24 months, counted as 732 days. --days=XX sets your own; the archive tables keep what is moved.
  • Monthly, at night. The script's own header suggests 30 1 1 * *: 01:30 on the first of each month.
  • It can take hours. The header warns that on a busy outbound system the run can take hours and the system is unusable while it runs.
  • Daily mode. --daily archives only call_log, vicidial_log_extended, vicidial_dial_log and vicidial_drop_log, and keeps the last 24 hours of each. --carrier-daily and --vlog-daily add the carrier log and vicidial_log to that run.
  • A dry check of the date. --calc-test only prints the cutoff date it would use, so you can see what "90 days" means before deleting anything.

There are also options to archive one table and stop (--vicidial-log-only, --call-log-only, --agent-log-only and others, most with a days option of their own), and three --only-trim-archive-level-* options that delete old rows from the archive tables themselves when even those grow too large.

Before the first run

The first run on a server that has never archived moves the most rows it ever will. Take a backup first (see what to keep in a VICIdial backup) and start it on a night with no calls planned. Check the free disk space too: every row is copied into the archive table before anything is deleted, and the recent rows stay in both tables, so the database grows by about the size of the log tables on the first run. After that, a monthly run adds and deletes only a month of rows, though it still reads the whole live table.

Timing: the part that bites

Cron runs these jobs in the server's configured time zone, not in your floor's. OPTIMIZE locks a MyISAM table while it is rebuilt, and the nightly run rebuilds vicidial_list and the call and agent logs, the tables that grow with every lead and every call. On one build we measured in October 2026, the box was set to Asia/Singapore, so the 01:03 optimize landed at 13:03 US Eastern, in the middle of a US shift.

Check two things on your server:

  1. timedatectl shows the time zone cron uses.
  2. crontab -l shows when each job runs.

If the nightly jobs fall inside your calling hours, move them, or set the server's time zone to the floor's. To see which agents were on a call while a job ran, the VICIdial real-time report is the screen to keep open.

Signs the database needs attention

  • SELECT COUNT(*) FROM vicidial_log returns millions of rows and the archive script is not in crontab -l.
  • SELECT oldest_logs_date FROM system_settings returns NULL (admin.php shows it as Oldest Logs Date). The archive script sets it only at the end of a full run, so NULL means it has not completed one; a server that runs only --daily stays NULL too.
  • The disk keeps filling. Archiving does not free space, because the archive tables keep every row; only the --only-trim-archive-level-* options delete from them. See whether a VICIdial server is idle for reading the server's own load figures.
  • The agent screen stalls at the same minute each day, and that minute matches a job in the table above.

To look at call history without writing SQL, VICIdial's own reports read the same tables: VICIdial call logs without SQL.

On a Trustane server

A server you run with Trustane has the crontab in the table above. The log archive script is not scheduled by default, because how much history to keep is your choice. The server's page in the console shows the database size and, under "Call log archiving", the number of rows in vicidial_log and whether the archive script is in the crontab ("archiving on" or "archiving off"). Before moving a server, see what to copy when moving VICIdial.

Next steps

Read crontab -l and timedatectl on your server today. If OPTIMIZE runs during your shift, move it. If ADMIN_archive_log_tables.pl is missing, run it once with --calc-test --days=180 to see the cutoff, take a backup, then add it monthly at a quiet hour. To run VICIdial on a server where this is already set up, order a server or see VICIdial hosting.

VICIdial is a trademark of its owner. Trustane is an independent hosting provider.

Sources

  1. VICIdial log archive script, SVN r4042
  2. VICIdial table optimize script, SVN r4042
  3. VICIdial hourly queue flush, SVN r4042
  4. VICIdial agent log cleanup, SVN r4042
  5. VICIdial dead callback purge, SVN r4042
  6. VICIdial reset of live server records, SVN r4042
  7. VICIdial table definitions, the archive tables, SVN r4037

Every VICIdial guide and article in one place: the complete VICIdial guide.

Trustane

Managed VICIdial hosting

Run it on cores of your own

Managed VICIdial, billed by the hour against a balance you top up.

Free for 7 days. Verify a payment method to start. Free-mail and some other sign-ups wait for a person, within one business day. Skip the wait with a paid server: ask in its first 7 days and its hosting is refunded in full.