Optimization of the 1C-Bitrix database

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Database Optimization in 1C-Bitrix

After years of a Bitrix site in operation, the database accumulates problems: bloated cache tables, outdated sessions, fragmented indices, inefficient queries without indexes. Database optimization is not a one-time operation but a regular process. Let's cover specific tables and methods.

Diagnosis: What Takes Up Space

Start with analyzing table sizes. In MySQL/MariaDB:

SELECT
    TABLE_NAME,
    ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2) AS size_mb,
    TABLE_ROWS
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'bitrix_db'
ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC
LIMIT 20;

For Bitrix sites typically: b_event_log, b_stat_session, b_stat_adv_back, b_search_content, b_cache_tag, b_file — account for 80% of database volume.

Cache Tables

b_cache_tag — cache tag table. When Bitrix flushes cache, it doesn't immediately delete outdated records, but marks them. The table grows constantly.

Clear outdated cache tags:

DELETE FROM b_cache_tag WHERE SITE_ID IS NULL AND CACHE_SALT IS NULL;

Or via admin panel Settings → Module Management → Main Module → Clear Cache.

Full table rebuild after cleanup:

OPTIMIZE TABLE b_cache_tag;

OPTIMIZE TABLE rebuilds physical storage, frees fragmented space. Run during minimum load — operation locks the table.

Session Table

b_user_session and b_sale_user_session store user sessions. Without configured cleanup, they grow infinitely.

Check if automatic cleanup is enabled: Settings → Product Settings → Main Module → "Session" tab. "Session lifetime" should match session.gc_maxlifetime in php.ini.

Force cleanup of sessions older than 24 hours:

DELETE FROM b_user_session
WHERE DATE_CREATE < DATE_SUB(NOW(), INTERVAL 24 HOUR);

DELETE FROM b_sale_user_session
WHERE DATE_INSERT < DATE_SUB(NOW(), INTERVAL 7 DAY);

Event Log

b_event_log — user action audit table. On active sites adds millions of records per month. Most projects don't need events older than 90 days.

DELETE FROM b_event_log WHERE DATE_CREATE < DATE_SUB(NOW(), INTERVAL 90 DAY);
OPTIMIZE TABLE b_event_log;

Configure automatic cleanup: Settings → Event Log → Clear Events → Keep events for last N days.

Statistics Tables

The statistic module fills b_stat_session, b_stat_page_adv, b_stat_adv_back. If statistics aren't used (many switch to Yandex.Metrica), disable the module entirely: Settings → Modules → Web Analytics → Disable. This stops writing and reduces DB load.

If disabling isn't possible — configure retention period: Settings → Web Analytics → Settings → Statistics Retention Depth.

Index Optimization and Slow Queries

Enable slow query log for identifying heavy queries. In my.cnf:

slow_query_log       = 1
slow_query_log_file  = /var/log/mysql/slow.log
long_query_time      = 1
log_queries_not_using_indexes = 1

For Bitrix typical bottlenecks:

Table Problem Solution
b_iblock_element Search by ACTIVE + IBLOCK_ID + TIMESTAMP_X without index CREATE INDEX ix_active_iblock ON b_iblock_element (ACTIVE, IBLOCK_ID, TIMESTAMP_X)
b_iblock_element_property JOIN without index on IBLOCK_PROPERTY_ID + VALUE Bitrix creates indexes when "Create Index" enabled in property settings
b_sale_order Selection by USER_ID + STATUS_ID CREATE INDEX ix_user_status ON b_sale_order (USER_ID, STATUS_ID)
b_search_content Outdated records from deleted pages Reindexing: /bitrix/admin/search_reindex.php

InnoDB Buffer Pool Size Configuration

For MySQL/MariaDB the most important performance parameter is innodb_buffer_pool_size. For server dedicated to database, set 60–70% of available RAM:

innodb_buffer_pool_size = 4G   # for server with 8 GB RAM
innodb_log_file_size    = 512M
innodb_flush_log_at_trx_commit = 2   # less guarantee, but significantly faster

innodb_flush_log_at_trx_commit = 2 allows loss of up to 1 second of transactions on power loss, but gives 2–5x write performance increase. Acceptable for most e-commerce.

Database Maintenance Schedule

Operation Frequency Tool
Clear b_event_log Weekly SQL or admin panel
Clear outdated sessions Daily (cron) SQL script
Optimize fragmented tables Monthly OPTIMIZE TABLE
Analyze slow query log Monthly pt-query-digest
Backup before optimization Before each ALTER TABLE mysqldump

Work Timelines

Scale Scope Timeline
Basic Cache cleanup, sessions, event log, OPTIMIZE TABLE 2–4 hours
Complete Analyze slow queries, optimize indexes, configure my.cnf, maintenance schedule 1–2 days