skip to Main Content

We have about 200 GB files inside temp folder in PostgreSQL. And it’s time to clear it but I’m not sure is it safe or not. Thats why I want to look at these files first. File names look like: pgsql_tmp644088.0. How can I open and read them? With Notepad I can only see some symbols, for example: ЎҐЖ№T ipadinstagram%instagram_stories j‹74. What is your reccomendations?

2

Answers


  1. Do not manually delete temp file. As a first step i would check what operations are using temp files. You have some options to enable logs on queries writing to temp files:

    1. Enable log_tmp_files

    or

    1. Use pgbadger

    2. Query table Pg_stat_statements, as follows:

      SELECT interval ‘1 millisecond’ * total_time AS total_exec_time,
      total_time / calls AS avg_exec_time_ms,
      temp_blks_written,
      query AS query
      FROM pg_stat_statements
      WHERE temp_blks_written > 0
      ORDER BY temp_blks_written DESC
      LIMIT 20;

    3. Query pg_stat_database to give db level stats, as follows:

      select datname, temp_files , pg_size_pretty(temp_bytes) as temp_file_size FROM pg_stat_database order by temp_bytes desc;

    4. Run EXPLAIN ANALYZE and compare work_mem size with values printed by explain analyze.

    As a general recommendation set temp_file_limit to a value different than -1 (default).
    Be sure to use correct indices to tune queries.
    Tune work_mem (carefully).
    Set statement_timeout to an optimal value.

    Please note:
    Temp files are created when memory is not sufficient.

    Login or Signup to reply.
  2. Simply restart PostgreSQL, and it should delete all the temporary files that were left behind.

    Normally, temporary files don’t exist longer than the duration of a query. Check for long running queries.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search