{"Entry":{"collection":"conn","key":"passfile","name":"passfile","aliases":["PGPASSFILE","passfile"],"metadata":{"aliases":["PGPASSFILE","passfile"],"category":"Authentication","content_hash":"8f9b9f637244497d351363e861725cbbc6685324c4aa07cc73a978f8bb9a31bb","imported_at":"2026-09-30T00:40:35.017212+08:00","name":"passfile","name_zh":"","slug":"passfile","summary":"Specifies the name of the file used to store passwords (see Section 32.15 ). Defaults to ~/.pgpass , or %APPDATA%\\postgresql\\pgpass.conf on Microsoft Windows. (No error is reported if this file does not exist.)"}},"Definition":{"Collection":"conn","Key":"passfile","SourceDatabase":"center","Version":"18","SourceTable":"connection_parameter","SourceKey":"passfile","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","Facts":{"comparison_data":{"compiled_default_expression":"NULL","default_evidence":[],"definition":"Specifies the name of the file used to store passwords (see Section 32.16 ). Defaults to ~/.pgpass , or %APPDATA%\\postgresql\\pgpass.conf on Microsoft Windows. (No error is reported if this file does not exist.)","documented":true,"environment":"PGPASSFILE","keyword":"passfile"},"comparison_hash":"93a8cf70f4f9dba491e67b0727d45c1f3504ec58f20f951dbb4eeda1de7e38d4","default_evidence":[],"description":["Specifies the name of the file used to store passwords (see Section 32.16 ). Defaults to ~/.pgpass , or %APPDATA%\\postgresql\\pgpass.conf on Microsoft Windows. (No error is reported if this file does not exist.)"],"documented":true,"environment":[{"description":"PGPASSFILE behaves the same as the passfile connection parameter.","name":"PGPASSFILE","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":"PGPASSFILE"},{"label":"Compiled fallback expression","value":"NULL"}],"keyword":"passfile","manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"LIBPQ-CONNECT-PASSFILE\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003epassfile\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eSpecifies the name of the file used to store passwords (see \u003ca class=\"xref\" href=\"/docs/18/libpq-pgpass.html\" title=\"32.16. The Password File\"\u003eSection 32.16\u003c/a\u003e). Defaults to \u003ccode class=\"filename\"\u003e~/.pgpass\u003c/code\u003e, or \u003ccode class=\"filename\"\u003e%APPDATA%\\postgresql\\pgpass.conf\u003c/code\u003e on Microsoft Windows. (No error is reported if this file does not exist.)\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv class=\"sect1\" id=\"LIBPQ-PGPASS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e32.16. The Password File \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe file \u003ccode class=\"filename\"\u003e.pgpass\u003c/code\u003e in a user's home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise). On Unix systems, the directory can be specified by the \u003ccode class=\"envar\"\u003eHOME\u003c/code\u003e environment variable, or if undefined, the home directory of the effective user. On Microsoft Windows the file is named \u003ccode class=\"filename\"\u003e%APPDATA%\\postgresql\\pgpass.conf\u003c/code\u003e (where \u003ccode class=\"filename\"\u003e%APPDATA%\u003c/code\u003e refers to the Application Data subdirectory in the user's profile). Alternatively, the password file to use can be specified using the connection parameter \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNECT-PASSFILE\"\u003epassfile\u003c/a\u003e or the environment variable \u003ccode class=\"envar\"\u003ePGPASSFILE\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThis file should contain lines of the following format:\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ehostname\u003c/code\u003e\u003c/em\u003e:\u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e:\u003cem class=\"replaceable\"\u003e\u003ccode\u003edatabase\u003c/code\u003e\u003c/em\u003e:\u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e:\u003cem class=\"replaceable\"\u003e\u003ccode\u003epassword\u003c/code\u003e\u003c/em\u003e\n\u003c/pre\u003e\n\u003cp\u003e(You can add a reminder comment to the file by copying the line above and preceding it with \u003ccode class=\"literal\"\u003e#\u003c/code\u003e.) Each of the first four fields can be a literal value, or \u003ccode class=\"literal\"\u003e*\u003c/code\u003e, which matches anything. The password field from the first line that matches the current connection parameters will be used. (Therefore, put more-specific entries first when you are using wildcards.) If an entry needs to contain \u003ccode class=\"literal\"\u003e:\u003c/code\u003e or \u003ccode class=\"literal\"\u003e\\\u003c/code\u003e, escape this character with \u003ccode class=\"literal\"\u003e\\\u003c/code\u003e. The host name field is matched to the \u003ccode class=\"literal\"\u003ehost\u003c/code\u003e connection parameter if that is specified, otherwise to the \u003ccode class=\"literal\"\u003ehostaddr\u003c/code\u003e parameter if that is specified; if neither are given then the host name \u003ccode class=\"literal\"\u003elocalhost\u003c/code\u003e is searched for. The host name \u003ccode class=\"literal\"\u003elocalhost\u003c/code\u003e is also searched for when the connection is a Unix-domain socket connection and the \u003ccode class=\"literal\"\u003ehost\u003c/code\u003e parameter matches \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e's default socket directory path. In a standby server, a database field of \u003ccode class=\"literal\"\u003ereplication\u003c/code\u003e matches streaming replication connections made to the primary server. The database field is of limited usefulness otherwise, because users have the same password for all databases in the same cluster.\u003c/p\u003e\n\u003cp\u003eOn Unix systems, the permissions on a password file must disallow any access to world or group; achieve this by a command such as \u003ccode class=\"command\"\u003echmod 0600 ~/.pgpass\u003c/code\u003e. If the permissions are less strict than this, the file will be ignored. On Microsoft Windows, it is assumed that the file is stored in a directory that is secure, so no special permissions check is made.\u003c/p\u003e\n\u003c/div\u003e\u003c/div\u003e","manual_path":"libpq-connect.html#LIBPQ-CONNECT-PASSFILE","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":["PGPASSFILE behaves the same as the passfile connection parameter."],"title":"Environment variable evidence"}],"signature":"passfile","source_option":{"compiled_default_expression":"NULL","declaration":"\"passfile\", \"PGPASSFILE\", NULL, NULL, \"Database-Password-File\", \"\", 64, offsetof(struct pg_conn, pgpassfile)","environment":"PGPASSFILE","keyword":"passfile","source_notes":[]},"sources":[{"anchor":"LIBPQ-CONNECT-PASSFILE","file":"libpq-connect.html","label":"18.6 English manual · libpq-connect.html","sha256":"c26a7fc3dcda6066cfe540641ae2690faf3d3c03277f30b4dfc2328ab45c212f","url":"/docs/18/libpq-connect.html#LIBPQ-CONNECT-PASSFILE"},{"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"},{"anchor":"","file":"libpq-pgpass.html","label":"18.6 English manual · libpq-pgpass.html","sha256":"b926f6b6ae4e7d962b276438025b3d894c1442a69d861200c7d5b09be48f38d5","url":"/docs/18/libpq-pgpass.html"}],"tables":[{"columns":[{"key":"name","label":"Variable"},{"key":"description","label":"Documented behavior"}],"key":"environment","rows":[{"description":"PGPASSFILE behaves the same as the passfile connection parameter.","name":{"text":"PGPASSFILE","url":"/docs/18/libpq-envars.html"}}],"title":"Environment fallback"}]},"ManualEvidence":{"manual_path":"libpq-connect.html#LIBPQ-CONNECT-PASSFILE","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-PASSFILE","file":"libpq-connect.html","label":"18.6 English manual · libpq-connect.html","sha256":"c26a7fc3dcda6066cfe540641ae2690faf3d3c03277f30b4dfc2328ab45c212f","url":"/docs/18/libpq-connect.html#LIBPQ-CONNECT-PASSFILE"},{"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"},{"anchor":"","file":"libpq-pgpass.html","label":"18.6 English manual · libpq-pgpass.html","sha256":"b926f6b6ae4e7d962b276438025b3d894c1442a69d861200c7d5b09be48f38d5","url":"/docs/18/libpq-pgpass.html"}]},"MeasuredEvidence":{}},"Text":{"Collection":"conn","Key":"passfile","SourceDatabase":"center","Version":"18","Locale":"en","Title":"passfile","Summary":"Specifies the name of the file used to store passwords (see Section 32.16 ). Defaults to ~/.pgpass , or %APPDATA%\\postgresql\\pgpass.conf on Microsoft Windows. (No error is reported if this file does not exist.)","BodyHTML":"\u003cdiv\u003e\u003cdl\u003e\u003cdt id=\"LIBPQ-CONNECT-PASSFILE\"\u003e\u003cspan\u003e\u003ccode\u003epassfile\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eSpecifies the name of the file used to store passwords (see \u003ca href=\"/docs/18/libpq-pgpass.html\" rel=\"nofollow\"\u003eSection 32.16\u003c/a\u003e). Defaults to \u003ccode\u003e~/.pgpass\u003c/code\u003e, or \u003ccode\u003e%APPDATA%\\postgresql\\pgpass.conf\u003c/code\u003e on Microsoft Windows. (No error is reported if this file does not exist.)\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv id=\"LIBPQ-PGPASS\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2\u003e32.16. The Password File \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe file \u003ccode\u003e.pgpass\u003c/code\u003e in a user\u0026#39;s home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise). On Unix systems, the directory can be specified by the \u003ccode\u003eHOME\u003c/code\u003e environment variable, or if undefined, the home directory of the effective user. On Microsoft Windows the file is named \u003ccode\u003e%APPDATA%\\postgresql\\pgpass.conf\u003c/code\u003e (where \u003ccode\u003e%APPDATA%\u003c/code\u003e refers to the Application Data subdirectory in the user\u0026#39;s profile). Alternatively, the password file to use can be specified using the connection parameter \u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-CONNECT-PASSFILE\" rel=\"nofollow\"\u003epassfile\u003c/a\u003e or the environment variable \u003ccode\u003ePGPASSFILE\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThis file should contain lines of the following format:\u003c/p\u003e\n\u003cpre\u003e\u003cem\u003e\u003ccode\u003ehostname\u003c/code\u003e\u003c/em\u003e:\u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e:\u003cem\u003e\u003ccode\u003edatabase\u003c/code\u003e\u003c/em\u003e:\u003cem\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e:\u003cem\u003e\u003ccode\u003epassword\u003c/code\u003e\u003c/em\u003e\n\u003c/pre\u003e\n\u003cp\u003e(You can add a reminder comment to the file by copying the line above and preceding it with \u003ccode\u003e#\u003c/code\u003e.) Each of the first four fields can be a literal value, or \u003ccode\u003e*\u003c/code\u003e, which matches anything. The password field from the first line that matches the current connection parameters will be used. (Therefore, put more-specific entries first when you are using wildcards.) If an entry needs to contain \u003ccode\u003e:\u003c/code\u003e or \u003ccode\u003e\\\u003c/code\u003e, escape this character with \u003ccode\u003e\\\u003c/code\u003e. The host name field is matched to the \u003ccode\u003ehost\u003c/code\u003e connection parameter if that is specified, otherwise to the \u003ccode\u003ehostaddr\u003c/code\u003e parameter if that is specified; if neither are given then the host name \u003ccode\u003elocalhost\u003c/code\u003e is searched for. The host name \u003ccode\u003elocalhost\u003c/code\u003e is also searched for when the connection is a Unix-domain socket connection and the \u003ccode\u003ehost\u003c/code\u003e parameter matches \u003cspan\u003elibpq\u003c/span\u003e\u0026#39;s default socket directory path. In a standby server, a database field of \u003ccode\u003ereplication\u003c/code\u003e matches streaming replication connections made to the primary server. The database field is of limited usefulness otherwise, because users have the same password for all databases in the same cluster.\u003c/p\u003e\n\u003cp\u003eOn Unix systems, the permissions on a password file must disallow any access to world or group; achieve this by a command such as \u003ccode\u003echmod 0600 ~/.pgpass\u003c/code\u003e. If the permissions are less strict than this, the file will be ignored. On Microsoft Windows, it is assumed that the file is stored in a directory that is secure, so no special permissions check is made.\u003c/p\u003e\n\u003c/div\u003e\u003c/div\u003e","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","ContentHash":"9c1215ed995a285575a6f3a380d2d19b72eccc7357b9837182f9b2e242ce5628","Payload":{"description":["Specifies the name of the file used to store passwords (see Section 32.16 ). Defaults to ~/.pgpass , or %APPDATA%\\postgresql\\pgpass.conf on Microsoft Windows. (No error is reported if this file does not exist.)"],"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"LIBPQ-CONNECT-PASSFILE\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003epassfile\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eSpecifies the name of the file used to store passwords (see \u003ca class=\"xref\" href=\"/docs/18/libpq-pgpass.html\" title=\"32.16. The Password File\"\u003eSection 32.16\u003c/a\u003e). Defaults to \u003ccode class=\"filename\"\u003e~/.pgpass\u003c/code\u003e, or \u003ccode class=\"filename\"\u003e%APPDATA%\\postgresql\\pgpass.conf\u003c/code\u003e on Microsoft Windows. (No error is reported if this file does not exist.)\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv class=\"sect1\" id=\"LIBPQ-PGPASS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e32.16. The Password File \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe file \u003ccode class=\"filename\"\u003e.pgpass\u003c/code\u003e in a user's home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise). On Unix systems, the directory can be specified by the \u003ccode class=\"envar\"\u003eHOME\u003c/code\u003e environment variable, or if undefined, the home directory of the effective user. On Microsoft Windows the file is named \u003ccode class=\"filename\"\u003e%APPDATA%\\postgresql\\pgpass.conf\u003c/code\u003e (where \u003ccode class=\"filename\"\u003e%APPDATA%\u003c/code\u003e refers to the Application Data subdirectory in the user's profile). Alternatively, the password file to use can be specified using the connection parameter \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNECT-PASSFILE\"\u003epassfile\u003c/a\u003e or the environment variable \u003ccode class=\"envar\"\u003ePGPASSFILE\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThis file should contain lines of the following format:\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ehostname\u003c/code\u003e\u003c/em\u003e:\u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e:\u003cem class=\"replaceable\"\u003e\u003ccode\u003edatabase\u003c/code\u003e\u003c/em\u003e:\u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e:\u003cem class=\"replaceable\"\u003e\u003ccode\u003epassword\u003c/code\u003e\u003c/em\u003e\n\u003c/pre\u003e\n\u003cp\u003e(You can add a reminder comment to the file by copying the line above and preceding it with \u003ccode class=\"literal\"\u003e#\u003c/code\u003e.) Each of the first four fields can be a literal value, or \u003ccode class=\"literal\"\u003e*\u003c/code\u003e, which matches anything. The password field from the first line that matches the current connection parameters will be used. (Therefore, put more-specific entries first when you are using wildcards.) If an entry needs to contain \u003ccode class=\"literal\"\u003e:\u003c/code\u003e or \u003ccode class=\"literal\"\u003e\\\u003c/code\u003e, escape this character with \u003ccode class=\"literal\"\u003e\\\u003c/code\u003e. The host name field is matched to the \u003ccode class=\"literal\"\u003ehost\u003c/code\u003e connection parameter if that is specified, otherwise to the \u003ccode class=\"literal\"\u003ehostaddr\u003c/code\u003e parameter if that is specified; if neither are given then the host name \u003ccode class=\"literal\"\u003elocalhost\u003c/code\u003e is searched for. The host name \u003ccode class=\"literal\"\u003elocalhost\u003c/code\u003e is also searched for when the connection is a Unix-domain socket connection and the \u003ccode class=\"literal\"\u003ehost\u003c/code\u003e parameter matches \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e's default socket directory path. In a standby server, a database field of \u003ccode class=\"literal\"\u003ereplication\u003c/code\u003e matches streaming replication connections made to the primary server. The database field is of limited usefulness otherwise, because users have the same password for all databases in the same cluster.\u003c/p\u003e\n\u003cp\u003eOn Unix systems, the permissions on a password file must disallow any access to world or group; achieve this by a command such as \u003ccode class=\"command\"\u003echmod 0600 ~/.pgpass\u003c/code\u003e. If the permissions are less strict than this, the file will be ignored. On Microsoft Windows, it is assumed that the file is stored in a directory that is secure, so no special permissions check is made.\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":["PGPASSFILE behaves the same as the passfile connection parameter."],"title":"Environment variable evidence"}],"tables":[{"columns":[{"key":"name","label":"Variable"},{"key":"description","label":"Documented behavior"}],"key":"environment","rows":[{"description":"PGPASSFILE behaves the same as the passfile connection parameter.","name":{"text":"PGPASSFILE","url":"/docs/18/libpq-envars.html"}}],"title":"Environment fallback"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
