Postgresql服务配置-设置参数

1、Parameter Names and Values

每个参数都有一个值。所有参数名称都不区分大小写。每个参数值都采用五种类型之一: 布尔、字符串、整数、浮点或枚举 (枚举)

  • Boolean:值可以是off, true, false, yes, no, 1, 0 (区分大小写)或其中一个值的任何明确前缀。
  • String:通常用单引号括起来,数字和标识符可以忽略单引号
  • Numeric:允许整数和浮点型
  • Numeric with Unit:带单位的数字,某些数字参数具有隐式单位,为方便起见, 可以使用显式指定的单位给出设置, 例如时间值的 "120 ms", 它们将转换为参数的实际单位。请注意, 该值必须以字符串 (带引号) 的形式写入才能使用此功能。单位名称区分大小写, 数值和单位之间可以有空白。
  • Enumerated:枚举不区分大小写。

2、Parameter Interaction via the Configuration File

通过参数文件配置

  • 通过更改文件postgresql.conf配置参数
  • 通过这种方式设置的参数,提供的是默认值
  • pg_ctl reload可使服务器重新读取配置文件
  • pg_file_settings查看参数文件配置的参数
查看参数在参数文件中的配置
postgres=# select * from pg_FILE_settings where name='max_connections';
sourcefile | sourceline | seqno | name | setting | applied | error
-----------------------------------------+------------+-------+-----------------+---------+---------+-------
/opt/postgres/data/postgresql.conf | 66 | 3 | max_connections | 100 | f |
/opt/postgres/data/postgresql.auto.conf | 9 | 30 | max_connections | 200 | t |
(2 rows)

3、Parameter Interaction via SQL

pg提供三种SQL命令用于配置参数

  • alter system命令更改全局(global/cluster)配置
  • alter database命令针对每个数据库更改设置,覆盖全局设置
  • alter role命令允许配置特定用户的参数值,覆盖全局和数据库设置

    注意:alter database和alter role仅对新的会话生效,且有些参数无法修改,使之永久生效,只能修改动态参数

postgres=# alter database postgres set max_connections=300;
ERROR: parameter "max_connections" cannot be changed without restarting the server
  • pg_settings查看当前参数配置

    注意:通过查询系统表pg_settings,可以了解更改配置后使参数生效是通过重新载入配置文件还是重启数据库服务。如果context显示postmaster需要重启数据库服务,执行pg_ctl restart;如果context显示sighup,重新加载pg_ctl即执行pg_ctl reload命令。

