October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How the WordPress Database Works and How to Manage It

A practical, version-aware guide to WordPress database tables, autoloaded options, WP-CLI backups, SQL inspection and safe cleanup.
Length12 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress stores nearly all of a site’s content and configuration in a MySQL or MariaDB database. Posts, pages, media records, revisions and custom post types are centered in wp_posts; settings are in wp_options; and accounts use wp_users plus wp_usermeta. WordPress combines those rows with PHP code and files to build each page.

Managing the database safely means exporting a restorable backup before changes, understanding which tables and relationships you are touching, keeping autoloaded options below 800 KB, and testing cleanup on a staging copy. The procedures below use WP-CLI where possible and treat direct SQL as a preview-and-verify operation rather than a shortcut.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the WordPress database does on every request

A WordPress installation has three cooperating layers:

  • Database: structured records such as post text, publication status, users, settings, comments and taxonomy relationships.
  • Files: WordPress core, themes, plugins, uploaded media and configuration files.
  • PHP runtime: code that reads database rows, applies permissions and filters, and renders the response.

When a visitor requests a page, WordPress loads configuration from wp-config.php, opens the database connection, reads options and then queries the records needed for that request. Plugins and themes can add tables or add rows to existing metadata tables. A database backup alone does not restore the complete site if the uploads, themes, plugins or wp-config.php file are missing; a reliable recovery plan covers both the database and the files.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

The wp_ prefix is only the default. During installation it can be changed, and security tools or hosts often use another prefix. Replace the example prefix in every command and query with the value defined by the $table_prefix setting in wp-config.php.

The core tables and what belongs in each

Names and the exact table set can vary by WordPress version, multisite configuration and installed extensions. These are the tables that matter most when diagnosing content or performance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Table What it stores How to think about it
wp_posts Posts, pages, custom post types, attachments, revisions and autosaves One table holds many content types; the post_type and status columns distinguish them.
wp_postmeta Key/value metadata attached to posts and attachments Custom fields and plugin data are linked through post_id.
wp_options Site-wide settings, cached values and transients The autoload column controls whether a value is loaded on every request.
wp_users Usernames, hashed passwords, email addresses and display details Authentication data belongs here; passwords are not stored as plain text.
wp_usermeta Roles, capabilities, preferences and other user metadata Rows connect to wp_users.ID through user_id.
wp_comments and wp_commentmeta Comments and their metadata Comment approval, author data and post association are stored separately from posts.
wp_terms, wp_termmeta, wp_term_taxonomy and wp_term_relationships Category, tag and custom-taxonomy names, metadata and relationships A post’s category assignment is a relationship rather than a text value copied into the post row.

The commonly cited single-site installation has 12 default tables, but the practical table count changes as WordPress evolves and plugins create their own tables. Do not use a fixed count as a health test. Inspect the actual database, especially on multisite, where each site can have its own numbered table set and network-wide tables.

How WordPress connects rows

Posts, metadata and revisions

Every row in wp_posts has an ID. A revision or attachment is another row whose fields identify its relationship to a parent post. The associated custom fields sit in wp_postmeta, where multiple rows can share one post_id. Deleting a post does not guarantee that every extension-specific metadata row is removed, which is why orphan checks should be part of a controlled cleanup.

Users, roles and capabilities

wp_users.ID identifies an account. Role and capability information is serialized into usermeta under a key based on the table prefix, so changing the prefix or editing those values manually can lock users out. Use WordPress or WP-CLI user commands for account changes instead of editing password or capability rows by hand.

Terms and relationships

A category or tag name is stored once in the terms tables. The taxonomy table records whether that term is a category, tag or custom taxonomy, and the relationships table links the term-taxonomy record to a post. This normalized design prevents the same label being copied into every post, but it means a taxonomy problem can involve several tables.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

wp_options and the autoload performance limit

wp_options contains familiar settings such as the site URL and active theme, but it also holds plugin configuration, cached values and transients. Its autoload column is a performance switch: autoloaded options are fetched on every page request, whether that particular request needs each value or not.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

The WordPress Optimization handbook recommends keeping the total size of autoloaded options under 800 KB. WordPress 6.6 added a Site Health check that reports a critical issue named Autoloaded options could affect performance when the total exceeds 800 KB. This is a threshold for investigation, not proof that one option is defective; a site can be slow for many other reasons.

Recent WordPress versions recognize values including yes, on, auto-on and auto as autoload states. A WordPress support moderator notes that yes and no are deprecated since WordPress 6.7 and that new entries use on or off. Check the values present in your installation before writing SQL, because labels can change between releases.

Measure before changing anything

Run this query in a read-only database console, replacing the prefix if necessary:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
SELECT autoload, COUNT(*) AS option_count, SUM(OCTET_LENGTH(option_value)) AS bytes
FROM wp_options
GROUP BY autoload
ORDER BY bytes DESC;

