Skip to content

Kernel tunning for PostgreSQL

Memory Management

  • vm.overcommit_memory = 2: Prevents the kernel from excessive memory usage, reducing the risk of OOM Killer terminating Postgres processes.
  • vm.swappiness = 1: Minimizes swapping of Postgres processes, as swapping significantly degrades database performance.
  • vm.min_free_kbytes = 102400: Reserves a certain amount of memory to handle unexpected peak demands, ensuring available memory for Postgres when needed.
  • Transparent Huge Pages (THP): Configure transparent_hugepage/enabled and transparent_hugepage/defrag to never disable THP, avoiding potential latency issues for Postgres.

Input/Output Management

  • vm.dirty_expire_centisecs = 1000: Determines when dirty pages are flushed to disk, affecting how Postgres writes to WAL and other files.
  • vm.dirty_background_bytes = 67108864: Sets the threshold for the kernel to start writing dirty data to disk in the background.
  • vm.dirty_bytes = 536870912: Specifies the maximum amount of dirty memory before Postgres processes immediately write out data.

File System and File Handling:

  • fs.file-max = [appropriate value]: Sets the limit on the number of open file descriptors system-wide, which should be sufficiently high to avoid limiting Postgres.

NUMA Configuration

  • vm.zone_reclaim_mode = 0: Disables NUMA memory reclaim, which may negatively impact Postgres performance on NUMA hardware.
  • kernel.numa_balancing = 0: Turns off automatic NUMA balancing, reducing unnecessary data movement across NUMA nodes for Postgres.

Process and Connection Scheduling:

  • kernel.sched_autogroup_enabled = 0: Improves Postgres scheduling by not grouping client connections, which can delay process wake-ups.

Network Configuration

  • net.ipv4.ip_nonlocal_bind = 1: Facilitates high availability setups for Postgres, where the service may need to bind to non-local IP addresses.
  • net.ipv4.ip_forward = 1: Enables IP forwarding if Postgres nodes require routing capabilities.
  • net.ipv4.ip_local_port_range = 10000 65535: Increases the port range for outgoing connections to accommodate more client connections for Postgres.
  • net.core.netdev_max_backlog = 10000: Determines the maximum number of packets, increasing backlog to handle peak network traffic without dropping packets.
  • net.ipv4.tcp_max_syn_backlog = 8192: Increases the queue length for incoming connections, preventing Postgres from dropping during a burst of new connections.
  • net.core.somaxconn = 65535: Sets the maximum queuing socket connection count for Postgres, allowing for more concurrent connections.
  • net.ipv4.tcp_tw_reuse = 1: Enables Postgres to quickly recycle sockets in TIME_WAIT state, beneficial for connection-heavy workloads.
Leave Your Message