FiveM SQL Optimization for Large RP Servers: Making Your Database Fast
A FiveM RP server is more database-centric than almost any other game server type. Player characters, inventories, jobs, vehicles, property ownership, skill levels, bank balances — almost every persistent gameplay element is stored in and retrieved from a SQL database. When the database slows down, the entire server slows down with it.
Identifying SQL Performance Issues
The first sign of database lag: scripted resource functions that depend on SQL return data take noticeably long, causing player-facing delays (inventory doesn't open instantly, job interaction pauses, etc.).
Use the FiveM profiler (/profiler) and check which resources consume the most server CPU time. If mysql-async or oxmysql shows high time, SQL is your bottleneck.
The oxmysql Resource
Most modern FiveM frameworks use oxmysql as the database bridge. Ensure you are using the latest version — earlier versions had connection pool issues that caused queries to queue up unnecessarily.
oxmysql configuration in server.cfg:
set mysql_connection_string "mysql://user:password@localhost/fivem_db?charset=utf8mb4&connectTimeout=60000&acquireTimeout=60000&timeout=60000&connectionLimit=50"
The connectionLimit=50 parameter is critical for busy servers — it allows up to 50 simultaneous database connections rather than waiting for a single connection to free up.
MariaDB Configuration for FiveM
In /etc/mysql/mariadb.conf.d/50-server.cnf:
[mysqld]
# Connection pool
max_connections = 200
thread_cache_size = 50
# InnoDB (FiveM uses InnoDB tables)
innodb_buffer_pool_size = 2G # 50% of available RAM
innodb_log_file_size = 256M
innodb_flush_method = O_DIRECT
innodb_flush_log_at_trx_commit = 2 # Performance vs. strict ACID
# Query cache
query_cache_type = 1
query_cache_size = 256M
The innodb_buffer_pool_size setting is the single most impactful MariaDB performance configuration. Set it to 50% of available server RAM — this keeps frequently accessed table data in memory rather than reading from disk on every query.
Slow Query Logging
Enable slow query logging to identify problem queries:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 0.5 # Log queries taking > 500ms
Review /var/log/mysql/slow.log regularly. Queries appearing repeatedly are candidates for index optimisation or script refactoring.
Common FiveM Query Optimisations
Add indexes for frequently queried columns:
-- If players are looked up by identifier frequently:
ALTER TABLE players ADD INDEX idx_identifier (identifier);
-- Inventory lookups by owner:
ALTER TABLE player_inventories ADD INDEX idx_owner (owner);
Missing indexes cause full table scans. On a database with 10,000 player records, a full scan vs. indexed lookup is the difference between 800ms and 2ms.
Run your FiveM server with an optimised database setup on Space-Node