OCTET_LENGTH counts stored bytes rather than characters, which gives a more useful estimate for the 800 KB guidance. To find the individual contributors, run:

SELECT option_name, autoload, OCTET_LENGTH(option_value) AS bytes
FROM wp_options
ORDER BY bytes DESC
LIMIT 50;

Large values are not automatically safe to delete. A page builder, ecommerce extension or multilingual plugin may need its settings on every request. Record the option name, owning plugin and current value before changing it.

Turn autoload off without deleting the option

Changing autoload is a performance change, not a removal. Prefer WP-CLI so the value is updated through WordPress APIs:

wp option get-autoload option_name
wp option set-autoload option_name off

Use the exact option key in place of option_name. If your installed WP-CLI version expects the older spelling, use the value supported by that version and verify the result with wp option get-autoload. Test the front end, login, administration screens and the plugin that owns the option on staging before applying the change to production.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Do not switch every option to off simply to make the total smaller. An option that is required during bootstrap can cause notices, missing features or repeated database queries when autoloading is disabled. The safe target is the smallest set of values that genuinely must load on every request.

Back up the database before maintenance

Take a full export before deleting rows, changing autoload flags, repairing tables or running optimization. A host’s daily snapshot is useful but should not be your only copy; keep at least one backup off the server and verify that it can be opened or restored.

WP-CLI export

wp db export calls mysqldump using DB_HOST, DB_NAME, DB_USER and DB_PASSWORD from wp-config.php. From the WordPress directory:

wp db export wordpress-backup.sql

For a focused diagnostic copy, you can export selected tables:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
wp db export options-users.sql --tables=wp_options,wp_users

Conversely, --exclude_tables skips tables you do not want in an export. Any valid mysqldump flag can be passed through WP-CLI, so check the command’s help output on your installed version before scripting a production backup. Move the resulting file away from the web root and protect it because it contains sensitive account and configuration data.

Backup plugin workflow

A backup plugin is appropriate when shell access is unavailable or when non-technical administrators need scheduled, off-server copies. Choose one that can export both the database and uploads, reports completion, retains multiple versions and supports a documented restore. Download a copy outside the server and perform a test restore on staging; a green backup status alone does not prove that the archive is usable.

Confirm the backup

  1. Check that the SQL file exists, has a plausible size and includes table creation statements.
  2. Store the file outside the public web directory and restrict its permissions.
  3. Record the WordPress version, PHP version, active plugins and table prefix alongside the backup.
  4. Restore the export to a disposable database or staging site and load the front end and administration area.

A safe, repeatable database-management procedure

  1. Identify the target. Write down the symptom, affected URL, option name or table. Do not begin with a blanket deletion query.
  2. Clone production to staging. Use a private copy with email sending disabled and any payment or webhook integrations disconnected.
  3. Export first. Create a full WP-CLI or plugin backup and keep a copy off-server.
  4. Measure. Check autoload totals, table sizes, row counts and error logs before changing data.
  5. Preview. Use SELECT queries or a plugin’s dry-run mode. Save the result so you know exactly what would be changed.
  6. Change the smallest set. Disable one unnecessary autoloaded option, remove one confirmed orphan group or apply one revision policy at a time.
  7. Test behavior. Clear caches, then test anonymous pages, logged-in pages, search, forms, media, scheduled tasks and the relevant plugin.
  8. Promote carefully. Repeat the tested change during a maintenance window, take a fresh backup and monitor logs and response times.
  9. Document and retain a rollback. Record the query or command, timestamp, affected rows and the backup filename.

Cleaning common sources of database bloat

Post revisions and autosaves

Revisions and autosaves are legitimate rows in wp_posts. They let editors recover earlier content, but a busy site can accumulate many versions. Decide how much history your editors need, then set a finite revision limit in wp-config.php, for example:

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
define( 'WP_POST_REVISIONS', 10 );

The number is a policy example, not a universal recommendation. Existing revisions require a separate, verified cleanup; changing the setting only limits future accumulation. Never delete revisions while an editorial recovery is in progress.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Expired transients

Transients are temporary values stored in wp_options, often with paired timeout rows. Expiration and removal are not identical events, so an expired value can remain until WordPress or an extension cleans it. Inspect the option names and owning plugin first. Use a documented transient-cleanup command or plugin in staging, then verify that caches, feeds, scheduled jobs and API integrations still work.

Orphaned metadata

Deleted posts, users or comments can leave metadata rows if an extension did not clean up. Preview candidates with a left join:

SELECT pm.meta_id, pm.post_id, pm.meta_key
FROM wp_postmeta AS pm
LEFT JOIN wp_posts AS p ON p.ID = pm.post_id
WHERE p.ID IS NULL
LIMIT 100;

