While investigating "Too many open files" errors reported in our parallel restore_command I noticed that the restore_command can inherit quite a lot of fds from the recovery process. This limits the number of fds available in the restore_command depending on the setting of system nofile and Postgres max_files_per_process.
I was wondering if we should consider closing these fds before calling restore_command? It seems like we could do this by forking first or by setting FD_CLOEXEC using fcntl() or O_CLOEXEC on open() where available.
Thoughts on this? Is this something we want to change or should I just recommend that users set nofile and max_files_per_process appropriately?