本文共 6233 字,大约阅读时间需要 20 分钟。
每个参数都有一个值。所有参数名称都不区分大小写。每个参数值都采用五种类型之一: 布尔、字符串、整数、浮点或枚举 (枚举)
通过参数文件配置
查看参数在参数文件中的配置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)
pg提供三种SQL命令用于配置参数
postgres=# alter database postgres set max_connections=300;ERROR: parameter "max_connections" cannot be changed without restarting the server
查看当前参数值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-backendlog_temp_files | superusermax_connections | postmaster(3 rows)context内容参考:https://www.postgresql.org/docs/10/view-pg-settings.htmlThere are several possible values of context. In order of decreasing difficulty of changing the setting, they are:internalThese 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.postmasterThese 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.sighupChanges 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-backendChanges 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.backendChanges 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.superuserThese 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.userThese 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.
查看参数大小postgres=# show shared_buffers;shared_buffers ----------------128MB(1 row)orpostgres=# 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执行
除了在数据库或角色级别设置全局默认值或附加重写外, 还可以通过 shell 工具将设置传递给 PostgreSQL。服务器和客户端库都通过 shell 接受参数值。
postgres -c log_connections=yes -c log_destination='syslog'
env PGOPTIONS="-c geqo=off -c statement_timeout=5min" psql
PostgreSQL 提供了几个功能, 用于将复杂的 poostgresql. conf 文件分解为子文件。在管理具有相关但不相同的配置的多台服务器时, 这些功能特别有用。
除了单个参数设置外, postgresql. conf 文件还可以包含指令, 这些指令指定要读取和处理的另一个文件, 就像此时将其插入到配置文件中一样。此功能允许将配置文件划分为物理上独立的部分。如:include 'filename'
文件名没有绝对路径时, 则将其视为相对于包含引用配置文件的目录
也可以指定整个目录。如:include_dir 'directory'
目录名称没有绝对路径时,则将其视为相对于包含引用配置文件的目录。
在指定的目录中, 将只包括名称以后缀. conf 结尾的非目录文件。的开始的文件名。字符也会被忽略, 以防止错误, 因为此类文件隐藏在某些平台上。包含目录中的多个文件按文件名顺序处理转载地址:http://pewsl.baihongyu.com/