A stats plugin that writes every page view into the site's database adds server work to each visit and grows without limit. Count visits with a browser-based analytics script, then remove the plugin and its tables.

A little slower every month

Pages on the site take a moment longer to open than they did last year, and no one can say when it started. Then the host emails: the site's database is approaching the limit for its plan.

Not much has been added to the site: a few posts a month, the same products, the same pages. Yet the database has grown many times over.

The usual cause on an older WordPress site is a visitor stats plugin installed years ago to count visits, which has been counting them, one row at a time, ever since.

It is an easy thing to miss. The plugin's numbers looked useful, and nothing about it seemed connected to speed.

How the plugin counts

A stats plugin of this kind runs inside the site. Every time a page is requested, it writes a new row to a table in the site's own database.

Each row holds the time, the page, the visitor's internet address, the browser and the page they came from.

Robots request pages too: search engines, feed readers, tools that copy content, programs probing for weak logins. Each of them writes a row exactly as a person would.

Nothing removes the rows. A site with modest traffic can collect millions of them, and the table becomes larger than the posts, pages and products put together.

What each recorded visit costs

The third matters most for speed. A cached page is served ready-made; to count visits, these plugins either bypass the cache or call back to the server from each page, so WordPress still runs for every visit.

None of these is dramatic on its own. Together, on a busy day, they make the difference between a page that opens at once and one that hesitates.

Signs the plugin is the cause

The plugin's own report pages are the slowest part of the dashboard, and they get slower each month. That alone points at its table.

The host can list the database's tables by size. One that dwarfs the rest, named after the plugin, settles the question before anything is changed.

If the site already runs an analytics script, the plugin is counting the same visits a second time, at the server's expense.

Counting in the visitor's browser

An analytics script, such as Google Analytics, works the other way round. A few lines in each page tell the visitor's browser to send the visit to the analytics service, which stores and reports it.

Your server sends the page and is done. Nothing is written to your database, the cache works normally, and the reports run on someone else's computers.

Most robots do not run scripts, so most of them never appear in the reports. The numbers describe people far more closely than a table full of robot requests.

Running both for a few weeks

Add the analytics script before removing anything. A few weeks of both lets you compare their figures and confirm the new reports cover what you used to check.

Expect the plugin's numbers to be higher. It counted robots and every page request; the analytics script counts browsers that run it.

Export anything from the old reports worth keeping, such as a yearly total of visits, before the tables go.

Removing the plugin and its tables

Deactivating the plugin stops new rows, but the table usually stays behind. Many plugins leave their tables in the database when removed, still filling backups and counting against the plan.

The leftover tables have to be removed directly in the database, a job for whoever manages the site. A full backup comes first, since a deleted table cannot be brought back.

After removal, the database can be optimised to give the freed space back, and the host can confirm the new size.

A worked example

A frozen dumpling maker in Burnaby sells to grocers and at farmers' markets, and its WordPress site lists flavours, cooking instructions, stockists and a wholesale enquiry form.

A stats plugin installed when the site was built had recorded every page request since. Its table had grown larger than everything else in the database combined, and the plugin's report page took a minute to open.

Wholesale buyers checking stockists or flavours never saw the plugin; they only saw pages that hesitated.

The developer added the analytics script to the theme, ran both for a month, and exported a yearly summary from the plugin's reports.

Then the plugin was deactivated and deleted, its tables removed after a full backup, and the database optimised, so backups no longer carry years of page requests.

Each page request now ends when the page is sent. The counting happens in the visitor's browser and on the analytics service's servers, and the database holds only the site.

The counter-case

Some sites need server-side records, for example to count downloads of files that cannot carry a script. The host's access logs already record every request, and log reports read them without touching the database.

A small, quiet site may also run a stats plugin for years without noticing, especially one that keeps only daily totals or clears old rows. The slowdown there is real but slight.

But a plugin that writes every visit and never clears its table only grows heavier, and a browser-based script does the same job without loading the site.

Moving the counting out of the database

  1. Ask the host which tables are largest.
  2. Confirm the stats plugin owns the biggest ones.
  3. Add an analytics script to every page.
  4. Run both for a few weeks, then export what you need.
  5. Deactivate and delete the plugin.
  6. Remove its leftover tables after a full backup.
  7. Optimise the database and check its size next month.

Step six is easy to overlook. Deleting the plugin stops new rows, but the old table stays behind, still filling backups and counting against the plan until someone removes it.

Older sites often make every page do extra work in another way too, as rounded corners and shadows built from dozens of images describes.


Frequently asked questions

Why does a stats plugin slow the site down?

It writes a new row to the database on every page request, robots included, and its tables grow without limit, so each visit costs the server extra work.

Will Google Analytics slow my pages the same way?

No. Its script runs in the visitor's browser and sends the visit to Google's servers. Nothing is written to your database, and caching keeps working.

Why are the plugin's numbers higher than Analytics?

The plugin counts every request, including search engines and other robots. Most robots do not run scripts, so they never reach the analytics reports.

Does deleting the plugin remove its data?

Often not. Many plugins leave their tables behind, still filling backups and counting against the plan, so they must be removed directly in the database.

Is it safe to delete the old tables?

Yes, once a full backup exists and anything worth keeping has been exported. Have whoever manages the site do it, since deleted tables cannot be recovered.

What should I keep from the old reports?

Usually a few summary figures, such as visits per year, for comparison. The detailed rows of past requests are rarely worth the space they take.

West Coast Media Solutions Inc. provides web design, web development, hosting, digital marketing, and business consulting to organisations across Canada, drawing on more than twenty-five years in the field.

Host warning that your database is getting large?

Ask us to look at your database, and we will tell you which tables have grown and what can safely go.

Start a Conversation