postgresql配置项说明

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

# -----------------------------
# 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.
#
# 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, or use "pg_ctl reload". Some
# parameters, which are marked below, require a server shutdown and restart to
# take effect.
#
# 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.
#
# Memory units: kB = kilobytes Time units: 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.

#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 = '' # write an extra PID file
# (change requires restart)


#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - 连接设置 -
listen_addresses = '*' #声明服务器监听客户端应用连接的TCP/IP,*表示所有,多个用逗号分隔
port = 5432
max_connections = 4000 #最大连接数据,每个连接占用400b的共享内存
superuser_reserved_connections = 3 #超级用户连接而保留的连接
unix_socket_permissions = 0700 # 确保权限安全
tcp_keepalives_idle = 30 # 间歇性发送TCP心跳包, 防止连接被网络设备中断.
tcp_keepalives_interval = 10
tcp_keepalives_count = 10

#-----

-------------------------------------------------------------------------
# 资源使用 (except WAL)
#------------------------------------------------------------------------------

# - 内存 -

shared_buffers = 128MB #数据库自己管理的共享内存大小,默认128M,建议设置1/4内存大小
huge_pages = try #尽量使用大页, 需要操作系统支持, 配置vm.nr_hugepages*2MB大于shared_buffers,可配置值try on off
temp_buffers = 8MB #设置每个数据库会话使用的临时缓冲区的最大数目,都是会话的本地缓冲区,只用于访问临时表
#max_prepared_transactions = 0 #设置可同时处于"准备好"状态的事务的最大数目,一般与max_connections一样大
#需要消耗600b的共享内存,每个事务的槽位,和锁空间
work_mem = 4MB #声明内部排序操作和散列在开始使用临时磁盘文件之前使用额内存数目

maintenance_work_mem = 512MB #声明在维护性操作中使用的最大内存数(vacuum,creat index,alter table)
#可以加速创建索引, 回收垃圾(假设没有设置autovacuum_work_mem)
autovacuum_work_mem = 512MB #设置进行vacuum进行时,可以用的内存,最小1M,-1表示使用maintenance_work_mem


#- 磁盘 -

#temp_file_limit = -1 # 每个会话的临时文件空间(kb),-1表示无极限

# - 内核资源使用 -

#max_files_per_process = 1000 # 每个进程允许同时打开的最大文件数目,默认1000
#shared_preload_libraries = '' # (change requires restart)

# - 基于cost的vacuum延迟 -
# 设置的目的是减少这些命令在并发活动数据库上的I/O影响

vacuum_cost_delay = 0 # 毫秒为单位,超过开销限制,进程休眠一会,0表示关闭
# 许多系统必须设置成10的倍数,如果不是则按照下一个倍数进行
vacuum_cost_page_hit = 1 # 锁住缓冲池,查找共享的散列表以及扫描页面的内容的开销(credits)
vacuum_cost_page_miss = 10 # 这个行为代表锁住缓冲池,查找共享散列表,从磁盘读取需要的数据块以及扫描它的内容的开销。 缺省值是 10。
vacuum_cost_page_dirty = 20 # 如果清理修改一个原先是干净的块的预计开销。它需要一个把脏的磁盘块再次冲刷到磁盘上的额外开销。 缺省值是 20
vacuum_cost_limit = 200 # 导致清理进程休眠的积累开销。缺省是 200

#------------------------------------------------------------------------------
# 后端写进程 (except WAL)
# 功能:
发出写"脏"共享缓冲区的命令
优点:
1.查询很少等待写动作的发生
2.减少checkpoint造成的性能下降
缺点:
1.增加了I/O总净负荷,因为同一个时间间隔内,一个页面可能会写好几次
#------------------------------------------------------------------------------

bgwriter_delay = 200ms #后端写进程每隔多少秒重复一次动作
bgwriter_lru_maxpages = 100

#一个周期最多写多少脏页
max_worker_processes = 20 # 如果要使用worker process, 最多可以允许fork 多少个worker进程


#------------------------------------------------------------------------------
# 预写日志(WRITE AHEAD LOG)
#------------------------------------------------------------------------------

# - Settings -

