PostgreSQL——服务器配置_{postgresql.conf}

一、设置参数

  • 所有参数名称都是不区分大小写的
  • 值为字符串时,需要单引号
  • 值为数值时不需要单引号,但带单位时,需要单引号
  • 配置文件(如:postgresql.conf、postgresql.auto.conf、pg_hba.conf) 默认在 database cluster 中
  • 可以在 postgresql.conf 中使用 include ‘file’ 或 include_dir ‘directory’ 形式插入外部文件或目录(其中的所有文件)内容

 二、文件位置

  • data_directory = '' 声明 database cluster 目录
  • hba_file = '' 指明 host base authentication 配置文件,通常是 pg_hba.conf(客户端认証主配置文件)
  • ident_file = '' 用于用户名匹配的配置文件,通常是 pg_ident.conf
  • external_pid_file = '' 声明此项将在 postmaster.pid 之外,生成一个額外的 PID 文件
  • 注:pg_ctl 与 initdb 的 -D 选项以及 PGDATA 环境变量指向的是 postgresql.conf 的位置,不是实际数据文件的位置,若配置文件与数据文件不在同一目录,必須在配置文件中指明 data_directory

三、连接与认証

  • listen_address = '' 监听目标,默认为 localhost ,多个 IP 用逗号分割,* 表示监听所有连接,0.0.0.0 表示监听所有 ipv4 连接,:: 表示监听所有 ipv6 连接,若留空,表示仅接受 Unix-domain sockets 本机连接
  • port = 5432 指明监听端口,默认 5432
  • max_connections = 100 最大并发连接数量,默认为 100 ,从服务器的此项设置必須大于或等于主服务器的值
  • superuser_reserved_connections = 3 为 PostgreSQL 的超級用户(通常为 postgres)預留的连接数,故普通客户端能连接的最大并发连接数量为 max_connections 减去本项之后的值
  • unix_socket_directories = '' 指明 Unix-domain sockets 的位置,以逗号分割多个值,若此项启用但值留空,则表示禁用 unix 域套接字连接,仅接受 TCP/IP 套接字连接
  • unix_socket_permissions = 0777 域套接字权限,默认为 0777 ,应设为 0700
  • authentication_timeout = ’1min‘ 默认是 1 分鈡,可设定范围 1s - 600s
  • ssl = off 是否启用 ssl 支持,默认是 off (bool 值无須加引号),启用设置 on
  • ssl_ca_file = ’‘ 用于証明客户端身份,指定包含可信任的 CA 机构信息(CA 的公钥等)的文件位置;若留空,则不进行客户端 SSL 认証
  • ssl_crl_file = ’‘ 用于証明客户端身份,指定包含其 CA 頒发机构的吊销列表的文件位置,在此列表中的客户端将不能连接 ;CRL 指 certificate revocation list
  • ssl_cert_file = ’‘ 用于証明服务端身份;指定服务器端 CA 証书的位置,默认是 server.crt
  • ssl_key_file = '' 用于証明服务端身份;指定服务器端 SSL 私钥的位置,默认是 server.key

四、資源消耗

  • shared_buffers = '128MB' Sets the amount of memory the database server uses for shared memory buffers,默认是 128MB ,对于专门的数据库服务器,应将其设置为物理内存的 25% 左右,最大不超过 40% ;同时需要上調 checkpoint_segments(9.5版本以前) 或 max_wal_size(9.6版本)
  • huge_pages = try 是否使用大頁内存,默认是 try ,即尽可能使用,否则转而使用普通的 4K 内存頁面;使用大頁可提高性能,仅在 Linux 平台上有效;另有 on 及 off 选项可用,分别代表强制使用大頁 及 不使用大頁
  • work_mem = '4MB' 单个排序、聚合、子查詢处理中使用的内存大小,默认是 4MB ,实际使用超限时会使用临时磁盘文件,设置较大的值可以提升性能,但并发較多时可能占用大量内存;
  • maintenance_work_mem = '64MB' 索引、外鍵等管理性操作可使用的最大内存数,默认为 64MB ,較大的值可以改进数据库转储、清理等操作的性能
  • max_stack_depth = '2MB' 服务器在栈中执行操作的最大深度,默认是 2MB ,較大的值可提升性能,但不能超过内核限制(使用 ulimits -s 查看),否则执行递归函数时可能会导致程序崩溃

五、Write Ahead Log

  • wal_level = minimal 預写式日志的记录級别,默认为 minimal ,推荐 replica(9.5及之前版本为 hot_standby),另可选 logical 
  • fsync = on 磁盘同步,Linux 平台实际执行的是 fdatasync ,默认为 on
  • full_page_writes = on 默认开启;When this parameter is on, the PostgreSQL server writes the entire content of each disk page to WAL during the first modification of that page after a checkpoint
  • wal_compression = off 是否启用 WAL 压缩,默认关闭,开启将节省磁盘空间,但消耗更多 cpu 資源
  • wal_buffers = '' 推荐设置 5-10M ;The amount of shared memory used for WAL data that has not yet been written to disk. The default setting of -1 selects a size equal to 1/32nd (about 3%) of shared_buffers, but not less than 64kB nor more than the size of one WAL segment, typically 16MB
  • wal_writer_delay = '' WAL 写入延时,单位 ms ,即毫秒,默认 200ms

六、复制

一 

原文地址:https://www.cnblogs.com/hadex/p/6008188.html