{"Entry":{"collection":"conn","key":"service","name":"service","aliases":["PGSERVICE","service"],"metadata":{"aliases":["PGSERVICE","service"],"category":"Connection destination","content_hash":"26f5feeefc5577c021992843a09e19e923862dcf75c7f7fedca2e19ea38e4648","derived_content_hash":"3777cfa5b35eece8bfbab49f6db225bd0d0ea624f040cbad64d585c8e5397d99","documentation_refresh":{"batch":"20261113","original_source_rev":"","versions":{"14":"14.25","15":"15.20","16":"16.16","17":"17.12","18":"18.7","19":"19rc2"}},"imported_at":"2026-09-30T00:40:35.075469+08:00","name":"service","name_zh":"","slug":"service","summary":"Service name to use for additional parameters. It specifies a service name in pg_service.conf that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See Section 32.16 ."}},"Definition":{"Collection":"conn","Key":"service","SourceDatabase":"center","Version":"18","SourceTable":"connection_parameter","SourceKey":"service","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","Facts":{"comparison_data":{"compiled_default_expression":"NULL","default_evidence":[],"definition":"Service name to use for additional parameters. It specifies a service name in pg_service.conf that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See Section 32.17 .","documented":true,"environment":"PGSERVICE","keyword":"service"},"comparison_hash":"33cedba025c46a36ecb8b488c2f6c5307331b49c92fe4b2893358ec554d9dd60","default_evidence":[],"description":["Service name to use for additional parameters. It specifies a service name in pg_service.conf that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See Section 32.17 ."],"description_zh":"用于额外参数的服务名称。它指定了 pg_service.conf 中保存额外连接参数的服务名称。这允许应用程序只指定一个服务名称，以便可以集中维护连接参数。参见 第 32.17 节 。","description_zh_html":"\u003cp\u003e连接参数 service。\u003c/p\u003e\u003ch3\u003e同版本中文手册定义\u003c/h3\u003e\u003cdd\u003e\u003cp\u003e\n        用于额外参数的服务名称。它指定了 \u003ccode class=\"filename\"\u003epg_service.conf\u003c/code\u003e 中保存额外连接参数的服务名称。这允许应用程序只指定一个服务名称，以便可以集中维护连接参数。参见\u003ca class=\"xref\" href=\"/zh/docs/18/libpq-pgservice.html\"\u003e第 32.17 节\u003c/a\u003e。\n\u003c/p\u003e\u003c/dd\u003e\u003cp\u003e\u003ca href=\"/zh/docs/18/libpq-connect.html#LIBPQ-CONNECT-SERVICE\"\u003e查看完整中文手册与上下文\u003c/a\u003e。\u003c/p\u003e","documented":true,"environment":[{"description":"PGSERVICE behaves the same as the service connection parameter.","name":"PGSERVICE","source_url":"/docs/18/libpq-envars.html"}],"facts":[{"label":"Client library","value":"libpq 18.6"},{"label":"Manual definition","value":"Documented"},{"label":"Source environment fallback","value":"PGSERVICE"},{"label":"Compiled fallback expression","value":"NULL"}],"facts_zh":[{"label":"客户端库","value":"libpq 18.6"},{"label":"手册定义","value":"手册已记载"},{"label":"源码中的环境变量回退","value":"PGSERVICE"},{"label":"编译时回退表达式","value":"NULL"}],"keyword":"service","manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"LIBPQ-CONNECT-SERVICE\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eservice\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eService name to use for additional parameters. It specifies a service name in \u003ccode class=\"filename\"\u003epg_service.conf\u003c/code\u003e that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See \u003ca class=\"xref\" href=\"/docs/18/libpq-pgservice.html\" title=\"32.17. The Connection Service File\"\u003eSection 32.17\u003c/a\u003e.\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv class=\"sect1\" id=\"LIBPQ-PGSERVICE\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e32.17. The Connection Service File \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe connection service file allows libpq connection parameters to be associated with a single service name. That service name can then be specified using the \u003ccode class=\"literal\"\u003eservice\u003c/code\u003e key word in a libpq connection string, and the associated settings will be used. This allows connection parameters to be modified without requiring a recompile of the libpq-using application. The service name can also be specified using the \u003ccode class=\"envar\"\u003ePGSERVICE\u003c/code\u003e environment variable.\u003c/p\u003e\n\u003cp\u003eService names can be defined in either a per-user service file or a system-wide file. If the same service name exists in both the user and the system file, the user file takes precedence. By default, the per-user service file is named \u003ccode class=\"filename\"\u003e~/.pg_service.conf\u003c/code\u003e. On Microsoft Windows, it is named \u003ccode class=\"filename\"\u003e%APPDATA%\\postgresql\\.pg_service.conf\u003c/code\u003e (where \u003ccode class=\"filename\"\u003e%APPDATA%\u003c/code\u003e refers to the Application Data subdirectory in the user's profile). A different file name can be specified by setting the environment variable \u003ccode class=\"envar\"\u003ePGSERVICEFILE\u003c/code\u003e. The system-wide file is named \u003ccode class=\"filename\"\u003epg_service.conf\u003c/code\u003e. By default it is sought in the \u003ccode class=\"filename\"\u003eetc\u003c/code\u003e directory of the \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e installation (use \u003ccode class=\"literal\"\u003epg_config --sysconfdir\u003c/code\u003e to identify this directory precisely). Another directory, but not a different file name, can be specified by setting the environment variable \u003ccode class=\"envar\"\u003ePGSYSCONFDIR\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eEither service file uses an \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eINI file\u003c/span\u003e”\u003c/span\u003e format where the section name is the service name and the parameters are connection parameters; see \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2. Parameter Key Words\"\u003eSection 32.1.2\u003c/a\u003e for a list. For example:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003e# comment\n[mydb]\nhost=somehost\nport=5433\nuser=admin\n\u003c/pre\u003e\n\u003cp\u003eAn example file is provided in the \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e installation at \u003ccode class=\"filename\"\u003eshare/pg_service.conf.sample\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eConnection parameters obtained from a service file are combined with parameters obtained from other sources. A service file setting overrides the corresponding environment variable, and in turn can be overridden by a value given directly in the connection string. For example, using the above service file, a connection string \u003ccode class=\"literal\"\u003eservice=mydb port=5434\u003c/code\u003e will use host \u003ccode class=\"literal\"\u003esomehost\u003c/code\u003e, port \u003ccode class=\"literal\"\u003e5434\u003c/code\u003e, user \u003ccode class=\"literal\"\u003eadmin\u003c/code\u003e, and other parameters as set by environment variables or built-in defaults.\u003c/p\u003e\n\u003c/div\u003e\u003c/div\u003e","manual_path":"libpq-connect.html#LIBPQ-CONNECT-SERVICE","precedence_evidence":["The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb , PQsetdbLogin and PQsetdb if no value is directly specified by the calling code. These are useful to avoid hard-coding database connection information into simple client applications, for example.","Service names can be defined in either a per-user service file or a system-wide file. If the same service name exists in both the user and the system file, the user file takes precedence. By default, the per-user service file is named ~/.pg_service.conf . On Microsoft Windows, it is named %APPDATA%\\postgresql\\.pg_service.conf (where %APPDATA% refers to the Application Data subdirectory in the user's profile). A different file name can be specified by setting the environment variable PGSERVICEFILE . The system-wide file is named pg_service.conf . By default it is sought in the etc directory of the PostgreSQL installation (use pg_config --sysconfdir to identify this directory precisely). Another directory, but not a different file name, can be specified by setting the environment variable PGSYSCONFDIR .","Connection parameters obtained from a service file are combined with parameters obtained from other sources. A service file setting overrides the corresponding environment variable, and in turn can be overridden by a value given directly in the connection string. For example, using the above service file, a connection string service=mydb port=5434 will use host somehost , port 5434 , user admin , and other parameters as set by environment variables or built-in defaults."],"related":[{"label":"Connection service file","url":"/docs/18/libpq-pgservice.html"},{"label":"Password file","url":"/docs/18/libpq-pgpass.html"},{"label":"All libpq environment variables","url":"/docs/18/libpq-envars.html"}],"release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[{"paragraphs":["The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb , PQsetdbLogin and PQsetdb if no value is directly specified by the calling code. These are useful to avoid hard-coding database connection information into simple client applications, for example.","Service names can be defined in either a per-user service file or a system-wide file. If the same service name exists in both the user and the system file, the user file takes precedence. By default, the per-user service file is named ~/.pg_service.conf . On Microsoft Windows, it is named %APPDATA%\\postgresql\\.pg_service.conf (where %APPDATA% refers to the Application Data subdirectory in the user's profile). A different file name can be specified by setting the environment variable PGSERVICEFILE . The system-wide file is named pg_service.conf . By default it is sought in the etc directory of the PostgreSQL installation (use pg_config --sysconfdir to identify this directory precisely). Another directory, but not a different file name, can be specified by setting the environment variable PGSYSCONFDIR .","Connection parameters obtained from a service file are combined with parameters obtained from other sources. A service file setting overrides the corresponding environment variable, and in turn can be overridden by a value given directly in the connection string. For example, using the above service file, a connection string service=mydb port=5434 will use host somehost , port 5434 , user admin , and other parameters as set by environment variables or built-in defaults."],"title":"Default resolution and service-file precedence"},{"paragraphs":["PGSERVICE behaves the same as the service connection parameter."],"title":"Environment variable evidence"},{"paragraphs":["Kerberos and GSSAPI authentication support specifying the service name"],"title":"Source declaration notes"},{"paragraphs":["PGSERVICE behaves the same as the service connection parameter.","PGSERVICEFILE specifies the name of the per-user connection service file (see Section 32.17 ). Defaults to ~/.pg_service.conf , or %APPDATA%\\postgresql\\.pg_service.conf on Microsoft Windows.","PGSYSCONFDIR sets the directory containing the pg_service.conf file and in a future version possibly other system-wide configuration files."],"title":"Service-file controls"}],"sections_zh":[{"paragraphs":["以下环境变量可用于选择连接参数的默认值，供 PQconnectdb 、 PQsetdbLogin 和 PQsetdb 在调用代码未直接指定参数值时使用。例如，这样可以避免在简单的客户端应用程序中硬编码数据库连接信息。","服务名称可以在每个用户的服务文件或系统范围的文件中定义。如果同一个服务名称存在于用户文件和系统文件中，则用户文件优先。默认情况下，每个用户的服务文件名为 ~/.pg_service.conf 。在Microsoft Windows上，它的名称为 %APPDATA%\\postgresql\\.pg_service.conf （其中 %APPDATA% 指用户配置文件夹中的应用数据子目录）。可以通过设置环境变量 PGSERVICEFILE 来指定不同的文件名。系统范围的文件名为 pg_service.conf 。默认情况下，在 PostgreSQL 安装的 etc 目录中寻找（使用 pg_config --sysconfdir 来准确识别此目录）。可以通过设置环境变量 PGSYSCONFDIR 来指定另一个目录，但不能指定不同的文件名。","从服务文件中获取的连接参数会与其他来源的参数合并。服务文件中的设置会覆盖相应的环境变量，而连接字符串中直接给出的值又会覆盖服务文件中的设置。例如，使用上述服务文件时，连接字符串 service=mydb port=5434 将使用主机 somehost 、端口 5434 、用户 admin ，以及由环境变量或内置默认值设置的其他参数。"],"title":"默认值解析与服务文件优先级"},{"paragraphs":["PGSERVICE 的行为与 service 连接参数相同。"],"title":"环境变量证据"},{"paragraphs":["Kerberos 和 GSSAPI 认证支持指定服务名。"],"title":"源码声明说明"},{"paragraphs":["PGSERVICE 的行为与 service 连接参数相同。","PGSERVICEFILE 指定每个用户的连接服务文件的名称（参见 第 32.17 节 ）。默认为 ~/.pg_service.conf ，或者在 Microsoft Windows 上为 %APPDATA%\\postgresql\\.pg_service.conf 。","PGSYSCONFDIR 设置包含 pg_service.conf 文件以及未来版本中可能出现的其他系统范围配置文件的目录。"],"title":"服务文件控制"}],"signature":"service","source_option":{"compiled_default_expression":"NULL","declaration":"\"service\", \"PGSERVICE\", NULL, NULL, \"Database-Service\", \"\", 20, offsetof(struct pg_conn, pgservice)","environment":"PGSERVICE","keyword":"service","source_notes":["Kerberos and GSSAPI authentication support specifying the service name"]},"sources":[{"anchor":"LIBPQ-CONNECT-SERVICE","file":"libpq-connect.html","label":"18.6 English manual · libpq-connect.html","sha256":"c26a7fc3dcda6066cfe540641ae2690faf3d3c03277f30b4dfc2328ab45c212f","url":"/docs/18/libpq-connect.html#LIBPQ-CONNECT-SERVICE"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","file":"src/interfaces/libpq/fe-connect.c","label":"18.6 libpq connection option declarations","sha256":"44a6e386cbfd67ebe768d6ef5493098119c2e6b4796239d53e5ed7b122b206a5","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"anchor":"","file":"libpq-envars.html","label":"18.6 English manual · libpq-envars.html","sha256":"d64db73f3d48127bb984a5f775e77b7bcca2ba4bd218333cf24a45fcdd7c4363","url":"/docs/18/libpq-envars.html"},{"anchor":"","file":"libpq-pgservice.html","label":"18.6 English manual · libpq-pgservice.html","sha256":"6035a3f0ee1d0fd80db5bf58834390b884eecd23206659bdf6f07560deea5aa7","url":"/docs/18/libpq-pgservice.html"}],"tables":[{"columns":[{"key":"name","label":"Variable"},{"key":"description","label":"Documented behavior"}],"key":"environment","rows":[{"description":"PGSERVICE behaves the same as the service connection parameter.","name":{"text":"PGSERVICE","url":"/docs/18/libpq-envars.html"}}],"title":"Environment fallback"}],"tables_zh":[{"columns":[{"key":"name","label":"变量"},{"key":"description","label":"手册记载的行为"}],"key":"environment","rows":[{"description":"PGSERVICE 的行为与 service 连接参数相同。","name":{"text":"PGSERVICE","url":"/docs/18/libpq-envars.html"}}],"title":"环境变量回退"}],"zh_from":{"authored_translation":"source-derived-identity","body_sha256":"2492e9592220156dcad1aab390cc5a7c599083bd6b1bcfa8f50a6879d6bddf78","kind":"same-version-chinese-manual-with-source-derived-identity","manual":{"anchor":"LIBPQ-CONNECT-SERVICE","build_id":107,"extraction":"exact-definition","fragment_sha256":"36a7a061d5a94fdf835b87183d5d40ed5fef5fa12fd24d355a480d083e50b231","locale":"zh-Hans","page_key":"libpq-connect.html","source_hash":"1555b03a2bc480920a9c72be9683ee3ddf99e8a5c17267c0dca73c42cd50e44c","source_revision":"unknown:rendered-translation-baseline","translated_from_revision":null,"translation_revision":"git:b1b500221dbe5437cfca004d6b04d3f6e422765d;html-sha256:08e987a66af27b98444a8057c256314eafa13611a3fb9e888214fc436824244b","url":"/zh/docs/18/libpq-connect.html#LIBPQ-CONNECT-SERVICE","version":"18"},"runtime_rerun":false,"source_facts_revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8"}},"ManualEvidence":{"manual_path":"libpq-connect.html#LIBPQ-CONNECT-SERVICE","release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"anchor":"LIBPQ-CONNECT-SERVICE","file":"libpq-connect.html","label":"18.6 English manual · libpq-connect.html","sha256":"c26a7fc3dcda6066cfe540641ae2690faf3d3c03277f30b4dfc2328ab45c212f","url":"/docs/18/libpq-connect.html#LIBPQ-CONNECT-SERVICE"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","file":"src/interfaces/libpq/fe-connect.c","label":"18.6 libpq connection option declarations","sha256":"44a6e386cbfd67ebe768d6ef5493098119c2e6b4796239d53e5ed7b122b206a5","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"anchor":"","file":"libpq-envars.html","label":"18.6 English manual · libpq-envars.html","sha256":"d64db73f3d48127bb984a5f775e77b7bcca2ba4bd218333cf24a45fcdd7c4363","url":"/docs/18/libpq-envars.html"},{"anchor":"","file":"libpq-pgservice.html","label":"18.6 English manual · libpq-pgservice.html","sha256":"6035a3f0ee1d0fd80db5bf58834390b884eecd23206659bdf6f07560deea5aa7","url":"/docs/18/libpq-pgservice.html"}]},"MeasuredEvidence":{}},"Text":{"Collection":"conn","Key":"service","SourceDatabase":"center","Version":"18","Locale":"en","Title":"service","Summary":"Service name to use for additional parameters. It specifies a service name in pg_service.conf that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See Section 32.17 .","BodyHTML":"\u003cdiv\u003e\u003cdl\u003e\u003cdt id=\"LIBPQ-CONNECT-SERVICE\"\u003e\u003cspan\u003e\u003ccode\u003eservice\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eService name to use for additional parameters. It specifies a service name in \u003ccode\u003epg_service.conf\u003c/code\u003e that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See \u003ca href=\"/docs/18/libpq-pgservice.html\" rel=\"nofollow\"\u003eSection 32.17\u003c/a\u003e.\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv id=\"LIBPQ-PGSERVICE\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2\u003e32.17. The Connection Service File \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe connection service file allows libpq connection parameters to be associated with a single service name. That service name can then be specified using the \u003ccode\u003eservice\u003c/code\u003e key word in a libpq connection string, and the associated settings will be used. This allows connection parameters to be modified without requiring a recompile of the libpq-using application. The service name can also be specified using the \u003ccode\u003ePGSERVICE\u003c/code\u003e environment variable.\u003c/p\u003e\n\u003cp\u003eService names can be defined in either a per-user service file or a system-wide file. If the same service name exists in both the user and the system file, the user file takes precedence. By default, the per-user service file is named \u003ccode\u003e~/.pg_service.conf\u003c/code\u003e. On Microsoft Windows, it is named \u003ccode\u003e%APPDATA%\\postgresql\\.pg_service.conf\u003c/code\u003e (where \u003ccode\u003e%APPDATA%\u003c/code\u003e refers to the Application Data subdirectory in the user\u0026#39;s profile). A different file name can be specified by setting the environment variable \u003ccode\u003ePGSERVICEFILE\u003c/code\u003e. The system-wide file is named \u003ccode\u003epg_service.conf\u003c/code\u003e. By default it is sought in the \u003ccode\u003eetc\u003c/code\u003e directory of the \u003cspan\u003ePostgreSQL\u003c/span\u003e installation (use \u003ccode\u003epg_config --sysconfdir\u003c/code\u003e to identify this directory precisely). Another directory, but not a different file name, can be specified by setting the environment variable \u003ccode\u003ePGSYSCONFDIR\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eEither service file uses an \u003cspan\u003e“\u003cspan\u003eINI file\u003c/span\u003e”\u003c/span\u003e format where the section name is the service name and the parameters are connection parameters; see \u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" rel=\"nofollow\"\u003eSection 32.1.2\u003c/a\u003e for a list. For example:\u003c/p\u003e\n\u003cpre\u003e# comment\n[mydb]\nhost=somehost\nport=5433\nuser=admin\n\u003c/pre\u003e\n\u003cp\u003eAn example file is provided in the \u003cspan\u003ePostgreSQL\u003c/span\u003e installation at \u003ccode\u003eshare/pg_service.conf.sample\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eConnection parameters obtained from a service file are combined with parameters obtained from other sources. A service file setting overrides the corresponding environment variable, and in turn can be overridden by a value given directly in the connection string. For example, using the above service file, a connection string \u003ccode\u003eservice=mydb port=5434\u003c/code\u003e will use host \u003ccode\u003esomehost\u003c/code\u003e, port \u003ccode\u003e5434\u003c/code\u003e, user \u003ccode\u003eadmin\u003c/code\u003e, and other parameters as set by environment variables or built-in defaults.\u003c/p\u003e\n\u003c/div\u003e\u003c/div\u003e","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","ContentHash":"57d96c0c72437025e8b838f928824b6b01ea82f7631a4810e228492943cd6d38","Payload":{"description":["Service name to use for additional parameters. It specifies a service name in pg_service.conf that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See Section 32.17 ."],"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"LIBPQ-CONNECT-SERVICE\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eservice\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eService name to use for additional parameters. It specifies a service name in \u003ccode class=\"filename\"\u003epg_service.conf\u003c/code\u003e that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See \u003ca class=\"xref\" href=\"/docs/18/libpq-pgservice.html\" title=\"32.17. The Connection Service File\"\u003eSection 32.17\u003c/a\u003e.\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv class=\"sect1\" id=\"LIBPQ-PGSERVICE\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e32.17. The Connection Service File \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe connection service file allows libpq connection parameters to be associated with a single service name. That service name can then be specified using the \u003ccode class=\"literal\"\u003eservice\u003c/code\u003e key word in a libpq connection string, and the associated settings will be used. This allows connection parameters to be modified without requiring a recompile of the libpq-using application. The service name can also be specified using the \u003ccode class=\"envar\"\u003ePGSERVICE\u003c/code\u003e environment variable.\u003c/p\u003e\n\u003cp\u003eService names can be defined in either a per-user service file or a system-wide file. If the same service name exists in both the user and the system file, the user file takes precedence. By default, the per-user service file is named \u003ccode class=\"filename\"\u003e~/.pg_service.conf\u003c/code\u003e. On Microsoft Windows, it is named \u003ccode class=\"filename\"\u003e%APPDATA%\\postgresql\\.pg_service.conf\u003c/code\u003e (where \u003ccode class=\"filename\"\u003e%APPDATA%\u003c/code\u003e refers to the Application Data subdirectory in the user's profile). A different file name can be specified by setting the environment variable \u003ccode class=\"envar\"\u003ePGSERVICEFILE\u003c/code\u003e. The system-wide file is named \u003ccode class=\"filename\"\u003epg_service.conf\u003c/code\u003e. By default it is sought in the \u003ccode class=\"filename\"\u003eetc\u003c/code\u003e directory of the \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e installation (use \u003ccode class=\"literal\"\u003epg_config --sysconfdir\u003c/code\u003e to identify this directory precisely). Another directory, but not a different file name, can be specified by setting the environment variable \u003ccode class=\"envar\"\u003ePGSYSCONFDIR\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eEither service file uses an \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eINI file\u003c/span\u003e”\u003c/span\u003e format where the section name is the service name and the parameters are connection parameters; see \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2. Parameter Key Words\"\u003eSection 32.1.2\u003c/a\u003e for a list. For example:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003e# comment\n[mydb]\nhost=somehost\nport=5433\nuser=admin\n\u003c/pre\u003e\n\u003cp\u003eAn example file is provided in the \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e installation at \u003ccode class=\"filename\"\u003eshare/pg_service.conf.sample\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eConnection parameters obtained from a service file are combined with parameters obtained from other sources. A service file setting overrides the corresponding environment variable, and in turn can be overridden by a value given directly in the connection string. For example, using the above service file, a connection string \u003ccode class=\"literal\"\u003eservice=mydb port=5434\u003c/code\u003e will use host \u003ccode class=\"literal\"\u003esomehost\u003c/code\u003e, port \u003ccode class=\"literal\"\u003e5434\u003c/code\u003e, user \u003ccode class=\"literal\"\u003eadmin\u003c/code\u003e, and other parameters as set by environment variables or built-in defaults.\u003c/p\u003e\n\u003c/div\u003e\u003c/div\u003e","related":[{"label":"Connection service file","url":"/docs/18/libpq-pgservice.html"},{"label":"Password file","url":"/docs/18/libpq-pgpass.html"},{"label":"All libpq environment variables","url":"/docs/18/libpq-envars.html"}],"sections":[{"paragraphs":["The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb , PQsetdbLogin and PQsetdb if no value is directly specified by the calling code. These are useful to avoid hard-coding database connection information into simple client applications, for example.","Service names can be defined in either a per-user service file or a system-wide file. If the same service name exists in both the user and the system file, the user file takes precedence. By default, the per-user service file is named ~/.pg_service.conf . On Microsoft Windows, it is named %APPDATA%\\postgresql\\.pg_service.conf (where %APPDATA% refers to the Application Data subdirectory in the user's profile). A different file name can be specified by setting the environment variable PGSERVICEFILE . The system-wide file is named pg_service.conf . By default it is sought in the etc directory of the PostgreSQL installation (use pg_config --sysconfdir to identify this directory precisely). Another directory, but not a different file name, can be specified by setting the environment variable PGSYSCONFDIR .","Connection parameters obtained from a service file are combined with parameters obtained from other sources. A service file setting overrides the corresponding environment variable, and in turn can be overridden by a value given directly in the connection string. For example, using the above service file, a connection string service=mydb port=5434 will use host somehost , port 5434 , user admin , and other parameters as set by environment variables or built-in defaults."],"title":"Default resolution and service-file precedence"},{"paragraphs":["PGSERVICE behaves the same as the service connection parameter."],"title":"Environment variable evidence"},{"paragraphs":["Kerberos and GSSAPI authentication support specifying the service name"],"title":"Source declaration notes"},{"paragraphs":["PGSERVICE behaves the same as the service connection parameter.","PGSERVICEFILE specifies the name of the per-user connection service file (see Section 32.17 ). Defaults to ~/.pg_service.conf , or %APPDATA%\\postgresql\\.pg_service.conf on Microsoft Windows.","PGSYSCONFDIR sets the directory containing the pg_service.conf file and in a future version possibly other system-wide configuration files."],"title":"Service-file controls"}],"tables":[{"columns":[{"key":"name","label":"Variable"},{"key":"description","label":"Documented behavior"}],"key":"environment","rows":[{"description":"PGSERVICE behaves the same as the service connection parameter.","name":{"text":"PGSERVICE","url":"/docs/18/libpq-envars.html"}}],"title":"Environment fallback"}]}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
