enable_result_cache_for_session toggles whether Redshift serves a cached result or re-executes a query.
Redshift stores the final result of read-only SELECT statements. When an identical query arrives, Redshift can return the saved result instantly, skipping scan and join work.
Disable the cache when you need real-time data (e.g., after an UPDATE on Orders
) or when benchmarking query performance. Otherwise, leave it on for speed.
Use the SET enable_result_cache_for_session
command. Changing the parameter affects only the current session and reverts on disconnect.
SET enable_result_cache_for_session TO { on | off };
— Switches cache use.RESET enable_result_cache_for_session;
— Returns to the default (on
).
1. Ensure fresh totals after inserting a new order.
2. Compare runtimes with and without caching.
-- Disable caching for real-time accuracy
SET enable_result_cache_for_session TO off;
SELECT customer_id,
SUM(total_amount) AS lifetime_spend
FROM Orders
GROUP BY customer_id;
-- Re-enable caching for the rest of your work
SET enable_result_cache_for_session TO on;
Keep caching enabled in dashboards and ad-hoc analysis. Toggle it off only for data-freshness-critical queries or performance testing.
Mistake 1 – Assuming data is stale when cache is off. Verify the session parameter; cached results appear only when it’s on
.
Mistake 2 – Disabling cache globally. Use session-level SET, not parameter groups, unless every workload needs fresh results.
No. Only read-only SELECT statements are eligible. Any write or lock excludes caching automatically.
Query STL_QUERY
. A value of 1
in result_cache_hit
means the cache satisfied the query.
No. The parameter affects only read-only SELECT statements. INSERT, UPDATE, DELETE, and COPY operations remain unaffected.
Yes. Wrap the query between SET enable_result_cache_for_session TO off
and RESET enable_result_cache_for_session
or turn it back to on
immediately after the statement.
Yes. A cached result is visible to any user who issues an identical query with identical search path and parameter settings.