0

I have a list of 36 queries ranging from low complexity(No joins) to high complexity(joins with subquery). I want to find the RAM Consumed by each query.

This is required for performance testing for the application which I am building.

Can anyone please help with the same?

I am creating a SQLAlchemy session object and executing raw queries directly.

  • 1
    I'm afraid this doesn't make much sense. Queries don't consume memory apart from storing their exact text, since they are simply strings of characters. The Postgres daemon and other related processes do consume memory, and a lot of it is shared and cannot be attributed to any one query. Please clarify your ultimate goal. – mustaccio Sep 11 '19 at 18:13
  • @mustaccio: that's not entirely true. A query can absolutely use memory, e.g. to store intermediate results, build hash tables, sort results and so on. – a_horse_with_no_name Sep 11 '19 at 18:42
  • 1
    If the query needs memory, you can see that if you look at the execution plan generated using explain (analyze, verbose) – a_horse_with_no_name Sep 11 '19 at 18:42
  • @a_horse_with_no_name may be I'm being too pedantic, but it's a postgres backend process that requests and uses memory, not the query (which still is just a string of characters). The plan will give an indication of how much memory the process might need to allocate for a particular query, but some of it may be shared between different queries executed by the same process. – mustaccio Sep 11 '19 at 18:48
  • @mustaccio Apologies for confusion. Requirement is to get approx RAM usage by postgres daemon and other related process when a particular query executes! – Devesh Krishnani Sep 12 '19 at 6:28
0

You can turn on "log_statement_stats", and look at the 'max resident size' line from the log file (or set client_min_messages TO log;).

Is is a pretty crummy interface, and the number it gives is the high water mark for the connection, so you would have to run each statement in a separate connection while testing it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.