Equivalent checks can be made for wp_usermeta joined to wp_users and wp_commentmeta joined to wp_comments. Do not run a delete based only on a null join: some plugins intentionally retain data for historical or migration purposes. Confirm ownership, export the candidate IDs and delete only rows proven to be disposable.

Spam and trashed content

Use the WordPress administration screens or supported WP-CLI commands to empty spam and trash after confirming that no legal, editorial or moderation requirement calls for retention. Database-level deletion bypasses those checks and can remove related metadata unexpectedly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Optimizing tables is not the same as cleaning data

wp db optimize asks the database server to optimize tables and recover unused storage where the engine supports it. It does not remove revisions, spam, expired transients or orphaned metadata. Run it after a tested cleanup, not instead of one, and check the command’s output and your server’s maintenance guidance first.

Storage-engine defaults and behavior have changed over WordPress and database releases, and published explanations are not consistent enough to assume one engine for every installation. Inspect the actual engine with your database tool before planning a table repair or conversion:

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
SHOW TABLE STATUS FROM your_database_name;

Table optimization can lock or heavily use a busy table, so schedule it during low traffic and keep a current backup.

Manual SQL versus a management plugin

Approach Advantages Risks and requirements
WP-CLI and SQL Scriptable, repeatable, precise and suitable for automation Requires shell or database access; a malformed query can delete data immediately.
Database-management plugin Visual previews, scheduled tasks and no shell access required Quality varies; broad cleanup actions may remove more than intended and add their own overhead.
Hosting backup tools Convenient snapshots and provider-managed storage Retention, restore scope and off-server access differ; do not rely on a single daily snapshot.

Use the least powerful method that can solve the problem. A plugin is reasonable for a reviewed, reversible task with a clear preview. WP-CLI is better when you need a repeatable command across many staging sites. Direct SQL is appropriate only when you understand the schema, have a tested export and can identify every affected row.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Multisite, plugins and changing schemas

Multisite adds site-specific table groups and network-wide settings. A plugin may install one table per site or a shared network table, so a query written for a single-site prefix can miss data or change the wrong site. Determine the current site ID, list tables, and read the plugin’s uninstall documentation before touching network data.

Core tables and autoload behavior evolve. The 800 KB recommendation remains the practical performance check, but accepted autoload labels and Site Health wording can differ by WordPress release. On a production site, use the documentation and command help that match the installed WordPress and WP-CLI versions rather than copying an old SQL snippet unchanged.

Troubleshooting database-management mistakes

The site shows a database connection error

  • Check that the database server is running and reachable from the web server.
  • Compare DB_HOST, database name, username and password in wp-config.php with the host’s current credentials.
  • Confirm that the account still has permission to the selected database.
  • Do not repair or import over the live database until you have a current export and know which copy is authoritative.

Site Health still reports oversized autoloaded options

  • Re-run the grouped OCTET_LENGTH query and include every autoload value used by your version.
  • Sort individual options by byte size and identify their owning plugins.
  • Disable autoload only for values that are not needed during every request.
  • Clear object and page caches, then recheck Site Health after the next requests have completed.

A plugin breaks after autoload is disabled

Restore the previous autoload value from your backup or with WP-CLI, clear caches and confirm the feature works again. Then ask the plugin author whether the option can be lazy-loaded or split into smaller settings. Do not leave a broken feature disabled merely to meet a numeric threshold.

A cleanup query affected too many rows

Stop further writes, preserve the database and application logs, and restore the export to staging first. Compare the affected IDs with the preview result. If production data must be restored, coordinate a maintenance window and account for orders, comments or other records created after the backup; a full restore can overwrite legitimate newer data.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A practical maintenance checklist

  • Keep at least one recent full database export and one off-server copy.
  • Test a restore on staging instead of assuming a backup is valid.
  • Monitor total autoloaded bytes and investigate before the 800 KB threshold becomes a critical Site Health warning.
  • Review the largest options after installing or removing major plugins.
  • Set a revision-retention policy that fits the editorial workflow.
  • Preview transient and orphaned-metadata cleanup, and keep an export of affected rows.
  • Use supported WordPress or WP-CLI commands for users, terms and plugin-owned data.
  • Run table optimization separately from content cleanup and schedule it for low traffic.
  • Recheck prefixes, multisite scope and version-specific autoload values before reusing a script.
  • Record every production change, its rollback method and the backup used.

What good database management looks like

A healthy WordPress database is not an empty database and does not have a magic table count. It is a database whose records are understood, backed up, and changed deliberately. Keep essential options available without loading unnecessary payloads, retain the revisions and metadata your site actually needs, and remove only data you can identify and restore. That approach protects content while addressing the performance and storage problems that database maintenance is meant to solve.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.