Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
In addition to the postgresql.conf
file already mentioned, PostgreSQL uses two other manually-edited configuration files, which control client authentication (their use is discussed in Chapter 20). By default, all three configuration files are stored in the database cluster's data directory. The parameters described in this section allow the configuration files to be placed elsewhere. (Doing so can ease administration. In particular it is often easier to ensure that the configuration files are properly backed-up when they are kept separate.)
data_directory
(string
)Specifies the directory to use for data storage. This parameter can only be set at server start.
config_file
(string
)Specifies the main server configuration file (customarily called postgresql.conf
). This parameter can only be set on the postgres
command line.
hba_file
(string
)Specifies the configuration file for host-based authentication (customarily called pg_hba.conf
). This parameter can only be set at server start.
ident_file
(string
)Specifies the configuration file for user name mapping (customarily called pg_ident.conf
). This parameter can only be set at server start. See also Section 20.2.
external_pid_file
(string
)Specifies the name of an additional process-ID (PID) file that the server should create for use by server administration programs. This parameter can only be set at server start.
In a default installation, none of the above parameters are set explicitly. Instead, the data directory is specified by the -D
command-line option or the PGDATA
environment variable, and the configuration files are all found within the data directory.
If you wish to keep the configuration files elsewhere than the data directory, the postgres
-D
command-line option or PGDATA
environment variable must point to the directory containing the configuration files, and the data_directory
parameter must be set inpostgresql.conf
(or on the command line) to show where the data directory is actually located. Notice that data_directory
overrides -D
and PGDATA
for the location of the data directory, but not for the location of the configuration files.
If you wish, you can specify the configuration file names and locations individually using the parameters config_file
, hba_file
and/or ident_file
. config_file
can only be specified on the postgres
command line, but the others can be set within the main configuration file. If all three parameters plus data_directory
are explicitly set, then it is not necessary to specify -D
or PGDATA
.
When setting any of these parameters, a relative path will be interpreted with respect to the directory in which postgres
is started.
All parameter names are case-insensitive. Every parameter takes a value of one of five types: boolean, string, integer, floating point, or enumerated (enum). The type determines the syntax for setting the parameter:
Boolean: Values can be written as on
, off
, true
, false
, yes
, no
, 1
, 0
(all case-insensitive) or any unambiguous prefix of one of these.
String: In general, enclose the value in single quotes, doubling any single quotes within the value. Quotes can usually be omitted if the value is a simple number or identifier, however.
Numeric (integer and floating point): A decimal point is permitted only for floating-point parameters. Do not use thousands separators. Quotes are not required.
Numeric with Unit: Some numeric parameters have an implicit unit, because they describe quantities of memory or time. The unit might be kilobytes, blocks (typically eight kilobytes), milliseconds, seconds, or minutes. An unadorned numeric value for one of these settings will use the setting's default unit, which can be learned from pg_settings
.unit
. For convenience, settings can be given with a unit specified explicitly, for example '120 ms'
for a time value, and they will be converted to whatever the parameter's actual unit is. Note that the value must be written as a string (with quotes) to use this feature. The unit name is case-sensitive, and there can be whitespace between the numeric value and the unit.
Valid memory units are kB
(kilobytes), MB
(megabytes), GB
(gigabytes), and TB
(terabytes). The multiplier for memory units is 1024, not 1000.
Valid time units are ms
(milliseconds), s
(seconds), min
(minutes), h
(hours), and d
(days).
Enumerated: Enumerated-type parameters are written in the same way as string parameters, but are restricted to have one of a limited set of values. The values allowable for such a parameter can be found frompg_settings
.enumvals
. Enum parameter values are case-insensitive.
The most fundamental way to set these parameters is to edit the file postgresql.conf
, which is normally kept in the data directory. A default copy is installed when the database cluster directory is initialized. An example of what this file might look like is:
One parameter is specified per line. The equal sign between name and value is optional. Whitespace is insignificant (except within a quoted parameter value) and blank lines are ignored. Hash marks (#
) designate the remainder of the line as a comment. Parameter values that are not simple identifiers or numbers must be single-quoted. To embed a single quote in a parameter value, write either two quotes (preferred) or backslash-quote.
Parameters set in this way provide default values for the cluster. The settings seen by active sessions will be these values unless they are overridden. The following sections describe ways in which the administrator or user can override these defaults.
The configuration file is reread whenever the main server process receives a SIGHUP signal; this signal is most easily sent by running pg_ctl reload
from the command line or by calling the SQL function pg_reload_conf()
. The main server process also propagates this signal to all currently running server processes, so that existing sessions also adopt the new values (this will happen after they complete any currently-executing client command). Alternatively, you can send the signal to a single server process directly. Some parameters can only be set at server start; any changes to their entries in the configuration file will be ignored until the server is restarted. Invalid parameter settings in the configuration file are likewise ignored (but logged) during SIGHUP processing.
In addition to postgresql.conf
, a PostgreSQL data directory contains a file postgresql.auto.conf
, which has the same format as postgresql.conf
but should never be edited manually. This file holds settings provided through the ALTER SYSTEM command. This file is automatically read whenever postgresql.conf
is, and its settings take effect in the same way. Settings in postgresql.auto.conf
override those in postgresql.conf
.
The system view pg_file_settings
can be helpful for pre-testing changes to the configuration file, or for diagnosing problems if a SIGHUP signal did not have the desired effects.
PostgreSQL provides three SQL commands to establish configuration defaults. The already-mentioned ALTER SYSTEM command provides a SQL-accessible means of changing global defaults; it is functionally equivalent to editing postgresql.conf
. In addition, there are two commands that allow setting of defaults on a per-database or per-role basis:
The ALTER DATABASE command allows global settings to be overridden on a per-database basis.
The ALTER ROLE command allows both global and per-database settings to be overridden with user-specific values.
Values set with ALTER DATABASE
and ALTER ROLE
are applied only when starting a fresh database session. They override values obtained from the configuration files or server command line, and constitute defaults for the rest of the session. Note that some settings cannot be changed after server start, and so cannot be set with these commands (or the ones listed below).
Once a client is connected to the database, PostgreSQL provides two additional SQL commands (and equivalent functions) to interact with session-local configuration settings:
The SHOW command allows inspection of the current value of all parameters. The corresponding function is current_setting(setting_name text)
.
The SET command allows modification of the current value of those parameters that can be set locally to a session; it has no effect on other sessions. The corresponding function is set_config(setting_name, new_value, is_local)
.
In addition, the system view pg_settings
can be used to view and change session-local values:
Querying this view is similar to using SHOW ALL
but provides more detail. It is also more flexible, since it's possible to specify filter conditions or join against other relations.
Using UPDATE on this view, specifically updating the setting
column, is the equivalent of issuing SET
commands. For example, the equivalent of
is:
In addition to setting global defaults or attaching overrides at the database or role level, you can pass settings to PostgreSQL via shell facilities. Both the server and libpq client library accept parameter values via the shell.
During server startup, parameter settings can be passed to the postgres
command via the -c
command-line parameter. For example,
Settings provided in this way override those set via postgresql.conf
or ALTER SYSTEM
, so they cannot be changed globally without restarting the server.
When starting a client session via libpq, parameter settings can be specified using the PGOPTIONS
environment variable. Settings established in this way constitute defaults for the life of the session, but do not affect other sessions. For historical reasons, the format of PGOPTIONS
is similar to that used when launching the postgres
command; specifically, the -c
flag must be specified. For example,
Other clients and libraries might provide their own mechanisms, via the shell or otherwise, that allow the user to alter session settings without direct use of SQL commands.
PostgreSQL provides several features for breaking down complex postgresql.conf
files into sub-files. These features are especially useful when managing multiple servers with related, but not identical, configurations.
In addition to individual parameter settings, the postgresql.conf
file can contain include directives, which specify another file to read and process as if it were inserted into the configuration file at this point. This feature allows a configuration file to be divided into physically separate parts. Include directives simply look like:
If the file name is not an absolute path, it is taken as relative to the directory containing the referencing configuration file. Inclusions can be nested.
There is also an include_if_exists
directive, which acts the same as the include
directive, except when the referenced file does not exist or cannot be read. A regular include
will consider this an error condition, but include_if_exists
merely logs a message and continues processing the referencing configuration file.
The postgresql.conf
file can also contain include_dir
directives, which specify an entire directory of configuration files to include. These look like
Non-absolute directory names are taken as relative to the directory containing the referencing configuration file. Within the specified directory, only non-directory files whose names end with the suffix .conf
will be included. File names that start with the .
character are also ignored, to prevent mistakes since such files are hidden on some platforms. Multiple files within an include directory are processed in file name order (according to C locale rules, i.e. numbers before letters, and uppercase letters before lowercase ones).
Include files or directories can be used to logically separate portions of the database configuration, rather than having a single large postgresql.conf
file. Consider a company that has two database servers, each with a different amount of memory. There are likely elements of the configuration both will share, for things such as logging. But memory-related parameters on the server will vary between the two. And there might be server specific customizations, too. One way to manage this situation is to break the custom configuration changes for your site into three files. You could add this to the end of your postgresql.conf
file to include them:
All systems would have the same shared.conf
. Each server with a particular amount of memory could share the same memory.conf
; you might have one for all servers with 8GB of RAM, another for those having 16GB. And finallyserver.conf
could have truly server-specific configuration information in it.
Another possibility is to create a configuration file directory and put this information into files there. For example, a conf.d
directory could be referenced at the end of postgresql.conf
:
Then you could name the files in the conf.d
directory like this:
This naming convention establishes a clear order in which these files will be loaded. This is important because only the last setting encountered for a particular parameter while the server is reading configuration files will be used. In this example, something set in conf.d/02server.conf
would override a value set in conf.d/01memory.conf
.
You might instead use this approach to naming the files descriptively:
This sort of arrangement gives a unique name for each configuration file variation. This can help eliminate ambiguity when several servers have their configurations all stored in one place, such as in a version control repository. (Storing database configuration files under version control is another good practice to consider.)\
這些參數控制伺服器端的統計數據收集功能。啟用統計數據收集後,可以透過 pg_stat 和 pg_statio 系列系統檢視表取得相關的資料。有關更多資訊,請參閱第 27 章。
track_activities
(boolean
)
啟用收集有關每個連線的當下執行命令的資訊以及該命令開始執行的時間的資訊。預設情況下,此參數是開啓的。請注意,即使啟用此功能,也不是所有使用者都可以取用,而只有超級使用者和擁有該連線的使用者可以檢視這些數據,因此它不會有安全風險。僅超級使用者可以變更此設定。
track_activity_query_size
(integer
)
為 pg_stat_activity.query 欄位指定保留的字元數,以追踪每個連線查詢當下執行的指令字串。預設值為1024。只能在伺服器啟動時設定此參數。
track_counts
(boolean
)
啟用有關資料庫活動的統計資訊收集。預設情況下,此參數是啟用的,因為 autovacuum 背景程序需要收集資訊。僅超級使用者可以變更此設定。
track_io_timing
(boolean
)
啟用資料庫 I/O 呼叫的計時。此參數預設情況下是處於關閉狀態,因為它將重複查詢作業系統當下的時間,這可能會導致某些平台上的大量運算成本。您可以使用 pg_test_timing 工具來測量系統計時的成本。I/O 時序資訊會顯示在 pg_stat_database 中,使用 BUFFERS 選項時在 EXPLAIN 的輸出中以及 pg_stat_statements 中顯示。僅超級使用者可以變更改此設定。
track_functions
(enum
)
啟用對函數呼叫計數和使用時間的追踪。指定 pl 僅追踪程序語言函數,all 則表示也追踪 SQL 和 C 語言函數。預設值為 none,這將停用函數統計資訊追踪。僅超級使用者可以變更此設定。
注意 不管此設定如何,都不會追踪足夠簡單以「inline」到呼叫查詢中的 SQL 語言函數。
stats_temp_directory
(string
)
設定用於儲存臨時統計數據的目錄。這可以是相對於資料目錄的路徑,也可以是絕對路徑。預設值為 pg_stat_tmp。將其指向基於 RAM 的檔案系統可以降低物理性 I/O 的要求,使得效能提升。只能在 postgresql.conf 檔案或伺服器命令列中設定此參數。
log_statement_stats
(boolean
)
log_parser_stats
(boolean
)
log_planner_stats
(boolean
)
log_executor_stats
(boolean
)
對於每個查詢,將相對應模組的效能統計數據輸出到伺服器日誌。這是一個粗略的分析工具,類似於 Unix getrusage() 作業系統的工具。log_statement_stats 總計整個查詢語句過程的統計數據,而其他的設定是每個查詢模組的統計數據。log_statement_stats 不能與任何其他模組選項同時啟用。預設情況下,所有這些選項都是停用的。只有超級使用者可以變更這些設定。
版本:11
這些配置參數提供了影響查詢最佳化程序選擇的查詢計劃決策方法。如果最佳化程序為特定查詢選擇的預設計劃並非最佳,則臨時的解決方案是使用這些配置參數來強制最佳化程序選擇不同的計劃。提高最佳化程序選擇的計劃素質的有效方法包括了調整計劃程序成本常數(請參閱第 19.7.2 節),手動執行 ANALYZE,增加 default_statistics_target 配置參數的值,以及增加為特定欄位收集的統計訊息量,使用 ALTER TABLE SET STATISTICS。
enable_bitmapscan
(boolean
)啟用或停用查詢計劃程序使用 bitmap 掃描計劃類型。預設為開啓。
enable_gathermerge
(boolean
)啟用或停用查詢計劃程序使用 gather merge 計劃類型。預設為開啓。
enable_hashagg
(boolean
)啟用或停用查詢計劃程序使用 hashed aggregation 計劃類型。預設為開啓。
enable_hashjoin
(boolean
)啟用或停用查詢計劃程序使用 hash-join 計劃類型。預設為開啓。
enable_indexscan
(boolean
)啟用或停用查詢計劃程序使用 index-scan 計劃類型。預設為開啓。
enable_indexonlyscan
(boolean
)啟用或停用查詢計劃程序使用 index-only 掃描計劃類型(請參閱第 11.11 節)。預設為開啓。
enable_material
(boolean
)啟用或停用查詢計劃程序對實作的使用。完全抑制實作是不可能的,但是關閉此變數會阻止計劃程序插入實體化的節點,除非真的需要它。預設為開啓。
enable_mergejoin
(boolean
)啟用或停用查詢計劃程序使用 merge-join 計劃類型。預設為開啓。
enable_nestloop
(boolean
)啟用或停用查詢計劃程序使用 nested-loop join 計劃。完全抑制 nested-loop join 是不可能的,但如果有其他可用方法,則關閉此變數會阻止規劃器使用它。預設為開啓。
enable_parallel_append
(boolean
)Enables or disables the query planner's use of parallel-aware append plan types. The default is on
.
enable_parallel_hash
(boolean
)Enables or disables the query planner's use of hash-join plan types with parallel hash. Has no effect if hash-join plans are not also enabled. The default is on
.
enable_partition_pruning
(boolean
)啟用或停用查詢計劃程序從查詢計劃中修剪分割資料表分割區的功能。 這也控制了計劃程序產生查詢計劃的功能,此功能使查詢執行程序可以在查詢執行期間刪除(忽略)分割區。 預設為 on。有關詳細資訊,請參閱第 5.11.4 節。
enable_partitionwise_join
(boolean
)Enables or disables the query planner's use of partitionwise join, which allows a join between partitioned tables to be performed by joining the matching partitions. Partitionwise join currently applies only when the join conditions include all the partition keys, which must be of the same data type and have exactly matching sets of child partitions. Because partitionwise join planning can use significantly more CPU time and memory during planning, the default is off
.
enable_partitionwise_aggregate
(boolean
)Enables or disables the query planner's use of partitionwise grouping or aggregation, which allows grouping or aggregation on a partitioned tables performed separately for each partition. If the GROUP BY
clause does not include the partition keys, only partial aggregation can be performed on a per-partition basis, and finalization must be performed later. Because partitionwise grouping or aggregation can use significantly more CPU time and memory during planning, the default is off
.
enable_seqscan
(boolean
)啟用或停用查詢計劃程序使用循序掃描計劃類型。完全抑制循序掃描是不可能的,但如果有其他方法可用,則關閉此變數會阻止計劃程序使用。預設為開啓。
enable_sort
(boolean
)啟用或停用查詢計劃程序使用明確的排序步驟。完全抑制明確排序是不可能的,但如果有其他可用方法,則關閉此變數會阻止計劃程序使用。預設為開啓。
enable_tidscan
(boolean
)啟用或停用查詢計劃程序使用 TID 掃描計劃類型。預設為開啓。
本節中描述的成本變數是以比例來使用的。只有它們的相對值很重要,因此按相同因子放大或縮小它們將不會讓規劃程式的選擇有所變化。預設情況下,這些成本變數基於連續頁面讀取的成本;也就是說,seq_page_cost 通常設定為 1.0,其他成本變數是相對參考其設定的。 但是,如果您願意,可以使用不同的比例,例如特定主機上的實際執行時間(以毫秒為單位)。
注意 不幸的是,並沒有明確定義的方法來決定成本變數的理想值。它們最好被視為特定安裝環境可能接受的所有查詢組合的平均值。這意味著僅僅根據一些實驗來改變它們都不是真正的最佳。
seq_page_cost
(floating point
)設定計劃程序對磁碟頁面讀取的成本估計,此成本是一系列連續讀取的一部分。預設值為 1.0。透過設定同名的 tablespace 參數,可以為特定資料表空間中的資料表和索引覆寫此值(請參閱 ALTER TABLESPACE)。
random_page_cost
(floating point
)Sets the planner's estimate of the cost of a non-sequentially-fetched disk page. The default is 4.0. This value can be overridden for tables and indexes in a particular tablespace by setting the tablespace parameter of the same name (see ALTER TABLESPACE).
Reducing this value relative to seq_page_cost
will cause the system to prefer index scans; raising it will make index scans look relatively more expensive. You can raise or lower both values together to change the importance of disk I/O costs relative to CPU costs, which are described by the following parameters.
Random access to mechanical disk storage is normally much more expensive than four times sequential access. However, a lower default is used (4.0) because the majority of random accesses to disk, such as indexed reads, are assumed to be in cache. The default value can be thought of as modeling random access as 40 times slower than sequential, while expecting 90% of random reads to be cached.
If you believe a 90% cache rate is an incorrect assumption for your workload, you can increase random_page_cost to better reflect the true cost of random storage reads. Correspondingly, if your data is likely to be completely in cache, such as when the database is smaller than the total server memory, decreasing random_page_cost can be appropriate. Storage that has a low random read cost relative to sequential, e.g. solid-state drives, might also be better modeled with a lower value for random_page_cost.
Although the system will let you set random_page_cost
to less than seq_page_cost
, it is not physically sensible to do so. However, setting them equal makes sense if the database is entirely cached in RAM, since in that case there is no penalty for touching pages out of sequence. Also, in a heavily-cached database you should lower both values relative to the CPU parameters, since the cost of fetching a page already in RAM is much smaller than it would normally be.
cpu_tuple_cost
(floating point
)設定計劃程序在查詢期間處理每個資料列的成本估算。預設值為 0.01。
cpu_index_tuple_cost
(floating point
)設定計劃程序在索引掃描期間處理每個索引項目的成本估計。預設值為 0.005。
cpu_operator_cost
(floating point
)設定計劃程序對查詢期間執行的每個運算子或函數的處理成本的估計。 預設值為 0.0025。
parallel_setup_cost
(floating point
)設定計劃程序對啟動平行工作程序的成本估計。預設值為 1000。
parallel_tuple_cost
(floating point
)設定計劃程序對從一個平行工作程序轉移到另一個程序的一個 tuple 的成本估算。預設值為 0.1。
min_parallel_table_scan_size
(integer
)Sets the minimum amount of table data that must be scanned in order for a parallel scan to be considered. For a parallel sequential scan, the amount of table data scanned is always equal to the size of the table, but when indexes are used the amount of table data scanned will normally be less. The default is 8 megabytes (8MB
).
min_parallel_index_scan_size
(integer
)Sets the minimum amount of index data that must be scanned in order for a parallel scan to be considered. Note that a parallel index scan typically won't touch the entire index; it is the number of pages which the planner believes will actually be touched by the scan which is relevant. The default is 512 kilobytes (512kB
).
effective_cache_size
(integer
)Sets the planner's assumption about the effective size of the disk cache that is available to a single query. This is factored into estimates of the cost of using an index; a higher value makes it more likely index scans will be used, a lower value makes it more likely sequential scans will be used. When setting this parameter you should consider both PostgreSQL's shared buffers and the portion of the kernel's disk cache that will be used for PostgreSQL data files. Also, take into account the expected number of concurrent queries on different tables, since they will have to share the available space. This parameter has no effect on the size of shared memory allocated by PostgreSQL, nor does it reserve kernel disk cache; it is used only for estimation purposes. The system also does not assume data remains in the disk cache between queries. The default is 4 gigabytes (4GB
).
The genetic query optimizer (GEQO) is an algorithm that does query planning using heuristic searching. This reduces planning time for complex queries (those joining many relations), at the cost of producing plans that are sometimes inferior to those found by the normal exhaustive-search algorithm. For more information see Chapter 59.
geqo
(boolean
)Enables or disables genetic query optimization. This is on by default. It is usually best not to turn it off in production; the geqo_threshold
variable provides more granular control of GEQO.
geqo_threshold
(integer
)Use genetic query optimization to plan queries with at least this many FROM
items involved. (Note that a FULL OUTER JOIN
construct counts as only one FROM
item.) The default is 12. For simpler queries it is usually best to use the regular, exhaustive-search planner, but for queries with many tables the exhaustive search takes too long, often longer than the penalty of executing a suboptimal plan. Thus, a threshold on the size of the query is a convenient way to manage use of GEQO.
geqo_effort
(integer
)Controls the trade-off between planning time and query plan quality in GEQO. This variable must be an integer in the range from 1 to 10. The default value is five. Larger values increase the time spent doing query planning, but also increase the likelihood that an efficient query plan will be chosen.
geqo_effort
doesn't actually do anything directly; it is only used to compute the default values for the other variables that influence GEQO behavior (described below). If you prefer, you can set the other parameters by hand instead.
geqo_pool_size
(integer
)Controls the pool size used by GEQO, that is the number of individuals in the genetic population. It must be at least two, and useful values are typically 100 to 1000. If it is set to zero (the default setting) then a suitable value is chosen based on geqo_effort
and the number of tables in the query.
geqo_generations
(integer
)Controls the number of generations used by GEQO, that is the number of iterations of the algorithm. It must be at least one, and useful values are in the same range as the pool size. If it is set to zero (the default setting) then a suitable value is chosen based on geqo_pool_size
.
geqo_selection_bias
(floating point
)Controls the selection bias used by GEQO. The selection bias is the selective pressure within the population. Values can be from 1.50 to 2.00; the latter is the default.
geqo_seed
(floating point
)Controls the initial value of the random number generator used by GEQO to select random paths through the join order search space. The value can range from zero (the default) to one. Varying the value changes the set of join paths explored, and may result in a better or worse best path being found.
default_statistics_target
(integer
)為沒有透過 ALTER TABLE SET STATISTICS 設定特定於欄位目標的資料表欄位設定預設的統計目標。較大的值會增加進行分析所需的時間,但可能會提高查詢計劃程序評估的準確度。預設值為 100。有關 PostgreSQL 查詢計劃程序使用統計資訊的更多說明,請參閱 14.2 節。
constraint_exclusion
(enum
)Controls the query planner's use of table constraints to optimize queries. The allowed values of constraint_exclusion
are on
(examine constraints for all tables), off
(never examine constraints), and partition
(examine constraints only for inheritance child tables and UNION ALL
subqueries). partition
is the default setting. It is often used with inheritance and partitioned tables to improve performance.
When this parameter allows it for a particular table, the planner compares query conditions with the table's CHECK
constraints, and omits scanning tables for which the conditions contradict the constraints. For example:
With constraint exclusion enabled, this SELECT
will not scan child1000
at all, improving performance.
Currently, constraint exclusion is enabled by default only for cases that are often used to implement table partitioning. Turning it on for all tables imposes extra planning overhead that is quite noticeable on simple queries, and most often will yield no benefit for simple queries. If you have no partitioned tables you might prefer to turn it off entirely.
Refer to Section 5.10.4 for more information on using constraint exclusion and partitioning.
cursor_tuple_fraction
(floating point
)Sets the planner's estimate of the fraction of a cursor's rows that will be retrieved. The default is 0.1. Smaller values of this setting bias the planner towards using “fast start” plans for cursors, which will retrieve the first few rows quickly while perhaps taking a long time to fetch all rows. Larger values put more emphasis on the total estimated time. At the maximum setting of 1.0, cursors are planned exactly like regular queries, considering only the total estimated time and not how soon the first rows might be delivered.
from_collapse_limit
(integer
)The planner will merge sub-queries into upper queries if the resulting FROM
list would have no more than this many items. Smaller values reduce planning time but might yield inferior query plans. The default is eight. For more information see Section 14.3.
Setting this value to geqo_threshold or more may trigger use of the GEQO planner, resulting in non-optimal plans. See Section 19.7.3.
join_collapse_limit
(integer
)The planner will rewrite explicit JOIN
constructs (except FULL JOIN
s) into lists of FROM
items whenever a list of no more than this many items would result. Smaller values reduce planning time but might yield inferior query plans.
By default, this variable is set the same as from_collapse_limit
, which is appropriate for most uses. Setting it to 1 prevents any reordering of explicit JOIN
s. Thus, the explicit join order specified in the query will be the actual order in which the relations are joined. Because the query planner does not always choose the optimal join order, advanced users can elect to temporarily set this variable to 1, and then specify the join order they desire explicitly. For more information see Section 14.3.
Setting this value to geqo_threshold or more may trigger use of the GEQO planner, resulting in non-optimal plans. See Section 19.7.3.
force_parallel_mode
(enum
)Allows the use of parallel queries for testing purposes even in cases where no performance benefit is expected. The allowed values of force_parallel_mode
are off
(use parallel mode only when it is expected to improve performance), on
(force parallel query for all queries for which it is thought to be safe), and regress
(like on
, but with additional behavior changes as explained below).
More specifically, setting this value to on
will add a Gather
node to the top of any query plan for which this appears to be safe, so that the query runs inside of a parallel worker. Even when a parallel worker is not available or cannot be used, operations such as starting a subtransaction that would be prohibited in a parallel query context will be prohibited unless the planner believes that this will cause the query to fail. If failures or unexpected results occur when this option is set, some functions used by the query may need to be marked PARALLEL UNSAFE
(or, possibly, PARALLEL RESTRICTED
).
Setting this value to regress
has all of the same effects as setting it to on
plus some additional effects that are intended to facilitate automated regression testing. Normally, messages from a parallel worker include a context line indicating that, but a setting of regress
suppresses this line so that the output is the same as in non-parallel execution. Also, the Gather
nodes added to plans by this setting are hidden in EXPLAIN
output so that the output matches what would be obtained if this setting were turned off
.
shared_buffers
(integer
)
設定資料庫伺服器用於共享記憶體緩衝區的大小。預設值通常為 128 MB,但如果您的核心設定不支援(在 initdb 期間確定),則可能會更少。此設定必須至少為128 KB。(非預設值的 BLCKSZ 會改變最小值。)但是,通常需要高於最小值的設定才能獲得良好的性能。此參數只能在伺服器啟動時設定。
如果您擁有 1GB 或更多記憶體的專用資料庫伺服器,shared_buffers 的合理起始值是系統記憶體的 25%。有些工作負載甚至可以為 shared_buffers 設定更大的值,但由於PostgreSQL 依賴於作業系統緩衝區,因此,把 shared_buffers 分配 40% 以上的記憶體大小不太可能比少量分配更好。shared_buffers 較大設定通常需要 max_wal_size 相對應的增加,以便分散在較長時間內寫入大量新資料或變更資料的過程。
在 RAM 小於 1GB 的系統上,更小比例是合適的,以便為作業系統留下足夠的空間。
huge_pages
(enum
)
啟用/停用大型記憶體頁面。有效值為 try(預設值),on 和 off。
目前,僅在 Linux 上支援此功能。設定為 try 時,在其他系統上會忽略該設定。
大型頁面的使用會使得頁面管理表更小,記憶體管理花費的 CPU 時間更少,從而提高了效能。有關更多詳細訊息,請參閱。
設定 huge_pages 後,伺服器將嘗試使用大型頁面,但如果失敗則回退到使用正常分配。如果為 on,則若無法使用大型頁面將使伺服器無法啟動。 off 時,則不會使用大型頁面。
temp_buffers
(integer
)
設定每個資料庫連線使用的最大臨時緩衝區大小。這些是僅用於存取臨時資料表的連線本地緩衝區。預設值為 8MB。可以在單個連線中變更設定,但只能在連線中首次使用臨時資料表之前更改;後續嘗試更改該值將不會對該連線產生任何影響。
連線將根據需要分配臨時緩衝區,直到 temp_buffers 的上限。實際上不需要很多臨時緩衝區的連線中設定較大值的成本只是 temp_buffers 中每個增量的緩衝區描述指標,或大約 64 個位元組。但是,如果實際使用緩衝區,則會消耗額外的 8192 位元組(或者通常為 BLCKSZ 個位元組)。
max_prepared_transactions
(integer
)
設定可同時處於「prepared」狀態的最大交易事務數量(請參閱 )。將此參數設定為零(這是預設值)的話,會停用預備交易的功能。此參數只能在伺服器啟動時設定。
如果您不打算使用預備交易事務,則應將此參數設定為零以防止意外建立預備的交易事務。如果您正在使用預備的交易事務,那麼您可能希望 max_prepared_transactions 至少與 一樣大,以便每個連線都可以至少有一個準備好的預備交易事務。
運行備用伺服器時,必須將此參數設定為與主服務器上相同或更高的值。 否則,查詢將不被允許在備用伺服器中。
work_mem
(integer
)
指定寫入暫存檔之前內部排序操作和雜湊表使用的記憶體大小。此值預設為 4 MB。請注意,對於複雜的查詢,可能會同時執行多個排序或雜湊作業;在開始將資料寫入暫存檔之前,每個操作都將被允許盡可能使用記憶體。此外,多個連線可以同時進行這些操作。因此,所使用的總記憶體量可能是 work_mem 值的許多倍;決定值時必須牢記此一事實。排序操作用於 ORDER BY,DISTINCT 和 merge JOIN。雜湊表用於 hash JOIN,hash aggregation 和 IN 子查詢處理。
hash_mem_multiplier
(floating point
)
Used to compute the maximum amount of memory that hash-based operations can use. The final limit is determined by multiplying work_mem
by hash_mem_multiplier
. The default value is 1.0, which makes hash-based operations subject to the same simple work_mem
maximum as sort-based operations.
Consider increasing hash_mem_multiplier
in environments where spilling by query operations is a regular occurrence, especially when simply increasing work_mem
results in memory pressure (memory pressure typically takes the form of intermittent out of memory errors). A setting of 1.5 or 2.0 may be effective with mixed workloads. Higher settings in the range of 2.0 - 8.0 or more may be effective in environments where work_mem
has already been increased to 40MB or more.
maintenance_work_mem
(integer
)
指定維護操作要使用的最大記憶體大小,例如 VACUUM,CREATE INDEX 和ALTER TABLE ADD FOREIGN KEY。預設為 64 MB。由於資料庫連線一次只能執行其中一個操作,不會有多個同時運行,因此將此值設定為遠大於 work_mem 是安全的。較大的設定可能會提高清理和恢復資料庫回復的效能。
autovacuum_work_mem
(integer
)
logical_decoding_work_mem
(integer
)
Specifies the maximum amount of memory to be used by logical decoding, before some of the decoded changes are written to local disk. This limits the amount of memory used by logical streaming replication connections. It defaults to 64 megabytes (64MB
). Since each replication connection only uses a single buffer of this size, and an installation normally doesn't have many such connections concurrently (as limited by max_wal_senders
), it's safe to set this value significantly higher than work_mem
, reducing the amount of decoded changes written to disk.
max_stack_depth
(integer
)
指定伺服器工作堆疊的最大安全深度。此參數的理想設定是核心強制執行的實際堆疊大小限制(由 ulimit -s 或其他等效設定),減去 1 MB 左右的安全範圍。需要安全額度,因為在伺服器的每個程序中都不會檢查堆疊深度,而是僅在關鍵的潛在遞迴程序(例如表示式求值)中檢查。預設設定是 2 MB,這是保守地小,不太可能冒崩潰的風險。但是,它可能太小而無法執行複雜的功能。只有超級使用者才能變更此設定。
將 max_stack_depth 設定為高於實際核心限制將意味著失控的遞迴函數可能導致單個後端程序崩潰。在 PostgreSQL 可以確定核心限制的平台上,伺服器不允許將此變數設定為不安全的值。但是,並非所有平台都有提供資訊,因此建議在選擇值時要小心。
shared_memory_type
(enum
)
dynamic_shared_memory_type
(enum
)
指定伺服器應使用的動態共享記憶體方法。可能的值是 posix(使用 shm_open 分配的 POSIX 共享記憶體),sysv(透過 shmget 分配的 System V 共享記憶體),windows(Windows 共享記憶體),mmap(使用儲存在資料目錄中的記憶體映射檔案來模擬共享記憶體) ),沒有(停用此功能)。並非所有平台都支援所有值;第一個受支援的選項是該平台的預設選項。通常不鼓勵使用 mmap 選項,這在任何平台上都不是預設選項,因為作業系統可能會將修改後的頁面重複寫回磁碟,從而增加系統 I/O 負載;但是,當 pg_dynshmem 目錄儲存在 RAM 磁碟上或其他共享記憶體裝置不可用時,它可能對除錯很有用。
temp_file_limit
(integer
)
指定程序可用於暫存檔的最大磁碟空間大小,例如排序和雜湊暫存檔,或持有游標的檔案。試圖超過此限制的交易將被取消。此值以 KB 為單位指定,-1(預設值)表示無限制。只有超級使用者可以變更改此設定。
此設定限制了給予 PostgreSQL 程序使用的所有暫存檔在任何時刻能使用的總空間。應該注意的是,用於臨時資料表的磁碟空間與在查詢執行過程中使用的暫存檔不同,並不會計入此限制。
max_files_per_process
(integer
)
設定每個伺服器子程序允許的同時最大開啓的檔案數。預設值是 1000 個檔案。如果核心可以確保每個程序的安全限制,則不必擔心此設定。但是在某些平台上(特別是大多數 BSD 系統),如果許多程序都嘗試開啓那麼多檔案,核心將允許單個程序打開比系統實際支援的更多的檔案。如果您發現自己看到“Too many open files”失敗,請嘗試減少此設定。此參數只能在伺服器啟動時設定。
此功能的目的是允許管理員減少這些指令對同時間資料庫活動的 I/O 影響。在許多情況下,像 VACUUM 和 ANALYZE 這樣的維護指令很快完成就不重要;但是,這些指令又通常非常重要,不會嚴重干擾系統執行其他資料庫操作的能力。基於成本的清理延遲為管理員提供了實現這一目標的途徑。
對於手動發出的 VACUUM 指令,預設情況下會停用此功能。要啟用它,請將 vacuum_cost_delay 變數設定為非零值。
vacuum_cost_delay
(integer
)
超出成本限制時程序將休眠的時間長度(以毫秒為單位)。預設值為零,這會停用成本考量的清理延遲功能。正值可實現成本考量的清理。請注意,在許多系統上,睡眠延遲的有效分辨率為 10 毫秒;將 vacuum_cost_delay 設定為不是 10 的倍數的值可能與將其設定為 10 的下一個更高倍數具有相同的結果。
當使用成本考量的資料庫清理時,vacuum_cost_delay 的適當值通常非常小,可能是 10 或 20 毫秒。調整清理的資源消耗最好透過變更其他清理成本參數來完成。
vacuum_cost_page_hit
(integer
)
清除共享緩衝區中找到的緩衝區估計成本。它表示鎖定緩衝池,查詢共享雜湊表和掃描頁面內容的成本。預設值為 1。
vacuum_cost_page_miss
(integer
)
清除必須從磁碟讀取的緩衝區的估計成本。這表示鎖定緩衝池,查詢共享雜湊表,從磁碟讀取所需塊並掃描其內容的成本。預設值為 10。
vacuum_cost_page_dirty
(integer
)
清理修改先前清理的區塊時産生的估計成本。它表示將已修改區塊再次更新到磁碟所需的額外 I/O。預設值為 20。
vacuum_cost_limit
(integer
)
累積成本將導致清理程序進入睡眠狀態。預設值為 200。
某些操作可能會持有關鍵的鎖定,因此應盡快完成。在此類操作期間不會發生成本考量的清理延遲。因此,成本可能會遠遠高於指定的限制。為了避免在這種情況下無意義的長延遲,實際延遲計算為 vacuum_cost_delay __* cumulative_balance / vacuum_cost_limit,最大為 vacuum_cost_delay _*_ 4。
有一個單獨的伺服器程序稱為背景寫入程序,其功能是發起「dirty」(新的或修改的)共享緩衝區的寫入。 它會寫入共享緩衝區,因此處理使用者查詢的伺服器程序很少或永遠不需要等待寫入的發生。但是,背景寫入程序確實導致 I/O 負載的整體的淨增加,因為雖然每個檢查點間隔可能只會寫一次 repeatedly-dirtied 頁面,但背景寫入程序可能會發起多次寫入,因為它在同一時間間隔內被變更了。本小節中討論的參數可用於調整適於本地需求的行為。
bgwriter_delay
(integer
)
指定背景寫入程序的輪詢之間的延遲。在每一次輪詢中,寫入程序發出一些 dirty 緩衝區的寫入(可透過以下參數控制)。然後它睡眠 bgwriter_delay 毫秒,再重複。但是,當緩衝池中沒有 dirty 緩衝區時,無論 bgwriter_delay 如何,它都會進入更長的睡眠狀態。預設值為 200 毫秒。請注意,在許多系統上,睡眠延遲的有效分辨率為 10 毫秒;將 bgwriter_delay 設定為不是 10 的倍數可能與將其設定為 10 的下一個更高倍數具有相同的結果。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
bgwriter_lru_maxpages
(integer
)
在每一次輪詢中,背景寫入程序將寫入多個緩衝區。將此值設定為零將停用背景寫入。(請注意,由單獨的專用輔助程序管理的檢查點不受影響。)預設值為 100 個緩衝區。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
bgwriter_lru_multiplier
(floating point
)
每次輪詢寫入的 dirty 緩衝區數量取決於最近幾輪中伺服器程序所需的新緩衝區數。將最近的平均需求乘以 bgwriter_lru_multiplier,得出下一輪期間所需緩衝區數量的估計值。寫入 dirty 緩衝區,直到有許多乾淨,可再利用的緩衝區可用。(但是,每輪不會寫入超過 bgwriter_lru_maxpages 的緩衝區。)因此,1.0 的設定表示準確寫出預測需要的緩衝區數量的「Just in time」策略。較大的值為需求中的峰值提供了一些緩衝,而較小的值有意地使寫入由伺服器程序完成。預設值為 2.0。 此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
bgwriter_flush_after
(integer
)
只要背景寫入程序寫入了超過 bgwriter_flush_after 個位元組,就會嘗試強制作業系統向底層儲存系統發出這些寫入操作。這樣做會限制核心頁面緩衝區中的 dirty 資料量,減少在檢查點結束時發出 fsync 時停止的可能性,或者作業系統在背景以較大批次寫回資料的可能性。通常這會導致事務延遲大大減少,但也有一些情況,特別是工作負載大於 shared_buffers,但小於作業系統的頁面緩衝,其效能可能會降低。 此設定可能對某些平台沒有影響。有效範圍介於 0(停用強制寫回)和2MB之間。Linux 上的預設值為 512kB,其他地方為 0。(如果 BLCKSZ 不是8kB,則預設值和最大值會按比例縮放。)此參數只能在 postgresql.conf 檔案或匼服器命令列中設定。
bgwriter_lru_maxpages 和 bgwriter_lru_multiplier 設定較小值可以減少背景寫入程序造成的額外 I/O 負載,但使伺服器程序更有可能必須為自己發出寫入要求,可能造成交互查詢的延遟。
effective_io_concurrency
(integer
)設定 PostgreSQL 期望可以同時執行的磁碟 I/O 操作數。提高此值將增加任何單個 PostgreSQL 連線嘗試同時啟動的 I/O 操作數。允許的範圍是 1 到 1000,或者為零以停用非同步 I/O 要求的使用。目前,此設定僅影響 bitmap heap 掃描。
對於磁碟機而言,此設定一個很好的起點是包含用於資料庫的 RAID 0 分散或 RAID 1 鏡像的單獨磁碟數量。(對於 RAID 5,不應計算奇偶校驗磁碟。)但是,如果資料庫通常忙於在同時連線中發出多個查詢,則較低的值可能足以使磁碟陣列保持忙碌狀態。高於保持磁碟繁忙所需的值只會導致額外的 CPU 開銷。SSD和其他基於內存的儲存通常可以處理許多同時要求,因此最佳值可能是數百個。
非同步 I/O 取決於某些作業系統缺乏的有效 posix_fadvise 函數。如果該功能不存在,則將此參數設定為零以外的任何值將導致錯誤。而在某些作業系統(例如,Solaris)上,此功能存在但實際上並沒有做任何事情。
maintenance_io_concurrency
(integer
)Similar to effective_io_concurrency
, but used for maintenance work that is done on behalf of many client sessions.
max_worker_processes
(integer
)設定系統可以支援的最大背景程序數量。此參數只能在伺服器啟動時設定。預定值為 8。
執行備用伺服器時,必須將此參數設定為與主伺服器上相同或更高的值。否則,將不允許在備用伺服器中進行查詢。
變更此值時,請考慮同步調整 max_parallel_workers 和 max_parallel_workers_per_gather。
max_parallel_workers_per_gather
(integer
)設定單個 Gather 或 Gather Merge 節點可以啟動的最大工作程序數量。同時工作程序取自 max_worker_processes 建立的程序池,由 max_parallel_workers 限制。請注意,請求的工作程序數量在執行時可能實際上不可用。如果發生這種情況,計劃將以比預期更少的工作程序運行,這可能是低效能的。預設值為 2。將此值設定為 0 將停用平行查詢執行。
請注意,平行查詢可能比非平行查詢消耗的資源要多得多,因為每個工作程序都是一個完全獨立的程序,與其他使用者連線對系統的影響大致相同。在為此設定選擇值時,以及在配置控制資源利用率的其他設定(例如work_mem)時,應考慮這一點。 諸如 work_mem 之類的資源限制被單獨應用於每個工作程序,這意味著所有程序的總利用率可能比通常用於任何單個程序的總利用率高得多。例如,使用 4 個工作程序的平行查詢可能會使用高達 5 倍的 CPU 時間、記憶體、I/O 頻寬等作為根本不使用工作程序的查詢。
max_parallel_maintenance_workers
(integer
)Note that parallel utility commands should not consume substantially more memory than equivalent non-parallel operations. This strategy differs from that of parallel query, where resource limits generally apply per worker process. Parallel utility commands treat the resource limit maintenance_work_mem
as a limit to be applied to the entire utility command, regardless of the number of parallel worker processes. However, parallel utility commands may still consume substantially more CPU resources and I/O bandwidth.
max_parallel_workers
(integer
)
設定系統可以支援平行查詢的最大工作程序數量。預設值為 8。增大或減小此值時,請考慮調整 max_parallel_workers_per_gather。另請注意,此值的設定高於 max_worker_processes 將不起作用,因為平行工作程序取自該設定所建立的工作程序池。
backend_flush_after
(integer
)
只要一個後端寫入了多個 backend_flush_after 字串,就會嘗試強制作業系統向底層儲存發出這些寫入操作。這樣做會限制核心頁面緩衝區中的非同步資料量,減少在檢查點結束時發出 fsync 時暫時停止的可能性,或者作業系統在後端以較大批量寫回資料的可能性。通常這會導致事務延遲大大減少,但也有一些情況,特別是工作負載大於shared_buffers,但小於作業系統的頁面暫存,其性能可能會降低。此設定可能對某些平台沒有影響。有效範圍介於 0(停用強制寫回)和 2MB 之間。預設值為 0,即沒有強制寫回。(如果 BLCKSZ 不是 8kB,則最大值與其成比例。)
old_snapshot_threshold
(integer
)
設定可以使用快照的最短時間,而不會在使用快照時發生快照過舊的錯誤。此參數只能在伺服器啟動時設定。
超過閾值,舊資料可能被清理。這可以幫助防止長時間使用的快照所面臨的資料膨脹。為了防止由於清理快照可能會顯示資料的錯誤結果,當快照早於此閾值時會産生錯誤,並且快照用於讀取自建構快照以來已修改的頁面。
值 -1 將停用此功能,並且是預設值。産品等級的有用值可能從少量幾小時到幾天不等。此設定將被強制為分鐘的顆粒度,並且僅允許小數字(例如 0 或 1 分鐘),因為它們有時可用於測試。雖然允許設定高達 60d,但請注意,在許多工作負載中,可能會在更短的時間範圍內發生極端資料膨脹或事務 ID 重覆。
啟用此功能後,關連末尾釋放的空間無法釋放到作業系統,因為這可能會刪除檢測快照過舊狀態所需的訊息。除非明確要求釋放(例如,使用 VACUUM FULL),否則分配給關連的所有空間仍與該關連相關聯,僅在該關連內重覆使用。
此設定不會嘗試保證在任何特定情況下都會産生錯誤。實際上,如果可以從已完成結果集合的游標産生正確的結果,即使引用資料表中的基礎資料列已被清理,也不會産生錯誤。有些資料表不能安全地儘早清理,因此不會受到此設定的影響,例如系統目錄。對於此類資料表,此設定既不會減少膨脹,也不會在掃描時產生快照過舊的錯誤。
log_destination
(string
)PostgreSQL 支援多種記錄伺服器訊息的方法,包括 stderr、csvlog 和 syslog。在 Windows 上,支援 eventlog。 將此參數設定為用逗號分隔的所需日誌目標的列表。 預設情況下僅記錄到 stderr。此參數只能在 postgresql.conf 檔案或伺服器命令中設定。
如果 csvlog 包含在 log_destination 中的話,則日誌將以「逗號分隔」(CSV)格式輸出,便於將日誌載入到其他程序中。詳情請參閱。 必須啟用 才能産生 CSV 格式的日誌輸出。
如果包含 stderr 或 csvlog,則會建立 current_logfiles 檔案以記錄日誌記錄收集器和相關日誌記錄目標目前正在使用的日誌檔案的位置。這提供了一種便捷的方式來查詢目前資料庫實例正在使用的日誌。這裡有這個檔案內容的一個例子:
當一個新的日誌檔案被建立為循環的效果,並且重新載入 log_destination 時,會重新建立 current_logfiles。當 log_destination 中不包含 stderr 和 csvlog,並且日誌記錄收集器被停用時,它將被刪除。
在大多數 Unix 系統上,您需要變更系統 syslog daemon 的配置,以便使用 log_destination 的 syslog 選項。PostgreSQL 可以登入到系統日誌工具 LOCAL0 到 LOCAL7(請參閱 ),但大多數平台上的預設 syslog 配置將放棄所有此類訊息。您需要加入如下的內容:
變更 syslog 背景程序的配置檔案以使其産生作用。
在 Windows 上,當您為 log_destination 使用 eventlog 選項時,應該向作業系統註冊事件來源及其函式庫,以便 Windows 事件查詢器可以清楚地顯示事件日誌消息。詳情請參閱。
logging_collector
(boolean
)此參數啟用日誌收集器,這是一個後端的程序,用於攔截發送到 stderr 的日誌訊息並將其重新輸出到日誌檔案。這種方法通常比記錄到 syslog 更有用,因為某些類型的訊息可能不會出現在 syslog 輸出之中。(一個常見的案例是動態連結程序失敗訊息;另一個案例是由如 archive_command 等腳本産生的錯誤訊息。)此參數只能在伺服器啟動時設定。
可以在不使用日誌收集器的情況下送到 stderr;日誌訊息將只發送到伺服器的 stderr 所指向的任何地方。但是,該方法僅適用於較低階的日誌程序,因為它不提供日誌檔案覆寫的簡便方法。另外,在某些不使用日誌收集器的平台上可能會導致日誌輸出遺失或出現亂碼,因為同時寫入同一日誌檔案的多個程序可能會覆蓋彼此的輸出。
日誌記錄收集器旨在永不遺失訊息。這意味著,如果負載極高,則在收集器落後時嘗試發送其他日誌消息時,伺服器程序可能會被阻止繼續執行。相比之下,如果系統日誌不能寫入訊息,系統日誌會傾向於丟棄訊息,這意味著在這種情況下它可能無法記錄某些訊息,但不會阻塞系統的其餘部分。
log_directory
(string
)當啟用 logging_collector 時,此參數確定將在其中建立日誌檔案的目錄。它可以被指定為絕對路徑,或相對於叢集的 data 目錄。該參數只能在 postgresql.conf 檔案或伺服器指令行中設定。預設值是 log。
log_filename
(string
)如果您指定的檔案名稱不含跳脫符號,則應該計劃使用日誌覆寫程序來避免最後存滿整個磁碟。在 8.4 之前的版本中,如果不存在 % 跳脫符號,PostgreSQL 會追加新日誌檔案建立時間的紀元,但已經不再是這種情況了。
如果在 log_destination 中啟用 CSV 格式的輸出,則會將時間戳記檔案名稱附加.csv 以建立 CSV 格式輸出的檔案名稱。 (如果 log_filename 以 .log 結尾,則替換後綴。)
該參數只能在 postgresql.conf 檔案或伺服器指令中設定。
log_file_mode
(integer
)在 Unix 系統上,此參數在啟用 logging_collector 時設定日誌檔案的權限。(在 Microsoft Windows 上,此參數將被忽略。)參數值預期為以 chmod 和 umask 系統呼叫接受的格式來指定的數字模式。(要使用習慣的八進制格式,數字必須以 0(零)開頭。)
預設權限為 0600,這意味著只有伺服器擁有者才能讀取或寫入日誌檔案。另一個常用的設定是 0640,允許擁有者組群的成員讀取文件。 但是請注意,要使用這種設定,您需要變更 log_directory 以將檔案儲存在叢集 data 目錄之外的某個位置。無論如何,使日誌檔案讓任何人都可讀是不明智的,因為它們可能包含敏感資料。
該參數只能在 postgresql.conf 檔案或伺服器指令中設定。
log_rotation_age
(integer
)當啟用 logging_collector 時,此參數決定單個日誌檔案的最長生命週期。經過指定的分鐘後,會建立一個新的日誌檔案。設定為零以停用基於時間的新日誌檔案建立。該參數只能在 postgresql.conf 檔案或伺服器指令中設定。
log_rotation_size
(integer
)當啟用 logging_collector 時,此參數決定單個日誌檔的大小上限。在超過上限的記錄被發送到日誌檔案後,將建立一個新的日誌檔案。設定為零以禁用基於大小的新日誌檔案創立。該參數只能在 postgresql.conf 檔案或伺服器指令中設定。
log_truncate_on_rotation
(boolean
)當啟用 logging_collector 時,此參數將導致 PostgreSQL 分割(覆蓋)而不是追加到任何具有相同名稱的現有日誌檔案。 但是,分割只會在由於基於時間的覆寫而打開新檔案時發生,而不是在伺服器啟動或基於大小的覆寫情況進行。關閉時,預先存在的檔案將被附加到所有情況下。例如,將此設定與 log_filename(如 postgresql-%H.log)結合使用可産生 24 個小時日誌檔案,然後循環覆蓋它們。該參數只能在 postgresql.conf 檔案或伺服器指令中設定。
例如:要保留 7 天的日誌,每天一個名稱為 server_log.Mon,server_log.Tue 等的日誌檔案,並自動使用本週的日誌覆蓋上週的日誌,將 log_filename 設定為server_log.%a,將 log_truncate_on_rotation 設定為 on,並將 log_rotation_age 到 1440。
又例如:要保留 24 小時的日誌,每小時記錄一個日誌檔案,但是如果日誌檔案大小超過 1GB,則會盡快輪換,將 log_filename 設定為 server_log.%H%M,log_truncate_on_rotation 為 on,log_rotation_age 為 60,log_rotation_size 為1000000。在 log_filename 中包含 %M 允許可能出現的任何大小驅動的旋轉,以選擇與小時的初始檔案名稱不同的檔案名稱。
syslog_facility
(enum
)當啟用日誌記錄到 syslog 時,此參數確定要使用的系統日誌的「設施」。 您可以選擇 LOCAL0,LOCAL1,LOCAL2,LOCAL3,LOCAL4,LOCAL5,LOCAL6,LOCAL7;預設值是 LOCAL0。另請參閱系統的 syslog 背景程序的文件。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
syslog_ident
(string
)當啟用日誌記錄到系統日誌時,此參數決定用於在系統日誌中識別 PostgreSQL 記錄的程序名稱。預設是 postgres。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
syslog_sequence_numbers
(boolean
)當記錄到系統日誌並且這是啓用的(預設),那麼每筆記錄將以遞增的序列號碼(例如[2])作為前置內容。這規避了「---最後一條記錄重複 N 次---」抑制了許多 syslog 實務上預設執行的操作。在更現代的 syslog 實作中,可以設定重複的記錄抑制(例如,rsyslog 中的 $RepeatedMsgReduction),所以這可能不是必要的。另外,如果你真的想要抑制重複的記錄,就可以關掉它。
此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
syslog_split_messages
(boolean
)當啟用日誌記錄到 syslog 時,此參數決定記錄如何傳遞到系統日誌。啟用時(預設),記錄按行分割,使得行長在 1024 字元以下,這是傳統 syslog 實作的典型大小限制。關閉時,PostgreSQL 伺服器日誌記錄會按原樣傳遞到系統日誌服務,並由系統日誌服務來處理潛在的龐大記錄。
如果 syslog 最終記錄到文字檔案,那麼效果將是相同的,並且最好將設定保留為開啟狀態,因為大多數 syslog 實作無法處理大量記錄,或者需要專門設定以處理它們。但是,如果系統日誌最終寫入其他媒體,將記錄邏輯上地組合在一起可能是必要的或更有用的。
此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
event_source
(string
)當啟用記錄到事件日誌時,此參數確定用於在記錄中識別 PostgreSQL 記錄的程序名稱。預設是 PostgreSQL。 此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
client_min_messages
(enum
)控制將哪些訊息等級要發送到用戶端。有效的值為 DEBUG5、DEBUG4、DEBUG3、DEBUG2、DEBUG1、LOG、NOTICE、WARNING、ERROR、FATAL 和 PANIC。每個等級包括其後的所有等級。等級越低,發送的訊息越少。預設值為 NOTICE。請注意,LOG 在此處的排名與 log_min_messages 中的排序不同。
log_min_messages
(enum
)控制將哪些訊息等級寫入伺服器日誌。有效的值為 DEBUG5、DEBUG4、DEBUG3、DEBUG2、DEBUG1、INFO、NOTICE、WARNING、ERROR、LOG、FATAL 和 PANIC。每個等級包括其後的所有等級。等級越低,發送到日誌的訊息越少。預設值為 WARNING。請注意,LOG 在此處的排序與 client_min_messages 中的排名不同。只有超級使用者才能變更此設定。
log_min_error_statement
(enum
)將導致錯誤情況的 SQL 語句記錄在伺服器日誌中。當下的 SQL 語句包含在指定的嚴重性或更高等級的任何訊息日誌項目中。有效值為 DEBUG5、DEBUG4、DEBUG3、DEBUG2、DEBUG1、INFO、NOTICE、WARNING、ERROR、LOG、FATAL 和 PANIC。預設值為 ERROR,這意味著將會記錄 ERROR、LOG、FATL 或 PANIC。要有效地關閉失敗語句的日誌記錄,請將此參數設定為PANIC。只有超級使用者才能變更此設定。
log_min_duration_statement
(integer
)如果語句執行達到指定的毫秒數,則會記錄每個已完成語句的執行時間。將此值設定為零將輸出所有語句的執行時間。減號(預設值)停用日誌記錄語句執行時間。例如,如果將其設定為 250ms,則將記錄執行 250ms 或更長時間的所有 SQL 語句。啟用此參數有助於在應用程序中追踪未優化的查詢。只有超級使用者才能變更此設定。
對於使用延伸查詢協議的用戶端,Parse、Bind 和 Execute 步驟的執行時間是獨立記錄的。
將此選項與 log_statement 一起使用時,由於 log_statement 而記錄的語句文字將不會在執行時間日誌訊息中重複。如果您不使用 syslog,建議您使用 log_line_prefix 記錄 PID 或連線 ID,以便可以使用 PID 或連線 ID將語句訊息連接到之後的執行時間訊息。
application_name
(string
)debug_print_parse
(boolean
) debug_print_rewritten
(boolean
) debug_print_plan
(boolean
)debug_pretty_print
(boolean
)設定後,debug_pretty_print 會放進 debug_print_parse,debug_print_rewritten 或debug_print_plan 産生的訊息。與關閉時使用的緊湊格式相比,這會產生更多可讀但更長的輸出。它預設開啟。
log_checkpoints
(boolean
)使檢查點和重新啟動點記錄在伺服器日誌中。日誌訊息中包含一些統計訊息,包括寫入的緩衝區數和寫入時間。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設為關閉。
log_connections
(boolean
)導致記錄每個嘗試連線到伺服器,以及成功完成用戶端身份驗證。只有超級使用者才能在連線開始時變更此參數,之後在連線中無法更改。預設為關閉。
注意 某些用戶端程序(如 psql)在確定是否需要密碼時會嘗試連線兩次,因此重複的“connection received”訊息不一定表示存在問題。
log_disconnections
(boolean
)導致連線終止會被記錄。日誌輸出提供類似於 log_connections 的訊息,以及連線的持續時間。只有超級使用者才能在連線開始時變更此參數,並且在連線中無法更改。預設為關閉。
log_duration
(boolean
)記錄每個已完成語句的持續時間。預設為關閉。只有超級使用者才能變更此設定。
對於使用延伸查詢協議的用戶端,Parse、Bind 和 Execute 步驟的持續時間是獨立記錄的。
log_error_verbosity
(enum
)log_hostname
(boolean
)預設情況下,連線日誌訊息僅顯示連線主機的 IP 位址。打開此參數就會記錄主機名。請注意,根據您的主機名稱解析設定,這可能會造成不可忽視的效能損失。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
log_line_prefix
(string
)這是一個 printf 樣式的字串,在每個日誌的開頭輸出。%字元開始「跳脫序列(escape sequence)」,它們會被狀態訊息替換,如下所述。 無法識別的跳脫字元會被忽略。其他字元將直接複製到日誌內容。某些跳脫字元只能由連線程序識別,並且將被背景程序(例如主伺服器程序)視為空。透過在 % 之後和選項之前指定數字文字,可以向左或向右對齊狀態訊息。負值會將狀態信息在右側填充空格以給予一個最小寬度,而正值將填充在左側。填充可用於增加日誌檔案中的可讀性。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值為'%m [%p]',用於記錄時間戳記和程序 ID。
%c 跳脫字元輸出一個幾乎唯一的連線指標,兩個由點分隔的 4 位元組的十六進制數字(不帶前導零)組成。數字是流程開始時間和程序 ID,因此 %c 也可以用作輸出這些項目的節省空間的方式。例如,要從 pg_stat_activity 産生連線指標,請使用以下查詢:
小技巧 如果為 log_line_prefix 設定了非空值,則通常應將其最後一個字元設為空格,以便與日誌行的其餘部分進行視覺隔離。也可以使用標點符號。
小技巧 Syslog 會産生成自己的時間戳記和程序 ID 訊息,因此如果要輸出到 syslog,可能不希望包含這些跳脫字元。
小技巧 當包含僅在使用者或資料庫名稱等連線(後端)內容中可用的訊息時,%q 跳脫字元非常有用。例如:
log_lock_waits
(boolean
)log_statement
(enum
)控制記錄哪些 SQL 語句。有效值為 none(off),ddl,mod 和 all(所有語句)。 ddl 記錄所有資料定義語句,例如 CREATE,ALTER 和 DROP 語句。mod 記錄所有 ddl 語句,以及 INSERT,UPDATE,DELETE,TRUNCATE 和 COPY FROM 等資料修改語句。如果包含的指令屬於適合的類型,也會記錄 PREPARE,EXECUTE 和 EXPLAIN ANALYZE 語句。對於使用延伸查詢協議的用戶端,在收到 Execute 訊息時會發生日誌記錄,並且包含 Bind 參數的值(任何嵌入的單引號標記加倍)。
預設值為 none。只有超級使用者才能變更此設定。
注意 即使是 log_statement = all 設定也不會記錄包含簡單語法錯誤的語句,因為只有在完成基本分析以確定語句類型後才會發出日誌訊息。在延伸查詢協議的情況下,此設定同樣不記錄在執行階段之前失敗的語句(即,在解析分析或計劃期間)。將 log_min_error_statement 設定為 ERROR(或更低)以記錄此類語句。
log_replication_commands
(boolean
)log_temp_files
(integer
)控制臨時檔案名稱和大小的記錄。可以為排序,雜湊和臨時查詢結果建立臨時檔案。移除時,會為每個臨時檔案建立一個日誌項目。值為 0 時會記錄所有臨時檔案訊息,而正值僅記錄大小大於或等於指定 KB 的檔案。預設設定為 -1,停用此類日誌記錄。只有超級使用者才能變更此設定。
log_timezone
(string
)在 log_destination 列表中包含 csvlog 提供了將日誌檔案匯入資料庫資料表的便捷方法。此選項以逗號分隔(CSV)格式送出日誌資料,其中包含以下欄位:時間戳記,毫秒,使用者名稱,資料庫名稱,程序 ID,用戶端主機:連接埠號號,連線 ID,每個連線的行號,指令標記,連線開始時間,虛擬交易事務 ID,一般交易事務 ID,錯誤嚴重性,SQLSTATE 代碼,錯誤訊息,錯誤訊息的詳細訊息,提示,導致錯誤的內部查詢(如果有的話),其中錯誤位置的字串位置,錯誤內容,導致錯誤的使用者查詢(如果有的話,由 log_min_error_statement 啟用),其中錯誤位置的字元數,PostgreSQL 原始碼中的錯誤位置(如果 log_error_verbosity 設定為 verbose)和應用程序名稱。以下是用於儲存 CSV 格式日誌輸出的範例資料表定義:
要將日誌檔案匯入此資料表,請使用 COPY FROM 指令:
您需要做一些事情來簡化匯入 CSV 日誌檔案:
設定 log_filename 和 log_rotation_age 使日誌檔案提供一致性,可預測的命名方案。這使您可以預測檔案名稱會是什麼,並知道單個日誌檔案何時完成而可以匯入。
將 log_rotation_size 設定為 0 可停用基於大小的日誌輪轉,因為它會使日誌檔案名稱難以預測。
將 log_truncate_on_rotation 設定為 on,以便舊的日誌資料不會與同一檔案中的新資料混合。
上面的資料表定義包含主鍵規範。這有助於防止意外匯入兩次相同的訊息。COPY 指令一次提交它匯入的所有資料,因此任何錯誤都會導致整個匯入失敗。如果匯入部分日誌檔案,並在稍後再次匯入該檔案時,主鍵重覆將導致匯入失敗。請等到日誌完成關閉後再匯入。此過程還可以防止意外匯入尚未完全寫入的部分資料列,這也會導致 COPY 失敗。
cluster_name
(string
)設定此叢集中所有伺服器程序的程序標題中顯示的叢集名稱。該名稱可以是任何少於 NAMEDATALEN 字元數的字串(標準版本中為 64 個字元)。cluster_name 值中只能使用可列印的 ASCII 字元。其他字元將被替換為問號(?)。如果此參數設定為空字串“”(這是預設值),則不顯示名稱。此參數只能在伺服器啟動時設定。
update_process_title
(boolean
)每當伺服器收到新的 SQL 指令時,都可以更新程序標題。此設定在大多數平台上預設為開啟,不過在 Windows 上預設為關閉,因為在 Windows 上更新程序標題的開銷較大。只有超級使用者可以變更此設定。
請注意,當 autovacuum 運行時,最多可以分配 倍的記憶體,因此請注意不要將預設值設定得太高。透過單獨設定 來控制它會有幫助。
指定每個 autovacuum 工作程序使用的最大記憶體。它預設為 -1,表示應該使用 的值。以其他方式執行時,此設定對 VACUUM 的行為沒有影響。
Specifies the shared memory implementation that the server should use for the main shared memory region that holds PostgreSQL's shared buffers and other shared data. Possible values are mmap
(for anonymous shared memory allocated using mmap
), sysv
(for System V shared memory allocated via shmget
) and windows
(for Windows shared memory). Not all values are supported on all platforms; the first supported option is the default for that platform. The use of the sysv
option, which is not the default on any platform, is generally discouraged because it typically requires non-default kernel settings to allow for large allocations (see ).
在執行 和 指令期間,系統會維護一個內部計數器,用於追踪執行的各種 I/O 操作的估計成本。當累計成本達到極限(由 vacuum_cost_limit 指定)時,執行操作的過程將在 sleep_cost_delay 指定的短時間內休眠。然後它將重置計數器並繼續執行。
在受支援的系統上預設值為 1,否則為 0。透過設定同名的 tablespace 參數,可以為特定資料表空間中的資料表覆寫此值(請參閱 )。
The default is 10 on supported systems, otherwise 0. This value can be overridden for tables in a particular tablespace by setting the tablespace parameter of the same name (see ).
有關平行查詢的更多訊息,請參閱。
Sets the maximum number of parallel workers that can be started by a single utility command. Currently, the parallel utility commands that support the use of parallel workers are CREATE INDEX
only when building a B-tree index, and VACUUM
without FULL
option. Parallel workers are taken from the pool of processes established by , limited by . Note that the requested number of workers may not actually be available at run time. If this occurs, the utility operation will run with fewer workers than expected. The default value is 2. Setting this value to 0 disables the use of parallel workers by utility commands.
當啟用 logging_collector 時,此參數設定建立的日誌檔案的檔案名稱。該值被視為 strftime 模式,因此 %-escapes 可用於指定隨時間變化的檔案名稱。(請注意,如果有任何時區相關的 %-escapes,計算將在由 指定的區域中完成。)支援的 %-escapes 與 Open Group 的 規範中列出的類似。請注意,系統的 strftime 並未直接使用,因此特定於平台的(非標準)延伸功能不起作用。預設值是 postgresql-%Y-%m-%d_%H%M%S.log。
說明了 PostgreSQL 使用的訊息嚴重性等級。如果將日誌記錄輸出發送到 syslog 或 Windows 的事件日誌,則嚴重性等級將按表格中所示進行轉換。
application_name 可以是少於 NAMEDATALEN 個字元的任何字串(標準版本中為 64 個字元)。它通常由應用程序在連線到伺服器時設定。此名稱將顯示在 pg_stat_activity 檢視表中,並包含在 CSV 日誌項目中。它還可以透過 參數包含在日常日誌項目中。application_name 中只能使用可列印的 ASCII 字元。其他字元將替換為問號(?)。
這些參數可以發出各種除錯輸出。設定後,它們將輸出産生的語法解析樹,查詢重寫程序輸出或每個已執行查詢的執行計劃。這些訊息以 LOG 訊息等級發出,因此預設情況下它們將顯示在伺服器日誌中,但不會發送到客戶端。您可以透過調整 或 來變更它。這些參數預設是關閉的。
注意 設定選項和將 log_min_duration_statement 設定為零之間的區別在於,超出 會強制記錄查詢的語句,但此選項不會。因此,如果啟用了 log_duration 且 log_min_duration_statement 具有正值,則會記錄所有持續時間,但僅包含超過閾值的語句的查詢語句。此行為對於在高負載環境中收集統計訊息非常有用。
控制記錄的每條訊息在伺服器日誌中寫入的詳細訊息量。有效值為 TERSE,DEFAULT 和 VERBOSE,每個都向顯示的訊息加上更多內容。TERSE 排除記錄DETAIL,HINT,QUERY 和 CONTEXT 錯誤訊息。VERBOSE 輸出包括 SQLSTATE 錯誤代碼(另請參閱)以及産生錯誤的原始檔案名稱,函數名稱和行號。只有超級使用者才能更改此設定。
控制連線等待時間超過 時是否產生日誌訊息。這對於確定鎖定等待是否導致性能較差很有用。預設是關閉的。只有超級使用者可以變更此設定。
讓每個複寫指令都記錄在伺服器日誌中。有關複寫指令的更多訊息,請參閱。預設值為 off。只有超級使用者才能變更此設定。
設定用於在伺服器日誌中寫入的時間戳記的時區。與 不同,此值是叢集範圍的,因此所有連線都將一致地報告時間戳記。內建的預設值是 GMT,但這通常在 postgresql.conf 中會再設定過;initdb 將在那裡安裝與其系統環境相對應的設定。有關更多訊息,請參閱。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
這些設定控制如何修改伺服器程序的程序標題。程序標題通常使用如 ps 或 Windows 上的 Process Explorer 查看。詳情請參閱。
DEBUG1..DEBUG5
提供連續且更詳細的訊息供開發人員使用。
DEBUG
INFORMATION
INFO
提供隱含用戶請求的訊息,例如來自 VACUUM VERBOSE 的輸出。
INFO
INFORMATION
NOTICE
提供可能對用戶有幫助的訊息,例如,截斷 long identifier 的通知。
NOTICE
INFORMATION
WARNING
提供可能出現問題的警告,例如交易事務區塊外的 COMMIT。
NOTICE
WARNING
ERROR
回報導致當下指令中止的錯誤。
WARNING
ERROR
LOG
回報管理員感興趣的訊息,例如檢查點的活動。
INFO
INFORMATION
FATAL
回報導致當下連線中止的錯誤。
ERR
ERROR
PANIC
回報導致所有資料庫連線中止的錯誤。
CRIT
ERROR
%a
應用名稱
yes
%u
使用者名稱
yes
%d
資料庫名稱
yes
%r
遠端主機名稱或 IP 位址,以及遠端連接埠
yes
%h
遠端主機名稱或 IP 位址
yes
%p
程序 ID
no
%t
時間戳記,不含毫秒
no
%m
時間戳記,包含毫秒
no
%n
時間戳記,包含毫秒(Unix epoch)
no
%i
指令標記:連線的當下指令類型
yes
%e
SQLSTATE 錯誤代碼
no
%c
連線 ID:詳見下文
no
%l
每個連線或程序的日誌行號,從 1 開始
no
%s
開始處理的時間戳記
no
%v
虛擬交易事務 ID(backendID / localXID)
no
%x
交易事務 ID(如果沒有分配,則為 0)
no
%q
不產生輸出,但告訴非連線程序在此字串中停止;被連線中程序忽略
no
%%
文字 %
no
有許多設定參數會影響資料庫系統的行為。在本章的第一部分中,我們將介紹如何瞭解如何設定參數。接下來的部分將詳細討論每個參數。
For additional information on tuning these settings, see Section 29.4.
wal_level
(enum
)wal_level
determines how much information is written to the WAL. The default value is replica
, which writes enough data to support WAL archiving and replication, including running read-only queries on a standby server. minimal
removes all logging except the information required to recover from a crash or immediate shutdown. Finally, logical
adds information necessary to support logical decoding. Each level includes the information logged at all lower levels. This parameter can only be set at server start.
In minimal
level, WAL-logging of some bulk operations can be safely skipped, which can make those operations much faster (see Section 14.4.7). Operations in which this optimization can be applied include:
CREATE TABLE AS
CREATE INDEX
CLUSTER
COPY
into tables that were created or truncated in the same transaction
But minimal WAL does not contain enough information to reconstruct the data from a base backup and the WAL logs, so replica
or higher must be used to enable WAL archiving (archive_mode) and streaming replication.
In logical
level, the same information is logged as with replica
, plus information needed to allow extracting logical change sets from the WAL. Using a level of logical
will increase the WAL volume, particularly if many tables are configured for REPLICA IDENTITY FULL
and many UPDATE
and DELETE
statements are executed.
In releases prior to 9.6, this parameter also allowed the values archive
and hot_standby
. These are still accepted but mapped to replica
.
fsync
(boolean
)If this parameter is on, the PostgreSQL server will try to make sure that updates are physically written to disk, by issuing fsync()
system calls or various equivalent methods (see wal_sync_method). This ensures that the database cluster can recover to a consistent state after an operating system or hardware crash.
While turning off fsync
is often a performance benefit, this can result in unrecoverable data corruption in the event of a power failure or system crash. Thus it is only advisable to turn off fsync
if you can easily recreate your entire database from external data.
Examples of safe circumstances for turning off fsync
include the initial loading of a new database cluster from a backup file, using a database cluster for processing a batch of data after which the database will be thrown away and recreated, or for a read-only database clone which gets recreated frequently and is not used for failover. High quality hardware alone is not a sufficient justification for turning off fsync
.
For reliable recovery when changing fsync
off to on, it is necessary to force all modified buffers in the kernel to durable storage. This can be done while the cluster is shutdown or while fsync
is on by running initdb --sync-only
, running sync
, unmounting the file system, or rebooting the server.
In many situations, turning off synchronous_commit for noncritical transactions can provide much of the potential performance benefit of turning off fsync
, without the attendant risks of data corruption.
fsync
can only be set in the postgresql.conf
file or on the server command line. If you turn this parameter off, also consider turning off full_page_writes.
synchronous_commit
(enum
)Specifies whether transaction commit will wait for WAL records to be written to disk before the command returns a “success” indication to the client. Valid values are on
, remote_apply
, remote_write
, local
, and off
. The default, and safe, setting is on
. When off
, there can be a delay between when success is reported to the client and when the transaction is really guaranteed to be safe against a server crash. (The maximum delay is three times wal_writer_delay.) Unlike fsync, setting this parameter to off
does not create any risk of database inconsistency: an operating system or database crash might result in some recent allegedly-committed transactions being lost, but the database state will be just the same as if those transactions had been aborted cleanly. So, turning synchronous_commit
off can be a useful alternative when performance is more important than exact certainty about the durability of a transaction. For more discussion see Section 29.3.
If synchronous_standby_names is non-empty, this parameter also controls whether or not transaction commits will wait for their WAL records to be replicated to the standby server(s). When set to on
, commits will wait until replies from the current synchronous standby(s) indicate they have received the commit record of the transaction and flushed it to disk. This ensures the transaction will not be lost unless both the primary and all synchronous standbys suffer corruption of their database storage. When set to remote_apply
, commits will wait until replies from the current synchronous standby(s) indicate they have received the commit record of the transaction and applied it, so that it has become visible to queries on the standby(s). When set to remote_write
, commits will wait until replies from the current synchronous standby(s) indicate they have received the commit record of the transaction and written it out to their operating system. This setting is sufficient to ensure data preservation even if a standby instance of PostgreSQL were to crash, but not if the standby suffers an operating-system-level crash, since the data has not necessarily reached stable storage on the standby. Finally, the setting local
causes commits to wait for local flush to disk, but not for replication. This is not usually desirable when synchronous replication is in use, but is provided for completeness.
If synchronous_standby_names
is empty, the settings on
, remote_apply
, remote_write
and local
all provide the same synchronization level: transaction commits only wait for local flush to disk.
This parameter can be changed at any time; the behavior for any one transaction is determined by the setting in effect when it commits. It is therefore possible, and useful, to have some transactions commit synchronously and others asynchronously. For example, to make a single multistatement transaction commit asynchronously when the default is the opposite, issue SET LOCAL synchronous_commit TO OFF
within the transaction.
wal_sync_method
(enum
)Method used for forcing WAL updates out to disk. If fsync
is off then this setting is irrelevant, since WAL file updates will not be forced out at all. Possible values are:
open_datasync
(write WAL files with open()
option O_DSYNC
)
fdatasync
(call fdatasync()
at each commit)
fsync
(call fsync()
at each commit)
fsync_writethrough
(call fsync()
at each commit, forcing write-through of any disk write cache)
open_sync
(write WAL files with open()
option O_SYNC
)
The open_
* options also use O_DIRECT
if available. Not all of these choices are available on all platforms. The default is the first method in the above list that is supported by the platform, except that fdatasync
is the default on Linux. The default is not necessarily ideal; it might be necessary to change this setting or other aspects of your system configuration in order to create a crash-safe configuration or achieve optimal performance. These aspects are discussed in Section 29.1. This parameter can only be set in the postgresql.conf
file or on the server command line.
full_page_writes
(boolean
)啟用此參數後,PostgreSQL 伺服器會在檢查點之後對該頁面的首次修改期間將每個磁碟頁面的全部內容寫入 WAL。這是必要的,因為在作業系統當機期間正在進行的頁面寫入可能僅部分完成,從而導致包含新舊資料混合在磁碟頁面之中。通常在 WAL 中所儲存的資料列層級更改資料不足以在當機後還原期間完全還原此類頁面。儲存完整的頁面映像可確保還原正確的頁面,但是這樣做的代價是增加了必須寫入 WAL 的資料量。 (由於 WAL 重放總是從檢查點開始,因此在檢查點之後每頁的第一次更改期間執行此操作就足夠了。也因此,減少全頁寫入成本的一種方法是增加檢查點間隔參數。)
停用此參數可加快正常操作的速度,但在系統故障後可能會導致不可恢復的資料損壞或未知的資料損壞。風險與關閉 fsync 相似,儘管較小,但應僅根據針對該參數建議的相同情況將其關閉。
禁用此參數不會影響使用 WAL 歸檔進行時間點還原作業(PITR)(請參閱第 25.3 節)。
該參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設為 on。
wal_log_hints
(boolean
)When this parameter is on
, the PostgreSQL server writes the entire content of each disk page to WAL during the first modification of that page after a checkpoint, even for non-critical modifications of so-called hint bits.
If data checksums are enabled, hint bit updates are always WAL-logged and this setting is ignored. You can use this setting to test how much extra WAL-logging would occur if your database had data checksums enabled.
This parameter can only be set at server start. The default value is off
.
wal_compression
(boolean
)When this parameter is on
, the PostgreSQL server compresses a full page image written to WAL when full_page_writes is on or during a base backup. A compressed page image will be decompressed during WAL replay. The default value is off
. Only superusers can change this setting.
Turning this parameter on can reduce the WAL volume without increasing the risk of unrecoverable data corruption, but at the cost of some extra CPU spent on the compression during WAL logging and on the decompression during WAL replay.
wal_buffers
(integer
)The amount of shared memory used for WAL data that has not yet been written to disk. The default setting of -1 selects a size equal to 1/32nd (about 3%) of shared_buffers, but not less than 64kB
nor more than the size of one WAL segment, typically 16MB
. This value can be set manually if the automatic choice is too large or too small, but any positive value less than 32kB
will be treated as 32kB
. If this value is specified without units, it is taken as WAL blocks, that is XLOG_BLCKSZ
bytes, typically 8kB. This parameter can only be set at server start.
The contents of the WAL buffers are written out to disk at every transaction commit, so extremely large values are unlikely to provide a significant benefit. However, setting this value to at least a few megabytes can improve write performance on a busy server where many clients are committing at once. The auto-tuning selected by the default setting of -1 should give reasonable results in most cases.
wal_writer_delay
(integer
)Specifies how often the WAL writer flushes WAL, in time terms. After flushing WAL the writer sleeps for the length of time given by wal_writer_delay
, unless woken up sooner by an asynchronously committing transaction. If the last flush happened less than wal_writer_delay
ago and less than wal_writer_flush_after
worth of WAL has been produced since, then WAL is only written to the operating system, not flushed to disk. If this value is specified without units, it is taken as milliseconds. The default value is 200 milliseconds (200ms
). Note that on many systems, the effective resolution of sleep delays is 10 milliseconds; setting wal_writer_delay
to a value that is not a multiple of 10 might have the same results as setting it to the next higher multiple of 10. This parameter can only be set in the postgresql.conf
file or on the server command line.
wal_writer_flush_after
(integer
)Specifies how often the WAL writer flushes WAL, in volume terms. If the last flush happened less than wal_writer_delay
ago and less than wal_writer_flush_after
worth of WAL has been produced since, then WAL is only written to the operating system, not flushed to disk. If wal_writer_flush_after
is set to 0
then WAL data is always flushed immediately. If this value is specified without units, it is taken as WAL blocks, that is XLOG_BLCKSZ
bytes, typically 8kB. The default is 1MB
. This parameter can only be set in the postgresql.conf
file or on the server command line.
commit_delay
(integer
)Setting commit_delay
adds a time delay before a WAL flush is initiated. This can improve group commit throughput by allowing a larger number of transactions to commit via a single WAL flush, if system load is high enough that additional transactions become ready to commit within the given interval. However, it also increases latency by up to the commit_delay
for each WAL flush. Because the delay is just wasted if no other transactions become ready to commit, a delay is only performed if at least commit_siblings
other transactions are active when a flush is about to be initiated. Also, no delays are performed if fsync
is disabled. If this value is specified without units, it is taken as microseconds. The default commit_delay
is zero (no delay). Only superusers can change this setting.
In PostgreSQL releases prior to 9.3, commit_delay
behaved differently and was much less effective: it affected only commits, rather than all WAL flushes, and waited for the entire configured delay even if the WAL flush was completed sooner. Beginning in PostgreSQL 9.3, the first process that becomes ready to flush waits for the configured interval, while subsequent processes wait only until the leader completes the flush operation.
commit_siblings
(integer
)Minimum number of concurrent open transactions to require before performing the commit_delay
delay. A larger value makes it more probable that at least one other transaction will become ready to commit during the delay interval. The default is five transactions.
checkpoint_timeout
(integer
)自動 WAL 檢查點之間的最長時間。如果指定的值不帶單位,則以秒為單位。有效範圍是 30 秒至 1 天。預設值為五分鐘(5 分鐘)。增大此參數可能會增加當機回復所需的時間。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
checkpoint_completion_target
(floating point
)指定檢查點完成的目標,佔檢查點之間總時間的一部分。預設值為 0.5。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
checkpoint_flush_after
(integer
)
Whenever more than this amount of data has been written while performing a checkpoint, attempt to force the OS to issue these writes to the underlying storage. Doing so will limit the amount of dirty data in the kernel's page cache, reducing the likelihood of stalls when an fsync
is issued at the end of the checkpoint, or when the OS writes data back in larger batches in the background. Often that will result in greatly reduced transaction latency, but there also are some cases, especially with workloads that are bigger than shared_buffers, but smaller than the OS's page cache, where performance might degrade. This setting may have no effect on some platforms. If this value is specified without units, it is taken as blocks, that is BLCKSZ
bytes, typically 8kB. The valid range is between 0
, which disables forced writeback, and 2MB
. The default is 256kB
on Linux, 0
elsewhere. (If BLCKSZ
is not 8kB, the default and maximum values scale proportionally to it.) This parameter can only be set in the postgresql.conf
file or on the server command line.
checkpoint_warning
(integer
)Write a message to the server log if checkpoints caused by the filling of WAL segment files happen closer together than this amount of time (which suggests that max_wal_size
ought to be raised). If this value is specified without units, it is taken as seconds. The default is 30 seconds (30s
). Zero disables the warning. No warnings will be generated if checkpoint_timeout
is less than checkpoint_warning
. This parameter can only be set in the postgresql.conf
file or on the server command line.
max_wal_size
(integer
)使 WAL 增長到自動 WAL 檢查點之間的最大大小。這是一個軟限制。在特殊情況下,例如重度負載,失敗的 archive_command 或較高的 wal_keep_segments 設定,WAL 大小可能會超過 max_wal_size。如果指定的該值不帶單位,則以 MegaByte 為單位。預設值為1 GB。增大此參數可能會增加當機回復所需的時間。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
min_wal_size
(integer
)As long as WAL disk usage stays below this setting, old WAL files are always recycled for future use at a checkpoint, rather than removed. This can be used to ensure that enough WAL space is reserved to handle spikes in WAL usage, for example when running large batch jobs. If this value is specified without units, it is taken as megabytes. The default is 80 MB. This parameter can only be set in the postgresql.conf
file or on the server command line.
archive_mode
(enum
)
When archive_mode
is enabled, completed WAL segments are sent to archive storage by setting archive_command. In addition to off
, to disable, there are two modes: on
, and always
. During normal operation, there is no difference between the two modes, but when set to always
the WAL archiver is enabled also during archive recovery or standby mode. In always
mode, all files restored from the archive or streamed with streaming replication will be archived (again). See Section 26.2.9 for details.
archive_mode
and archive_command
are separate variables so that archive_command
can be changed without leaving archiving mode. This parameter can only be set at server start. archive_mode
cannot be enabled when wal_level
is set to minimal
.
archive_command
(string
)
The local shell command to execute to archive a completed WAL file segment. Any %p
in the string is replaced by the path name of the file to archive, and any %f
is replaced by only the file name. (The path name is relative to the working directory of the server, i.e., the cluster's data directory.) Use %%
to embed an actual %
character in the command. It is important for the command to return a zero exit status only if it succeeds. For more information see Section 25.3.1.
This parameter can only be set in the postgresql.conf
file or on the server command line. It is ignored unless archive_mode
was enabled at server start. If archive_command
is an empty string (the default) while archive_mode
is enabled, WAL archiving is temporarily disabled, but the server continues to accumulate WAL segment files in the expectation that a command will soon be provided. Setting archive_command
to a command that does nothing but return true, e.g. /bin/true
(REM
on Windows), effectively disables archiving, but also breaks the chain of WAL files needed for archive recovery, so it should only be used in unusual circumstances.
archive_timeout
(integer
)
The archive_command is only invoked for completed WAL segments. Hence, if your server generates little WAL traffic (or has slack periods where it does so), there could be a long delay between the completion of a transaction and its safe recording in archive storage. To limit how old unarchived data can be, you can set archive_timeout
to force the server to switch to a new WAL segment file periodically. When this parameter is greater than zero, the server will switch to a new segment file whenever this amount of time has elapsed since the last segment file switch, and there has been any database activity, including a single checkpoint (checkpoints are skipped if there is no database activity). Note that archived files that are closed early due to a forced switch are still the same length as completely full files. Therefore, it is unwise to use a very short archive_timeout
— it will bloat your archive storage. archive_timeout
settings of a minute or so are usually reasonable. You should consider using streaming replication, instead of archiving, if you want data to be copied off the master server more quickly than that. If this value is specified without units, it is taken as seconds. This parameter can only be set in the postgresql.conf
file or on the server command line.
This section describes the settings that apply only for the duration of the recovery. They must be reset for any subsequent recovery you wish to perform.
“Recovery” covers using the server as a standby or for executing a targeted recovery. Typically, standby mode would be used to provide high availability and/or read scalability, whereas a targeted recovery is used to recover from data loss.
To start the server in standby mode, create a file called standby.signal
in the data directory. The server will enter recovery and will not stop recovery when the end of archived WAL is reached, but will keep trying to continue recovery by connecting to the sending server as specified by the primary_conninfo
setting and/or by fetching new WAL segments using restore_command
. For this mode, the parameters from this section and Section 19.6.3 are of interest. Parameters from Section 19.5.5 will also be applied but are typically not useful in this mode.
To start the server in targeted recovery mode, create a file called recovery.signal
in the data directory. If both standby.signal
and recovery.signal
files are created, standby mode takes precedence. Targeted recovery mode ends when the archived WAL is fully replayed, or when recovery_target
is reached. In this mode, the parameters from both this section and Section 19.5.5 will be used.
restore_command
(string
)The local shell command to execute to retrieve an archived segment of the WAL file series. This parameter is required for archive recovery, but optional for streaming replication. Any %f
in the string is replaced by the name of the file to retrieve from the archive, and any %p
is replaced by the copy destination path name on the server. (The path name is relative to the current working directory, i.e., the cluster's data directory.) Any %r
is replaced by the name of the file containing the last valid restart point. That is the earliest file that must be kept to allow a restore to be restartable, so this information can be used to truncate the archive to just the minimum required to support restarting from the current restore. %r
is typically only used by warm-standby configurations (see Section 26.2). Write %%
to embed an actual %
character.
It is important for the command to return a zero exit status only if it succeeds. The command will be asked for file names that are not present in the archive; it must return nonzero when so asked. Examples:
An exception is that if the command was terminated by a signal (other than SIGTERM, which is used as part of a database server shutdown) or an error by the shell (such as command not found), then recovery will abort and the server will not start up.
This parameter can only be set at server start.
archive_cleanup_command
(string
)This optional parameter specifies a shell command that will be executed at every restartpoint. The purpose of archive_cleanup_command
is to provide a mechanism for cleaning up old archived WAL files that are no longer needed by the standby server. Any %r
is replaced by the name of the file containing the last valid restart point. That is the earliest file that must be kept to allow a restore to be restartable, and so all files earlier than %r
may be safely removed. This information can be used to truncate the archive to just the minimum required to support restart from the current restore. The pg_archivecleanup module is often used in archive_cleanup_command
for single-standby configurations, for example:
Note however that if multiple standby servers are restoring from the same archive directory, you will need to ensure that you do not delete WAL files until they are no longer needed by any of the servers. archive_cleanup_command
would typically be used in a warm-standby configuration (see Section 26.2). Write %%
to embed an actual %
character in the command.
If the command returns a nonzero exit status then a warning log message will be written. An exception is that if the command was terminated by a signal or an error by the shell (such as command not found), a fatal error will be raised.
This parameter can only be set in the postgresql.conf
file or on the server command line.
recovery_end_command
(string
)This parameter specifies a shell command that will be executed once only at the end of recovery. This parameter is optional. The purpose of the recovery_end_command
is to provide a mechanism for cleanup following replication or recovery. Any %r
is replaced by the name of the file containing the last valid restart point, like in archive_cleanup_command.
If the command returns a nonzero exit status then a warning log message will be written and the database will proceed to start up anyway. An exception is that if the command was terminated by a signal or an error by the shell (such as command not found), the database will not proceed with startup.
This parameter can only be set in the postgresql.conf
file or on the server command line.
By default, recovery will recover to the end of the WAL log. The following parameters can be used to specify an earlier stopping point. At most one of recovery_target
, recovery_target_lsn
, recovery_target_name
, recovery_target_time
, or recovery_target_xid
can be used; if more than one of these is specified in the configuration file, an error will be raised. These parameters can only be set at server start.
recovery_target
= 'immediate'
This parameter specifies that recovery should end as soon as a consistent state is reached, i.e. as early as possible. When restoring from an online backup, this means the point where taking the backup ended.
Technically, this is a string parameter, but 'immediate'
is currently the only allowed value.
recovery_target_name
(string
)This parameter specifies the named restore point (created with pg_create_restore_point()
) to which recovery will proceed.
recovery_target_time
(timestamp
)This parameter specifies the time stamp up to which recovery will proceed. The precise stopping point is also influenced by recovery_target_inclusive.
recovery_target_xid
(string
)This parameter specifies the transaction ID up to which recovery will proceed. Keep in mind that while transaction IDs are assigned sequentially at transaction start, transactions can complete in a different numeric order. The transactions that will be recovered are those that committed before (and optionally including) the specified one. The precise stopping point is also influenced by recovery_target_inclusive.
recovery_target_lsn
(pg_lsn
)This parameter specifies the LSN of the write-ahead log location up to which recovery will proceed. The precise stopping point is also influenced by recovery_target_inclusive. This parameter is parsed using the system data type pg_lsn
.
The following options further specify the recovery target, and affect what happens when the target is reached:
recovery_target_inclusive
(boolean
)Specifies whether to stop just after the specified recovery target (on
), or just before the recovery target (off
). Applies when recovery_target_lsn, recovery_target_time, or recovery_target_xid is specified. This setting controls whether transactions having exactly the target WAL location (LSN), commit time, or transaction ID, respectively, will be included in the recovery. Default is on
.
recovery_target_timeline
(string
)Specifies recovering into a particular timeline. The value can be a numeric timeline ID or a special value. The value current
recovers along the same timeline that was current when the base backup was taken. The value latest
recovers to the latest timeline found in the archive, which is useful in a standby server. latest
is the default.
You usually only need to set this parameter in complex re-recovery situations, where you need to return to a state that itself was reached after a point-in-time recovery. See Section 25.3.5 for discussion.
recovery_target_action
(enum
)Specifies what action the server should take once the recovery target is reached. The default is pause
, which means recovery will be paused. promote
means the recovery process will finish and the server will start to accept connections. Finally shutdown
will stop the server after reaching the recovery target.
The intended use of the pause
setting is to allow queries to be executed against the database to check if this recovery target is the most desirable point for recovery. The paused state can be resumed by using pg_wal_replay_resume()
(see Table 9.86), which then causes recovery to end. If this recovery target is not the desired stopping point, then shut down the server, change the recovery target settings to a later target and restart to continue recovery.
The shutdown
setting is useful to have the instance ready at the exact replay point desired. The instance will still be able to replay more WAL records (and in fact will have to replay WAL records since the last checkpoint next time it is started).
Note that because recovery.signal
will not be removed when recovery_target_action
is set to shutdown
, any subsequent start will end with immediate shutdown unless the configuration is changed or the recovery.signal
file is removed manually.
This setting has no effect if no recovery target is set. If hot_standby is not enabled, a setting of pause
will act the same as shutdown
.
listen_addresses
(string
)指定伺服器監聽用戶端應用程序連線的 TCP/IP 位址。該值採用逗號分隔的主機名稱或數字 IP 位址列表的形式。特殊項目「*」對應於所有可用的 IP。項目 0.0.0.0 允許監聽所有 IPv4 位址,還有「::」允許監聽所有 IPv6 位址。如果列表為空,則伺服器根本不監聽任何 IP 接口,在這種情況下,就只能使用 Unix-domain socket 來連接它。預設值是 localhost,它只允許進行本地 TCP/IP loopback 連線。儘管用戶端身份驗證(第 20 章)允許對誰可以存取伺服器進行細維的控制,但 listen_addresses 控制哪些 IP 接受連線嘗試,這有助於防止在不安全的網路接口上重複發出惡意的連線請求。此參數只能在伺服器啟動時設定。
port
(integer
)伺服器監聽的 TCP 連接埠;預設是 5432。請注意,相同的連接埠號號用於伺服器監聽的所有 IP 地址。此參數只能在伺服器啟動時設定。
max_connections
(integer
)決定資料庫伺服器的最大同時連線數。預設值通常為 100 個連線,但如果您的核心設定不支援它(在 initdb 期間確定),則可能會更少。該參數只能在伺服器啟動時設定。
運行備用伺服器時,必須將此參數設定為與主服務器上相同或更高的值。 否則,查詢將不被允許在備用伺服器中使用。
superuser_reserved_connections
(integer
)決定為 PostgreSQL 超級使用者連線保留的連線「插槽」的數量。最多 max_connections 連線可以同時活動。當活動同時連線的數量為 max_connections 減去 superuser_reserved_connections 以上時,新連線將僅接受超級使用者,並且不會接受新的複寫作業連線。
預設值是三個連線。該值必須小於 max_connections 的值。此參數只能在伺服器啟動時設定。
unix_socket_directories
(string
)指定伺服器要監聽來自用戶端應用程序以 Unix-domain socket 連線的目錄。列出由逗號分隔的多個目錄可以建立多個 socket。項目之間的空白會被忽略;如果您需要在名稱中包含空格或逗號,請用雙引號括住目錄名稱。空值表示不監聽任何 Unix-domain socket,在這種情況下,只有 TCP/IP 協定可用於連線到服務器。預設值通常是 /tmp,但可以在編譯時變更。此參數只能在伺服器啟動時設定。
除了名為 .s.PGSQL.nnnn 的 socket 檔案本身之外,其中 nnnn 是伺服器的連接埠號號,將在每個 unix_socket_directories 目錄中建立一個名為 .s.PGSQL.nnnn.lock 的普通檔案。這兩個檔案都不應該手動刪除。
這個參數與 Windows 無關,它沒有 Unix-domain socket。
unix_socket_group
(string
)
設定 Unix-domain socket 的群組。(socket 的使用者始終是啟動伺服器的使用者。)結合參數 unix_socket_permissions,可以將其用作為 Unix-domain socket 的附加存取控制機制。預設情況下,這是空字符串,它使用服務器用戶的預設群組。此參數只能在伺服器啟動時設定。
這個參數與 Windows 無關,它沒有 Unix-domain socket。
unix_socket_permissions
(integer
)
設定 Unix-domain socket 的存取權限。Unix-domain socket 使用一般的 Unix 檔案系統權限設定。期望的參數值是以 chmod 和 umask 系統呼叫可接受的格式指定數字模式。(要使用習慣的八進制格式,數字必須以 0(零)開頭。)
預設權限是 0777,意味著任何人都可以進行連線。合理的選擇是 0770(僅使用者和其群組,另請參閱 unix_socket_group)和 0700(僅使用者本身)。(請注意,對於Unix-domain socket,只有寫入權限很重要,所以設定還是撤消讀取或執行權限都沒有意義。)
這種存取控制機制獨立於第 20 章中所描述的機制。
此參數只能在伺服器啟動時設定。
此參數在某些系統上無關緊要,特別是從 Solaris 10 開始的 Solaris,會完全忽略權限許可。在那裡,透過將 unix_socket_directories 指向具有僅限於所需的搜尋權限的目錄,就可以實現類似的效果。這個參數與 Windows 也是無關的,它沒有 Unix-domain socket。
bonjour
(boolean
)
透過 Bonjour 啟用伺服器存在的廣播。預設是關閉的。此參數只能在伺服器啟動時設定。
bonjour_name
(string
)
指定 Bonjour 的服務名稱。如果此參數設定為空字串''(這是預設值),則使用電腦名稱。 如果伺服器未使用 Bonjour 支援進行編譯,則此參數將被忽略。此參數只能在伺服器啟動時設定。
tcp_keepalives_idle
(integer
)
指定 TCP 在發送 Keepalive 訊息給用戶端之後保持連線的秒數。值為 0 時使用系統預設值。此參數僅在支援 TCP_KEEPIDLE 或等效網路選項的系統上以及在 Windows 上受到支援;在其他系統上,它必須是零。在透過 Unix-domain socket 的連線中,該參數將被忽略並始終為零。
在 Windows 上,值為 0 會將此參數設定為2小時,因為 Windows 不提供讀取系統預設值的方法。
tcp_keepalives_interval
(integer
)
指定用戶端未回應的 TCP 保持活動訊息應重新傳輸的秒數。值為 0 時使用系統預設值。此參數僅在支援 TCP_KEEPINTVL 或等效網路選項的系統上以及在 Windows 上受到支援;在其他系統上,它必須是零。在透過 Unix-domain socket 的連線中,此參數將被忽略並始終為零。
在 Windows 上,值為 0 會將此參數設定為 1 秒,因為 Windows 不提供讀取系統預設值的方法。
tcp_keepalives_count
(integer
)
指定在伺服器連線到用戶端之前可能已經失去的 TCP 保持連線的數量。值為 0 時使用系統預設值。此參數僅在支援 TCP_KEEPCNT 或等效網路選項的系統上受到支持;在其他系統上,它必須是零。在透過 Unix-domain socket 的連線中,此參數將被忽略並始終為零。
此參數在 Windows 上不支援,並且必須為零。
authentication_timeout
(integer
)以秒為單位設定用戶端身份驗證的最長時間。如果可能的用戶端在這段時間內還沒有完成認證協議,伺服器將會關閉連線。這可以防止掛起的用戶端無限期地佔用連線。預設值是一分鐘。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
password_encryption
(enum
)在 CREATE ROLE 或 ALTER ROLE 中指定了密碼後,此參數確定用於加密密碼的演算法。預設值為 md5,它將密碼儲存為 MD5 雜湊值(也可以使用 on,作為 md5 的別名)。將此參數設定為 scram-sha-256 將使用 SCRAM-SHA-256 來加密密碼。
請注意,較舊的用戶端程式可能會缺乏對 SCRAM 身份驗證機制的支援,因此不適用於使用 SCRAM-SHA-256 加密的密碼。有關更多詳細資訊,請參閱 20.5 節。
ssl
(boolean
)
啟用 SSL 連線。使用前請先閱讀第 18.9 節。 此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設是關閉的。
ssl_ca_file
(string
)
指定包含 SSL 伺服器證書頒發機構(CA)的檔案名稱。相對路徑與資料目錄有關。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值為空,表示未載入 CA 檔案,並且不執行用戶端證書驗證。
在以前的 PostgreSQL 版本中,該檔案的名稱被硬性指定為 root.crt。
ssl_cert_file
(string
)
指定包含 SSL 伺服器證書的檔案名稱。相對路徑與資料目錄有關。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值是 server.crt。
ssl_crl_file
(string
)
指定包含 SSL 伺服器證書吊銷列表(CRL)的文件的名稱。相對路徑與資料目錄有關。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值為空,表示沒有加載 CRL 檔案。
在以前的 PostgreSQL 版本中,該檔案的名稱被硬性指定為 root.crl。
ssl_key_file
(string
)
指定包含 SSL 伺服器私鑰的檔案名稱。相對路徑與資料目錄有關。 此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值是 server.key。
ssl_ciphers
(string
)
指定允許在安全連線上使用的 SSL 密碼套件列表。有關此設定的語法和支援的列表,請參閱 OpenSSL 軟體套件中的密碼手冊文件。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值為 HIGH:MEDIUM:+3DES:!aNULL。這個預設通常是一個合理的設定,除非您有特定的安全要求。
預設值延伸說明:
HIGH
使用來自 HIGH group 的密碼套件(例如:AES,Camellia,3DES)
MEDIUM
使用來自 MEDIUM group 的密碼套件(例如:RC4,SEED)
+3DES
HIGH 的 OpenSSL 預設順序有問題,因為它的 3DES 高於 AES128。這是錯誤的,因為 3DES 比 AES128 提供較低的安全性,而且速度也更慢。+3DES 將所有其他高級和中級密碼重新排序。
!aNULL
停用不進行身份驗證的匿名密碼套件。這種密碼套件容易受到中間人攻擊,因此不應使用。
可用的密碼套件詳細訊息將因 OpenSSL 版本而異。使用命令 openssl ciphers -v'HIGH:MEDIUM:+3DES:!aNULL'
來查看當下安裝的 OpenSSL 版本細節。請注意,此列表在運行時基於伺服器密鑰型別進行過濾。
ssl_prefer_server_ciphers
(boolean
)
指定是否使用伺服器的 SSL 密碼設定,而不是用戶端的。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值是 true。
較舊的 PostgreSQL 版本並沒有此設定,始終使用用戶端的設定。此設定主要是為了與這些版本的相容性。使用伺服器的選項通常更好,因為伺服器更有可能做適當的配置。
ssl_ecdh_curve
(string
)
指定要在 ECDH 密鑰交換中使用的 curve 名稱。它需要所有連線的用戶端支援。它不需要與伺服器的 curve 鍵使用的相同。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設為 prime256v1。
最常用 curve 的 OpenSSL 名稱為:prime256v1(NIST P-256),secp384r1(NIST P-384),secp521r1(NIST P-521)。可用 curve 的完整列表可以使用 openssl ecparam -list_curves 指令列出。但並非所有的結果都可以在 TLS 中使用。
password_encryption
(enum
)
當在 CREATE ROLE 或 ALTER ROLE 中指定密碼時,此參數決定用於加密密碼的演算法。預設值是md5,它將密碼儲存為MD5 hash(on 也被接受,作為 md5 的別名)。將此參數設定為 scram-sha-256 時將使用 SCRAM-SHA-256 加密密碼。
請注意,較舊的用戶端可能缺少對 SCRAM 認證機制的支援,因此不適用於使用 SCRAM-SHA-256 加密的密碼。有關更多詳細訊息,請參閱第 20.3.2 節。
ssl_dh_params_file
(string
)
指定包含用於所謂的 ephemeral DH family 的 SSL 加密的 Diffie-Hellman 參數的檔案名稱。預設值為空,在這種情況下,使用預設編譯的 DH 參數。如果攻擊者設法破解眾所周知的編譯 DH 參數,則使用自行定義 DH 參數可以減少暴露的可能性。 您可以使用指令 openssl dhparam -out dhparams.pem 2048
建立您自己的DH參數檔案。
此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
krb_server_keyfile
(string
)
設定 Kerberos 伺服器密鑰檔案的位置。有關詳細訊息,請參閱第 20.3.3 節。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
krb_caseins_users
(boolean
)
設定是否應該區分大小寫地處理 GSSAPI 用戶名。預設是關閉的(區分大小寫)。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
db_user_namespace
(boolean
)
此參數啟用每個資料庫分別的使用者名稱。預設是關閉的。 此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
如果開啓的話,您應該將使用者建立為 username@dbname。當連線用戶端傳遞使用者名稱時,@和資料庫名稱將附加到使用者名稱中,並且該伺服器會查詢特定於資料庫的使用者名稱。請注意,當您在 SQL 環境中建立名稱包含 @ 的使用者時,您需要以引號括住使用者名稱。
啟用此參數後,您仍然可以建立普通的全域使用者。在用戶端指定使用者名稱時簡單追加 @,例如 joe@。在使用者名稱被伺服器查詢之前,@ 將被剝離。
db_user_namespace 會導致用戶端和伺服器的使用者名稱表示方式不同。身份驗證檢查始終使用伺服器的使用者名稱完成,因此必須為伺服器的使用者名稱配置身份驗證方法,而不是用戶端。而 md5 在用戶端和伺服器上均使用使用者名稱作為 salt,所以 md5 不能與 db_user_namespace 一起使用。
此功能是一種臨時措施,到找到完整的解決方案的時候,這個選項將被刪除。
有關設定 SSL 的更多資訊,請參閱第 18.9 節。
ssl
(boolean
)
啟用 SSL 連線。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設為 off。
ssl_ca_file
(string
)
Specifies the name of the file containing the SSL server certificate authority (CA). Relative paths are relative to the data directory. This parameter can only be set in the postgresql.conf
file or on the server command line. The default is empty, meaning no CA file is loaded, and client certificate verification is not performed.
ssl_cert_file
(string
)
Specifies the name of the file containing the SSL server certificate. Relative paths are relative to the data directory. This parameter can only be set in the postgresql.conf
file or on the server command line. The default is server.crt
.
(string
)
Specifies the name of the file containing the SSL server certificate revocation list (CRL). Relative paths are relative to the data directory. This parameter can only be set in the postgresql.conf
file or on the server command line. The default is empty, meaning no CRL file is loaded.
ssl_key_file
(string
)
Specifies the name of the file containing the SSL server private key. Relative paths are relative to the data directory. This parameter can only be set in the postgresql.conf
file or on the server command line. The default is server.key
.
ssl_ciphers
(string
)
Specifies a list of SSL cipher suites that are allowed to be used on secure connections. See the ciphers manual page in the OpenSSL package for the syntax of this setting and a list of supported values. This parameter can only be set in the postgresql.conf
file or on the server command line. The default value is HIGH:MEDIUM:+3DES:!aNULL
. The default is usually a reasonable choice unless you have specific security requirements.
Explanation of the default value:
HIGH
Cipher suites that use ciphers from HIGH
group (e.g., AES, Camellia, 3DES)
MEDIUM
Cipher suites that use ciphers from MEDIUM
group (e.g., RC4, SEED)
+3DES
The OpenSSL default order for HIGH
is problematic because it orders 3DES higher than AES128. This is wrong because 3DES offers less security than AES128, and it is also much slower. +3DES
reorders it after all other HIGH
and MEDIUM
ciphers.
!aNULL
Disables anonymous cipher suites that do no authentication. Such cipher suites are vulnerable to man-in-the-middle attacks and therefore should not be used.
Available cipher suite details will vary across OpenSSL versions. Use the command openssl ciphers -v 'HIGH:MEDIUM:+3DES:!aNULL'
to see actual details for the currently installed OpenSSL version. Note that this list is filtered at run time based on the server key type
ssl_prefer_server_ciphers
(boolean
)
Specifies whether to use the server's SSL cipher preferences, rather than the client's. This parameter can only be set in the postgresql.conf
file or on the server command line. The default is true
.
Older PostgreSQL versions do not have this setting and always use the client's preferences. This setting is mainly for backward compatibility with those versions. Using the server's preferences is usually better because it is more likely that the server is appropriately configured.
ssl_ecdh_curve
(string
)
Specifies the name of the curve to use in ECDH key exchange. It needs to be supported by all clients that connect. It does not need to be the same curve used by the server's Elliptic Curve key. This parameter can only be set in the postgresql.conf
file or on the server command line. The default is prime256v1
.
OpenSSL names for the most common curves are: prime256v1
(NIST P-256), secp384r1
(NIST P-384), secp521r1
(NIST P-521). The full list of available curves can be shown with the command openssl ecparam -list_curves
. Not all of them are usable in TLS though.
ssl_dh_params_file
(string
)
Specifies the name of the file containing Diffie-Hellman parameters used for so-called ephemeral DH family of SSL ciphers. The default is empty, in which case compiled-in default DH parameters used. Using custom DH parameters reduces the exposure if an attacker manages to crack the well-known compiled-in DH parameters. You can create your own DH parameters file with the command openssl dhparam -out dhparams.pem 2048
.
This parameter can only be set in the postgresql.conf
file or on the server command line.
ssl_passphrase_command
(string
)
Sets an external command to be invoked when a passphrase for decrypting an SSL file such as a private key needs to be obtained. By default, this parameter is empty, which means the built-in prompting mechanism is used.
The command must print the passphrase to the standard output and exit with code 0. In the parameter value, %p
is replaced by a prompt string. (Write %%
for a literal %
.) Note that the prompt string will probably contain whitespace, so be sure to quote adequately. A single newline is stripped from the end of the output if present.
The command does not actually have to prompt the user for a passphrase. It can read it from a file, obtain it from a keychain facility, or similar. It is up to the user to make sure the chosen mechanism is adequately secure.
This parameter can only be set in the postgresql.conf
file or on the server command line
ssl_passphrase_command_supports_reload
(boolean
)
This parameter determines whether the passphrase command set by ssl_passphrase_command
will also be called during a configuration reload if a key file needs a passphrase. If this parameter is false (the default), then ssl_passphrase_command
will be ignored during a reload and the SSL configuration will not be reloaded if a passphrase is needed. That setting is appropriate for a command that requires a TTY for prompting, which might not be available when the server is running. Setting this parameter to true might be appropriate if the passphrase is obtained from a file, for example.
This parameter can only be set in the postgresql.conf
file or on the server command line.
deadlock_timeout
(integer
)這是查看是否存在交易鎖定鎖死情況之前,所等待的時間量(以毫秒為單位)。檢查鎖死是相對昂貴的,所以伺服器在每次等待鎖定時都不會執行這個動作。我們樂觀地認為鎖死在產品應用程式中並不常見,所以在檢查鎖死之前等待鎖定一段時間。增加此值可減少無謂的鎖死檢查所浪費的時間,但會減慢真正鎖死錯誤的回報速度。預設值是 1 秒,這可能是您實際需要的最小值。 在負載很重的伺服器上,您可能需要提升一些。理想情況下,此設定應該超過您典型的交易時間,以便提高在伺服器決定檢查鎖死之前鎖定就被解除的可能性。只有超級使用者可以變更此設定。
當設定 log_lock_waits 時,此參數還會確定在發出有關鎖定等待的日誌消息之前需要等待的時間長度。如果您試圖查看鎖定延遲,則可能需要設定比正常情況更短的 deadlock_timeout。
max_locks_per_transaction
(integer
)共享鎖定資料表追踪 max_locks_per_transaction *(max_connections + max_prepared_transactions)個物件(例如資料表)上的交易鎖定;因此,在任何時候都可以鎖定許多不同的物件。 此參數控制為每個交易事務分配的平均對象鎖數量; 只要所有交易的鎖定符合鎖定資料表,個別交易就可以鎖定更多的對象。 這不是可以鎖定的資料列數;該值是無限的。預設值 64 在歷史上證明是足夠的,但如果在單個交易事務中有許多不同資料表的查詢,則可能需要提高此值。例如有很多子資料表的父資料表的查詢。此參數只能在伺服器啟動時設定。
運行備用伺服器時,必須將此參數設定為與主服務器上相同或更高的值。 否則,查詢將不被允許在備用伺服器中。
max_pred_locks_per_transaction
(integer
)共享的 predicate lock 資料表追踪 max_pred_locks_per_transaction *(max_connections + max_prepared_transactions)個物件(例如資料表)上的交易鎖定;因此,在任何時候不會有比這個數字更多的物件被鎖定。此參數控制為每個交易事務分配的平均物件鎖定的數量;只要所有交易的鎖定符合鎖定資料表,個別交易就可以鎖定更多的物件。不是可以鎖定的資料列數;該值是無限的。預設值 64 通常在測試中足夠了,但如果您的用戶端在單個可序列化交易事務中觸及許多不同的資料表,您可能需要提高此值。此參數只能在伺服器啟動時設定。
max_pred_locks_per_relation
(integer
)這可以控制在鎖定被提升為鎖定整個關連之前,單個關連的多少個 page 或 tuple 可以被 predicate-lock。大於或等於零的值表示絕對限制,而負值表示 max_pred_locks_per_transaction 除以此設定的絕對值。預設值是 -2,它保留了先前版本 PostgreSQL 的行為。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
max_pred_locks_per_page
(integer
)這可以控制在將鎖定升級為覆蓋整個 page 之前,單個 page 上有多少資料列可以 predicate-locked。 預設值是 2。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。\
19.13.1. Previous PostgreSQL Versions
19.13.2. Platform and Client Compatibility
array_nulls
(
boolean
)
This controls whether the array input parser recognizes unquotedNULL
as specifying a null array element. By default, this ison
, allowing array values containing null values to be entered. However,PostgreSQLversions before 8.2 did not support null values in arrays, and therefore would treatNULL
as specifying a normal array element with the string value“NULL”. For backward compatibility with applications that require the old behavior, this variable can be turnedoff
.
Note that it is possible to create array values containing null values even when this variable isoff
.
backslash_quote
(
enum
)
This controls whether a quote mark can be represented by\'
in a string literal. The preferred, SQL-standard way to represent a quote mark is by doubling it (''
) butPostgreSQLhas historically also accepted\'
. However, use of\'
creates security risks because in some client character set encodings, there are multibyte characters in which the last byte is numerically equivalent to ASCII\
. If client-side code does escaping incorrectly then a SQL-injection attack is possible. This risk can be prevented by making the server reject queries in which a quote mark appears to be escaped by a backslash. The allowed values ofbackslash_quote
areon
(allow\'
always),off
(reject always), andsafe_encoding
(allow only if client encoding does not allow ASCII\
within a multibyte character).safe_encoding
is the default setting.
Note that in a standard-conforming string literal,\
just means\
anyway. This parameter only affects the handling of non-standard-conforming literals, including escape string syntax (E'...'
).
default_with_oids
(
boolean
)
This controls whetherCREATE TABLE
andCREATE TABLE AS
include an OID column in newly-created tables, if neitherWITH OIDS
norWITHOUT OIDS
is specified. It also determines whether OIDs will be included in tables created bySELECT INTO
. The parameter isoff
by default; inPostgreSQL8.0 and earlier, it wason
by default.
The use of OIDs in user tables is considered deprecated, so most installations should leave this variable disabled. Applications that require OIDs for a particular table should specifyWITH OIDS
when creating the table. This variable can be enabled for compatibility with old applications that do not follow this behavior.
escape_string_warning
(
boolean
)
When on, a warning is issued if a backslash (\
) appears in an ordinary string literal ('...'
syntax) andstandard_conforming_strings
is off. The default ison
.
Applications that wish to use backslash as escape should be modified to use escape string syntax (E'...'
), because the default behavior of ordinary strings is now to treat backslash as an ordinary character, per SQL standard. This variable can be enabled to help locate code that needs to be changed.
lo_compat_privileges
(
boolean
)
InPostgreSQLreleases prior to 9.0, large objects did not have access privileges and were, therefore, always readable and writable by all users. Setting this variable toon
disables the new privilege checks, for compatibility with prior releases. The default isoff
. Only superusers can change this setting.
Setting this variable does not disable all security checks related to large objects — only those for which the default behavior has changed inPostgreSQL9.0. For example,lo_import()
andlo_export()
need superuser privileges regardless of this setting.
operator_precedence_warning
(
boolean
)
When on, the parser will emit a warning for any construct that might have changed meanings sincePostgreSQL9.4 as a result of changes in operator precedence. This is useful for auditing applications to see if precedence changes have broken anything; but it is not meant to be kept turned on in production, since it will warn about some perfectly valid, standard-compliant SQL code. The default isoff
.
SeeSection 4.1.6for more information.
quote_all_identifiers
(
boolean
)
When the database generates SQL, force all identifiers to be quoted, even if they are not (currently) keywords. This will affect the output ofEXPLAIN
as well as the results of functions likepg_get_viewdef
. See also the--quote-all-identifiers
option ofpg_dumpandpg_dumpall.
standard_conforming_strings
(
boolean
)
This controls whether ordinary string literals ('...'
) treat backslashes literally, as specified in the SQL standard. Beginning inPostgreSQL9.1, the default ison
(prior releases defaulted tooff
). Applications can check this parameter to determine how string literals will be processed. The presence of this parameter can also be taken as an indication that the escape string syntax (E'...'
) is supported. Escape string syntax (Section 4.1.2.2) should be used if an application desires backslashes to be treated as escape characters.
synchronize_seqscans
(
boolean
)
This allows sequential scans of large tables to synchronize with each other, so that concurrent scans read the same block at about the same time and hence share the I/O workload. When this is enabled, a scan might start in the middle of the table and then“wrap around”the end to cover all rows, so as to synchronize with the activity of scans already in progress. This can result in unpredictable changes in the row ordering returned by queries that have noORDER BY
clause. Setting this parameter tooff
ensures the pre-8.3 behavior in which a sequential scan always starts from the beginning of the table. The default ison
.
transform_null_equals
(
boolean
)
When on, expressions of the formexpr
= NULL(orNULL =expr
) are treated asexpr
_IS NULL, that is, they return true ifexpr
evaluates to the null value, and false otherwise. The correct SQL-spec-compliant behavior ofexpr
_= NULLis to always return null (unknown). Therefore this parameter defaults tooff
.
However, filtered forms inMicrosoft Accessgenerate queries that appear to useexpr
= NULLto test for null values, so if you use that interface to access the database you might want to turn this option on. Since expressions of the formexpr
= NULLalways return the null value (using the SQL standard interpretation), they are not very useful and do not appear often in normal applications so this option does little harm in practice. But new users are frequently confused about the semantics of expressions involving null values, so this option is off by default.
Note that this option only affects the exact form= NULL
, not other comparison operators or other expressions that are computationally equivalent to some expression involving the equals operator (such asIN
). Thus, this option is not a general fix for bad programming.
Refer toSection 9.2for related information.
search_path
(string
)這個參數表示,當一個物件(資料表、資料型別、函數等)以未指定 schema 的簡單名稱引用時,其搜尋的路徑順序。當不同 schema 中有相同名稱的物件時,將採用搜尋路徑中第一個找到的物件。不在搜尋路徑中的任何 schema 中物件,就只能透過使用限定名稱來指定其 schema 來引用。
search_path 的內容必須是逗號分隔的 schema 名稱列表。任何非現有 schema 的名稱,或是使用者不具有 USAGE 權限的 schema,都將被忽略。
如果其中一個項目是特殊名稱 $user,則會使用 SESSION_USER 回傳的名稱作為 schema 名稱,確認該 schema 存在且使用者具有 USAGE 權限。 (如果沒有權限,$user 將被忽略。)
系統目錄 pg_catalog 一定會被搜尋,無論是否列在搜尋路徑中。如果列在搜尋路徑中了,那麼它將按照指定的順序被搜尋。 如果 pg_catalog 不在搜尋路徑中,那麼它將會優先被搜尋。
同樣地,目前連線的臨時資料表的schema,pg_temp_nnn,如果它存在的話,就一定會被搜尋。它可以透過使用別名 pg_temp 明確列在搜尋路徑中。如果沒有在搜尋路徑中列出的話,則優先搜尋(在 pg_catalog 之前)。但是,臨時 schema 只是搜索關連(資料表、view,序列等)和資料型別名稱。不會搜尋函數或運算子名稱。
建立物件時沒有指定特定的 schema,那麼它們將被放置在 search_path 中的第一個有效 schema 中。如果搜尋路徑為空,則會產生錯誤。
這個參數的預設值是 “$user”,public。此設定用來支援共享資料庫,沒有使用者具有私有 schema、所有共享使用 public、私人自有 schema ,以及以上情境的組合。其他的需求也可以透過更改預設的搜索路徑設置來達到,無論是全域或自有搜尋路徑。
搜尋路徑的目前內容可以使用 SQL 函數 current_schemas 來檢查(詳見 9.25 節)。這與檢查 search_path 的內容並不完全相同,因為 current_schemas 表示 search_path 中出現的項目是如何解析的。
有關 schema 處理的更多訊息,請參見第 5.9 節。
row_security
(boolean
)此參數控制在資料列安全原則檢查時是否進行錯誤中斷。設定為 on 時,安全原則以正常方式運作。當設定為 off 時,除非查詢失敗,否則會至少符合一個原則。 預設值為 on。變更為 off 時,將會限制資料列的可視性,而可能造成不正確的結果;例如,pg_dump 就會變更其預設值。此參數對於可以繞過每個安全原則的角色,也就是對具有 BYPASSRLS 屬性的超級使用者和角色都不會產生影響。
有關於資料列安全原則的更多訊息,請參閱 CREATE POLICY。
default_tablespace
(string
)此參數指的是在 CREATE 指令未明確指定資料表空間(tablespace)時用於建立的資料庫物件(資料表和索引)的預設資料表空間。
該值可以是資料表空間的名稱,也可以是使用空字串表示為目前資料庫的預設資料表空間。如果該值與不符合任何現有的資料表空間名稱時,PostgreSQL 將自動使用目前資料庫的預設資料表空間。如果指定了非預設的資料表空間,則使用者必須具有 CREATE 權限,否則建立的操作將會失敗。
這個參數不用於臨時資料表;對於臨時資料表來說,會參考 temp_tablespaces 參數。
建立資料庫時也不會使用這個參數。預設情況下,新的資料庫將複製的樣板資料庫,並繼承其資料表空間的設定。
有關於資料表空間的更多資訊,請參閱第 23.6 節。
default_toast_compression
(enum
)This variable sets the default TOAST compression method for values of compressible columns. (This can be overridden for individual columns by setting the COMPRESSION
column option in CREATE TABLE
or ALTER TABLE
.) The supported compression methods are pglz
and (if PostgreSQL was compiled with --with-lz4
) lz4
. The default is pglz
.
temp_tablespaces
(string
)此參數指定在 CREATE 指令未指定資料表空間時創立臨時物件(臨時資料表和臨時資料表的索引)的資料表空間。用於排序大量資料集的臨時檔案也在這些資料表空間中創立。
該內容是資料表空間名稱的列表。當列表中有多個名稱時,PostgreSQL 在每次建立臨時物件時都會隨機選擇一個列表成員;除非是在一個交易中,連續建立的臨時物件將會被放置在列表的後續資料表空間中。 如果列表的元素是空字串,PostgreSQL 將自動使用目前資料庫的預設資料表空間。
設定 temp_tablespaces 時,指定一個不存在的資料表空間會造成錯誤,因為指定一個使用者沒有 CREATE 權限的資料表空間。但是,使用先前設定的內容時,不存在的資料表空間將被忽略,使用者缺少 CREATE 權限的資料表空間也將被忽略。特別是,在使用 postgresql.conf 中設定的內容時,此規則適用。
預設值是一個空字串,這將會使用目前資料庫的預設資料空間中建立所有臨時物件。
另請參閱本頁的 default_tablespace。
check_function_bodies
(boolean
)這個參數通常是啓用(on)的。如果把它關閉(off)的話,將在 CREATE FUNCTION 時關閉函數內容檢驗的措施。停用檢驗可避免檢驗過程的副作用,避免由於物件引用等問題所導致的誤報。例如以其他使用者載入函數之前,將此參數設置為 off;pg_dump 將會自動執行此操作。
default_transaction_isolation
(enum
)每組 SQL 交易查詢都有一個隔離的等級,可以是「read uncommitted」、「read committed」、「repeatable read」或「serializable」。此參數控制每個新的交易產生時的預設隔離等級。預設是「read committed」。
請參閱第 13 章和 SET TRANSACTION 以取得更多訊息。
default_transaction_read_only
(boolean
)一個唯讀的 SQL 交易不能更新非臨時的資料表。此參數控制每個新的交易的預設為唯讀狀態。預設是關閉(off)的(可讀/可寫)。
請參閱 SET TRANSACTION 以取得更多訊息。
default_transaction_deferrable
(boolean
)以 serializable 的隔離等級執行時,可延遲的唯讀 SQL 交易可能會被延遲,稍後才允許繼續。但是,一旦開始執行,就不會產生確保可序列化所需的任何成本;所以序列化代碼將不會因為同步更新而強制中止,使得這個選項適合用於長時間運行的唯讀交易。
此參數控制每個新交易查詢的預設可延期狀態。它目前對讀寫交易或者低於 serializable 隔離等級的操作沒有影響。預設是關閉(off)的。
請參閱 SET TRANSACTION 以取得更多訊息。
session_replication_role
(enum
)控制目前連線與複寫相關觸發器與規則。設定此參數需要超級使用者權限,會導致放棄任何先前快取的查詢計劃。可能的值是 origin(預設)、replica 和 local。 有關更多訊息,請參閱 ALTER TABLE。
statement_timeout
(integer
)任何指令執行超過指定的時間時,就會中止其執行。時間單位為 millisecond(毫秒)。以伺服器接受到的時間起算。 如果 log_min_error_statement 設定為 ERROR 或更低的等級時,則超時的查詢語句將被記錄下來。設定值為零(預設值),將其關閉功能。
不建議在 postgresql.conf 中設定 statement_timeout,因為它會影響所有的連線。
lock_timeout
(integer
)當你企圖鎖定資料表、索引、資料列或其他資料庫物件上時,任何等待超過指定的毫秒數的語句都會被強制中止。時間限制會分別適用於每次鎖定取得的嘗試。此限制適用於明確的鎖定請求(例如 LOCK TABLE 或 SELECT FOR UPDATE without NOWAIT)以及隱含的鎖定請求。如果將 log_min_error_statement 設定為 ERROR 或更低的等級時,則會記錄超時的語查詢句。設定值為零(預設值),將其關閉功能。
與 statement_timeout 不同,這個超時設定只會在等待鎖定的時候有作用。請注意,如果 statement_timeout 不為零,則將 lock_timeout 設定為相同或更大的值是毫無意義的,因為查詢語句超時總是會首先觸發。
不建議在 postgresql.conf 中設定 lock_timeout,因為這會影響所有的連線。
idle_in_transaction_session_timeout
(integer
)如果空閒時間超過指定的持續時間時(以毫秒為單位)未完成的交易將會被終止。這會釋放該連線所持有的任何鎖定,並使連線可以重新使用;也只有 tuple 才能看到這個交易被清除。有關這方面的更多細節,請參閱第 25.1 節。
預設值 0 表停用此功能。
idle_session_timeout
(integer
)終止任何已閒置(也就是等待用戶端查詢中)但不在交易事務中且超過指定時間的連線。 如果此值未指定單位,則以毫秒為單位。0 值(預設值)為停用此功能。
Unlike the case with an open transaction, an idle session without a transaction imposes no large costs on the server, so there is less need to enable this timeout than idle_in_transaction_session_timeout
.
Be wary of enforcing this timeout on connections made through connection-pooling software or other middleware, as such a layer may not react well to unexpected connection closure. It may be helpful to enable this timeout only for interactive sessions, perhaps by applying it only to particular users.
vacuum_freeze_table_age
(integer
)如果資料表的 pg_class.relfrozenxid 欄位值已達到此設定的指定時間,VACUUM 將主動執行掃描。主動的掃描不同於一般的 VACUUM,因為它會訪問每個可能包含解開的 XID 或 MXID的頁面,而不僅僅是那些可能包含廢棄 tuple 的頁面。預設是 1.5 億筆交易。 儘管使用者可以設定的範圍為 0 到 20 億,但 VACUUM 將自動地將有效值限制為 autovacuum_freeze_max_age 的 95%,以便在啟動資料表的 anti-wraparound 自動清理之前,定期的手動 VACUUM 有機會運行。欲了解更多訊息,請參閱第 24.1.5 節。
vacuum_freeze_min_age
(integer
)指定 VACUUM 是否決定在掃描資料表時凍結資料列版本的截止期限(交易中)。預設是5000萬交易。 儘管使用者可以設定此值為 0 到 10 億之間的任何值,但 VACUUM 將自動地將有效值限制為 autovacuum_freeze_max_age 值的一半,以便在強制自動清理之間沒有過短的不合理時間間隔。欲了解更多訊息,請參閱第 24.1.5 節。
vacuum_multixact_freeze_table_age
(integer
)如果資料表的 pg_class.relminmxid 欄位值已達到此設定指定的時間,VACUUM 將主動執行掃描。主動的掃描不同於一般的 VACUUM,因為它會訪問每個可能包含解開的 XID 或 MXID 的頁面,而不僅僅是那些可能包含廢棄 tuple 的頁面。預設值是 1.5 億個交易。儘管使用者可以設定的範圍為 0 到 20 億,但 VACUUM 將自動地將有效值限制為 autovacuum_freeze_max_age的 95%,以便在啟動資料表的 anti-wraparound 自動清理之前,定期的手動 VACUUM 有機會運行。欲了解更多訊息,請參閱第 24.1.5 節。
vacuum_multixact_freeze_min_age
(integer
)指定 VACUUM 在掃描資料表時是使用較新的 transaction ID 或是 multixact ID,來替換多個 multixact ID 的截斷年限(以 multixact 表示)。預設是500萬個 multixact。儘管使用者可以設定此值為 0 到 10 億之間的任何值,但 VACUUM 將自動地將有效值限制為 autovacuum_freeze_max_age 值的一半,以便在強制自動清理之間沒有過短的不合理時間間隔。欲了解更多訊息,請參閱 第 24.1.5.1 節。
vacuum_cleanup_index_scale_factor
(floating point
)Specifies the fraction of the total number of heap tuples counted in the previous statistics collection that can be inserted without incurring an index scan at the VACUUM
cleanup stage. This setting currently applies to B-tree indexes only.
If no tuples were deleted from the heap, B-tree indexes are still scanned at the VACUUM
cleanup stage when at least one of the following conditions is met: the index statistics are stale, or the index contains deleted pages that can be recycled during cleanup. Index statistics are considered to be stale if the number of newly inserted tuples exceeds the vacuum_cleanup_index_scale_factor
fraction of the total number of heap tuples detected by the previous statistics collection. The total number of heap tuples is stored in the index meta-page. Note that the meta-page does not include this data until VACUUM
finds no dead tuples, so B-tree index scan at the cleanup stage can only be skipped if the second and subsequent VACUUM
cycles detect no dead tuples.
The value can range from 0
to 10000000000
. When vacuum_cleanup_index_scale_factor
is set to 0
, index scans are never skipped during VACUUM
cleanup. The default value is 0.1
.
bytea_output
(enum
)設定預設的輸出格式型別為bytea
。合法的設定值為 hex(預設)和 escape(傳統的 PostgreSQL 格式)。請參閱第 8.4 節取得更多資訊。無論這個設定如何,bytea 型別在輸入時,兩種格式都能接受。
xmlbinary
(enum
)設定如何在 XML 中編碼二進位數值。例如,當 bytea 值被函數 xmlelement 或 xmlforest 轉換為XML時,就適用這個設定。可以使用的值是 base64 和 hex,都是在 XML Schema 標準中定義的。 預設值是 base64。有關 XML 相關函數的更多訊息,請參閱第 9.14 節。
實際上的選擇主要是習慣問題,僅受限於客戶端應用程式中的可能限制。這兩種方法都支援所有可能的值,儘管 hex 編碼會比 base64 編碼稍大。
xmloption
(enum
)在 XML 和字串之間轉換時,設定是否隱含 DOCUMENT 或 CONTENT。請參閱 8.13 節的描述。有效值是 DOCUMENT 和 CONTENT。預設值是 CONTENT。
根據 SQL 標準,設定此選項的命令是
這個語法在 PostgreSQL 中也是可以使用的。
gin_pending_list_limit
(integer
)設定啟用 fastupdate 時使用的 GIN 排程列表的最大空間。如果列表大於這個最大空間,則透過將其中的項目整批移動到主 GIN 資料結構來清除它。預設值是 4MB。透過更改索引的儲存參數,可以為單個 GIN 索引覆寫此設定。有關更多訊息,請參閱第 64.4.1 節和第 64.5 節。
DateStyle
(string
)設定日期和時間內容的顯示格式,以及解釋模糊日期輸入的規則。由於歷史的因素,此參數包含兩個獨立的參數:輸出格式規範(ISO、Postgres、SQL 或 German)以及年/月/日次序(DMY、MDY 或 YMD)的輸入/輸出規範。它們可以單獨或一起設定。 關鍵字 Euro 和 European 是 DMY 的同義詞;關鍵字 US、NonEuro 和 NonEuropean 是 MDY 的同義詞。有關更多訊息,請參閱第 8.5 節。 內建的預設值是 ISO、MDY,但是 initdb 會以使用所選的 lc_time 語言環境相對應的設定來初始化設定內容。
IntervalStyle
(enum
)設定間隔時間內容的顯示格式。設定為 sql_standard 時,將產生合於 SQL 標準的間隔時間的輸出。當 DateStyle 參數設定為 ISO 時,設定為 postgres(預設值)將會產生與 8.4 之前的 PostgreSQL 版本相容輸出。當 DateStyle 參數設定為 non-ISO 時,設定為 postgres_verbose 將生成與 8.4之前的 PostgreSQL 版本相容輸出。 設定為 iso_8601 時,將產生 ISO 8601 中 4.4.3.2 節裡所定義的時間間隔「格式與標誌符」相容的輸出。
Interval Style 參數也會影響模糊區間輸入的解釋。有關更多訊息,請參閱第 8.5.4 節。
TimeZone
(string
)設定顯示和解釋時間戳記的時區。內建的預設值是 GMT,但通常會在 postgresql.conf 中被覆寫;initdb 將在安裝時取得其系統環境相對應的設定。 有關更多訊息,請參閱第 8.5.3 節。
timezone_abbreviations
(string
)設定日期時間輸入能被伺服器接受的時區縮寫集合。預設是「Default」,這是一個在世界大部分地區都可以使用的集合;還有「Australia」和「India」,並且可以為特定定義安裝其他集合。 更多訊息詳見 B.3 節。
extra_float_digits
(integer
)此參數調整顯示浮點數的位數,包括 float4、float8 和地理資料型別。參數值會被加到標準位數之中(FLT_DIG 或 DBL_DIG)。此值可以設定為 3,以包含部分有效數字;這對於需要精確回存浮點數資料特別有用。或者可以將其設定為負數來減少不需要的數字。請另參閱第 8.1.3 節。
client_encoding
(string
)設定用戶端編碼(字元集)。預設是使用資料庫的編碼方式。在 23.3.1 節描述了 PostgreSQL 資料庫支援的字元集。
lc_messages
(string
)設定訊息顯示的語言。可接受的值取決於系統;關於更多訊息,請參閱第 23.1 節。如果此參數設定為空字串(預設值),則該值將以系統相關的方式從伺服器的執行環境中繼承。
在某些系統上,此語言環境類別並不存在。設定這個參數仍然可以運作,但不會有任何影響。此外,也可能還沒有用於所需語言翻譯的訊息。在這種情況下,你會繼續看到英文訊息。
只有系統管理者可以更改此設定,因為它會影響發送到伺服器日誌以及用戶端的訊息,而不正確的值可能會影響伺服器日誌的可讀性。
lc_monetary
(string
)設定用於格式化貨幣金額的區域配置,例如 to_char 系列函數。可接受的值取決於系統;關於更多訊息,請參閱第 23.1 節。如果此參數設定為空字串(預設值),則該值將以系統相關的方式從伺服器的執行環境中繼承。
lc_numeric
(string
)設定用於格式化數字的區域配置,例如 to_char 系列函數。可接受的值取決於系統;關於更多訊息,請參閱第 23.1 節。如果此參數設定為空字串(預設值),則該值將以系統相關的方式從伺服器的執行環境中繼承。
lc_time
(string
)設定用於格式化時間的區域配置,例如 to_char 系列函數。可接受的值取決於系統;關於更多訊息,請參閱第 23.1 節。如果此參數設定為空字串(預設值),則該值將以系統相關的方式從伺服器的執行環境中繼承。
default_text_search_config
(string
)選擇全文檢索的設定,用於那些無法指定語系的全文檢索函數。 更多說明詳見第12章。內建的預設值為 pg_catalog.simple,但如果可以識別與該語言環境匹配的配置,則 initdb 將使用與所選 lc_ctype 語言環境相對應的設置來初始化配置設定。
有幾個設定可用於將共享函式庫預載到伺服器中,以便載入延伸功能並展現性能優勢。例如,設定 '$libdir / mylib' 能將 mylib.so(在某些平台上是 mylib.sl)從安裝的標準函式庫目錄中預載。這些設定之間的差異主要是控制在何時生效,以及需要哪些權限才能更改它們。
PostgreSQL 的程序語言庫可以用這種方式預載,通常語法是 '$libdir/plXXX',其中 XXX 是 pgsql、perl、tcl 或 python。
只有專門用於 PostgreSQL 的共享函式庫才能以這種方式載入。每個支援 PostgreSQL 的函式庫都有一個「magic block」,它會被檢查以確保相容性。由於這個原因的關係,非 PostgreSQL 函式庫不能以這種方式載入。你可能可以使用作業系統的功能,例如 LD_PRELOAD。
一般來說,都需要詳閱該函式庫的文件,以獲得載入該函式庫推薦的方法.
local_preload_libraries
(string
)此參數指定一個或多個要在連線啟動時預載的共享函式庫。它是逗號分隔的函式庫名稱列表,其中每個名稱都被以 LOAD 命令處理。 項目之間的空白都會被忽略;如果需要在名稱中包含空格或逗號,請用雙引號括住函式庫名稱。參數值僅在連線開始時生效。 後續更改都不起作用。如果未找到指定的函式庫,則連線嘗試將會失敗。
這個選項可以由任何使用者設定。因此,可以載入的函式庫僅限於出現在標準函式庫目錄的外掛目錄中的函式庫。 (資料庫管理員有責任確保在那裡只安裝了「安全的」函式庫。)local_preload_libraries 中的項目可以明確指定此目錄,例如 $libdir/plugins/mylib,或者只指定函式庫名稱 mylib 與 $libdir/plugins/mylib 具有相同的效果。
此功能的目的是允許非特權用戶將調教或性能測試函式庫加載到特定的連線中,而不需要明確的 LOAD 命令。為此,通常使用用戶端上的 PGOPTIONS 環境變數或透過使用 ALTER ROLE SET 來設定此參數。
但是,除非一個模組是專門設計用於非超級用戶的方式,否則這通常不適合使用。請參考使用 session_preload_libraries 參數。
session_preload_libraries
(string
)此參數指定一個或多個要在連線啟動時預載的共享函式庫。它是逗號分隔的函式庫名稱列表,其中每個名稱都被以 LOAD 命令處理。. 項目之間的空白都會被忽略;如果需要在名稱中包含空格或逗號,請用雙引號括住函式庫名稱。參數值僅在連線開始時生效。 後續更改都不起作用。如果未找到指定的函式庫,則連線嘗試將會失敗。 只有超級使用者可以調整此參數。
此功能的目的是允許除錯或性能測試的函式庫載入到特定的連線中,而不需要指示明確的 LOAD 指令。例如,透過使用 ALTER ROLE SET 設定此參數,可以為指定用戶的所有連線啟用 auto_explain。此外,可以在不重新啟動服務的情況下更改此參數(但更改僅在啟動新的連線時生效),因此即使應用於所有連線,以這種方式增加新的模組也很容易。
與 shared_preload_libraries 不同,在連線啟動時載入函式庫時並沒有很大的效能優勢,相對於第一次使用時。 但是,使用連接池時會有一些優勢。
shared_preload_libraries
(string
)此參數指定一個或多個要在伺服器啟動時預載的共享函式庫。它是逗號分隔的函式庫名稱列表,其中每個名稱都被以 LOAD 命令處理。. 項目之間的空白都會被忽略;如果需要在名稱中包含空格或逗號,請用雙引號括住函式庫名稱。參數值僅在伺服器啓動時生效。 後續更改都不起作用。如果未找到指定的函式庫,則連線嘗試將會失敗。
有些函式庫需要執行某些只能在 postmaster 啟動時才能執行的操作,例如分配共享記憶體,保留輕量級鎖定或啟動背景執行程序。 這些函式庫必須在伺服器啟動時通過此參數載入。有關詳細信息,請參閱各別函式庫的文件。
其他的函式庫也可以預先載入。通過預先載入共享函式庫,首次使用函式庫時可以減少啟動時間的成本。但是,啟動每個新伺服器服務的時間可能會略有增加,即使該服務從不使用該函式庫。因此,此參數僅適用於大多數連線中將使用的函式庫。另外,更改此參數需要重新啟動伺服器,因此這不適用於短期除錯事務的需求,請改為使用 session_preload_libraries。
注意在Windows主機上,在伺服器啟動時預載函式庫不會減少啟動每個新伺服器服務所需的時間;每個伺服器服務程將重新加載所有預載函式庫。但是,shared_preload_libraries 仍然是有用的,在你的 Windows 主機的 postmaster 啓動時操作所需的函式庫。
dynamic_library_path
(string
)如果需要開啓一個可動態載入的模組,並且在 CREATE FUNCTION 或 LOAD 指令中使用沒有目錄名稱的模組檔案(即該名稱不包含斜線),系統將在此路徑中搜尋所需的檔案。
dynamic_library_path 的內容必須是由冒號(或在 Windows 上是分號)分隔的絕對路徑的列表。如果該列表項目以特殊字符串 $libdir 開頭,那麼編譯後的 PostgreSQL 函式庫目錄會被替換為 $libdir;這是安裝標準 PostgreSQL 發行版所提供的模組的路徑。(可以使用 pg_config --pkglibdir 查詢此目錄的路徑。)例如:
或者,在 Windows 環境中:
此參數的預設值是「$libdir」。如果此值設定為空字串,則將關閉自動路徑搜尋。
超級使用者可以在服務執行時更改此參數,但以這種方式完成的設定只會持續到用戶端連線結束,因此應將此方法保留用於開發階段使用。建議使用此參數的方式是在 postgresql.conf 設定檔中。
gin_fuzzy_search_limit
(integer
)由 GIN 索引掃描回傳集合大小的軟上限。詳情請參閱第 66.5 節。
這些設定控制自動資料清理(autovacuum)功能的行為。有關更多訊息,請參閱第 24.1.6 節。請注意,許多這些設定可以基於每個資料表進行調整;請參閱儲存參數的說明。
autovacuum
(boolean
)
控制伺服器是否應該執行 autovacuum 啟動程序背景程序。這是預設開啟的;但是,track_counts 也必須啟用 autovacuum 工作。此參數只能在 postgresql.conf 檔案或伺服器命令行中設定;但是,可以透過變更資料表儲存參數來禁用單個資料表的自動清除。
請注意,即使禁用此參數,系統也會在必要時啟動自動清理過程以防止交易事務 ID 重覆。有關更多訊息,請參閱第 24.1.5 節。
log_autovacuum_min_duration
(integer
)
如果 autovacuum 執行的每個操作至少運行了指定的毫秒數,則會被記錄下來。 將其設定為零會記錄所有自動清理操作。-1(預設值)禁用記錄自動清理操作。例如,如果將此設定為 250ms,則會記錄所有執行 250ms 或更長時間的自動清理和分析。另外,當此參數設定為除 -1 之外的任何值時,如果由於存在衝突鎖定而導致 autovacuum 操作被跳過,則會記錄一條記錄。啟用此參數可以有助於跟踪自動清理活動。此參數只能在 postgresql.conf 檔案或伺服器命令行中設定;但是可以透過變更資料表的儲存參數來覆寫單個資料表的設定。
autovacuum_max_workers
(integer
)
指定可能在任何時間運行的自動清理程序的最大數目(除了自動清理啟動程序)。預設值是 3。該參數只能在伺服器啟動時設定。
autovacuum_naptime
(integer
)
指定在任何資料庫上執行 autovacuum 之間的最小延遲。 在每一輪背景程序檢查資料庫並根據需要為該資料庫中的資料表發出 VACUUM 和 ANALYZE 命令。延遲以秒為單位進行測量,預設值為 1 分鐘。該參數只能在 postgresql.conf 檔案或伺服器命令行中設定。
autovacuum_vacuum_threshold
(integer
)
指定在任何一個資料表中觸發 VACUUM 所需的更新或刪除 tuple 的最小數目。預設值是 50 個 tuple。此參數只能在 postgresql.conf 檔案或伺服器命令行中設定;但是可以透過變更資料儲存參數來覆寫單個資料表的設定。
autovacuum_vacuum_insert_threshold
(integer
)
指定在任何一張資料表中觸發 VACUUM 所需的 INSERT tuple 數量。預設值為 1000 個 tuple。如果指定 -1,則 VACUUM 將不會基於 INSERT 數量而被觸發。此參數只能在 postgresql.conf 檔案中或在伺服器命令列上設定;但是可以透過修改資料表儲存參數來覆寫某個特定資料表的設定。
autovacuum_analyze_threshold
(integer
)
指定在任何一個資料表中觸發 ANALYZE 所需的插入、更新或刪除的 tuple 的最小數目。預設值是 50 個 tuple。此參數只能在 postgresql.conf 檔案或伺服器命令行中設定;但是可以透過變更資料表儲存參數來覆寫單個資料表的設定。
autovacuum_vacuum_scale_factor
(floating point
)
決定觸發 VACUUM 時,指定要加到 autovacuum_vacuum_threshold 的資料表大小的比例。預設值是0.2(資料表大小的 20%)。此參數只能在 postgresql.conf 檔案或伺服器命令行中設定;但是可以透過變更資料表儲存參數來覆寫單個資料表的設定。
autovacuum_vacuum_insert_scale_factor
(floating point
)
Specifies a fraction of the table size to add to autovacuum_vacuum_insert_threshold
when deciding whether to trigger a VACUUM
. The default is 0.2 (20% of table size). This parameter can only be set in the postgresql.conf
file or on the server command line; but the setting can be overridden for individual tables by changing table storage parameters.
autovacuum_analyze_scale_factor
(floating point
)
指定在決定是否觸發 ANALYZE 時加到 autovacuum_analyze_threshold 的資料表大小的比例。預設值是 0.1(資料表大小的 10%)。此參數只能在 postgresql.conf 檔案或伺服器命令行中設定;但是可以透過變更資料表儲存參數來覆寫單個資料表的設定。
autovacuum_freeze_max_age
(integer
)
指定資料表的 pg_class.relfrozenxid 參數在 VACUUM 操作時被強制阻止資料表中的交易事務 ID 重覆之前可以達到的最大期限(在交易事務中)。請注意,系統將啟動 autovacuum 程序以防止重覆,即使禁用 autovacuum 時也會進行。
Vacuum 還允許從 pg_xact 子目錄中刪除舊檔案,這就是為什麼預設值是相對較低的 2 億次事務。該參數只能在伺服器啟動時設定,但透過變更資料表儲存參數可以減少單個資表的設定。有關更多訊息,請參閱第 24.1.5 節。
autovacuum_multixact_freeze_max_age
(integer
)
指定資料表的 pg_class.relminmxid 參數在 VACUUM 操作以防止資料表中的多個事務ID 重覆之前可以達到的最大時間(以 multixacts 表示)。請注意,系統將啟動 autovacuum 程序以防止重覆,即使禁用 autovacuum 也會進行。
資料庫清理 multixacts 還允許從 pg_multixact/members 和 pg_multixact/offset 子目錄中刪除舊檔案,這就是為什麼預設值是相對較低的 4 億個 multixacts。該參數只能在伺服器啟動時設定,但透過變更資料表儲存參數可以減少單個資料表的設定。有關更多訊息,請參閱第 24.1.5.1 節。
autovacuum_vacuum_cost_delay
(integer
)
指定將在自動 VACUUM 操作中使用的成本延遲值。如果指定了 -1,則將使用標準的 vacuum_cost_delay 值。預設值是 20 毫秒。此參數只能在 postgresql.conf 檔案或伺務器命令行中設定;但是可以透過變更資料表儲存參數來覆寫單個資料表的設定。
autovacuum_vacuum_cost_limit
(integer
)
指定將在自動 VACUUM 操作中使用的成本上限值。如果指定了 -1(這是預設值),則將使用標準的 vacuum_cost_limit 值。請注意,如果有多個工作程序,則在運行的自動清理工作程序之間會按比例分配值,以便每個工作程序的限制總和不超過此參數的值。此參數只能在 postgresql.conf 檔案或伺服器命令行中設定;但也可以透過變更資料表儲存參數來覆寫單個資料表的設定。
版本:11
這些設定控制內建的串流複寫功能行為(請參閱第 26.2.5 節)。伺服器指的是主伺服務器或備用伺服器。主伺服器可以發送資料,而備用伺服器始終是複寫資料的接收者。當使用串聯複寫(請參閱第 26.2.7 節)時,備用伺服器也可以是發送者和接收者。參數主要用於發送和備用伺服器,但某些參數僅在主伺服器上有意義。如果需要,設定是跨群集的,不會産生問題。
可以在將資料複寫發送到一個或多個備用伺服器的任何伺服器上設定這些參數。主伺服器始終是發送伺服器,因此必須在主伺服器上設定這些參數。備用資料庫成為主資料庫後,這些參數的作用也不會改變。
max_wal_senders
(integer
)指定來自備用伺服器或串流複寫備份用戶端的最大同時連線數(即同時運行的 WAL 發送程序的最大數量)。預設值為 10,0 表示停用複寫。WAL 發送方程序也計入連線總數,因此參數不能設定高於 max_connections。突然串流用戶端中斷連線可能會導致遺留連線插槽,直到達到超時。因此此參數應設定為略高於預期用戶端的最大數量,以便中斷連線的用戶端可以立即重新連線。此參數只能在伺服器啟動時設定。wal_level 必須設定為 replica 或更高設定才能允許來自備用伺服器的連線。
max_replication_slots
(integer
)指定伺服器可以支援的最大複寫槽數(請參閱第 26.2.6 節)。預設值為 10。此參數只能在伺服器啟動時設定。必須將 wal_level 設定為 replica 或更高設定才能使用複寫槽。將其設定為低於目前現有複寫插槽數的值將阻止伺服器啟動。
wal_keep_segments
(integer
)指定保留在 pg_wal 目錄中的過時日誌段落檔案的最小數量,以防備用伺服器需要取得它們以進行串流複寫。每個段落段通常為 16 MB。如果連線到發送伺服器的備用伺服器落後於 wal_keep_segments 個段落以上,則發送伺服器可能會刪除備用資料庫仍需要的 WAL 段落,在這種情況下,複寫連線將會終止。因此,下游連線最終也會失敗。(但是,如果正在使用 WAL Archive,則備用伺服器可以透過從 Archive 中取得段落來進行回復。)
這僅設定 pg_wal 中保留的最小段落數量;系統可能需要為 WAL 存檔保留更多段落或從檢查點回復。如果 wal_keep_segments 為零(預設值),則系統不會為備用目的保留任何額外的段落,因此備用伺服器可用的舊 WAL 段落數是上一個檢查點的位置和WAL 歸檔狀態的函數。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
max_slot_wal_keep_size
(integer
)指定在檢查點時間允許複寫槽(replication slots)保留在 pg_wal 目錄中的 WAL 檔案最大大小。如果 max_slot_wal_keep_size 為 -1(預設值),則複寫槽可能會保留無限數量的 WAL 檔案。否則,如果複寫槽的 restart_lsn 落後於目前 LSN 超過設定大小,就會刪除所需的 WAL 檔案,使用該複寫槽的備用資料庫可能就不再能夠繼續複寫。您可以在 pg_replication_slots 中看到複寫槽的 WAL 可用性。
wal_sender_timeout
(integer
)終止靜止狀態超過指定毫秒數的複寫連線。這對於發送伺服器檢測備用伺服器當機或網路斷線很有用。值為零會停用超時機制。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值為 60 秒。
track_commit_timestamp
(boolean
)記錄事務的提交時間。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。預設值為 off。
可以將要複寫資料發送到一個或多個備用伺服器,在主要伺服器上設定這些參數。請注意,除了這些參數之外,還必須在主要伺服器上正確設定 wal_level,可以選擇啟用 WAL 歸檔(參閱第 19.5.3 節)。備用伺服器上這些參數的值是無意義的,儘管您可能希望將它們設定在那裡以預備備用資料庫成為主要伺服器的可能性。
synchronous_standby_names
(string
)指定可支援同步複寫的備用伺服器列表,如第 26.2.8 節中所述。 將有一個或多個線上同步的備用資料庫;在這些備用伺服器確認收到其資料後,將允許等待提交的事務繼續進行。同步備用資料庫將是其名稱出現在此列表中的那些,並且即時以串流傳輸資料(如 pg_stat_replication 檢視表中的串流傳輸狀態所示)。指定多個同步備用資料庫可以達到非常高的可用性並防止資料遺失。
用於此目的的備用伺服器的名稱是以備用資料庫的 application_name 設定,在備用資料庫的連線資訊中設定。如果是物理性複寫的備用,則應在 recovery.conf 中的 primary_conninfo 設定中進行設定;預設的是 cluster_name 的內容,不然就會是 walreceiver。對於邏輯性複寫,可以在訂閱的連線訊息中設定,並且預設為訂閱名稱。對於其他複寫的串流使用者,請查閱其文件。
此參數使用以下任一語法指定備用伺服器列表:
其中 num_sync 是交易事務需要等待回覆的同步備用數量,而 standby_name 是備用伺服器的名稱。FIRST 和 ANY 指定從列出的伺服器中選擇同步備用資料庫的方法。
關鍵字 FIRST 與 num_sync 合併使用,指定基於優先的同步複寫,讓事務提交等待,直到將其 WAL 記錄複寫到優先選擇的 num_sync 同步備用資料庫。例如,FIRST 3(s1,s2,s3,s4)的設定將使得每個提交等待從備用伺服器 s1,s2,s3 和 s4 中選擇的三個較優先的備用資料庫回覆。名稱在列表中較早出現的備用資料庫具有較高的優先等級,並被視為是同步的。此列表中稍後出現的其他備用伺服器代表潛在的同步備用資料庫。如果任何當下的同步備用資料庫因任何原因斷開連線,它將立即被替換為次高優先等級的備用資料庫。關鍵字 FIRST 是選用的。
關鍵字 ANY 與 num_sync 一起使用,指定需要仲裁的同步複寫,使事務提交等待,直到將其 WAL 記錄複寫到至少 num_sync 列出的備用資料庫。例如,ANY 3(s1,s2,s3,s4)的設定將使得每個提交在 s1,s2,s3 和 s4 的至少任何三個備用資料回覆時繼續進行。
FIRST 和 ANY 都不區分大小寫。 如果將這些關鍵字用作備用伺服器的名稱,則其 standby_name 必須使用雙引號。
第三種語法在 PostgreSQL 版本 9.6 之前使用,仍然受支援。它與 FIRST 和 num_sync 等於 1 的第一個語法相同。例如,FIRST 1(s1,s2)和 s1,s2 具有相同的含義:s1 或 s2 被選為同步的備用伺服器。
特殊符號 * 表示匹配任何備用名稱。
沒有其他機制來強制備用名稱的唯一性。如果重複的話,其中一個備用資料庫將被視為更優先的,但無法確切說是哪一個。
注意 每個 standby_name 都應具有有效 SQL 識別字的形式,除非是 *。如有必要,您可以使用雙引號。但請注意,standby_names 與備用 application name 都不區分大小寫,無論是否為雙引號。
如果此處未指定同步的備用伺服器名稱,則不啟用同步複寫,事務提交就不會等待複寫。這是預設配置。即使啟用了同步複寫,也可以將單個事務設定為不等待複寫,方法是將 synchronous_commit 參數設定為 local 或 off。
此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
vacuum_defer_cleanup_age
(integer
)指定 VACUUM 和 HOT 更新將延遲清除過期資料列版本的事務數。預設值為 0 事務,這意味著可以盡快刪除過期資料列的版本。也就是說,只要它們不再對任何開放的事務是可見的。您可能希望在支持熱備用伺服器的主要服務器上將其設定為非零值,如第 26.5 節中所述。這樣可以讓備用資料庫上的查詢有更多時間完成,而不會因過早清理資料列而導致衝突。但是,由於該值是根據主要服務器上所發生的寫入事務的數量來衡量的,因此很難預測備用查詢可用多少額外的寬限時間。 此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
您還應該考慮在備用伺服器上設定 hot_standby_feedback 作為使用此參數的替代方法。
這不會阻止已達到 old_snapshot_threshold 指定期間的過時資料列清除。
這些設定控制要接收複寫資料的備用伺服器行為,與主伺服器上的設定是無關的。
primary_conninfo
(string
)Specifies a connection string to be used for the standby server to connect with a sending server. This string is in the format described in Section 33.1.1. If any option is unspecified in this string, then the corresponding environment variable (see Section 33.14) is checked. If the environment variable is not set either, then defaults are used.
The connection string should specify the host name (or address) of the sending server, as well as the port number if it is not the same as the standby server's default. Also specify a user name corresponding to a suitably-privileged role on the sending server (see Section 26.2.5.1). A password needs to be provided too, if the sender demands password authentication. It can be provided in the primary_conninfo
string, or in a separate ~/.pgpass
file on the standby server (use replication
as the database name). Do not specify a database name in the primary_conninfo
string.
This parameter can only be set in the postgresql.conf
file or on the server command line. If this parameter is changed while the WAL receiver process is running, that process is signaled to shut down and expected to restart with the new setting (except if primary_conninfo
is an empty string). This setting has no effect if the server is not in standby mode.
primary_slot_name
(string
)Optionally specifies an existing replication slot to be used when connecting to the sending server via streaming replication to control resource removal on the upstream node (see Section 26.2.6). This parameter can only be set in the postgresql.conf
file or on the server command line. If this parameter is changed while the WAL receiver process is running, that process is signaled to shut down and expected to restart with the new setting. This setting has no effect if primary_conninfo
is not set or the server is not in standby mode.
promote_trigger_file
(string
)
Specifies a trigger file whose presence ends recovery in the standby. Even if this value is not set, you can still promote the standby using pg_ctl promote
or calling pg_promote()
. This parameter can only be set in the postgresql.conf
file or on the server command line.
hot_standby
(boolean
)指定是否可以在回復期間連線和執行查詢,如第 26.5 節中所述。預設值為 on。 此參數只能在伺服器啟動時設定。它僅在歸檔回復或備機模式下有效。
max_standby_archive_delay
(integer
)當 Hot Standby 處於啟用狀態時,此參數確定備用伺服器在取消與即將套用的 WAL 項目衝突的備用查詢之前應等待的時間,如第 26.5.2 節中所述。當從 WAL 歸檔中讀取 WAL 資料時,max_standby_archive_delay 適用(因此不是當下的)。預設值為 30 秒。如果未指定,則單位為毫秒。值 -1 時允許備用資料庫永遠等待衝突查詢完成。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
請注意,max_standby_archive_delay 與取消前查詢可以執行的最長時間不同;相反地,它是允許套用任何一個 WAL 資料段的最大總時間。因此,如果一個查詢在 WAL 資料段中導致顯著延遲,則後續衝突查詢將具有更少的寬限時間。
max_standby_streaming_delay
(integer
)當 Hot Standby 處於啓用狀態時,此參數決定備用伺服器在取消與即將套用的 WAL 項目衝突的備用查詢之前應等待的時間,如第 26.5.2 節中所述。當透過串流複寫接收 WAL 資料時,套用max_standby_streaming_delay。預設值為 30 秒。如果未指定,則單位為毫秒。值 -1 時允許備用資料庫永遠等待衝突查詢完成。此參數只能在 postgresql.conf 檔案或伺服器命令列中設定。
請注意,max_standby_streaming_delay 與取消前查詢可以執行的最長時間不同;相反地,它是從主伺服器收到 WAL 資料後允許套用的最大總時間。因此,如果一個查詢導致顯著延遲,則後續衝突查詢將具有更少的寬限時間,直到備用伺服器再次趕上。
wal_receiver_create_temp_slot
(boolean
)Specifies whether the WAL receiver process should create a temporary replication slot on the remote instance when no permanent replication slot to use has been configured (using primary_slot_name). The default is off. This parameter can only be set in the postgresql.conf
file or on the server command line. If this parameter is changed while the WAL receiver process is running, that process is signaled to shut down and expected to restart with the new setting.
wal_receiver_status_interval
(integer
)Specifies the minimum frequency for the WAL receiver process on the standby to send information about replication progress to the primary or upstream standby, where it can be seen using the pg_stat_replication
view. The standby will report the last write-ahead log location it has written, the last position it has flushed to disk, and the last position it has applied. This parameter's value is the maximum interval, in seconds, between reports. Updates are sent each time the write or flush positions change, or at least as often as specified by this parameter. Thus, the apply position may lag slightly behind the true position. Setting this parameter to zero disables status updates completely. This parameter can only be set in the postgresql.conf
file or on the server command line. The default value is 10 seconds.
hot_standby_feedback
(boolean
)Specifies whether or not a hot standby will send feedback to the primary or upstream standby about queries currently executing on the standby. This parameter can be used to eliminate query cancels caused by cleanup records, but can cause database bloat on the primary for some workloads. Feedback messages will not be sent more frequently than once per wal_receiver_status_interval
. The default value is off
. This parameter can only be set in the postgresql.conf
file or on the server command line.
If cascaded replication is in use the feedback is passed upstream until it eventually reaches the primary. Standbys make no other use of feedback they receive other than to pass upstream.
This setting does not override the behavior of old_snapshot_threshold
on the primary; a snapshot on the standby which exceeds the primary's age threshold can become invalid, resulting in cancellation of transactions on the standby. This is because old_snapshot_threshold
is intended to provide an absolute limit on the time which dead rows can contribute to bloat, which would otherwise be violated because of the configuration of a standby.
wal_receiver_timeout
(integer
)Terminate replication connections that are inactive longer than the specified number of milliseconds. This is useful for the receiving standby server to detect a primary node crash or network outage. A value of zero disables the timeout mechanism. This parameter can only be set in the postgresql.conf
file or on the server command line. The default value is 60 seconds.
wal_retrieve_retry_interval
(integer
)Specify how long the standby server should wait when WAL data is not available from any sources (streaming replication, local pg_wal
or WAL archive) before retrying to retrieve WAL data. This parameter can only be set in the postgresql.conf
file or on the server command line. The default value is 5 seconds. Units are milliseconds if not specified.
This parameter is useful in configurations where a node in recovery needs to control the amount of time to wait for new WAL data to be available. For example, in archive recovery, it is possible to make the recovery more responsive in the detection of a new WAL log file by reducing the value of this parameter. On a system with low WAL activity, increasing it reduces the amount of requests necessary to access WAL archives, something useful for example in cloud environments where the amount of times an infrastructure is accessed is taken into account.
recovery_min_apply_delay
(integer
)By default, a standby server restores WAL records from the sending server as soon as possible. It may be useful to have a time-delayed copy of the data, offering opportunities to correct data loss errors. This parameter allows you to delay recovery by a specified amount of time. For example, if you set this parameter to 5min
, the standby will replay each transaction commit only when the system time on the standby is at least five minutes past the commit time reported by the master. If this value is specified without units, it is taken as milliseconds. The default is zero, adding no delay.
It is possible that the replication delay between servers exceeds the value of this parameter, in which case no delay is added. Note that the delay is calculated between the WAL time stamp as written on master and the current time on the standby. Delays in transfer because of network lag or cascading replication configurations may reduce the actual wait time significantly. If the system clocks on master and standby are not synchronized, this may lead to recovery applying records earlier than expected; but that is not a major issue because useful settings of this parameter are much larger than typical time deviations between servers.
The delay occurs only on WAL records for transaction commits. Other records are replayed as quickly as possible, which is not a problem because MVCC visibility rules ensure their effects are not visible until the corresponding commit record is applied.
The delay occurs once the database in recovery has reached a consistent state, until the standby is promoted or triggered. After that the standby will end recovery without further waiting.
This parameter is intended for use with streaming replication deployments; however, if the parameter is specified it will be honored in all cases except crash recovery. hot_standby_feedback
will be delayed by use of this feature which could lead to bloat on the master; use both together with care.
Synchronous replication is affected by this setting when synchronous_commit
is set to remote_apply
; every COMMIT
will need to wait to be applied.
This parameter can only be set in the postgresql.conf
file or on the server command line.
這些設定控制著邏輯複寫訂閱伺服器的行為。它們與發佈者的設定無關。
請注意,wal_receiver_timeout,wal_receiver_status_interval 和 wal_retrieve_retry_interval 組態參數也會影響邏輯複寫的工作程序。
max_logical_replication_workers
(int
)指定邏輯複寫工作程序的最大數量。這包括應用工作程序和資料表同步的工作程序。
邏輯複寫工作程序來自 max_worker_processes 定義的資源池。
預設值為 4。
max_sync_workers_per_subscription
(integer
)每個訂閱的最大同步工作程序數目。此參數控制訂閱初始化期間或增加新資料表時初始資料副本的平行處理數量。
目前,每個資料表只會有一個同步工作程序。
同步工作程序來自 max_logical_replication_workers 定義的資源池。
預設值為 2。
This feature was designed to allow parameters not normally known to PostgreSQL to be added by add-on modules (such as procedural languages). This allows extension modules to be configured in the standard ways.
Custom options have two-part names: an extension name, then a dot, then the parameter name proper, much like qualified names in SQL. An example is plpgsql.variable_conflict
.
Because custom options may need to be set in processes that have not loaded the relevant extension module, PostgreSQL will accept a setting for any two-part parameter name. Such variables are treated as placeholders and have no function until the module that defines them is loaded. When an extension module is loaded, it will add its variable definitions, convert any placeholder values according to those definitions, and issue warnings for any unrecognized placeholders that begin with its extension name.\
The following parameters are intended for work on the PostgreSQL source code, and in some cases to assist with recovery of severely damaged databases. There should be no reason to use them on a production database. As such, they have been excluded from the sample postgresql.conf
file. Note that many of these parameters require special source compilation flags to work at all.
allow_system_table_mods
(boolean
)
Allows modification of the structure of system tables. This is used by initdb
. This parameter can only be set at server start.
ignore_system_indexes
(boolean
)
Ignore system indexes when reading system tables (but still update the indexes when modifying the tables). This is useful when recovering from damaged system indexes. This parameter cannot be changed after session start.
post_auth_delay
(integer
)
The amount of time to delay when a new server process is started, after it conducts the authentication procedure. This is intended to give developers an opportunity to attach to the server process with a debugger. If this value is specified without units, it is taken as seconds. A value of zero (the default) disables the delay. This parameter cannot be changed after session start.
pre_auth_delay
(integer
)
The amount of time to delay just after a new server process is forked, before it conducts the authentication procedure. This is intended to give developers an opportunity to attach to the server process with a debugger to trace down misbehavior in authentication. If this value is specified without units, it is taken as seconds. A value of zero (the default) disables the delay. This parameter can only be set in the postgresql.conf
file or on the server command line.
trace_notify
(boolean
)
Generates a great amount of debugging output for the LISTEN
and NOTIFY
commands. client_min_messages or log_min_messages must be DEBUG1
or lower to send this output to the client or server logs, respectively.
trace_recovery_messages
(enum
)
Enables logging of recovery-related debugging output that otherwise would not be logged. This parameter allows the user to override the normal setting of log_min_messages, but only for specific messages. This is intended for use in debugging Hot Standby. Valid values are DEBUG5
, DEBUG4
, DEBUG3
, DEBUG2
, DEBUG1
, and LOG
. The default, LOG
, does not affect logging decisions at all. The other values cause recovery-related debug messages of that priority or higher to be logged as though they had LOG
priority; for common settings of log_min_messages
this results in unconditionally sending them to the server log. This parameter can only be set in the postgresql.conf
file or on the server command line.
trace_sort
(boolean
)
If on, emit information about resource usage during sort operations. This parameter is only available if the TRACE_SORT
macro was defined when PostgreSQL was compiled. (However, TRACE_SORT
is currently defined by default.)
trace_locks
(boolean
)
If on, emit information about lock usage. Information dumped includes the type of lock operation, the type of lock and the unique identifier of the object being locked or unlocked. Also included are bit masks for the lock types already granted on this object as well as for the lock types awaited on this object. For each lock type a count of the number of granted locks and waiting locks is also dumped as well as the totals. An example of the log file output is shown here:
Details of the structure being dumped may be found in src/include/storage/lock.h
.
This parameter is only available if the LOCK_DEBUG
macro was defined when PostgreSQL was compiled.
trace_lwlocks
(boolean
)
If on, emit information about lightweight lock usage. Lightweight locks are intended primarily to provide mutual exclusion of access to shared-memory data structures.
This parameter is only available if the LOCK_DEBUG
macro was defined when PostgreSQL was compiled.
trace_userlocks
(boolean
)
If on, emit information about user lock usage. Output is the same as for trace_locks
, only for advisory locks.
This parameter is only available if the LOCK_DEBUG
macro was defined when PostgreSQL was compiled.
trace_lock_oidmin
(integer
)
If set, do not trace locks for tables below this OID. (use to avoid output on system tables)
This parameter is only available if the LOCK_DEBUG
macro was defined when PostgreSQL was compiled.
trace_lock_table
(integer
)
Unconditionally trace locks on this table (OID).
This parameter is only available if the LOCK_DEBUG
macro was defined when PostgreSQL was compiled.
debug_deadlocks
(boolean
)
If set, dumps information about all current locks when a deadlock timeout occurs.
This parameter is only available if the LOCK_DEBUG
macro was defined when PostgreSQL was compiled.
log_btree_build_stats
(boolean
)
If set, logs system resource usage statistics (memory and CPU) on various B-tree operations.
This parameter is only available if the BTREE_BUILD_STATS
macro was defined when PostgreSQL was compiled.
wal_consistency_checking
(string
)
This parameter is intended to be used to check for bugs in the WAL redo routines. When enabled, full-page images of any buffers modified in conjunction with the WAL record are added to the record. If the record is subsequently replayed, the system will first apply each record and then test whether the buffers modified by the record match the stored images. In certain cases (such as hint bits), minor variations are acceptable, and will be ignored. Any unexpected differences will result in a fatal error, terminating recovery.
The default value of this setting is the empty string, which disables the feature. It can be set to all
to check all records, or to a comma-separated list of resource managers to check only records originating from those resource managers. Currently, the supported resource managers are heap
, heap2
, btree
, hash
, gin
, gist
, sequence
, spgist
, brin
, and generic
. Only superusers can change this setting.wal_debug
(boolean
)
If on, emit WAL-related debugging output. This parameter is only available if the WAL_DEBUG
macro was defined when PostgreSQL was compiled.
ignore_checksum_failure
(boolean
)
Only has effect if data checksums are enabled.
Detection of a checksum failure during a read normally causes PostgreSQL to report an error, aborting the current transaction. Setting ignore_checksum_failure
to on causes the system to ignore the failure (but still report a warning), and continue processing. This behavior may cause crashes, propagate or hide corruption, or other serious problems. However, it may allow you to get past the error and retrieve undamaged tuples that might still be present in the table if the block header is still sane. If the header is corrupt an error will be reported even if this option is enabled. The default setting is off
, and it can only be changed by a superuser.
zero_damaged_pages
(boolean
)
Detection of a damaged page header normally causes PostgreSQL to report an error, aborting the current transaction. Setting zero_damaged_pages
to on causes the system to instead report a warning, zero out the damaged page in memory, and continue processing. This behavior will destroy data, namely all the rows on the damaged page. However, it does allow you to get past the error and retrieve rows from any undamaged pages that might be present in the table. It is useful for recovering data if corruption has occurred due to a hardware or software error. You should generally not set this on until you have given up hope of recovering data from the damaged pages of a table. Zeroed-out pages are not forced to disk so it is recommended to recreate the table or the index before turning this parameter off again. The default setting is off
, and it can only be changed by a superuser.
jit_debugging_support
(boolean
)
If LLVM has the required functionality, register generated functions with GDB. This makes debugging easier. The default setting is off
. This parameter can only be set at server start.
jit_dump_bitcode
(boolean
)
Writes the generated LLVM IR out to the file system, inside data_directory. This is only useful for working on the internals of the JIT implementation. The default setting is off
. This parameter can only be changed by a superuser.
jit_expressions
(boolean
)
Determines whether expressions are JIT compiled, when JIT compilation is activated (see Section 31.2). The default is on
.
jit_profiling_support
(boolean
)
If LLVM has the required functionality, emit the data needed to allow perf to profile functions generated by JIT. This writes out files to $HOME/.debug/jit/
; the user is responsible for performing cleanup when desired. The default setting is off
. This parameter can only be set at server start.
jit_tuple_deforming
(boolean
)
Determines whether tuple deforming is JIT compiled, when JIT compilation is activated (see Section 31.2). The default is on
.
exit_on_error
(boolean
)
If on, any error will terminate the current session. By default, this is set to off, so that only FATAL errors will terminate the session.
restart_after_crash
(boolean
)
When set to on, which is the default, PostgreSQL will automatically reinitialize after a backend crash. Leaving this value set to on is normally the best way to maximize the availability of the database. However, in some circumstances, such as when PostgreSQL is being invoked by clusterware, it may be useful to disable the restart so that the clusterware can gain control and take any actions it deems appropriate.
data_sync_retry
(boolean
)
When set to off, which is the default, PostgreSQL will raise a PANIC-level error on failure to flush modified data files to the file system. This causes the database server to crash. This parameter can only be set at server start.
On some operating systems, the status of data in the kernel's page cache is unknown after a write-back failure. In some cases it might have been entirely forgotten, making it unsafe to retry; the second attempt may be reported as successful, when in fact the data has been lost. In these circumstances, the only way to avoid data loss is to recover from the WAL after any failure is reported, preferably after investigating the root cause of the failure and replacing any faulty hardware.
If set to on, PostgreSQL will instead report an error but continue to run so that the data flushing operation can be retried in a later checkpoint. Only set it to on after investigating the operating system's treatment of buffered data in case of write-back failure.
The following “parameters” are read-only, and are determined when PostgreSQL is compiled or when it is installed. As such, they have been excluded from the sample postgresql.conf
file. These options report various aspects of PostgreSQL behavior that might be of interest to certain applications, particularly administrative front-ends.
block_size
(integer
)
Reports the size of a disk block. It is determined by the value of BLCKSZ
when building the server. The default value is 8192 bytes. The meaning of some configuration variables (such as shared_buffers) is influenced by block_size
. See Section 19.4 for information.
data_checksums
(boolean
)
Reports whether data checksums are enabled for this cluster. See data checksums for more information.
debug_assertions
(boolean
)
Reports whether PostgreSQL has been built with assertions enabled. That is the case if the macro USE_ASSERT_CHECKING
is defined when PostgreSQL is built (accomplished e.g. by the configure
option --enable-cassert
). By default PostgreSQL is built without assertions.
integer_datetimes
(boolean
)
Reports whether PostgreSQL was built with support for 64-bit-integer dates and times. As of PostgreSQL 10, this is always on
.
lc_collate
(string
)
Reports the locale in which sorting of textual data is done. See Section 23.1 for more information. This value is determined when a database is created.
lc_ctype
(string
)
Reports the locale that determines character classifications. See Section 23.1 for more information. This value is determined when a database is created. Ordinarily this will be the same as lc_collate
, but for special applications it might be set differently.
max_function_args
(integer
)
Reports the maximum number of function arguments. It is determined by the value of FUNC_MAX_ARGS
when building the server. The default value is 100 arguments.
max_identifier_length
(integer
)
Reports the maximum identifier length. It is determined as one less than the value of NAMEDATALEN
when building the server. The default value of NAMEDATALEN
is 64; therefore the default max_identifier_length
is 63 bytes, which can be less than 63 characters when using multibyte encodings.
max_index_keys
(integer
)
Reports the maximum number of index keys. It is determined by the value of INDEX_MAX_KEYS
when building the server. The default value is 32 keys.
segment_size
(integer
)
Reports the number of blocks (pages) that can be stored within a file segment. It is determined by the value of RELSEG_SIZE
when building the server. The maximum size of a segment file in bytes is equal to segment_size
multiplied by block_size
; by default this is 1GB.
server_encoding
(string
)
Reports the database encoding (character set). It is determined when the database is created. Ordinarily, clients need only be concerned with the value of client_encoding.
server_version
(string
)
Reports the version number of the server. It is determined by the value of PG_VERSION
when building the server.
server_version_num
(integer
)
Reports the version number of the server as an integer. It is determined by the value of PG_VERSION_NUM
when building the server.
wal_block_size
(integer
)
Reports the size of a WAL disk block. It is determined by the value of XLOG_BLCKSZ
when building the server. The default value is 8192 bytes.
wal_segment_size
(integer
)
Reports the number of blocks (pages) in a WAL segment file. The total size of a WAL segment file in bytes is equal to wal_segment_size
multiplied by wal_block_size
; by default this is 16MB. See Section 30.4 for more information.
For convenience there are also single letter command-line option switches available for some parameters. They are described in . Some of these options exist for historical reasons, and their presence as a single-letter option does not necessarily indicate an endorsement to use the option heavily.
-B
x
shared_buffers =
x
-d
x
log_min_messages = DEBUG
x
-e
datestyle = euro
-fb
, -fh
, -fi
, -fm
, -fn
, -fo
, -fs
, -ft
enable_bitmapscan = off
, enable_hashjoin = off
, enable_indexscan = off
, enable_mergejoin = off
, enable_nestloop = off
, enable_indexonlyscan = off
, enable_seqscan = off
, enable_tidscan = off
-F
fsync = off
-h
x
listen_addresses =
x
-i
listen_addresses = '*'
-k
x
unix_socket_directories =
x
-l
ssl = on
-N
x
max_connections =
x
-O
allow_system_table_mods = on
-p
x
port =
x
-P
ignore_system_indexes = on
-s
log_statement_stats = on
-S
x
work_mem =
x
-tpa
, -tpl
, -te
log_parser_stats = on
, log_planner_stats = on
, log_executor_stats = on
-W
x
post_auth_delay =
x