This error means a query generated temporary files that exceeded the temp_file_limit parameter. PostgreSQL writes data to disk when a sort or hash operation cannot fit in memory (as configured by work_mem). The temp_file_limit parameter caps how much disk space these temporary files can consume per session, protecting your instance from queries that exhaust storage.
To resolve this, increase temp_file_limit for all roles, verify the new value, and re-run your query. If the query is a one-time operation, restore the original limit afterward.
Increase the temp_file_limit
Log on to your RDS instance using Data Management (DMS). For details, see Use DMS to log on to an ApsaraDB RDS for PostgreSQL instance.
In the left-side navigation pane of the DMS console, double-click the target database. The SQLConsole tab opens.
Run the following statement to check the current limit:
show temp_file_limit;Run the following statement to increase the limit:
alter role all set temp_file_limit = <new_limit_kb>;Replace
<new_limit_kb>with the new limit in KB. The value must exceed the temporary file size shown in the error message. For example, if the error reports8388608kb, set the limit to20000000kb.Close the SQLConsole tab, then reopen it using the SQL Console tab. Run
show temp_file_limit;again to confirm the new value is in effect.Re-run the original SQL statement to verify the error is gone.
If this was a one-time query, restore temp_file_limit to its original value after the query completes. Leaving an elevated limit in place allows temporary files to grow without bound, which can exhaust your instance's storage and cause the instance to be locked.Identify the queries generating large temporary files
Before increasing the limit, identify which query is responsible. Use log_temp_files to log temporary file activity, then correlate with active sessions.
Enable logging for temporary files larger than 1 GiB (unit: KB):
alter role all set log_temp_files = 1048576;After enabling logging, check postgresql.log to see which SQL statements generated large temporary files. You can also query active sessions in real time:
select pid, query, state from pg_stat_activity where state = 'active';This helps you decide whether to permanently raise temp_file_limit, optimize the query (for example, by increasing work_mem to reduce disk spills), or both.
Application scope
ApsaraDB RDS for PostgreSQL