{"Entry":{"collection":"guc","key":"log_line_prefix","name":"log_line_prefix","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Reporting and Logging / What to Log","category_zh":"","changed_in":["10","18"],"changes":[{"documentation_changed":false,"fields":{},"from":"7.4","status":"added","to":"8.0"},{"documentation_changed":true,"fields":{},"from":"8.0","status":"changed","to":"8.1"},{"documentation_changed":true,"fields":{},"from":"8.1","status":"changed","to":"8.2"},{"documentation_changed":true,"fields":{},"from":"8.2","status":"changed","to":"8.3"},{"documentation_changed":true,"fields":{},"from":"8.3","status":"changed","to":"8.4"},{"documentation_changed":true,"fields":{},"from":"8.4","status":"changed","to":"9.0"},{"documentation_changed":true,"fields":{},"from":"9.1","status":"changed","to":"9.2"},{"documentation_changed":true,"fields":{},"from":"9.3","status":"changed","to":"9.4"},{"documentation_changed":true,"fields":{},"from":"9.4","status":"changed","to":"9.5"},{"documentation_changed":true,"fields":{},"from":"9.5","status":"changed","to":"9.6"},{"documentation_changed":true,"fields":{"boot_val":{"from":"","to":"%m [%p] "}},"from":"9.6","status":"changed","to":"10"},{"documentation_changed":true,"fields":{},"from":"12","status":"changed","to":"13"},{"documentation_changed":true,"fields":{},"from":"13","status":"changed","to":"14"},{"documentation_changed":true,"fields":{},"from":"15","status":"changed","to":"16"},{"documentation_changed":true,"fields":{},"from":"16","status":"changed","to":"17"},{"documentation_changed":true,"fields":{"extra_desc":{"from":"If blank, no prefix is used.","to":"An empty string means no prefix."}},"from":"17","status":"changed","to":"18"},{"documentation_changed":true,"fields":{},"from":"19","status":"changed","to":"20"}],"content_hash":"87afdece2539693bbd3ec88c314284cf047648fe9ff56d08c2448dc4bb02abb8","context":"","default_changed_in":["10"],"default_history":[{"from":"9.0","to":"9.6","value":"Empty string"},{"from":"10","to":"19","value":"%m [%p] "}],"editorial":{"advice":{"olap":"Analytical jobs can justify richer log_line_prefix telemetry, but account for long statements, large bind values, and bursty completion patterns in the log pipeline.","oltp":"Tune log_line_prefix against an explicit observability question and a measured log-volume budget. Prefer selective thresholds, sampling, or role-level overrides over indiscriminate capture.","small":"Keep log_line_prefix useful but bounded: verify disk, collector, retention, and redaction capacity before increasing detail or frequency."},"mechanism":["log_line_prefix controls information prefixed to each log line. An empty string means no prefix. Percent escapes add session, user, database, process, application, and timing context; csvlog and jsonlog already carry structured fields separately.","log_line_prefix is a SIGHUP-context setting: a configuration reload activates the new server value without a restart; subsequent operations that consult it use the refreshed value.","It changes emitted diagnostic data rather than query semantics, but volume, sensitive content, log_line_prefix, destinations, collector throughput, and retention determine operational cost and usefulness."],"pitfalls":["Editing log_line_prefix without reloading configuration and verifying the effective value and subsequent behavior.","Enabling richer logging without budgeting collector throughput, storage, retention, and downstream query cost.","Writing SQL text, bind values, identities, or host data without a redaction and access-control policy.","Omitting process, session, database, user, or application identity needed to correlate multiline text logs."],"references":[{"title":"PostgreSQL 19 Beta 4: log_line_prefix","url":"https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-LOG-LINE-PREFIX"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["application_name","cluster_name","update_process_title","log_timezone","log_hostname"],"summary":"log_line_prefix is the PostgreSQL setting that controls information prefixed to each log line."},"enumvals":[],"first_version":"8.0","group":"Reporting and Logging","group_slug":"logging","imported_at":"2026-09-30T00:40:57.350662+08:00","intro_commit":{},"key":"log_line_prefix","last_version":"20","max_val":"","min_val":"","name":"log_line_prefix","position":230,"present_in":["8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"short_desc":"This is a printf-style string that is output at the beginning of each log line.","short_desc_zh":"","source_rev":"english-manuals:e12cef740d6d81b35da3ef71d6040ab07f5358dc7b70758cd3e2b2ffbc8f6a0c","unit":"","vartype":"string"}},"Definition":{"Collection":"guc","Key":"log_line_prefix","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"log_line_prefix","SourceRevision":"english-manuals:e12cef740d6d81b35da3ef71d6040ab07f5358dc7b70758cd3e2b2ffbc8f6a0c","Facts":{"boot_val":"%m [%p] ","category":"Reporting and Logging / What to Log","context":"sighup","description":"This is a printf-style string that is output at the beginning of each log line. % characters begin “escape sequences” that are replaced with status information as outlined below. Unrecognized escapes are ignored. Other characters are copied straight to the log line. Some escapes are only recognized by session processes, and will be treated as empty by background processes such as the main server process. Status information may be aligned either left or right by specifying a numeric literal after the % and before the option. A negative value will cause the status information to be padded on the right with spaces to give it a minimum width, whereas a positive value will pad on the left. Padding can be useful to aid human readability in log files. This parameter can only be set in the postgresql.conf file or on the server command line. The default is '%m [%p] ' which logs a time stamp and the process ID. Escape Effect Session only %a Application name yes %u User name yes %d Database name yes %r Remote host name or IP address, and remote port yes %h Remote host name or IP address yes %L Local address (the IP address on the server that the client connected to) yes %b Backend type no %p Process ID no %P Process ID of the parallel group leader, if this process is a parallel query worker no %t Time stamp without milliseconds no %m Time stamp with milliseconds no %n Time stamp with milliseconds (as a Unix epoch) no %i Command tag: type of session's current command yes %e SQLSTATE error code no %c Session ID: see below no %l Number of the log line for each session or process, starting at 1 no %s Process start time stamp no %v Virtual transaction ID (procNumber/localXID); see Section 67.1 no %x Transaction ID (0 if none is assigned); see Section 67.1 no %q Produces no output, but tells non-session processes to stop at this point in the string; ignored by session processes no %Q Query identifier of the current query. Query identifiers are not computed by default, so this field will be zero unless compute_query_id parameter is enabled or a third-party module that computes query identifiers is configured. yes %% Literal % no The backend type corresponds to the column backend_type in the view pg_stat_activity, but additional types can appear in the log that don't show in that view. The %c escape prints a quasi-unique session identifier, consisting of two 4-byte hexadecimal numbers (without leading zeros) separated by a dot. The numbers are the process start time and the process ID, so %c can also be used as a space saving way of printing those items. For example, to generate the session identifier from pg_stat_activity, use this query: SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' || to_hex(pid) FROM pg_stat_activity; Tip If you set a nonempty value for log_line_prefix, you should usually make its last character be a space, to provide visual separation from the rest of the log line. A punctuation character can be used too. Tip Syslog produces its own time stamp and process ID information, so you probably do not want to include those escapes if you are logging to syslog. Tip The %q escape is useful when including information that is only available in session (backend) context like user or database name. For example: log_line_prefix = '%m [%p] %q%u@%d/%a ' Note The %Q escape always reports a zero identifier for lines output by log_statement because log_statement generates output before an identifier can be calculated, including invalid statements for which an identifier cannot be calculated.","doc":{"anchor":"GUC-LOG-LINE-PREFIX","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"An empty string means no prefix.","lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"log_line_prefix","short_desc":"Controls information prefixed to each log line.","source":"pg-settings-source-snapshot","unit":null,"vartype":"string"},"ManualEvidence":{"doc":{"anchor":"GUC-LOG-LINE-PREFIX","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"log_line_prefix","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"log_line_prefix","Summary":"","BodyHTML":"\u003cp\u003e这是一个\u003ccode\u003eprintf\u003c/code\u003e风格的字符串，它在每个日志行的开头输出。\u003ccode\u003e%\u003c/code\u003e字符开始\u003cspan\u003e“\u003cspan\u003e转义序列\u003c/span\u003e”\u003c/span\u003e，它将按下文描述被替换为状态信息。未识别的转义被忽略。其他字符被直接复制到日志行。某些转义只被会话进程识别并且被主服务器进程等后台进程当作空。通过指定一个在%之后和该选项之前的数字可以让状态信息左对齐或右对齐。负值将导致在右边用空格填充状态信息以达到最小宽度，而正值则在左边填充。填充对于日志文件的人类可读性大有帮助。\u003c/p\u003e\u003cp\u003e这个参数只能在\u003ccode\u003epostgresql.conf\u003c/code\u003e文件中或在服务器命令行上设置。默认值是\u003ccode\u003e\u0026#39;%m [%p] \u0026#39;\u003c/code\u003e，它记录时间戳和进程ID。\u003c/p\u003e\u003cdiv\u003e\u003ctable\u003e\u003cthead\u003e\u003ctr\u003e\u003cth\u003e转义\u003c/th\u003e\u003cth\u003e效果\u003c/th\u003e\u003cth\u003e只限会话\u003c/th\u003e\u003c/tr\u003e\u003c/thead\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%a\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e应用名\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%u\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e用户名\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%d\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e数据库名\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%r\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e远程主机名或 IP 地址，以及远程端口\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%h\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e远程主机名或 IP 地址\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%L\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e本地地址（客户端所连接的服务器 IP 地址）\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%b\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e后端类型\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%p\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e进程 ID\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%P\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e如果该进程是并行查询工作进程，则为并行组领导者的进程 ID\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%t\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e无毫秒的时间戳\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%m\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e带毫秒的时间戳\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%n\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e带毫秒精度的 Unix 时间戳\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%i\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e命令标签：会话当前命令的类型\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%e\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eSQLSTATE 错误代码\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%c\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e会话 ID：见下文\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%l\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e对每个会话或进程的日志行号，从 1 开始\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%s\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e进程开始的时间戳\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%v\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e虚拟事务 ID（procNumber/localXID）；参见\u003ca href=\"/docs/18/transaction-id.html\" rel=\"nofollow\"\u003e第 67.1 节\u003c/a\u003e\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%x\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e事务 ID（如果未分配则为 0）；参见\u003ca href=\"/docs/18/transaction-id.html\" rel=\"nofollow\"\u003e第 67.1 节\u003c/a\u003e\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%q\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e不产生输出，但是告诉非会话进程在字符串的这一点停止；会话进程忽略\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%Q\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e当前查询的查询标识符。查询标识符默认是不计算的，所以该字段将为零，除非\u003ca href=\"/docs/18/runtime-config-statistics.html#GUC-COMPUTE-QUERY-ID\" rel=\"nofollow\"\u003ecompute_query_id\u003c/a\u003e参数被激活或者配置了计算查询标识符的第三方模块\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode\u003e%%\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e字面字符 \u003ccode\u003e%\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\u003c/div\u003e\u003cp\u003e后端类型对应视图 \u003ca href=\"/docs/18/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW\" rel=\"nofollow\"\u003e\u003ccode\u003epg_stat_activity\u003c/code\u003e\u003c/a\u003e中的\u003ccode\u003ebackend_type\u003c/code\u003e列。但是其他类型可能会出现在日志中而不显示在该视图中。\u003c/p\u003e\u003cp\u003e\u003ccode\u003e%c\u003c/code\u003e转义打印一个准唯一的会话标识符，它由两个 4 字节的十六进制数（不带先导零）组成，以点号分隔。这些数字是进程启动时间和进程 ID，因此\u003ccode\u003e%c\u003c/code\u003e也可以用来节省空间地输出这两项信息。例如，要从\u003ccode\u003epg_stat_activity\u003c/code\u003e生成会话标识符，使用这个查询：\u003c/p\u003e\u003cpre\u003eSELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || \u0026#39;.\u0026#39; ||\n       to_hex(pid)\nFROM pg_stat_activity;\n\u003c/pre\u003e\u003cdiv\u003e\n提示\u003cp\u003e如果你为\u003ccode\u003elog_line_prefix\u003c/code\u003e设置了非空值，你通常应该让它的最后一个字符为空格，这样可与日志行的其余部分在视觉上区分开。也可以使用标点符号。\u003c/p\u003e\u003c/div\u003e\u003cdiv\u003e\n提示\u003cp\u003e\u003cspan\u003eSyslog\u003c/span\u003e产生自己的时间戳和进程 ID 信息，因此如果你记录到\u003cspan\u003esyslog\u003c/span\u003e你可能不希望包括那些转义。\u003c/p\u003e\u003c/div\u003e\u003cdiv\u003e\n提示\u003cp\u003e在包括仅在会话（后端）上下文中可用的信息（如用户名或者数据库名）时，\u003ccode\u003e%q\u003c/code\u003e转义很有用。例如：\u003c/p\u003e\u003cpre\u003elog_line_prefix = \u0026#39;%m [%p] %q%u@%d/%a \u0026#39;\n\u003c/pre\u003e\u003c/div\u003e\u003cdiv\u003e\n注意\u003cp\u003e对于\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-STATEMENT\" rel=\"nofollow\"\u003elog_statement\u003c/a\u003e输出的行，\u003ccode\u003e%Q\u003c/code\u003e 总是报告零标识符，因为\u003ccode\u003elog_statement\u003c/code\u003e在标识符能被计算之前生成输出，也包括无法计算标识符的无效语句。\u003c/p\u003e\u003c/div\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"c84c5516994ed898a236ca3c28af1a53a3bad2a56961d5f34862b38ae133712f","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e这是一个\u003ccode class=\"function\"\u003eprintf\u003c/code\u003e风格的字符串，它在每个日志行的开头输出。\u003ccode class=\"literal\"\u003e%\u003c/code\u003e字符开始\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e转义序列\u003c/span\u003e”\u003c/span\u003e，它将按下文描述被替换为状态信息。未识别的转义被忽略。其他字符被直接复制到日志行。某些转义只被会话进程识别并且被主服务器进程等后台进程当作空。通过指定一个在%之后和该选项之前的数字可以让状态信息左对齐或右对齐。负值将导致在右边用空格填充状态信息以达到最小宽度，而正值则在左边填充。填充对于日志文件的人类可读性大有帮助。\u003c/p\u003e\u003cp\u003e这个参数只能在\u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e文件中或在服务器命令行上设置。默认值是\u003ccode class=\"literal\"\u003e'%m [%p] '\u003c/code\u003e，它记录时间戳和进程ID。\u003c/p\u003e\u003cdiv class=\"informaltable\"\u003e\u003ctable class=\"informaltable\"\u003e\u003cthead\u003e\u003ctr\u003e\u003cth\u003e转义\u003c/th\u003e\u003cth\u003e效果\u003c/th\u003e\u003cth\u003e只限会话\u003c/th\u003e\u003c/tr\u003e\u003c/thead\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%a\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e应用名\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%u\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e用户名\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%d\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e数据库名\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%r\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e远程主机名或 IP 地址，以及远程端口\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%h\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e远程主机名或 IP 地址\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%L\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e本地地址（客户端所连接的服务器 IP 地址）\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%b\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e后端类型\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%p\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e进程 ID\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%P\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e如果该进程是并行查询工作进程，则为并行组领导者的进程 ID\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%t\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e无毫秒的时间戳\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%m\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e带毫秒的时间戳\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%n\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e带毫秒精度的 Unix 时间戳\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%i\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e命令标签：会话当前命令的类型\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%e\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eSQLSTATE 错误代码\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%c\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e会话 ID：见下文\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%l\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e对每个会话或进程的日志行号，从 1 开始\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%s\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e进程开始的时间戳\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%v\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e虚拟事务 ID（procNumber/localXID）；参见\u003ca href=\"/docs/18/transaction-id.html\" title=\"67.1. 事务与标识符\"\u003e第 67.1 节\u003c/a\u003e\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%x\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e事务 ID（如果未分配则为 0）；参见\u003ca href=\"/docs/18/transaction-id.html\" title=\"67.1. 事务与标识符\"\u003e第 67.1 节\u003c/a\u003e\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%q\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e不产生输出，但是告诉非会话进程在字符串的这一点停止；会话进程忽略\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%Q\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e当前查询的查询标识符。查询标识符默认是不计算的，所以该字段将为零，除非\u003ca href=\"/docs/18/runtime-config-statistics.html#GUC-COMPUTE-QUERY-ID\"\u003ecompute_query_id\u003c/a\u003e参数被激活或者配置了计算查询标识符的第三方模块\u003c/td\u003e\u003ctd\u003e是\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003e%%\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e字面字符 \u003ccode class=\"literal\"\u003e%\u003c/code\u003e\u003c/td\u003e\u003ctd\u003e否\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\u003c/div\u003e\u003cp\u003e后端类型对应视图 \u003ca href=\"/docs/18/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW\" title=\"27.2.3. pg_stat_activity\"\u003e\u003ccode class=\"structname\"\u003epg_stat_activity\u003c/code\u003e\u003c/a\u003e中的\u003ccode class=\"structfield\"\u003ebackend_type\u003c/code\u003e列。但是其他类型可能会出现在日志中而不显示在该视图中。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"literal\"\u003e%c\u003c/code\u003e转义打印一个准唯一的会话标识符，它由两个 4 字节的十六进制数（不带先导零）组成，以点号分隔。这些数字是进程启动时间和进程 ID，因此\u003ccode class=\"literal\"\u003e%c\u003c/code\u003e也可以用来节省空间地输出这两项信息。例如，要从\u003ccode class=\"literal\"\u003epg_stat_activity\u003c/code\u003e生成会话标识符，使用这个查询：\u003c/p\u003e\u003cpre\u003eSELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' ||\n       to_hex(pid)\nFROM pg_stat_activity;\n\u003c/pre\u003e\u003cdiv class=\"tip\"\u003e\n提示\u003cp\u003e如果你为\u003ccode class=\"varname\"\u003elog_line_prefix\u003c/code\u003e设置了非空值，你通常应该让它的最后一个字符为空格，这样可与日志行的其余部分在视觉上区分开。也可以使用标点符号。\u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"tip\"\u003e\n提示\u003cp\u003e\u003cspan class=\"application\"\u003eSyslog\u003c/span\u003e产生自己的时间戳和进程 ID 信息，因此如果你记录到\u003cspan class=\"application\"\u003esyslog\u003c/span\u003e你可能不希望包括那些转义。\u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"tip\"\u003e\n提示\u003cp\u003e在包括仅在会话（后端）上下文中可用的信息（如用户名或者数据库名）时，\u003ccode class=\"literal\"\u003e%q\u003c/code\u003e转义很有用。例如：\u003c/p\u003e\u003cpre\u003elog_line_prefix = '%m [%p] %q%u@%d/%a '\n\u003c/pre\u003e\u003c/div\u003e\u003cdiv class=\"note\"\u003e\n注意\u003cp\u003e对于\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-STATEMENT\"\u003elog_statement\u003c/a\u003e输出的行，\u003ccode class=\"literal\"\u003e%Q\u003c/code\u003e 总是报告零标识符，因为\u003ccode class=\"varname\"\u003elog_statement\u003c/code\u003e在标识符能被计算之前生成输出，也包括无法计算标识符的无效语句。\u003c/p\u003e\u003c/div\u003e","doc_same_as":""}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
