postgresql.conf
是PostgreSQL数据库服务器的主要配置文件之一,它包含了许多重要的参数,用于配置数据库服务器的各种行为。下面是一些常用的参数的详细说明:
-
listen_addresses
:这个参数指定PostgreSQL服务器监听的IP地址。默认情况下,它设置为localhost,只允许本地连接。如果你想允许来自其他IP地址的连接,你需要将它设置为你的服务器的公共IP地址。 -
port
:这个参数指定PostgreSQL服务器监听的端口号。默认情况下,它设置为5432。 -
max_connections
:这个参数指定PostgreSQL服务器允许的最大连接数。默认情况下,它设置为100。 -
shared_buffers
:这个参数指定PostgreSQL服务器用于缓存数据的内存大小。默认情况下,它设置为128MB。 -
work_mem
:这个参数指定每个查询可用的内存量。默认情况下,它设置为4MB。 -
maintenance_work_mem
:这个参数指定PostgreSQL服务器用于维护操作的内存量。默认情况下,它设置为64MB。 -
effective_cache_size
:这个参数指定PostgreSQL服务器可以使用的系统缓存的大小。默认情况下,它设置为4GB。 -
checkpoint_timeout
:这个参数指定PostgreSQL服务器执行自动检查点的时间间隔。默认情况下,它设置为5分钟。 -
wal_level
:这个参数指定PostgreSQL服务器记录事务日志的级别。默认情况下,它设置为minimal。 -
max_wal_size
:这个参数指定PostgreSQL服务器允许的最大事务日志文件大小。默认情况下,它设置为1GB。 -
min_wal_size
:这个参数指定PostgreSQL服务器允许的最小事务日志文件大小。默认情况下,它设置为80MB。 -
max_worker_processes
:这个参数指定PostgreSQL服务器允许的最大后台工作进程数。默认情况下,它设置为8 -
log_line_prefix
: 这个参数指定日志信息的前缀,可以包括时间、用户名、数据库名、进程ID等信息。默认情况下,它设置为"%t [%p]: [%l-1] user=%u,db=%d,",表示输出日志信息的时间、进程ID、日志级别减1、用户名和数据库名等信息。 -
log_destination
:这个参数指定PostgreSQL服务器的日志输出目的地,可以是stderr、syslog、csvlog等。默认情况下,它设置为stderr。 -
log_min_messages
:这个参数指定日志输出的最小级别。默认情况下,它设置为WARNING,表示只输出警告级别及以上的日志信息。 -
datestyle
:这个参数指定日期的格式。默认情况下,它设置为ISO,表示使用ISO标准的日期格式。 -
timezone
:这个参数指定时区。默认情况下,它设置为UTC。 -
default_statistics_target
:这个参数指定查询优化器在收集统计信息时使用的样本数目。默认情况下,它设置为100。 -
autovacuum
:这个参数指定是否启用自动VACUUM。默认情况下,它设置为on。 -
vacuum_cost_limit
:这个参数指定VACUUM操作的成本限制,当VACUUM操作的成本超过该限制时,它将停止执行。默认情况下,它设置为200。 -
autovacuum_vacuum_scale_factor
: 这个参数指定自动VACUUM操作的触发阈值,当表中已删除行的占比达到该阈值时,自动触发VACUUM操作。默认情况下,它设置为0.2。 -
autovacuum_analyze_scale_factor
: 这个参数指定自动VACUUM操作的触发阈值,当表中新增行的占比达到该阈值时,自动触发ANALYZE操作。默认情况下,它设置为0.1。 -
autovacuum_vacuum_cost_limit
: 这个参数指定自动VACUUM操作的成本限制,当VACUUM操作的成本超过该限制时,它将停止执行。默认情况下,它设置为-1,表示不设置成本限制。 -
autovacuum_vacuum_scale_factor
: 这个参数指定自动VACUUM操作的触发阈值,当表中已删除行的占比达到该阈值时,自动触发VACUUM操作。默认情况下,它设置为0.2。 -
checkpoint_completion_target
: 这个参数指定执行检查点操作时,需要将多少缓存中的数据写入磁盘。默认情况下,它设置为0.5。 -
default_text_search_config
: 这个参数指定全文搜索使用的默认配置。默认情况下,它设置为pg_catalog.simple。 -
max_parallel_workers
: 这个参数指定允许的最大并行工作进程数。默认情况下,它设置为8。 -
max_parallel_workers_per_gather
: 这个参数指定每个查询允许的最大并行工作进程数。默认情况下,它设置为2。 -
jit
: 这个参数指定是否启用JIT(即时编译)优化。默认情况下,它设置为off。 -
jit_above_cost
: 这个参数指定在哪些查询成本高于该阈值时,JIT优化将被启用。默认情况下,它设置为100000。
这些参数是PostgreSQL配置文件中的一部分。在修改配置文件时,需要谨慎处理,避免对数据库的正常运行造成影响。如果不确定如何配置,可以参考PostgreSQL官方文档或寻求专业的帮助。
下面是关于Postgresql 13.7 postgresql.conf配置文件详解部分:
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
# 该文件由如下格式的行组成:
# name = value
#
# (The "=" is optional.) Whitespace may be used. Comments are introduced with
# "#" anywhere on a line. The complete list of parameter names and allowed
# values can be found in the PostgreSQL documentation.
# (=是可选的。)可以使用空格。注释在一行中的任意位置用“#”引入。参数名称和允许的值的完整列表可以在PostgreSQL文档中找到。
# The commented-out settings shown in this file represent the default values.
# Re-commenting a setting is NOT sufficient to revert it to the default value;
# you need to reload the server.
# 该文件中显示的带注释的设置表示默认值。重新注释一个设置不足以将其恢复为默认值;您需要重新加载服务器。
# This file is read on server startup and when the server receives a SIGHUP
# signal. If you edit the file on a running system, you have to SIGHUP the
# server for the changes to take effect, run "pg_ctl reload", or execute
# "SELECT pg_reload_conf()". Some parameters, which are marked below,
# require a server shutdown and restart to take effect.
# 该文件在服务器启动和服务器接收到SIGHUP信号时读取。如果你在一个正在运行的系统上编辑这个文件,你必须SIGHUP服务器以便修改生效,运行"pg_ctl reload",或者执行"SELECT pg_reload_conf()"。下面标记的一些参数需要服务器关闭和重新启动才能生效。
# Any parameter can also be given as a command-line option to the server, e.g.,
# "postgres -c log_connections=on". Some parameters can be changed at run time
# with the "SET" SQL command.
# 任何参数也可以作为命令行选项提供给服务器,例如,"postgres -c log_connections=on"。一些参数可以在运行时使用“SET”SQL命令更改。
# Memory units: B = bytes Time units: us = microseconds
# kB = kilobytes ms = milliseconds
# MB = megabytes s = seconds
# GB = gigabytes min = minutes
# TB = terabytes h = hours
# d = days
#------------------------------------------------------------------------------
# FILE LOCATIONS 文件位置
#------------------------------------------------------------------------------
# The default values of these variables are driven from the -D command-line
# option or PGDATA environment variable, represented here as ConfigDir.
# 这些变量的默认值由-D命令行选项或PGDATA环境变量驱动,在这里表示为ConfigDir。
#data_directory = 'ConfigDir' # use data in another directory 使用其他目录中的数据
# (change requires restart) 改变需要重新启动数据库
#hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file 基于主机的认证文件
# (change requires restart)
#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file 识别配置文件
# (change requires restart)
# If external_pid_file is not explicitly set, no extra PID file is written.
# 如果没有显式地设置external_pid_file,则不会写入额外的PID文件。
#external_pid_file = '' # write an extra PID file 写一个额外的PID文件
# (change requires restart)
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION 连接和身份验证
#------------------------------------------------------------------------------
# - Connection Settings - 连接设置
listen_addresses = '*' # what IP address(es) to listen on; 侦听的IP地址是什么;
# comma-separated list of addresses; 逗号分隔的地址列表;
# defaults to 'localhost'; use '*' for all 默认为'localhost';全部使用“*”
# (change requires restart)
port = 5432 # (change requires restart) #端口
max_connections = 100 # (change requires restart) # 数据库最大连接数
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp' # comma-separated list of directories 以逗号分隔的目录列表
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation 以0开始使用八进制表示法
# (change requires restart)
#bonjour = off # advertise server via Bonjour 通过Bonjour广告服务器
# (change requires restart)
#bonjour_name = '' # defaults to the computer name 默认为计算机名
# (change requires restart)
# - TCP settings -
# see "man tcp" for details
#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; TCP_KEEPIDLE,单位为秒;
# 0 selects the system default 0选择系统默认值
#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
# 0 selects the system default
#tcp_keepalives_count = 0 # TCP_KEEPCNT;
# 0 selects the system default
#tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds; TCP_USER_TIMEOUT,以毫秒为单位;
# 0 selects the system default
# - Authentication - 身份验证
#authentication_timeout = 1min # 1s-600s
password_encryption = scram-sha-256 # md5 or scram-sha-256
#db_user_namespace = off
# GSSAPI using Kerberos 使用Kerberos的GSSAPI
#krb_server_keyfile = 'FILE:${sysconfdir}/krb5.keytab'
#krb_caseins_users = off
# - SSL -
#ssl = off
#ssl_ca_file = ''
#ssl_cert_file = 'server.crt'
#ssl_crl_file = ''
#ssl_key_file = 'server.key'
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
#ssl_prefer_server_ciphers = on
#ssl_ecdh_curve = 'prime256v1'
#ssl_min_protocol_version = 'TLSv1.2'
#ssl_max_protocol_version = ''
#ssl_dh_params_file = &