I need some help of expert in Postgres. I'm getting a problem in my application.
Problem: PG::InsufficientResources:
ERROR: could not open shared memory segment "/PostgreSQL.1477116630": Too many open files in system
STATEMENT: SELECT "work_orders".* FROM "work_orders" WHERE (created_at < '2025-04-07 19:58:00.668344' AND rascunho is true) ORDER BY "work_orders"."id" ASC LIMIT 1ドル
I have tried some changes with AI help but no success. Here is my Postgres configuration:
postgresql.conf
:
listen_addresses = '*'
port = 5432
superuser_reserved_connections = 3
unix_socket_directories = '/var/run/postgresql, /tmp'
max_connections = 200
shared_buffers = 4864MB
effective_cache_size = 14592MB
maintenance_work_mem = 1216MB
checkpoint_completion_target = 0.9
wal_buffers = 16MB
default_statistics_target = 100
random_page_cost = 1.1
effective_io_concurrency = 200
work_mem = 6225kB
huge_pages = off
min_wal_size = 1GB
max_wal_size = 4GB
max_worker_processes = 10
max_parallel_workers_per_gather = 4
max_parallel_workers = 10
max_parallel_maintenance_workers = 4
max_prepared_transactions = 400
ulimit
settings made in /etc/security/limits.conf
:
postgres soft nofile 65535
postgres hard nofile 65535
root soft nofile 65535
root hard nofile 65535
nucleusdb soft nofile 65535
nucleusdb hard nofile 65535
Changes in the systemd service (/etc/systemd/system/postgresql.service.d/override.conf
):
[Service]
LimitNOFILE=65535.
During the day I got a lot of these messages, here is a screen shot. 288 errors during 12 hours!
screen shot of the error messages
2 Answers 2
My guess is that the "Too many open files" message was translated from a different language, and that you are hitting the limit of 1000 open files per PostgreSQL process. Try increasing the parameter max_files_per_process
.
When LimitNOFILE
is not enough, it is reported as Too many open files
. Whereas Too many open files in system
is about a separate Linux kernel limit for the entire system: fs.file-max
sysctl or /proc/sys/fs/file-max
procfs pseudo file.