wal_level = archive #预写日志模式 minimal, archive, hot_standby, or logical
fsync = on #设置同步方式
synchronous_commit = off # 如果磁盘的IOPS能力一般, 建议使用异步提交来提高性能, 但是数据库crash或操作系统crash时, 最多可能丢失2*wal_writer_delay时间段产生的事务日志(在wal buffer中).
# off, local, remote_write, or on
wal_sync_method = fsync # 用来向磁盘强制更新 WAL 数据的方法。 如果 fsync 是关闭的,那么这个设置就是无关的, 因为所有更新都不会强制输出
# supported by the operating system:
# open_datasync(用带 O_DSYNC 选项的 open() 打开 WAL 文件)
# fdatasync 每次提交的时候都调用 fdatasync()),
# fsync (每次提交的时候调用 fsync())
# fsync_writethrough(每次提交的时候调用 fsync(),强制写出任何磁盘写缓冲区)
# open_sync 用带 O_SYNC 选项的 open() 写 WAL 文件)
full_page_writes = on # 服务器在checkpoint之后在对页面的第一次写时将整个页面写到wal里面
#wal_compression = off # enable compression of full-page writes
#wal_log_hints = off # also do full page writes of non-critical updates
# (change requires restart)
wal_buffers = -1 # 放在共享内存里用于WAL数据的磁盘页面缓冲区的数目,最小32kb,-1表示基于share buffer的设置
wal_writer_delay = 200ms # 每隔多长时间进行一次写

commit_delay = 0 # 向WAL缓冲区写入记录和将缓冲区刷新到磁盘上之间的时间延迟,以微妙计range 0-100000, in microseconds
# 0表示无延迟
commit_siblings = 5 # 在commit_delay时间内,最少打开的并发事务数range 1-1000

# - Checkpoints -
checkpoint_segments = 1024 # 最大多少大小的段发生一次checkpoint,等于shared_buffers除以单个wal segment的大小.
checkpoint_timeout = 5min # 最大多长时间发生一次checkpoint
#max_wal_size = 1GB
#min_wal_size = 80MB
#checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0
#checkpoint_warning = 30s # 0 disables

# - 归档日志Archiving -

archive_mode = on # 开启归档模式; off, on, or always

archive_command = '' # 归档命令
# placeholders: %p = path of file to archive
# %f = file name only
# e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
#archive_timeout = 0 # force a logfile segment switch after this
# number of seconds; 0 disables


#--------------------------------

----------------------------------------------
# 查看规划期QUERY TUNING
#------------------------------------------------------------------------------

# - Planner Method Configuration -

#enable_bitmapscan = on #打开或者关闭规划器对位图扫描规划类型的使用。缺省是 on。
#enable_hashagg = on #打开或者关闭查询规划器对散列聚集规划类型的时候。缺省是 on
#enable_hashjoin = on #打开或者关闭查询规划器对散列连接规划类型的使用。 缺省是 on。
#enable_indexscan = on #打开或者关闭查询规划器对融合连接规划类型的使用。 缺省是 on。
#enable_indexonlyscan = on
#enable_material = on
#enable_mergejoin = on #打开或者关闭查询规划器对嵌套循环连接规划类型的使用。 我们不可能完全消除嵌套循环连接,
#但是把这个变量关闭就会让规划器在存在其它方法的时候优先选择其他的。 缺省是 on。
#enable_nestloop = on #打开或者关闭查询规划器对嵌套循环连接规划类型的使用
#enable_seqscan = on #打开或者关闭查询规划器对顺序扫描规划类型的使用
#enable_sort = on #打开或者关闭查询规划器使用明确的排序步骤
#enable_tidscan = on #打开或者关闭查询规划器对 TID 扫描规划类型的使用

# - 规划期开销常量(Planner Cost Constants) -

#seq_page_cost = 1.0 # measured on an arbitrary scale
#random_page_cost = 4.0 # same scale as above
#cpu_tuple_cost = 0.01 # same scale as above
#cpu_index_tuple_cost = 0.005 # same scale as above
#cpu_operator_cost = 0.0025 # same scale as above
#effective_cache_size = 4GB

# - 基于查询优化器Genetic Query Optimizer -

#geqo = on #允许或禁止基因优化
#geqo_threshold = 12 #只有当涉及的FROM关系数量至少有这么多个的时候,才使用基因查询优化
#geqo_effort = 5 #控制geqo里规划时间和查询规划的有效性之间的平衡range 1-10
#geqo_pool_size = 0 #控制geqo使用的池大小
#geqo_generations = 0 #控制geqo使用的子代的数目
#geqo_selection_bias = 2.0 #控制geqo使用的选择性偏好 range 1.5-2.0
#geqo_seed = 0.0 # range 0.0-1.0

