postgres - pg_stat_statements directory Does pg_stat_statements use the same stats_temp_directory directory? Our stats_temp_directory is under /var/run/postgresql which resides in tmps. We have about 500 databases in an instance and set pg_stat_statements.max to 10000000 (20000 statements / db).

We don't want pg_stat_statements to be a major factor of i/o (we execute tons of short running queries). Can't seems to find this info in the pg_stat_statements.

postgres=# select version();
                                                                     version                                                                     
-------------------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.6.10 on x86_64-pc-linux-gnu (Ubuntu 9.6.10-1.pgdg16.04+1), compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609, 64-bit
(1 row)
pg_stat_statements always uses the literal directory "pg_stat_tmp", even if the "stats_temp_directory" parameter has been changed to point elsewhere.

See this note from the source code:


  Location of external query text file.  We don't keep it in the core
   system's stats_temp_directory.  The core system can safely use that GUC
   setting, because the statistics collector temp file paths are set only once
   as part of changing the GUC, but pg_stat_statements has no way of avoiding
   race conditions.  Besides, we only expect modest, infrequent I/O for query
   strings, so placing the file on a faster filesystem is not compelling.


Are your tons of short-running queries all entirely different queries?  If they all normalize to a smaller set of queries (i.e. groups that differ only in supplied parameter values, not in SQL syntax elements or SQL identifiers) then they won't generate IO because pg_stat_statements only needs to update the in-memory counters, not the on-disk normalized query text.