{"Entry":{"collection":"psql","key":"cmd-63-6f-6e-6e-65-63-74","name":"\\connect","aliases":["\\connect"],"metadata":{"aliases":["\\connect"],"category":"Connections and sessions","content_hash":"2fe194f836053f75ea64ba847566f356437cf65fbf3a364a1500ab2ef969ea31","imported_at":"2026-09-30T00:40:44.724198+08:00","name":"\\connect","name_zh":"","slug":"cmd-63-6f-6e-6e-65-63-74","summary":"Establishes a new connection to a PostgreSQL server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a conninfo connection string as detailed in Section 32.1.1 . If no arguments are given, a new connection is made using the same parameters as before."}},"Definition":{"Collection":"psql","Key":"cmd-63-6f-6e-6e-65-63-74","SourceDatabase":"center","Version":"18","SourceTable":"psql_command","SourceKey":"cmd-63-6f-6e-6e-65-63-74","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","Facts":{"command":"\\connect","comparison_data":{"definition":"Establishes a new connection to a PostgreSQL server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a conninfo connection string as detailed in Section 32.1.1 . If no arguments are given, a new connection is made using the same parameters as before. Specifying any of dbname , username , host or port as - is equivalent to omitting that parameter. The new connection can re-use connection parameters from the previous connection; not only database name, user, host, and port, but other settings such as sslmode . By default, parameters are re-used in the positional syntax, but not when a conninfo string is given. Passing a first argument of -reuse-previous=on or -reuse-previous=off overrides that default. If parameters are re-used, then any parameter not explicitly specified as a positional parameter or in the conninfo string is taken from the existing connection's parameters. An exception is that if the host setting is changed from its previous value using the positional syntax, any hostaddr setting present in the existing connection's parameters is dropped. Also, any password used for the existing connection will be re-used only if the user, host, and port settings are not changed. When the command neither specifies nor reuses a particular parameter, the libpq default is used. If the new connection is successfully made, the previous connection is closed. If the connection attempt fails (wrong user name, access denied, etc.), the previous connection will be kept if psql is in interactive mode. But when executing a non-interactive script, the old connection is closed and an error is reported. That may or may not terminate the script; if it does not, all database-accessing commands will fail until another \\connect command is successfully executed. This distinction was chosen as a user convenience against typos on the one hand, and a safety mechanism that scripts are not accidentally acting on the wrong database on the other hand. Note that whenever a \\connect command attempts to re-use parameters, the values re-used are those of the last successful connection, not of any failed attempts made subsequently. However, in the case of a non-interactive \\connect failure, no parameters are allowed to be re-used later, since the script would likely be expecting the values from the failed \\connect to be re-used. Examples: =\u003e \\c mydb myuser host.dom 6432 =\u003e \\c service=foo =\u003e \\c \"host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable\" =\u003e \\c -reuse-previous=on sslmode=require -- changes only sslmode =\u003e \\c postgresql://tom@localhost/mydb?application_name=myapp","modifiers":[],"signature":"\\c or \\connect [ -reuse-previous= on|off ] [ dbname [ username ] [ host ] [ port ] | conninfo ]","spellings":["\\c","\\connect"]},"comparison_hash":"7eec058f2a8c37a10165d730115ffc7243eb563659ce0c6d0f320323d2903d6c","description":["Establishes a new connection to a PostgreSQL server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a conninfo connection string as detailed in Section 32.1.1 . If no arguments are given, a new connection is made using the same parameters as before."],"facts":[{"label":"Client","value":"psql 18.6"},{"label":"Case-sensitive spelling","value":"\\connect"}],"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"APP-PSQL-META-COMMAND-C-LC\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\c\u003c/code\u003e or \u003ccode class=\"literal\"\u003e\\connect [ -reuse-previous=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eon|off\u003c/code\u003e\u003c/em\u003e ] [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e ] [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e ] [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e ] | \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e ]\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eEstablishes a new connection to a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e connection string as detailed in \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1. Connection Strings\"\u003eSection 32.1.1\u003c/a\u003e. If no arguments are given, a new connection is made using the same parameters as before.\u003c/p\u003e\n\u003cp\u003eSpecifying any of \u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e, \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e, \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e or \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e as \u003ccode class=\"literal\"\u003e-\u003c/code\u003e is equivalent to omitting that parameter.\u003c/p\u003e\n\u003cp\u003eThe new connection can re-use connection parameters from the previous connection; not only database name, user, host, and port, but other settings such as \u003cem class=\"replaceable\"\u003e\u003ccode\u003esslmode\u003c/code\u003e\u003c/em\u003e. By default, parameters are re-used in the positional syntax, but not when a \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is given. Passing a first argument of \u003ccode class=\"literal\"\u003e-reuse-previous=on\u003c/code\u003e or \u003ccode class=\"literal\"\u003e-reuse-previous=off\u003c/code\u003e overrides that default. If parameters are re-used, then any parameter not explicitly specified as a positional parameter or in the \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is taken from the existing connection's parameters. An exception is that if the \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e setting is changed from its previous value using the positional syntax, any \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehostaddr\u003c/code\u003e\u003c/em\u003e setting present in the existing connection's parameters is dropped. Also, any password used for the existing connection will be re-used only if the user, host, and port settings are not changed. When the command neither specifies nor reuses a particular parameter, the \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e default is used.\u003c/p\u003e\n\u003cp\u003eIf the new connection is successfully made, the previous connection is closed. If the connection attempt fails (wrong user name, access denied, etc.), the previous connection will be kept if \u003cspan class=\"application\"\u003epsql\u003c/span\u003e is in interactive mode. But when executing a non-interactive script, the old connection is closed and an error is reported. That may or may not terminate the script; if it does not, all database-accessing commands will fail until another \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e command is successfully executed. This distinction was chosen as a user convenience against typos on the one hand, and a safety mechanism that scripts are not accidentally acting on the wrong database on the other hand. Note that whenever a \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e command attempts to re-use parameters, the values re-used are those of the last successful connection, not of any failed attempts made subsequently. However, in the case of a non-interactive \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e failure, no parameters are allowed to be re-used later, since the script would likely be expecting the values from the failed \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e to be re-used.\u003c/p\u003e\n\u003cp\u003eExamples:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003e=\u0026gt; \\c mydb myuser host.dom 6432\n=\u0026gt; \\c service=foo\n=\u0026gt; \\c \"host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable\"\n=\u0026gt; \\c -reuse-previous=on sslmode=require    -- changes only sslmode\n=\u0026gt; \\c postgresql://tom@localhost/mydb?application_name=myapp\n\u003c/pre\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","manual_path":"app-psql.html#APP-PSQL-META-COMMAND-C-LC","modifiers":[],"related":[{"label":"\\c","url":"/wiki/psql/cmd-63/?v=18"},{"label":"psql command-line options and complete manual","url":"/wiki/tool/psql/?v=18"}],"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":[],"signature":"\\c or \\connect [ -reuse-previous= on|off ] [ dbname [ username ] [ host ] [ port ] | conninfo ]","sources":[{"anchor":"APP-PSQL-META-COMMAND-C-LC","file":"app-psql.html","label":"18.6 English manual · app-psql.html","sha256":"fa2a1d39294b8854318e82e93f71272c645ed88150ecc2786c28902c3f32782c","url":"/docs/18/app-psql.html#APP-PSQL-META-COMMAND-C-LC"}],"spellings":["\\c","\\connect"],"tables":[{"columns":[{"key":"command","label":"Command"},{"key":"modifiers","label":"Documented suffix modifiers"}],"key":"spellings","rows":[{"command":{"text":"\\c","url":"/wiki/psql/cmd-63/?v=18"},"modifiers":"None listed in this signature"},{"command":{"text":"\\connect","url":"/wiki/psql/cmd-63-6f-6e-6e-65-63-74/?v=18"},"modifiers":"None listed in this signature"}],"title":"Spellings in this manual definition"}]},"ManualEvidence":{"manual_path":"app-psql.html#APP-PSQL-META-COMMAND-C-LC","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":"APP-PSQL-META-COMMAND-C-LC","file":"app-psql.html","label":"18.6 English manual · app-psql.html","sha256":"fa2a1d39294b8854318e82e93f71272c645ed88150ecc2786c28902c3f32782c","url":"/docs/18/app-psql.html#APP-PSQL-META-COMMAND-C-LC"}]},"MeasuredEvidence":{}},"Text":{"Collection":"psql","Key":"cmd-63-6f-6e-6e-65-63-74","SourceDatabase":"center","Version":"18","Locale":"en","Title":"\\connect","Summary":"Establishes a new connection to a PostgreSQL server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a conninfo connection string as detailed in Section 32.1.1 . If no arguments are given, a new connection is made using the same parameters as before.","BodyHTML":"\u003cdiv\u003e\u003cdl\u003e\u003cdt id=\"APP-PSQL-META-COMMAND-C-LC\"\u003e\u003cspan\u003e\u003ccode\u003e\\c\u003c/code\u003e or \u003ccode\u003e\\connect [ -reuse-previous=\u003cem\u003e\u003ccode\u003eon|off\u003c/code\u003e\u003c/em\u003e ] [ \u003cem\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e [ \u003cem\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e ] [ \u003cem\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e ] [ \u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e ] | \u003cem\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e ]\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eEstablishes a new connection to a \u003cspan\u003ePostgreSQL\u003c/span\u003e server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a \u003cem\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e connection string as detailed in \u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" rel=\"nofollow\"\u003eSection 32.1.1\u003c/a\u003e. If no arguments are given, a new connection is made using the same parameters as before.\u003c/p\u003e\n\u003cp\u003eSpecifying any of \u003cem\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e, \u003cem\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e, \u003cem\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e or \u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e as \u003ccode\u003e-\u003c/code\u003e is equivalent to omitting that parameter.\u003c/p\u003e\n\u003cp\u003eThe new connection can re-use connection parameters from the previous connection; not only database name, user, host, and port, but other settings such as \u003cem\u003e\u003ccode\u003esslmode\u003c/code\u003e\u003c/em\u003e. By default, parameters are re-used in the positional syntax, but not when a \u003cem\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is given. Passing a first argument of \u003ccode\u003e-reuse-previous=on\u003c/code\u003e or \u003ccode\u003e-reuse-previous=off\u003c/code\u003e overrides that default. If parameters are re-used, then any parameter not explicitly specified as a positional parameter or in the \u003cem\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is taken from the existing connection\u0026#39;s parameters. An exception is that if the \u003cem\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e setting is changed from its previous value using the positional syntax, any \u003cem\u003e\u003ccode\u003ehostaddr\u003c/code\u003e\u003c/em\u003e setting present in the existing connection\u0026#39;s parameters is dropped. Also, any password used for the existing connection will be re-used only if the user, host, and port settings are not changed. When the command neither specifies nor reuses a particular parameter, the \u003cspan\u003elibpq\u003c/span\u003e default is used.\u003c/p\u003e\n\u003cp\u003eIf the new connection is successfully made, the previous connection is closed. If the connection attempt fails (wrong user name, access denied, etc.), the previous connection will be kept if \u003cspan\u003epsql\u003c/span\u003e is in interactive mode. But when executing a non-interactive script, the old connection is closed and an error is reported. That may or may not terminate the script; if it does not, all database-accessing commands will fail until another \u003ccode\u003e\\connect\u003c/code\u003e command is successfully executed. This distinction was chosen as a user convenience against typos on the one hand, and a safety mechanism that scripts are not accidentally acting on the wrong database on the other hand. Note that whenever a \u003ccode\u003e\\connect\u003c/code\u003e command attempts to re-use parameters, the values re-used are those of the last successful connection, not of any failed attempts made subsequently. However, in the case of a non-interactive \u003ccode\u003e\\connect\u003c/code\u003e failure, no parameters are allowed to be re-used later, since the script would likely be expecting the values from the failed \u003ccode\u003e\\connect\u003c/code\u003e to be re-used.\u003c/p\u003e\n\u003cp\u003eExamples:\u003c/p\u003e\n\u003cpre\u003e=\u0026gt; \\c mydb myuser host.dom 6432\n=\u0026gt; \\c service=foo\n=\u0026gt; \\c \u0026#34;host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable\u0026#34;\n=\u0026gt; \\c -reuse-previous=on sslmode=require    -- changes only sslmode\n=\u0026gt; \\c postgresql://tom@localhost/mydb?application_name=myapp\n\u003c/pre\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","ContentHash":"434a3f8fa4e87e4804dbc1212e9bc74c915da9c6e3beb3fc0e44ea241092fff2","Payload":{"description":["Establishes a new connection to a PostgreSQL server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a conninfo connection string as detailed in Section 32.1.1 . If no arguments are given, a new connection is made using the same parameters as before."],"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"APP-PSQL-META-COMMAND-C-LC\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\c\u003c/code\u003e or \u003ccode class=\"literal\"\u003e\\connect [ -reuse-previous=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eon|off\u003c/code\u003e\u003c/em\u003e ] [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e ] [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e ] [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e ] | \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e ]\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eEstablishes a new connection to a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e connection string as detailed in \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1. Connection Strings\"\u003eSection 32.1.1\u003c/a\u003e. If no arguments are given, a new connection is made using the same parameters as before.\u003c/p\u003e\n\u003cp\u003eSpecifying any of \u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e, \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e, \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e or \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e as \u003ccode class=\"literal\"\u003e-\u003c/code\u003e is equivalent to omitting that parameter.\u003c/p\u003e\n\u003cp\u003eThe new connection can re-use connection parameters from the previous connection; not only database name, user, host, and port, but other settings such as \u003cem class=\"replaceable\"\u003e\u003ccode\u003esslmode\u003c/code\u003e\u003c/em\u003e. By default, parameters are re-used in the positional syntax, but not when a \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is given. Passing a first argument of \u003ccode class=\"literal\"\u003e-reuse-previous=on\u003c/code\u003e or \u003ccode class=\"literal\"\u003e-reuse-previous=off\u003c/code\u003e overrides that default. If parameters are re-used, then any parameter not explicitly specified as a positional parameter or in the \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is taken from the existing connection's parameters. An exception is that if the \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e setting is changed from its previous value using the positional syntax, any \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehostaddr\u003c/code\u003e\u003c/em\u003e setting present in the existing connection's parameters is dropped. Also, any password used for the existing connection will be re-used only if the user, host, and port settings are not changed. When the command neither specifies nor reuses a particular parameter, the \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e default is used.\u003c/p\u003e\n\u003cp\u003eIf the new connection is successfully made, the previous connection is closed. If the connection attempt fails (wrong user name, access denied, etc.), the previous connection will be kept if \u003cspan class=\"application\"\u003epsql\u003c/span\u003e is in interactive mode. But when executing a non-interactive script, the old connection is closed and an error is reported. That may or may not terminate the script; if it does not, all database-accessing commands will fail until another \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e command is successfully executed. This distinction was chosen as a user convenience against typos on the one hand, and a safety mechanism that scripts are not accidentally acting on the wrong database on the other hand. Note that whenever a \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e command attempts to re-use parameters, the values re-used are those of the last successful connection, not of any failed attempts made subsequently. However, in the case of a non-interactive \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e failure, no parameters are allowed to be re-used later, since the script would likely be expecting the values from the failed \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e to be re-used.\u003c/p\u003e\n\u003cp\u003eExamples:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003e=\u0026gt; \\c mydb myuser host.dom 6432\n=\u0026gt; \\c service=foo\n=\u0026gt; \\c \"host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable\"\n=\u0026gt; \\c -reuse-previous=on sslmode=require    -- changes only sslmode\n=\u0026gt; \\c postgresql://tom@localhost/mydb?application_name=myapp\n\u003c/pre\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","related":[{"label":"\\c","url":"/wiki/psql/cmd-63/?v=18"},{"label":"psql command-line options and complete manual","url":"/wiki/tool/psql/?v=18"}],"sections":[],"tables":[{"columns":[{"key":"command","label":"Command"},{"key":"modifiers","label":"Documented suffix modifiers"}],"key":"spellings","rows":[{"command":{"text":"\\c","url":"/wiki/psql/cmd-63/?v=18"},"modifiers":"None listed in this signature"},{"command":{"text":"\\connect","url":"/wiki/psql/cmd-63-6f-6e-6e-65-63-74/?v=18"},"modifiers":"None listed in this signature"}],"title":"Spellings in this manual definition"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":[{"Version":"18","Ordinal":0,"Command":"\\c","Signature":"\\c or \\connect [ -reuse-previous= on|off ] [ dbname [ username ] [ host ] [ port ] | conninfo ]","Modifiers":[]},{"Version":"18","Ordinal":1,"Command":"\\connect","Signature":"\\c or \\connect [ -reuse-previous= on|off ] [ dbname [ username ] [ host ] [ port ] | conninfo ]","Modifiers":[]}],"SQLState":null,"Evidence":null}