# - 其他规划器选项Other Planner Options -

#default_statistics_target = 100 #为没有用 ALTER TABLE SET STATISTICS 设置字段相关目标的表中其它字段设置缺省统计目标。
#更大的数值增加了 ANALYZE 所需要的时间,但是可能会改善规划器的估计质量# range 1-10000
#constraint_exclusion = partition # on, off, or partition
#cursor_tuple_fraction = 0.1 # range 0.0-1.0
#from_collapse_limit = 8
#join_collapse_limit = 8 # 1 disables collapsing of explicit
# JOIN clauses


#------------------------------------------------------------------------------
# 错误报告和日志 ERROR REPORTING AND LOGGING
#---------------------------------------------------------------------------

---

# - Where to Log -

log_destination = 'csvlog' # Valid values are combinations of
# stderr, csvlog, syslog, and eventlog,
# depending on platform. csvlog
# requires logging_collector to be on.

# This is used when logging to stderr:
logging_collector = on #开启日志捕获
log_directory = '' # 日志写入的目录
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' #日志文件名称,
#log_file_mode = 0600 # creation mode for log files,
log_truncate_on_rotation = on #这个选项将导致 PostgreSQL截断(覆盖),而不是附加到任何同名的现有日志文件上
log_rotation_age = 1d #设置一个独立的日志文件的最大生存期 0 disables.
log_rotation_size = 10MB #设置独立日志文件的最大尺寸 0 disables.


# - 什么时候记录日志 When to Log -

#client_min_messages = notice # values in order of decreasing detail:
# debug5
# debug4
# debug3
# debug2
# debug1
# log
# notice
# warning
# error

#log_min_messages = warning # values in order of decreasing detail:
# debug5
# debug4
# debug3
# debug2
# debug1
# info
# notice
# warning
# error
# log
# fatal
# panic

#log_min_error_statement = error # values in order of decreasing detail:
# debug5
# debug4
# debug3
# debug2
# debug1
# info
# notice
# warning
# error
# log
# fatal
# panic (effectively off)

#log_min_duration_statement = -1 # 慢查询日志-1 is disabled, 0 logs all statements
# and their durations, > 0 logs only
# statements running at least this number
# of milliseconds


# - 记录什么 What to Log -

log_checkpoints = on
log_connections = on
log_disconnections = on
log_duration = on #导致每个满足log_statement之条件已完成语句的持续时间都写入日志
log_error_verbosity = verbose # 在日志中输出代码位置#log_hostname = off
log_line_prefix = '%t ' # special values:
# %a = application name
# %u = user name
# %d = database name
# %r = remote host and port
# %h = remote host
# %p = process ID
# %t = timestamp without milliseconds
# %m = timestamp with milliseconds
# %i = command tag
# %e = SQL state
# %c = session ID
# %l = session line number
# %s = session start timestamp
# %v = virtual transaction ID
# %x = transaction ID (0 if none)
# %q = stop here in non-session
# processes
# %% = '%'
# e.g. '<%u%%%d> '
log_lock_waits = on # log lock waits >= deadlock_timeout
log_statement = 'ddl' # none, ddl, mod, all
log_timezone = 'Asia/Hong_Kong'



#--------------------------------------------

----------------------------------
# 运行时统计 RUNTIME STATISTICS
#------------------------------------------------------------------------------

# - Query/Index Statistics Collector -

#track_activities = on
#track_counts = on
#track_io_timing = off
#track_functions = none # none, pl, all
#track_activity_query_size = 1024 # (change requires restart)
#stats_temp_directory = 'pg_stat_tmp'


# - Statistics Monitoring -

#log_parser_stats = off
#log_planner_stats = off
#log_executor_stats = off
#log_statement_stats = off


#------------------------------------------------------------------------------
# 自动清理 AUTOVACUUM PARAMETERS
#------------------------------------------------------------------------------

autovacuum = on # 开启autovacumm子进程
log_autovacuum_min_duration = 0 # 记录超过设置时间的autovacuum信息 -1 disables, 0所有都记录,
autovacuum_max_workers = 10 # 最大子进程数
autovacuum_naptime = 1min # 指定autovacuum进程运行的最小间隔
autovacuum_vacuum_threshold = 50 # autovacuum 进程进行vacuum 操作的阀值条件一,(指修改,删除的记录数。)
autovacuum_analyze_threshold = 50 # autovacuum 进程进行 analyze 操作的阀值条件一,(指插入,修改,删除的记录数。)
autovacuum_vacuum_scale_factor = 0.2 # autovacuum因子, autovacuum 进程进行 vacuum 操作的阀值条件二,,默认为 0.2
#autovacuum进程进行 vacuum 触发条件
#表上(update,delte 记录) >= autovacuum_vacuum_scale_factor* reltuples(表上记录数) +
#autovacuum_vacuum_threshold

