Skip to main content
Most database problems show up as memory that seems to leak, connections that run out or queries that get slow. Start from the symptom below; engine details are on the PostgreSQL, MySQL, MongoDB and Redis pages.

RAM keeps growing

What it means: the database’s RAM chart climbs after it starts and then stays high, even when traffic drops. Why it happens: the RAM shown in the dashboard is the instance’s whole memory, including the operating system’s file cache that the engine keeps warm. Each engine also holds memory on purpose:
  • PostgreSQL: shared_buffers (25% of the RAM) plus the file cache.
  • MongoDB: the WiredTiger cache, and an allocator that keeps freed memory for reuse.
  • MySQL: the InnoDB buffer pool (128 MB unless you raised it) plus the file cache.
  • Redis: the data itself, up to 90% of the RAM.
Climbing and then flattening out is normal, not a leak. When it is a problem: if the database runs out of memory, it is stopped and stays stopped until you start it again (there is no automatic restart after an out-of-memory stop). Then:
  1. Start it from the dashboard.
  2. Find what grew: a query or aggregation over too much data, too many connections (each one costs memory), or on Redis keys without an expiry.
  3. Reduce that, or give the database more RAM.

Too many connections

What it means: new connections are refused: Why it happens: every database accepts up to 256 simultaneous connections (253 for your clients on PostgreSQL), whatever its size. The usual causes are a new client or connection per request, a pool per module instead of per process, several apps or shards each with a large pool, or on MongoDB many MongoClient instances (each adds 2 monitoring connections to its pool). How to fix:
  1. Create one pool or client per process at startup and reuse it everywhere (pg.Pool, mysql2.createPool, one MongoClient, one Redis client).
  2. Size the pools so that every process together stays under the limit, with a margin: 4 processes with a pool of 20 use 80.
  3. Open the database’s Insights tab to see which client addresses hold the connections (the third part of each IP address is masked).

Slow queries

What it means: requests to your app get slow, and the database’s CPU stays high. How to find them: the Insights tab lists the slow queries, refreshed every 60 seconds:
  • PostgreSQL and MySQL: statements with their mean time, listed once any run took 100 ms or more.
  • MongoDB: single operations of 100 ms or more, from the profiler.
  • Redis: the SLOWLOG, commands of 10 ms or more.
How to fix: run the engine’s explain on the slow query and add the index it needs (EXPLAIN ANALYZE on PostgreSQL, EXPLAIN on MySQL, explain("executionStats") on MongoDB). On Redis, replace commands that walk the whole keyspace or a giant key (KEYS, HGETALL on huge hashes) with SCAN, HSCAN and SSCAN. A query that reads a lot of data also needs RAM: more RAM keeps more of it in cache.

The database stopped by itself

The disk is full

Each database has 10 GB of storage, fixed. Data, indexes and the engine’s own files share it: PostgreSQL’s write-ahead log (256 to 512 MB), MongoDB’s diagnostic data (up to 200 MB), MySQL’s mysql.slow_log table when you turn the slow log on, and on Redis the room a save needs next to its data file. How to fix:
  1. Delete or archive data you don’t need, and drop unused indexes. Files such as images and uploads belong in Blob Storage, not in the database.
  2. Return the space: on PostgreSQL a plain VACUUM makes it reusable inside the table, while VACUUM FULL gives it back to the disk but needs free space the size of the table while it runs. On MySQL, OPTIMIZE TABLE rebuilds the table. On MongoDB, compact on the collection.
  3. On MongoDB, start the database from the dashboard first, then free space right away.
A database close to its 10 GB may also fail to snapshot: an export is limited to about 10 GB, and PostgreSQL and MySQL exports are uncompressed SQL text. Keep a margin.

Slow to start after a stop

What it means: right after starting, PostgreSQL answers the database system is not yet accepting connections, or MySQL takes a long time to accept connections. Why it happens: stopping a database gives it 5 seconds to shut down cleanly; a busy database may need longer and is then stopped by force. On the next start it runs its crash recovery (PostgreSQL replays its write-ahead log, MySQL’s InnoDB recovers its tables), which takes longer on large databases. How to fix: wait for the recovery to finish; nothing is lost by waiting. Stop the database when its write load is low.

Contact us

If you continue facing technical difficulties, our specialized support team is available to assist you. Contact us and we’ll be happy to help you resolve any issue: support quality is a big part of why developers rate Square Cloud 4.9/5 across 402 reviews on Google and Trustpilot.