查看当前参数值
postgres=# select name,setting,unit,context,sourcefile from pg_settings where name='max_connections';
name | setting | unit | context | sourcefile
-----------------+---------+------+------------+-----------------------------------------
max_connections | 200 | | postmaster | /opt/postgres/data/postgresql.auto.conf
(1 row)
查看是否需要重启
postgres=# select name,context from pg_settings where name in ('max_connections','log_connections','log_temp_files');
name | context
-----------------+-------------------
log_connections | superuser-backend
log_temp_files | superuser
max_connections | postmaster
(3 rows)
context内容参考:
https://www.postgresql.org/docs/10/view-pg-settings.html
There are several possible values of context. In order of decreasing difficulty of changing the setting, they are:
internal
These settings cannot be changed directly; they reflect internally determined values. Some of them may be adjustable by rebuilding the server with different configuration options, or by changing options supplied to initdb.
postmaster
These settings can only be applied when the server starts, so any change requires restarting the server. Values for these settings are typically stored in the postgresql.conf file, or passed on the command line when starting the server. Of course, settings with any of the lower context types can also be set at server start time.
sighup
Changes to these settings can be made in postgresql.conf without restarting the server. Send a SIGHUP signal to the postmaster to cause it to re-read postgresql.conf and apply the changes. The postmaster will also forward the SIGHUP signal to its child processes so that they all pick up the new value.
superuser-backend
Changes to these settings can be made in postgresql.conf without restarting the server. They can also be set for a particular session in the connection request packet (for example, via libpq's PGOPTIONS environment variable), but only if the connecting user is a superuser. However, these settings never change in a session after it is started. If you change them in postgresql.conf, send a SIGHUP signal to the postmaster to cause it to re-read postgresql.conf. The new values will only affect subsequently-launched sessions.
backend
Changes to these settings can be made in postgresql.conf without restarting the server. They can also be set for a particular session in the connection request packet (for example, via libpq's PGOPTIONS environment variable); any user can make such a change for their session. However, these settings never change in a session after it is started. If you change them in postgresql.conf, send a SIGHUP signal to the postmaster to cause it to re-read postgresql.conf. The new values will only affect subsequently-launched sessions.
superuser
These settings can be set from postgresql.conf, or within a session via the SET command; but only superusers can change them via SET. Changes in postgresql.conf will affect existing sessions only if no session-local value has been established with SET.
user
These settings can be set from postgresql.conf, or within a session via the SET command. Any user is allowed to change their session-local value. Changes in postgresql.conf will affect existing sessions only if no session-local value has been established with SET.
  • pg_settings视图可以查看和修改(只能修改会话级别的值)
    In addition, the system view pg_settings can be used to view and change session-local values
  • 客户端连接后可以使用show和set命令设置当前会话的参数值,不影响其他会话。show调用内部函数current_setting,set调用内部函数set_config(setting_name, new_value, is_local)
查看参数大小
postgres=# show shared_buffers;
shared_buffers
----------------
128MB
(1 row)
or
postgres=# SELECT name,setting,unit,current_setting(name) FROM pg_settings WHERE name='shared_buffers';
name | setting | unit | current_setting
----------------+---------+------+-----------------
shared_buffers | 16384 | 8kB | 128MB
(1 row)

注意:set命令只能由superuser执行

4、Parameter Interaction via the Shell

除了在数据库或角色级别设置全局默认值或附加重写外, 还可以通过 shell 工具将设置传递给 PostgreSQL。服务器和客户端库都通过 shell 接受参数值。

  • 在服务器启动过程中, 可以通过-c 命令行参数将参数设置传递给 postgres
postgres -c log_connections=yes -c log_destination='syslog'
  • 通过 libpq 启动客户端会话时, 可以使用 PGOPOPS 环境变量指定参数设置。以这种方式建立的设置构成会话生存期的默认值, 但不会影响其他会话。由于历史原因, POSTGRES 的格式类似于启动 postgres 命令时使用的格式;具体而言, 必须指定-c 标志。例如,
env PGOPTIONS="-c geqo=off -c statement_timeout=5min" psql

5、Managing Configuration File Contents

PostgreSQL 提供了几个功能, 用于将复杂的 poostgresql. conf 文件分解为子文件。在管理具有相关但不相同的配置的多台服务器时, 这些功能特别有用。
除了单个参数设置外, postgresql. conf 文件还可以包含指令, 这些指令指定要读取和处理的另一个文件, 就像此时将其插入到配置文件中一样。此功能允许将配置文件划分为物理上独立的部分。如:

include 'filename'

文件名没有绝对路径时, 则将其视为相对于包含引用配置文件的目录

也可以指定整个目录。如:

include_dir 'directory'

目录名称没有绝对路径时,则将其视为相对于包含引用配置文件的目录。

在指定的目录中, 将只包括名称以后缀. conf 结尾的非目录文件。的开始的文件名。字符也会被忽略, 以防止错误, 因为此类文件隐藏在某些平台上。包含目录中的多个文件按文件名顺序处理

Postgresql服务器配置-设置参数相关推荐

  1. mysql设置参数0和1_MySQL 8.0 首个自适应参数横空出世

    什么是自适应参数 MySQL8.0推出一个号称可以自适应服务器的参数,保证在各种不同的服务器.虚拟机.容器下自动适配服务器资源,让我们一起来看看到底它能做到什么地步. 自适应参数是如何设置和适应变化的 ...

  2. 使用福禄克CFP单模光纤测试仪像专家一样设置参数!

    在使用福禄克CFP单模光纤测试仪测试光纤链路时,如果要测试一个光纤接头的损耗,不可能只测量单个光纤接头,必须将其与类似的已知质量接头相匹配.这里光纤接头损耗指的是配对光纤接头的损耗,这也是为什么要设置 ...

  3. functools.partial()==>预先设置参数,使得之后调用的时候,减少函数的参数

    import functoolsdef add(a):print(a + 1)add(2) #输出3newAdd = functools.partial(add,2)newAdd() #输出3 首先大 ...

  4. 设置linearlayout最大高度_ICEM CFD网格设置参数意义

    线下工程实例专题计划 (2019年10月-2020年1月) ICEM CFD网格设置参数意义 一般来说,线和边单位参数设置,Height.Height Ratio和层数是常用的3个参数.如果只设置了层 ...

  5. PostgreSQL的常见参数和技巧

    墨墨导读:本文主要详述PostgreSQL的常见参数以及一些技巧. 1. psql命令 1.1 General options 1.1.1- ? 我们可以psql -?或者psql --help看下p ...

  6. python scipy optimize_scipy.optimize.fminbound:设置参数的界限

    我正在尝试使用的fminbound函数优化函数scipy.optimize公司模块.我想设置参数边界以使答案在物理上合理(例如,&gt:0).在import scipy.optimize as ...

  7. 西门子mag6000接线_电磁流量计MAG5000或MAG6000,通过脉冲输出累积流量,脉冲输出如何接线,如何设置参数?...

    脉冲输出分有源(变送器内部供电)输出和无源(外部供电)输出两种方式: 有源输出:端子57和58,其中57为正端,58为负端,直接将57和58对应连接到脉冲接收装置的正负端即可: 无源输出:端子56和5 ...

  8. camera(17)---设置摄像头方向、打开线程与预览线程、设置参数、Camera外设按键、自动对焦与触摸对焦、拍照、人脸检测、位置管理、旋转管理、变焦、录像

    [Android]设置摄像头方向.打开线程与预览线程.设置参数.Camera外设按键.自动对焦与触摸对焦.拍照.人脸检测.位置管理.旋转管理.变焦.录像 阅读数:1673 设置摄像头方向.打开线程与预 ...

  9. Android学习笔记---16_采用SharedPreferences保存用户偏好设置参数

    16_采用SharedPreferences保存用户偏好设置参数 Android学习笔记---16_采用SharedPreferences保存用户偏好设置参数 2013-03-08 16_采用Shar ...

最新文章

  1. SAP WM 二步法确认TO场景下WM库存状态变化
  2. 亚马逊是如何进行软件开发的
  3. php 服务器运行状态,检查服务器各种服务的运行状态
  4. Winform中实现连接Mysql并获取所有表名
  5. leetcode最小面积_LeetCode—— 939. 最小面积矩形(JavaScript)
  6. Hibernate缓存基础知识
  7. 房价在手,天下我有 --反手就撸一个爬虫(终)
  8. leetcode 1232. 缀点成线
  9. leetocde1129. 颜色交替的最短路径(bfs)
  10. 智能会议系统(32)---WebRTC学习之三:录音和播放
  11. VisualGDB调试,实现VS环境下调试Android
  12. 全才出书,值得一读——Leo推荐《我也能做CTO之程序员职业规划》
  13. 苹果6s强制删除id锁_苹果ID锁安全神话破灭!2分钟就能解锁
  14. Linux 虚拟机配置静态IP地址
  15. openwrt使用tayga/totd实现NAT64/DNS64
  16. Linux高级应用(三)液晶屏显示图片
  17. IPC Send timeout detected模拟和总结
  18. 搜狗浏览器屏蔽广告插件_搜狗浏览器屏蔽芒果TV视频广告:被判不正当竞争,赔了12万...
  19. linux常用命令导图
  20. 掌握正确的指法---击键要领、雨儿五笔打字视频

热门文章

  1. Samba+lamp完成指定任务
  2. apache2.4中layout模块和ssi模块的冲突
  3. 进程中的 hp1006MC.exe是什么,怎么解决
  4. call,apply,bind,new实现原理
  5. Nginx的upstream目前支持5种分配方式
  6. 六边形块级元素的绘制
  7. ng2项目启动过程出现‘getSymbolByModule' of undefined‘错误
  8. Linux 系统修复
  9. 局部变量和static变量
  10. 重启服务才可连接BOOT服务器