autovacuum_analyze_scale_factor = 0.1 #autoanalyze 因子,autovacuum 进程进行 analyze 操作的阀值条件二,,默认为 0.1
#autovacuum进程进行 analyze 触发条件
#表上(insert,update,delte 记录) >= autovacuum_analyze_scale_factor* reltuples(表上记录数) +
#autovacuum_analyze_threshold

autovacuum_freeze_max_age = 200000000 #指定表上事务的最大年龄,默认为2亿,达到这个阀值将触发 autovacuum进程,从而避免 wraparound。
#表上的事务年龄可以通过 pg_class.relfrozenxid 查询。

autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age
# before forced vacuum
# (change requires restart)
#autovacuum_vacuum_cost_delay = 20ms # 当autovacuum进程即将执行时,对 vacuum 执行 cost 进行评估,如果超过 autovacuum_vacuum_cost_limit
# 设置值时,则延迟,这个延迟的时间即为 autovacuum_vacuum_cost_delay。如果值为 -1, 表示使用
# vacuum_cost_delay 值,默认值为 20 ms

#autovacuum_vacuum_cost_limit = -1 # 这个值为 autovacuum 进程的评估阀值, 默认为 -1, 表示使用 "vacuum_cost_limit " 值,如果在执行
#autovacuum 进程期间评估的 cost 超过 autovacuum_vacuum_cost_limit, 则 autovacuum 进程则

会休眠。

#------------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#------------------------------------------------------------------------------

# - Statement Behavior -

#search_path = '"$user", public' # schema names
#default_tablespace = '' # a tablespace name, '' uses the default
#temp_tablespaces = '' # a list of tablespace names, '' uses
# only default tablespace
#check_function_bodies = on
default_transaction_isolation = 'read committed'
#default_transaction_read_only = off
#default_transaction_deferrable = off
#session_replication_role = 'origin'
#statement_timeout = 0 # in milliseconds, 0 is disabled
#lock_timeout = 0 # in milliseconds, 0 is disabled
#vacuum_freeze_min_age = 50000000
#vacuum_freeze_table_age = 150000000
#vacuum_multixact_freeze_min_age = 5000000
#vacuum_multixact_freeze_table_age = 150000000
#bytea_output = 'hex' # hex, escape
#xmlbinary = 'base64'
#xmloption = 'content'
#gin_fuzzy_search_limit = 0
#gin_pending_list_limit = 4MB

# - Locale and Formatting -

datestyle = 'iso, ymd'
#intervalstyle = 'postgres'
timezone = 'Asia/Hong_Kong'
#timezone_abbreviations = 'Default' # Select the set of available time zone
# abbreviations. Currently, there are
# Default
# Australia (historical usage)
# India
# You can create your own file in
# share/timezonesets/.
#extra_float_digits = 0 # min -15, max 3
#client_encoding = sql_ascii # actually, defaults to database
# encoding

# These settings are initialized by initdb, but they can be changed.
lc_messages = 'Chinese (Simplified)_People''s Republic of China.936' # locale for system error message
# strings
lc_monetary = 'Chinese (Simplified)_People''s Republic of China.936' # locale for monetary formatting
lc_numeric = 'Chinese (Simplified)_People''s Republic of China.936' # locale for number formatting
lc_time = 'Chinese (Simplified)_People''s Republic of China.936' # locale for time formatting

# default configuration for text search
default_text_search_config = 'pg_catalog.simple'

# - Other Defaults -

#dynamic_library_path = '$libdir'
#local_preload_libraries = ''
#session_preload_libraries = ''


#------------------------------------------------------------------------------
#锁管理 LOCK MANAGEMENT
#------------------------------------------------------------------------------

deadlock_timeout = 1s
max_locks_per_transaction = 64 # min 10
# (change requires restart)
# Note: Each lock table slot uses ~270 bytes of shared memory, and there are
# max_locks_per_transaction * (max_connections + max_prepared_transactions)
# lock table slots.
max_pred_locks_per_transaction = 64 # min 10
# (change requires restart)



相关文档
最新文档