PostgreSql parameter configuration

1. Access control parameter configuration

https://xiaosonggong.blog.csdn.net/article/details/124264877

2. Database parameter configuration

2.1 Overview

  The parameter configuration parameters of PostgreSQL are centrally managed in the postgresql.conf file, which is similar to Oracle's pfile file. In addition, PostgreSQL also has a postgresql.auto.conf file, which saves the settings modified by the alter system command , similar to Oracle's spfile, the difference is as follows:

postgresql.conf pfile postgresql.auto.conf spfile
ASCII text file ASCII text file ASCII text file binary file
edit manually edit manually Manual editing, alter system modification alter system modify
Restart the library or reload the configuration file to take effect Restart the library with pfile to take effect Restart the library or reload the configuration file to take effect Take effect immediately or restart the library to take effect

2.2 Definition rule description

Examples are as follows :

--postgresql.conf 部分示例
# - Memory -

shared_buffers = 128MB                  # min 128kB
                                        # (change requires restart)
#huge_pages = try                       # on, off, or try
                                        # (change requires restart)
#temp_buffers = 8MB                     # min 800kB
#max_prepared_transactions = 0          # zero disables the feature
                                        # (change requires restart)

--postgresql.auto.conf 部分示例
listen_addresses = '*'
max_connections = '200'
superuser_reserved_connections = '10'
shared_buffers = '500MB'
log_destination = 'csvlog'
logging_collector = 'on'
log_directory = 'logs'
  • Each line specifies a parameter.
  • The equal sign between name and value is optional, shared_buffers = 128MB is equivalent to shared_buffers 128MB.
  • Whitespace is meaningless (except within a quoted parameter value) and blank lines are ignored.
  • The pound sign (#) represents a comment.
  • The parameter names of all configuration items are case insensitive, shared_buffers = 128MB is equivalent to SHARED_BUFFERS = 128MB.
  • If the file contains multiple entries for the same parameter, all but the last are ignored.
  • The postgresql.auto.conf file overrides the configuration of the same name in the postgresql.conf file.
  • All relative path information is relative to the database data directory, such as the above log directory logs, the full path is $PGDATA/logs.
  • The comment information after the parameter is the description of the parameter. For example, # min 128kB above means that the minimum value of shared_buffers is 128kB. # (change requires restart) means that the modification of the shared_buffers parameter needs to restart the database to take effect. If the comment does not indicate that the database needs to be restarted to take effect, generally reloading the configuration file will take effect.
pg_ctl reload -D 数据目录

Equivalent to connecting to the database to execute

select pg_reload_conf();
  • The parameter value has the following 5 data types:

Boolean: Boolean values ​​are case-insensitive and can be on, off, true, false, yes, no, 1, 0.
Integer: The value can specify the unit, such as some memory configuration parameters can specify KB, MB, GB and other units.
Floating point number: You can specify a decimal value, such as "1.0".
String: A string enclosed in single quotes, such as 'csvlog'.
Enums: Strings enclosed in single quotes are not required.

2.3 Configuration Tips

1) Support include to call external files

When managing large numbers of servers, a modular management configuration is often efficient.

--调用外部配置文件
include '/home/postgres/conf.d/shared.conf'
include '/home/postgres/conf.d/memory.conf'
include '/home/postgres/conf.d/server.conf'

--调用外部目录
include_dir '/home/postgres/conf.d'

--目录中配置文件可以按如下方式命令
00shared.conf
01memory.conf
02server.conf

When calling an external directory, there are the following restrictions :

  • Only non-directory files ending in .conf are included.
  • Filenames beginning with a . character are ignored.
  • The database will be called sequentially according to the naming method. When there are duplicate parameters, the configuration called last will overwrite the previous configuration.

2) Query related information about parameter configuration

--show 参数名可查看当前生效参数配置
postgres=# show log_statement;
 log_statement
---------------
 ddl
--上述效果等同于
postgres=# select setting from pg_settings where name = 'log_statement';
 setting
---------
 ddl

--枚举类型可选参数值查询
postgres=# select enumvals from pg_settings where name = 'log_statement';
      enumvals
--------------------
 {none,ddl,mod,all}

--参数描述查询
postgres=# select short_desc,extra_desc from pg_settings where name = 'log_statement';
             short_desc              | extra_desc
-------------------------------------+------------
 Sets the type of statements logged. |

--查询参数默认单位
postgres=# select unit from pg_settings where name = 'autovacuum_vacuum_cost_delay';
 unit
------
 ms

--查询参数如何生效
postgres=# select context from pg_settings where name  = 'log_statement';
  context
-----------
 superuser

Description of context field value :

internal : These parameters are read-only parameters, some of which are hard-coded by the postgres program, or determined with different editing options; some parameters are determined when the database instance is initially used, such as running when creating an instance Initdb, you can use some command-line parameter options to determine the value of certain parameters, such as using -k in initdb to initially turn the parameter "data_checksums" to "on", and then you can no longer change the value of
this parameter. Such parameter values ​​cannot be configured in postgresql.conf because they are hard-coded by the postgres program or when the instance is initialized.
postmaster : Changing the value of this parameter requires restarting the PostgreSQL instance. After these parameters can be changed in the postgresql.onf file, the PostgreSQL instance needs to be restarted for the modification to take effect.
sighup : changing the value of such parameters in the postgresql.conf file does not need to restart the database, but only needs to send a SIGHUP signal to the postmaster process to let it restart and load and configure new parameter values. Of course, after the postmaster process receives the SIGHUP signal, it will also send the SIGHUP signal to its child processes, so that the new parameter values ​​will take effect in all processes.
backend : Changing such settings in the postgresql.conf file does not require restarting the server, but only needs to send a SIGHUP signal to the postmaster to let it reread the new configuration values ​​in the postgresql.conf file, but the new configuration values ​​will only appear in In the new connection after modification, the value of this parameter in the existing connection will not change. The value of such parameters can also be changed by some parameters of the connection when creating a new connection. For example, the configuration value for this connection can be changed through libpq's PGOPTIONS environment variable.
superuser: Such parameters can be changed by superusers using the SET command, such as the parameter "deadlock_timeout" for detecting deadlock timeout. When a super user changes the value of this parameter, it will only affect his own sesssion configuration, and will not affect other users' configuration of this parameter. Sending a SIGHUP signal to the Postmaster process will only affect subsequent connections, not existing connections.
user : This type of parameter can be used by ordinary users to use the SET command to change the configuration value in this connection. This type of parameter is no different from the superuser type parameter except that ordinary users can also change it.

3) postgresql.conf parameter configuration

https://xiaosonggong.blog.csdn.net/article/details/121038380

Guess you like

Origin blog.csdn.net/songyundong1993/article/details/132160399