0
0
PostgreSQLquery~20 mins

Work_mem and effective_cache_size tuning in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Work_mem and effective_cache_size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding work_mem impact on query execution

Which of the following best describes the effect of increasing work_mem in PostgreSQL?

AIt increases the memory available for each sort or hash operation, potentially reducing disk usage during query execution.
BIt increases the total memory available for all queries combined, preventing out-of-memory errors.
CIt controls the size of the shared buffer cache used for caching disk pages.
DIt limits the maximum size of the query result set returned to the client.
Attempts:
2 left
💡 Hint

Think about what happens when PostgreSQL sorts or hashes data during a query.

🧠 Conceptual
intermediate
2:00remaining
Role of effective_cache_size in query planning

What does the effective_cache_size setting in PostgreSQL represent?

AThe maximum size of the shared buffer pool inside PostgreSQL.
BAn estimate of the OS disk cache available for PostgreSQL to use, influencing planner cost estimates.
CThe amount of memory PostgreSQL uses for sorting operations.
DThe total memory allocated to all active connections.
Attempts:
2 left
💡 Hint

Consider how PostgreSQL guesses if data is likely cached in memory.

query_result
advanced
3:00remaining
Effect of work_mem on sort operation

Given the following PostgreSQL configuration and query, what will be the output of EXPLAIN ANALYZE regarding sort method?

SET work_mem = '64kB';
EXPLAIN ANALYZE SELECT * FROM large_table ORDER BY column1;
PostgreSQL
SET work_mem = '64kB';
EXPLAIN ANALYZE SELECT * FROM large_table ORDER BY column1;
ASort method: external merge Disk, indicating disk usage due to insufficient work_mem.
BSort method: quicksort in-memory, indicating sort fits in work_mem.
CSort method: no sort needed, data already ordered.
DSort method: hash aggregate, unrelated to sorting.
Attempts:
2 left
💡 Hint

Think about what happens when work_mem is too small for sorting large data.

📝 Syntax
advanced
2:00remaining
Correctly setting effective_cache_size

Which of the following commands correctly sets effective_cache_size to 4GB in PostgreSQL?

ASET effective_cache_size = '4000MB';
BSET effective_cache_size = 4GB;
CALTER DATABASE SET effective_cache_size = 4GB;
DALTER SYSTEM SET effective_cache_size = '4GB';
Attempts:
2 left
💡 Hint

Remember the syntax for persistent configuration changes in PostgreSQL.

optimization
expert
3:00remaining
Optimizing work_mem for concurrent queries

You have a PostgreSQL server with 32GB RAM and expect up to 20 concurrent queries, each performing multiple sorts. Which work_mem setting is most appropriate to avoid memory exhaustion while allowing efficient sorting?

ASet work_mem to 500MB to allow multiple sorts per query without exceeding RAM.
BSet work_mem to 1GB to maximize sort performance per query.
CSet work_mem to 100MB to balance memory usage and concurrency.
DSet work_mem to 2GB since total memory is large enough for all queries.
Attempts:
2 left
💡 Hint

Calculate memory usage as work_mem * sorts per query * concurrent queries.