High swap usage
Learn what high Swap usage means, what can cause it, and how to solve it.
What is Swap for?
High Swap is usually not a problem unless other resources (such as RAM) are constrained.
Every Supabase project runs on its own dedicated virtual machine. The machine's underlying specs and hardware depend on your compute add-on. If your hardware isn't suitable for your workload, you might experience high Swap usage.
Swap is a portion of your instance's disk that is reserved for the operating system to use when the available RAM has been utilized. As it uses the disk, Swap is slower to access and is generally used as a last resort.
Swap can be used even if your instance has plenty of RAM. If this is the case, do not worry. Your instance might try to "preemptively swap" by swapping background processes to make space for your traffic in RAM.
When is high Swap concerning?
High Swap is concerning if your instance is using all of the available RAM (i.e. consistently using more than 75%).
High Swap usage can affect your database performance. For example, you might see:
- Slower query responses.
- Degraded performance due to swapping regularly between RAM and disk.
- Higher Disk I/O due to swapping regularly.
Monitor your Swap
You can check your Swap usage directly on the Supabase Platform. Navigate to the Database page of the Reports section.
You can also monitor your resources and set up alerts using Prometheus/Grafana. See the metrics guide for more information.
An example repository to ingest metrics and visualize them with Grafana is provided in the linked guide, where we maintain a list of the exported metrics.
Some useful metrics to monitor are (this is not an exhaustive list):
node_memory_SwapFree_bytes
- The total amount of Swap available in bytes.node_disk_io_time_seconds_total
andnode_disk_io_now
- The amount of time spent on disk I/O. An increase might be an indirect sign of excessive swapping, but not always.node_memory_MemTotal_bytes
andnode_memory_MemFree_bytes
- The total RAM and available RAM.node_vmstat_pswpin
andnode_vmstat_pswpout
- The number of pages that have been swapped in or out (monitoring this for spikes means that your instance is swapping).
Common reasons for high Swap usage
Everything you do with your Supabase project requires compute. Hence, there can be many reasons for high Swap usage. Here are some common ones:
- Query performance: You might have high read traffic or queries that process a large amount of data on disk (this can happen even if you are returning a small amount of data).
- Missing indexes: Your database might have to scan through a large amount of data to find the information it needs. Creating indexes helps your database find data faster. See the indexes guide to learn more.
- Unsuitable compute: The compute size of your Supabase project might not be suitable for your application as you might have more traffic or run resource-intensive operations.
- Workload style: The usage pattern of your Supabase project might be more read heavy, or involve large amounts of data.
- Extensions: You might be using extensions that perform intensive operations on large datasets. This increases resource usage.
Solving high Swap usage
If you find that your RAM and Swap usage are high, you have three options:
- Optimize performance: Get more out of your instance's resources by optimizing your usage. See the performance tuning guide and our production readiness guide.
- Upgrade your compute: You can get a Compute Add-on for your project. Navigate to the Addons section in project settings to see your upgrade options.
- Read Replicas: You can spread the load on your Supabase project by creating a Read Replica. See the read replicas guide for more information.