
Running a small website on a VPS often means using MariaDB as your database. When traffic grows, too many database connections can slow your site or crash it. Learning how to monitor MariaDB connections on a small VPS helps you catch problems early. This guide shows simple, low-cost ways to keep your database healthy.
Quick Overview: Why Monitor MariaDB Connections on a Small VPS?
A small VPS has limited RAM and CPU. MariaDB opens a new connection for each visitor or script that needs data. Each connection uses memory. If too many connections open at once, your server runs out of resources. Your website slows down or stops working.
By learning to monitor MariaDB connections on a small VPS, you can:
- Spot slow queries that hold connections open
- See when traffic spikes happen
- Prevent your site from crashing
- Keep hosting costs low by avoiding upgrades
- Fix WordPress or CMS issues fast
This guide uses free tools and simple commands. You do not need expensive software. Everything works on a basic Linux VPS.
Method 1: Monitor MariaDB Connections Using Built-in Commands
MariaDB comes with built-in commands. You do not need to install anything. These commands work on every VPS. They are the fastest way to check your database.
Step 1.1: Using SHOW PROCESSLIST and SHOW STATUS
First, log in to your VPS using SSH. Then open the MariaDB prompt:
- Open your terminal or SSH client.
- Type
mysql -u root -pand press Enter. - Enter your MariaDB root password.
- Run this command to see all active queries:
SHOW FULL PROCESSLIST;
This shows every connection. You see the user, host, database, command type, time, and query. Long-running queries appear at the top.
To see total connection stats, run:
SHOW STATUS LIKE 'Threads%';
Key values to watch:
Threads_connected— current open connectionsThreads_running— connections actively running queriesMax_used_connections— peak connections since server start
Compare Threads_connected with your max_connections limit. If it gets close, you have a problem.
Step 1.2: Checking Active and Sleeping Connections
Not all connections are equal. Some are active. Some are sleeping (idle). To monitor MariaDB connections on a small VPS, you must know the difference.
- In the MariaDB prompt, run:
SHOW STATUS LIKE 'Threads%';
- Look at
Threads_connectedvsThreads_running. - The gap shows sleeping connections.
- To see only sleeping connections, run:
SELECT * FROM information_schema.processlist WHERE command = 'Sleep' AND time > 60;
This finds idle connections older than 60 seconds. Too many sleeping connections waste memory. You can kill them with:
KILL connection_id;
Replace connection_id with the number from the list.
Method 2: Use Lightweight CLI Tools to Monitor MariaDB on a Small VPS
Command-line tools give you live views. They use very little RAM. Perfect for a small VPS with 1GB or 2GB of memory.
Step 2.1: Real-time Monitoring with mytop
mytop shows MariaDB activity like the Linux top command. It refreshes every few seconds.
- Install mytop on Ubuntu/Debian:
sudo apt install mytop
On CentOS/AlmaLinux:
sudo dnf install mytop
- Create a config file at
~/.mytop:
user=root
pass=yourpassword
host=localhost
db=information_schema
delay=3
port=3306
socket=
batchmode=0
header=1
color=1
- Run mytop:
mytop
You see a live list of queries. Press s to sort by time. Press k to kill a query. Press q to quit.
Step 2.2: Using mysqladmin for Quick Connection Checks
mysqladmin is built into MariaDB. It gives fast stats without installing new tools.
- Check current connection count:
mysqladmin -u root -p status
Output shows uptime, threads, questions, slow queries, and open tables.
- Watch connections in real time:
mysqladmin -u root -p -i 5 extended-status | grep Threads
This refreshes every 5 seconds. You see thread counts live.
- To see the process list:
mysqladmin -u root -p processlist
Use this when mytop is not available. It works on any VPS.
Method 3: Automate Monitoring with Custom Bash Scripts (Zero-Cost)
Scripts save time. They run in the background. You get alerts when problems start. This is the best way to monitor MariaDB connections on a small VPS without paying for tools.
Step 3.1: Writing a Script to Check MariaDB Connection Limits
- Create a new script file:
nano ~/check_mariadb.sh
- Paste this code:
#!/bin/bash
USER="root"
PASS="yourpassword"
WARN=80
CONN=$(mysql -u $USER -p$PASS -sNe "SHOW STATUS LIKE 'Threads_connected';" | awk '{print $2}')
MAX=$(mysql -u $USER -p$PASS -sNe "SHOW VARIABLES LIKE 'max_connections';" | awk '{print $2}')
PCT=$((CONN * 100 / MAX))
if [ $PCT -ge $WARN ]; then
echo "Warning: MariaDB at ${PCT}% capacity ($CONN/$MAX)"
fi
- Save and make it executable:
chmod +x ~/check_mariadb.sh
- Test it:
~/check_mariadb.sh
If connections pass 80% of the limit, the script prints a warning.
Step 3.2: Setting Up Cron Jobs and Alert Notifications
- Open your crontab:
crontab -e
- Add a line to run the script every 5 minutes:
*/5 * * * * /root/check_mariadb.sh >> /var/log/mariadb_monitor.log 2>&1
- To get email alerts, install mailutils:
sudo apt install mailutils
- Update the script to send email:
Add this line inside the if block:
echo "MariaDB high connections" | mail -s "DB Alert" you@example.com
Now you get an email when connections spike. This is a free way to monitor MariaDB connections on a small VPS 24/7.
Method 4: Monitor MariaDB Connections with Low-Resource Dashboards
Dashboards show graphs. They help you see trends over time. Some dashboards use too much RAM. The ones below work on small VPS plans.
Step 4.1: Setting Up Netdata for Small VPS Environments
Netdata uses about 100MB of RAM. It gives live charts for MariaDB.
- Install Netdata with one command:
wget -O /tmp/netdata-kickstart.sh https://get.netdata.cloud/kickstart.sh && sh /tmp/netdata-kickstart.sh
- Open your browser and go to:
http://your-vps-ip:19999
- Find MariaDB charts under the “Database” section.
- You see connections, queries, and slow queries in real time.
- To save RAM, edit the config:
nano /etc/netdata/netdata.conf
Set update every = 2 and limit history to 1 hour.
Step 4.2: Using Grafana Agent for Lightweight Metrics
Grafana Agent is lighter than full Grafana. It sends metrics to a remote server.
- Install the agent:
sudo apt install grafana-agent
- Edit the config at
/etc/grafana-agent.yaml. - Add a MariaDB exporter job using
mysqld_exporter:
sudo apt install prometheus-mysqld-exporter
- Start the exporter:
sudo systemctl enable --now prometheus-mysqld-exporter
- The exporter runs on port 9104. Grafana Agent scrapes it and sends data to Grafana Cloud (free tier available).
This setup uses under 50MB of RAM. A great way to monitor MariaDB connections on a small VPS with pretty graphs.
How to Troubleshoot High Connection Spikes on a Small VPS
When connections spike, your site slows down. You need to find the cause fast. Here are the most common causes and fixes.
Step 5.1: Identifying Slow Queries and Locks
- Enable the slow query log:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add these lines under [mysqld]:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
- Restart MariaDB:
sudo systemctl restart mariadb
- Check the log:
tail -f /var/log/mysql/slow.log
- To see locks right now, run:
SHOW OPEN TABLES WHERE In_use > 0;
Fix slow queries by adding indexes or rewriting the SQL. This is key when you monitor MariaDB connections on a small VPS.
Step 5.2: Managing WordPress/CMS Cron Jobs and Traffic Spikes
WordPress runs cron jobs on every page load. This opens many connections. To fix this:
- Disable default WP cron. Edit
wp-config.php:
define('DISABLE_WP_CRON', true);
- Add a real system cron:
*/15 * * * * wget -q -O - https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
- Use a caching plugin like WP Super Cache or LiteSpeed Cache.
- Block bad bots with a firewall or
fail2ban.
These steps cut connection counts by 50% or more on busy sites.
Optimize MariaDB Connection Settings for Small VPS Resources
Default MariaDB settings fit big servers. On a small VPS, you must tune them. The right settings let you handle more traffic with less RAM.
Step 6.1: Configuring max_connections and wait_timeout
- Edit the MariaDB config:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
- Under
[mysqld], add or change:
max_connections = 100
wait_timeout = 60
interactive_timeout = 60
connect_timeout = 10
- For a 1GB VPS, keep
max_connectionsbetween 50 and 150. - Restart MariaDB:
sudo systemctl restart mariadb
- Verify the new values:
mysql -u root -p -e "SHOW VARIABLES LIKE 'max_connections';"
Lower wait_timeout kills idle connections faster. This frees RAM for active users.
Step 6.2: Implementing Connection Pooling for Small Websites
Connection pooling reuses open connections. It cuts the cost of opening new ones. For small sites, use these options:
- ProxySQL — a free proxy that pools MariaDB connections. Uses about 80MB RAM.
- PHP persistent connections — set
pdo_mysql.persist = Oninphp.ini. - Application-level pooling — many CMS plugins offer this.
To install ProxySQL on Ubuntu:
- Add the repo and install:
sudo apt install proxysql
- Configure backends to point to localhost:3306.
- Point your app to ProxySQL on port 6033.
Pooling is a smart way to monitor MariaDB connections on a small VPS while handling more traffic.
FAQ: Monitoring MariaDB Connections on a Small VPS
Q1: How often should I check my MariaDB connections?
A: Check once a day at first. Use a cron script every 5 minutes for alerts. If your site is stable, weekly checks are enough.
Q2: What is a safe max_connections value for a 1GB VPS?
A: Start with 100. Watch your RAM usage. If free RAM stays above 200MB, you can raise it slowly to 150.
Q3: Can I monitor MariaDB connections on a small VPS without installing tools?
A: Yes. Use SHOW PROCESSLIST, SHOW STATUS, and mysqladmin. All are built in.
Q4: Why do sleeping connections matter?
A: Each sleeping connection uses memory. Too many waste RAM and slow your VPS. Lower wait_timeout to fix this.
Q5: Is Netdata too heavy for a 512MB VPS?
A: Netdata uses about 100MB. On a 512MB VPS, it may be tight. Use mysqladmin scripts instead for such small plans.
Q6: How do I know if a plugin is causing connection spikes?
A: Check the slow query log. Look for table names from plugins. Disable the plugin and watch if connections drop.
Conclusion and Final Best Practices
Learning to monitor MariaDB connections on a small VPS keeps your website fast and stable. You do not need costly tools. Built-in commands, light CLI tools, bash scripts, and low-RAM dashboards all work well.
Follow these best practices:
- Check connections daily at first, then weekly
- Set
max_connectionsandwait_timeoutto fit your RAM - Use a cron script to alert you when connections spike
- Log slow queries and fix them fast
- Disable default WordPress cron and use system cron
- Add a cache plugin to cut database load
- Consider connection pooling if traffic grows
Start with Method 1 today. Open your SSH client and run SHOW PROCESSLIST. See how many connections your site uses right now. Then add a script from Method 3 for alerts. Step by step, you will master your small VPS and keep your website running smooth in 2026 and beyond.
