热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

Postgres与OS内核相关的几个参数设置

Postgres与OS内核相关的几个参数设置Postgres在postgresql.conf里面的配置参数有几个是和OS的内核参数紧密相关的,通常默认值是偏小的,但设置过大也会造成Postgres的启动失败,官方文档(Part17.3)有较详细的说明,但没有例子,这里给出实际示例。测试环

Postgres与OS内核相关的几个参数设置 Postgres在postgresql.conf里面的配置参数有几个是和OS的内核参数紧密相关的,通常默认值是偏小的,但设置过大也会造成Postgres的启动失败,官方文档(Part 17.3)有较详细的说明,但没有例子,这里给出实际示例。 测试环

Postgres与OS内核相关的几个参数设置

Postgres在postgresql.conf里面的配置参数有几个是和OS的内核参数紧密相关的,通常默认值是偏小的,但设置过大也会造成Postgres的启动失败,官方文档(Part 17.3)有较详细的说明,但没有例子,这里给出实际示例。

测试环境:

DB: postgres 9.1.3

OS: CentOS 6.2 / Redhat

--内核参数文件位置:

/proc/sys/kernel

/etc/sysctl.conf

[root@localhost ~]# sysctl -a|more

kernel.shmmax = 68719476736

kernel.shmall = 4294967296

kernel.shmmni = 4096

kernel.msgmax = 65536

kernel.msgmni = 2005

kernel.msgmnb = 65536

[postgres@localhost ~]$ cat /proc/sys/kernel/sem

250 32000 32 128

(semmsl semmns semopm semmni)

1.shared_buffers VS shmget

shared_buffers是共享内存的意思,如果该值超过系统的内存值(包括swap),会造成启动失败

shmget是get share memory,它是创建一个共享内存的函数

[root@localhost ~]# free -m

total used free shared buffers cached

Mem: 1006 872 134 0 100 629

-/+ buffers/cache: 142 863

Swap: 2015 13 2002

[root@localhost ~]# su - postgres

[postgres@localhost ~]$ vi /database/pgdata/postgresql.conf

shared_buffers = 5GB

[postgres@localhost ~]$ pg_start

server starting

[postgres@localhost ~]$ FATAL: could not create shared memory segment: Cannot allocate memory

DETAIL: Failed system call was shmget(key=1949001, size=5609447424, 03600).

HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter. You can either reduce the request size or reconfigure the kernel with larger SHMALL. To reduce the request size (currently 5609447424 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.

The PostgreSQL documentation contains more information about shared memory configuration.

解决办法是减小shared_buffers、max_connections值,也或者加大shmall值、加大内存和swap,如果设置超大,大过内核值,则直接报错Invalid argument,如

[postgres@localhost ~]$ vi /database/pgdata/postgresql.conf

shared_buffers = 222222GB

max_cOnnections= 100

[postgres@localhost ~]$ pg_start

server starting

[postgres@localhost ~]$ FATAL: invalid value for parameter "shared_buffers": "222222GB"

HINT: Value exceeds integer range.

2.max_connections VS semget

max_connections是最大连接数,即允许客户端连接的最大连接数,增大连接可以允许接入更多的客户端,但设置过大同样会造成DB启动失败

semget是获取信号的一个函数,即get semaphore

[postgres@localhost ~]$ vi /database/pgdata/postgresql.conf

max_cOnnections= 5000

[postgres@localhost ~]$ pg_start

server starting

[postgres@localhost ~]$ FATAL: could not create semaphores: No space left on device

DETAIL: Failed system call was semget(1949125, 17, 03600).

HINT: This error does *not* mean that you have run out of disk space. It occurs when either the system limit for the maximum number of semaphore sets (SEMMNI), or the system wide maximum number of semaphores (SEMMNS), would be exceeded. You need to raise the respective kernel parameter. Alternatively, reduce PostgreSQL's consumption of semaphores by reducing its max_connections parameter.

The PostgreSQL documentation contains more information about configuring your system for PostgreSQL.

上述的空间不够不是指的是磁盘空间不够,而是创建semaphores时空间参数不够,系统调用参数semget报错,但是错误信息感觉有些迷惑......解决办法通常是减小max_connections,或者增大内核参数,如semmni,semmns等,在/proc/sys/kernel/sem里面调整,如

[root@localhost ~]# sysctl -w kernel.sem="500 64000 50 150"

kernel.sem = 500 64000 50 150

[root@localhost ~]# cat /proc/sys/kernel/sem

500 64000 50 150

附参数说明

Name Desc Reasonable Value

shmmax Maximum size of shared memory segment (bytes) at least several megabytes (see text)

shmmin Minimum size of shared memory segment (bytes) 1

shmall Total amount of shared memory available (bytes or pages) if bytes, same as SHMMAX; if pages, ceil(SHMMAX/PAGE_SIZE)

shmseg Maximum number of shared memory segments per process only 1 segment is needed, but the default is much higher

shmmni Maximum number of shared memory segments system-wide like SHMSEG plus room for other applications

semmni Maximum number of semaphore identifiers (i.e., sets) at least ceil((max_connections + autovacuum_max_workers + 4) / 16)

semmns Maximum number of semaphores system-wide ceil((max_connections + autovacuum_max_workers

+ 4) / 16) * 17 plus room for other applications

semmsl Maximum number of semaphores per set at least 17

semmap Number of entries in semaphore map see text

semvmx Maximum value of semaphore at least 1000 (The default is often 32767; do not change unless necessary)

共享内存的使用:

usage Approximate shared memory bytes

Connections (1800 + 270 * max_locks_per_transaction) * max_connections

Autovacuum workers (1800 + 270 * max_locks_per_transaction) * autovacuum_max_workers

Prepared transactions (770 + 270 * max_locks_per_transaction) * max_prepared_transactions

Shared disk buffers (block_size + 208) * shared_buffers

Wal buffers (wal_block_size + 8) * wal_buffers

Fixed space requirements 770KB


推荐阅读
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • CentOS 7部署KVM虚拟化环境之一架构介绍
    本文介绍了CentOS 7部署KVM虚拟化环境的架构,详细解释了虚拟化技术的概念和原理,包括全虚拟化和半虚拟化。同时介绍了虚拟机的概念和虚拟化软件的作用。 ... [详细]
  • CEPH LIO iSCSI Gateway及其使用参考文档
    本文介绍了CEPH LIO iSCSI Gateway以及使用该网关的参考文档,包括Ceph Block Device、CEPH ISCSI GATEWAY、USING AN ISCSI GATEWAY等。同时提供了多个参考链接,详细介绍了CEPH LIO iSCSI Gateway的配置和使用方法。 ... [详细]
  • 本文介绍了在Linux系统中设置文件ACL权限的方法和使用说明,包括在centos7.3和centos6.9中开启ACL权限的两种方法:在挂载时指定打开ACL权限和修改默认的属性信息。同时提供了对ACL权限的详细解释和应用场景。 ... [详细]
  • 本文介绍了在CentOS 6.4系统中更新源地址的方法,包括备份现有源文件、下载163源、修改文件名、更新列表和系统,并提供了相应的命令。 ... [详细]
  • Vagrant虚拟化工具的安装和使用教程
    本文介绍了Vagrant虚拟化工具的安装和使用教程。首先介绍了安装virtualBox和Vagrant的步骤。然后详细说明了Vagrant的安装和使用方法,包括如何检查安装是否成功。最后介绍了下载虚拟机镜像的步骤,以及Vagrant镜像网站的相关信息。 ... [详细]
  • Linux下安装依赖包版本高解决方法
    本文介绍了在Linux系统下,当已安装的依赖包版本高于需要安装的依赖包版本时,解决方法包括欺骗安装程序和修改相关配置文件等操作。针对不同情况,提供了不同的解决方案。 ... [详细]
  • centos安装Mysql的方法及步骤详解
    本文介绍了centos安装Mysql的两种方式:rpm方式和绿色方式安装,详细介绍了安装所需的软件包以及安装过程中的注意事项,包括检查是否安装成功的方法。通过本文,读者可以了解到在centos系统上如何正确安装Mysql。 ... [详细]
  • Centos下安装memcached+memcached教程
    本文介绍了在Centos下安装memcached和使用memcached的教程,详细解释了memcached的工作原理,包括缓存数据和对象、减少数据库读取次数、提高网站速度等。同时,还对memcached的快速和高效率进行了解释,与传统的文件型数据库相比,memcached作为一个内存型数据库,具有更高的读取速度。 ... [详细]
  • Centos7搭建ELK(Elasticsearch、Logstash、Kibana)教程及注意事项
    本文介绍了在Centos7上搭建ELK(Elasticsearch、Logstash、Kibana)的详细步骤,包括下载安装包、安装Elasticsearch、创建用户、修改配置文件等。同时提供了使用华为镜像站下载安装包的方法,并强调了保证版本一致的重要性。 ... [详细]
  • Linux下安装免费杀毒软件ClamAV及使用方法
    本文介绍了在Linux系统下安装免费杀毒软件ClamAV的方法,并提供了使用该软件更新病毒库和进行病毒扫描的指令参数。同时还提供了官方安装文档和下载地址。 ... [详细]
  • LVS实现负载均衡的原理LVS负载均衡负载均衡集群是LoadBalance集群。是一种将网络上的访问流量分布于各个节点,以降低服务器压力,更好的向客户端 ... [详细]
  • CentOS7.8下编译muduo库找不到Boost库报错的解决方法
    本文介绍了在CentOS7.8下编译muduo库时出现找不到Boost库报错的问题,并提供了解决方法。文章详细介绍了从Github上下载muduo和muduo-tutorial源代码的步骤,并指导如何编译muduo库。最后,作者提供了陈硕老师的Github链接和muduo库的简介。 ... [详细]
  • 本文详细介绍了在Centos7上部署安装zabbix5.0的步骤和注意事项,包括准备工作、获取所需的yum源、关闭防火墙和SELINUX等。提供了一步一步的操作指南,帮助读者顺利完成安装过程。 ... [详细]
author-avatar
梦天使悠然
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有