linux – 如何设置shmall,shmmax,shmni等…一般和postgresql

前端之家收集整理的这篇文章主要介绍了linux – 如何设置shmall,shmmax,shmni等…一般和postgresql前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经使用 documentation from PostgreSQL来设置它,例如这个配置:
  1. >>> cat /proc/meminfo
  2. MemTotal: 16345480 kB
  3. MemFree: 1770128 kB
  4. Buffers: 382184 kB
  5. Cached: 10432632 kB
  6. SwapCached: 0 kB
  7. Active: 9228324 kB
  8. Inactive: 4621264 kB
  9. Active(anon): 7019996 kB
  10. Inactive(anon): 548528 kB
  11. Active(file): 2208328 kB
  12. Inactive(file): 4072736 kB
  13. Unevictable: 0 kB
  14. Mlocked: 0 kB
  15. SwapTotal: 0 kB
  16. SwapFree: 0 kB
  17. Dirty: 3432 kB
  18. Writeback: 0 kB
  19. AnonPages: 3034588 kB
  20. Mapped: 4243720 kB
  21. Shmem: 4533752 kB
  22. Slab: 481728 kB
  23. SReclaimable: 440712 kB
  24. SUnreclaim: 41016 kB
  25. KernelStack: 1776 kB
  26. PageTables: 39208 kB
  27. NFS_Unstable: 0 kB
  28. Bounce: 0 kB
  29. WritebackTmp: 0 kB
  30. CommitLimit: 8172740 kB
  31. Committed_AS: 14935216 kB
  32. VmallocTotal: 34359738367 kB
  33. VmallocUsed: 399340 kB
  34. VmallocChunk: 34359334908 kB
  35. HardwareCorrupted: 0 kB
  36. AnonHugePages: 456704 kB
  37. HugePages_Total: 0
  38. HugePages_Free: 0
  39. HugePages_Rsvd: 0
  40. HugePages_Surp: 0
  41. Hugepagesize: 2048 kB
  42. DirectMap4k: 12288 kB
  43. DirectMap2M: 16680960 kB
  44.  
  45. >>> ipcs -l
  46.  
  47. ------ Shared Memory Limits --------
  48. max number of segments = 4096
  49. max seg size (kbytes) = 4316816
  50. max total shared memory (kbytes) = 4316816
  51. min seg size (bytes) = 1
  52.  
  53. ------ Semaphore Limits --------
  54. max number of arrays = 128
  55. max semaphores per array = 250
  56. max semaphores system wide = 32000
  57. max ops per semop call = 32
  58. semaphore max value = 32767
  59.  
  60. ------ Messages Limits --------
  61. max queues system wide = 31918
  62. max size of message (bytes) = 8192
  63. default max size of queue (bytes) = 16384

sysctl.conf提取,由我计算:

  1. kernel.shmall = 1079204
  2. kernel.shmmax = 4420419584

postgresql.conf非默认值,由我计算:

  1. max_connections = 60 # (change requires restart)
  2. shared_buffers = 4GB # min 128kB
  3. work_mem = 4MB # min 64kB
  4. wal_sync_method = open_sync # the default is the first option
  5. checkpoint_segments = 16 # in logfile segments,min 1,16MB each
  6. checkpoint_completion_target = 0.9 # checkpoint target duration,0.0 - 1.0
  7. effective_cache_size = 6GB

这个合适吗?如果不是(或不一定),在哪种情况下是否合适?

我们确实注意到这个配置有很好的性能改进,你会如何改进它?

如何计算内核内存管理参数?

任何人都可以解释如何从头开始真正设置它们吗?

解决方法

我在这里回答了另一个问题:

Git fails to push with error ‘out of memory’

我不是在这里回答你的所有问题,而是你标题中的问题:

How to set shmall,shmmax,shmni,etc … in general and for postgresql

对于某些内核发行版,有一些设置会阻止内核将最大内存分配给单个进程:

  1. Set Kernel Parameters
  2. Modify the "/etc/sysctl.conf" file to include the lines appropriate to your operating system.
  3. # Red Hat Enterprise Linux 3.0 and CentOS 3.x
  4. kernel.shmmax = 2147483648
  5. kernel.shmmni = 4096
  6. kernel.shmall = 2097152
  7. kernel.shmmin = 1
  8. kernel.shmseg = 10
  9.  
  10. # semaphores:
  11. semmsl,semmns,semopm,semmni kernel.sem = 250 32000 100 128
  12. fs.file-max = 65536
  13.  
  14. # Red Hat Enterprise Linux 4.0 and CentOS 4.x
  15. kernel.shmmax = 536870912
  16. kernel.shmmni = 4096
  17. kernel.shmall = 2097152

如果您的进程超出限制,尽管系统上报告了最大内存,但内核将终止该进程.

注意:请注意这些设置.您可能不希望使用该示例中的设置,因为我从环境中的服务器中提取它们.

一些额外的注意事项:

  1. To Update and test kernel settings with sysctl,use following commands:
  2.  
  3. List current settings: sysctl -A|grep shm
  4.  
  5. sysctl -w kernel.shmmax=<value> to write in sysctl.conf
  6. sysctl -p /etc/sysctl.conf to read/reload the values from sysctl.conf
  7.  
  8. Disable secure linux by editing the "/etc/selinux/config" file,making sure the SELINUX flag is set as follows.
  9.  
  10. SELINUX=disabled

Is this appropriate ? If not (or not necessarily),in which case would
it be appropriate ?

当ISP提供商不希望单个客户进程占用共享服务器上的所有资源时,通常在数据中心环境中更严格地定义内核设置.

您通常不必设置内核内存参数,除非您有一个由于资源不足而被内核杀死的进程.

在某些情况下,postgres还可以为特定页面大小分配更多内存,而不是共享内存中可用的内容

  1. * The Postgresql server Failed to start. Please check the log output:
  2. 2011-11-04 05:06:26 UTC FATAL: could not create shared memory segment: Invalid
  3. argument
  4. 2011-11-04 05:06:26 UTC DETAIL: Failed system call was shmget(key=5432001,size
  5. =161849344,03600).
  6. 2011-11-04 05:06:26 UTC HINT: This error usually means that Postgresqls reques
  7. t for a shared memory segment exceeded your kernels SHMMAX parameter. You can
  8. either reduce the request size or reconfigure the kernel with larger SHMMAX. To
  9. reduce the request size (currently 161849344 bytes),reduce Postgresqls shared
  10. _buffers parameter (currently 19200) and/or its max_connections parameter (curre
  11. ntly 53).
  12. If the request size is already small,its possible that it is less than
  13. your kernels SHMMIN parameter,in which case raising the request size or recon
  14. figuring SHMMIN is called for.
  15. The Postgresql documentation contains more information about shared memo
  16. ry configuration.
  17. fail!

可以通过调整内核资源设置来解决上述示例等错误.此处详细介绍了用于确定资源设置的建议设置和方法

http://www.postgresql.org/docs/9.1/static/kernel-resources.html

但是,除非遇到与postgres进程相关的资源不足情况,否则您实际上不必触摸这些设置.这些情况通常发生在分配给它们的资源很少的共享环境或服务器中.

Can anybody explain how to really set them from the ground up ?

对于Postgres调整,您应该阅读:

http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server

猜你在找的Linux相关文章