PostgresDB 53200: Out of memory

When the database server runs out of memory during an operation.
  1. Check current memory usage:
  2. SELECT pg_size_pretty(pg_database_size(current_database())) AS db_size;
  3. Identify large objects consuming space:
  4. SELECT nspname || '.' || relname AS "relation",
    pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
    FROM pg_class C
    LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
    WHERE nspname NOT IN ('pg_catalog', 'information_schema')
    ORDER BY pg_total_relation_size(C.oid) DESC
    LIMIT 10;
  5. Check long-running queries that might be locking resources:
  6. SELECT pid, now() - pg_stat_activity.query_start AS duration, query, state
    FROM pg_stat_activity
    WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes'
    AND state != 'idle'
    ORDER BY duration DESC;
  7. Terminate long-running queries if necessary:
  8. SELECT pg_cancel_backend(pid);
  9. If the issue persists, consider increasing the memory available to PostgreSQL:
    • Temporarily increase the work_mem setting for the current session:
    • SET work_mem = '256MB';
    • For a more permanent solution, modify postgresql.conf and restart the database:
      • Find the file location:
      • SHOW config_file;
      • Edit postgresql.conf, increase work_mem and/or shared_buffers, then restart PostgreSQL.

Never debug

PostgresDB

manually again

Let Dr. Droid create custom investigation plans for your infrastructure.

Book Demo
Automate Debugging for
PostgresDB
See how Dr. Droid creates investigation plans for your infrastructure.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid