{"Entry":{"collection":"psql","key":"cmd-63","name":"\\c","aliases":["\\c"],"metadata":{"aliases":["\\c"],"category":"Connections and sessions","content_hash":"9981d1e7b9bd32a2290dd0b63a27f1cb740fff5868fb6e7a2fd9a405f32f6c58","derived_content_hash":"3726f6695bb2d054dd1fac55a4f951b894137b0bd5a19aa561543dd733313ea4","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:44.711381+08:00","name":"\\c","name_zh":"","slug":"cmd-63","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","SourceDatabase":"center","Version":"18","SourceTable":"psql_command","SourceKey":"cmd-63","SourceRevision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","Facts":{"command":"\\c","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."],"description_zh":"建立到 PostgreSQL 服务器的新连接。可以使用位置语法（数据库名称、用户、主机和端口中的一个或多个）指定要使用的连接参数，也可以使用 conninfo 连接字符串，详见 第 32.1.1 节 。如果没有给出参数，则使用与之前相同的参数建立新连接。","description_zh_html":"\u003cdd\u003e\u003cp\u003e\n        建立到 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 服务器的新连接。可以使用位置语法（数据库名称、用户、主机和端口中的一个或多个）指定要使用的连接参数，也可以使用 \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e 连接字符串，详见\u003ca class=\"xref\" href=\"/zh/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1. 连接字符串\"\u003e第 32.1.1 节\u003c/a\u003e。如果没有给出参数，则使用与之前相同的参数建立新连接。\n        \u003c/p\u003e\u003cp\u003e\n        将 \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 或\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e 中的任意一个指定为\n        \u003ccode class=\"literal\"\u003e-\u003c/code\u003e，等同于省略该参数。\n        \u003c/p\u003e\u003cp\u003e\n        新连接可以重用前一个连接的连接参数；不仅包括数据库名称、用户、主机和端口，还包括其他设置，如 \u003cem class=\"replaceable\"\u003e\u003ccode\u003esslmode\u003c/code\u003e\u003c/em\u003e。默认情况下，参数在位置语法中被重用，但在给定 \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e 字符串时不会被重用。传递 \u003ccode class=\"literal\"\u003e-reuse-previous=on\u003c/code\u003e 或 \u003ccode class=\"literal\"\u003e-reuse-previous=off\u003c/code\u003e 作为第一个参数将覆盖该默认设置。如果参数被重用，则任何未明确指定为位置参数或在 \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e 字符串中的参数将从现有连接的参数中获取。一个例外是，如果使用位置语法更改 \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e 设置，使其不同于先前的值，则现有连接参数中存在的任何 \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehostaddr\u003c/code\u003e\u003c/em\u003e 设置将被删除。此外，仅当用户、主机和端口设置未更改时，才会重用现有连接使用的任何密码。当命令既不指定也不重用特定参数时，将使用 \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e 的默认值。\n        \u003c/p\u003e\u003cp\u003e\n        如果新连接成功建立，则关闭先前的连接。如果连接尝试失败（用户名错误，访问被拒绝等），且 \u003cspan class=\"application\"\u003epsql\u003c/span\u003e 处于交互模式，则保留先前的连接。但在执行非交互脚本时，旧连接将被关闭并报告错误。这可能会或可能不会终止脚本；如果没有终止，直到成功执行另一个\u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e 命令之前，所有访问数据库的命令都将失败。采用这种区别，一方面是为了方便用户应对输入笔误，另一方面是为了防止脚本意外操作错误的数据库。请注意，每当\u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e 命令尝试重新使用参数时，重新使用的值是最后一个成功连接的值，而不是随后的任何失败尝试的值。但是，在非交互\u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e 失败的情况下，不允许稍后重新使用参数，因为脚本可能期望从失败的\u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e 中重新使用值。\n        \u003c/p\u003e\u003cp\u003e\n        示例：\n        \u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\n=\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    -- 仅更改 sslmode\n=\u0026gt; \\c postgresql://tom@localhost/mydb?application_name=myapp\n\u003c/pre\u003e\u003c/dd\u003e","documentation_revision":{"inputs":[{"file":"app-psql.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","version":"18.7"},{"file":"app-psql.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"cb475c53a16d9e06358f5e6c9c5649645db92568cfd319f230c62c9f57ae090b","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"},"facts":[{"label":"Client","value":"psql 18.7"},{"label":"Case-sensitive spelling","value":"\\c"}],"facts_zh":[{"label":"客户端","value":"psql 18.7"},{"label":"区分大小写的写法","value":"\\c"}],"localization":{"documentation_release":"18.7","language":"en","source_language":"en","source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552","status":"same-version-reviewed-manual"},"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\u003cp\u003e\n        Establishes a new connection to a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e\n        server.  The connection parameters to use can be specified either\n        using a positional syntax (one or more of database name, user,\n        host, and port), or using a \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e\n        connection string as detailed in\n        \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\n        new connection is made using the same parameters as before.\n        \u003c/p\u003e\u003cp\u003e\n        Specifying any\n        of \u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e,\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e,\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e or\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\n        as \u003ccode class=\"literal\"\u003e-\u003c/code\u003e is equivalent to omitting that parameter.\n        \u003c/p\u003e\u003cp\u003e\n        The new connection can re-use connection parameters from the previous\n        connection; not only database name, user, host, and port, but other\n        settings such as \u003cem class=\"replaceable\"\u003e\u003ccode\u003esslmode\u003c/code\u003e\u003c/em\u003e.  By default,\n        parameters are re-used in the positional syntax, but not when\n        a \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is given.  Passing a\n        first argument of \u003ccode class=\"literal\"\u003e-reuse-previous=on\u003c/code\u003e\n        or \u003ccode class=\"literal\"\u003e-reuse-previous=off\u003c/code\u003e overrides that default.  If\n        parameters are re-used, then any parameter not explicitly specified as\n        a positional parameter or in the \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e\n        string is taken from the existing connection's parameters.  An\n        exception is that if the \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e setting\n        is changed from its previous value using the positional syntax,\n        any \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehostaddr\u003c/code\u003e\u003c/em\u003e setting present in the\n        existing connection's parameters is dropped.\n        Also, any password used for the existing connection will be re-used\n        only if the user, host, and port settings are not changed.\n        When the command neither specifies nor reuses a particular parameter,\n        the \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e default is used.\n        \u003c/p\u003e\u003cp\u003e\n        If the new connection is successfully made, the previous\n        connection is closed.\n        If the connection attempt fails (wrong user name, access\n        denied, etc.), the previous connection will be kept if\n        \u003cspan class=\"application\"\u003epsql\u003c/span\u003e is in interactive mode.  But when\n        executing a non-interactive script, the old connection is closed\n        and an error is reported.  That may or may not terminate the\n        script; if it does not, all database-accessing commands will fail\n        until another \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e command is successfully\n        executed.  This distinction was chosen as\n        a user convenience against typos on the one hand, and a safety\n        mechanism that scripts are not accidentally acting on the\n        wrong database on the other hand.\n        Note that whenever a \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e command attempts\n        to re-use parameters, the values re-used are those of the last\n        successful connection, not of any failed attempts made subsequently.\n        However, in the case of a\n        non-interactive \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e failure, no parameters\n        are allowed to be re-used later, since the script would likely be\n        expecting the values from the failed \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e\n        to be re-used.\n        \u003c/p\u003e\u003cp\u003e\n        Examples:\n        \u003c/p\u003e\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\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","manual_path":"app-psql.html#APP-PSQL-META-COMMAND-C-LC","modifiers":[],"related":[{"label":"\\connect","url":"/wiki/psql/cmd-63-6f-6e-6e-65-63-74/?v=18"},{"label":"psql command-line options and complete manual","url":"/wiki/tool/psql/?v=18"}],"related_zh":[{"label":"\\connect","url":"/wiki/psql/cmd-63-6f-6e-6e-65-63-74/?v=18"},{"label":"psql 命令行选项及完整手册","url":"/wiki/tool/psql/?v=18"}],"release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.7","major":"18","manifest":{"major":"18","release":"18.7","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd","source_url":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2"},"ref":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2","revision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd"},"sections":[],"sections_zh":[],"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.7 English manual · app-psql.html","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","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"}],"tables_zh":[{"columns":[{"key":"command","label":"命令"},{"key":"modifiers","label":"手册中的后缀修饰符"}],"key":"spellings","rows":[{"command":{"text":"\\c","url":"/wiki/psql/cmd-63/?v=18"},"modifiers":"此语法签名未列出"},{"command":{"text":"\\connect","url":"/wiki/psql/cmd-63-6f-6e-6e-65-63-74/?v=18"},"modifiers":"此语法签名未列出"}],"title":"本版手册中的写法"}],"zh_from":"same-version-manual"},"ManualEvidence":{"manual_path":"app-psql.html#APP-PSQL-META-COMMAND-C-LC","release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.7","major":"18","manifest":{"major":"18","release":"18.7","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd","source_url":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2"},"ref":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2","revision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd"},"sources":[{"anchor":"APP-PSQL-META-COMMAND-C-LC","file":"app-psql.html","label":"18.7 English manual · app-psql.html","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","url":"/docs/18/app-psql.html#APP-PSQL-META-COMMAND-C-LC"}]},"MeasuredEvidence":{}},"Text":{"Collection":"psql","Key":"cmd-63","SourceDatabase":"center","Version":"18","Locale":"en","Title":"\\c","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\u003cp\u003e\n        Establishes a new connection to a \u003cspan\u003ePostgreSQL\u003c/span\u003e\n        server.  The connection parameters to use can be specified either\n        using a positional syntax (one or more of database name, user,\n        host, and port), or using a \u003cem\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e\n        connection string as detailed in\n        \u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" rel=\"nofollow\"\u003eSection 32.1.1\u003c/a\u003e.  If no arguments are given, a\n        new connection is made using the same parameters as before.\n        \u003c/p\u003e\u003cp\u003e\n        Specifying any\n        of \u003cem\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e,\n        \u003cem\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e,\n        \u003cem\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e or\n        \u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\n        as \u003ccode\u003e-\u003c/code\u003e is equivalent to omitting that parameter.\n        \u003c/p\u003e\u003cp\u003e\n        The new connection can re-use connection parameters from the previous\n        connection; not only database name, user, host, and port, but other\n        settings such as \u003cem\u003e\u003ccode\u003esslmode\u003c/code\u003e\u003c/em\u003e.  By default,\n        parameters are re-used in the positional syntax, but not when\n        a \u003cem\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is given.  Passing a\n        first argument of \u003ccode\u003e-reuse-previous=on\u003c/code\u003e\n        or \u003ccode\u003e-reuse-previous=off\u003c/code\u003e overrides that default.  If\n        parameters are re-used, then any parameter not explicitly specified as\n        a positional parameter or in the \u003cem\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e\n        string is taken from the existing connection\u0026#39;s parameters.  An\n        exception is that if the \u003cem\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e setting\n        is changed from its previous value using the positional syntax,\n        any \u003cem\u003e\u003ccode\u003ehostaddr\u003c/code\u003e\u003c/em\u003e setting present in the\n        existing connection\u0026#39;s parameters is dropped.\n        Also, any password used for the existing connection will be re-used\n        only if the user, host, and port settings are not changed.\n        When the command neither specifies nor reuses a particular parameter,\n        the \u003cspan\u003elibpq\u003c/span\u003e default is used.\n        \u003c/p\u003e\u003cp\u003e\n        If the new connection is successfully made, the previous\n        connection is closed.\n        If the connection attempt fails (wrong user name, access\n        denied, etc.), the previous connection will be kept if\n        \u003cspan\u003epsql\u003c/span\u003e is in interactive mode.  But when\n        executing a non-interactive script, the old connection is closed\n        and an error is reported.  That may or may not terminate the\n        script; if it does not, all database-accessing commands will fail\n        until another \u003ccode\u003e\\connect\u003c/code\u003e command is successfully\n        executed.  This distinction was chosen as\n        a user convenience against typos on the one hand, and a safety\n        mechanism that scripts are not accidentally acting on the\n        wrong database on the other hand.\n        Note that whenever a \u003ccode\u003e\\connect\u003c/code\u003e command attempts\n        to re-use parameters, the values re-used are those of the last\n        successful connection, not of any failed attempts made subsequently.\n        However, in the case of a\n        non-interactive \u003ccode\u003e\\connect\u003c/code\u003e failure, no parameters\n        are allowed to be re-used later, since the script would likely be\n        expecting the values from the failed \u003ccode\u003e\\connect\u003c/code\u003e\n        to be re-used.\n        \u003c/p\u003e\u003cp\u003e\n        Examples:\n        \u003c/p\u003e\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\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","SourceRevision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","ContentHash":"f0a5d62234e55ea09244f7444aea673c1e7e3eb0a68777ce3d1859ed66f1f4d6","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\u003cp\u003e\n        Establishes a new connection to a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e\n        server.  The connection parameters to use can be specified either\n        using a positional syntax (one or more of database name, user,\n        host, and port), or using a \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e\n        connection string as detailed in\n        \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\n        new connection is made using the same parameters as before.\n        \u003c/p\u003e\u003cp\u003e\n        Specifying any\n        of \u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e,\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e,\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e or\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\n        as \u003ccode class=\"literal\"\u003e-\u003c/code\u003e is equivalent to omitting that parameter.\n        \u003c/p\u003e\u003cp\u003e\n        The new connection can re-use connection parameters from the previous\n        connection; not only database name, user, host, and port, but other\n        settings such as \u003cem class=\"replaceable\"\u003e\u003ccode\u003esslmode\u003c/code\u003e\u003c/em\u003e.  By default,\n        parameters are re-used in the positional syntax, but not when\n        a \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e string is given.  Passing a\n        first argument of \u003ccode class=\"literal\"\u003e-reuse-previous=on\u003c/code\u003e\n        or \u003ccode class=\"literal\"\u003e-reuse-previous=off\u003c/code\u003e overrides that default.  If\n        parameters are re-used, then any parameter not explicitly specified as\n        a positional parameter or in the \u003cem class=\"replaceable\"\u003e\u003ccode\u003econninfo\u003c/code\u003e\u003c/em\u003e\n        string is taken from the existing connection's parameters.  An\n        exception is that if the \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehost\u003c/code\u003e\u003c/em\u003e setting\n        is changed from its previous value using the positional syntax,\n        any \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehostaddr\u003c/code\u003e\u003c/em\u003e setting present in the\n        existing connection's parameters is dropped.\n        Also, any password used for the existing connection will be re-used\n        only if the user, host, and port settings are not changed.\n        When the command neither specifies nor reuses a particular parameter,\n        the \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e default is used.\n        \u003c/p\u003e\u003cp\u003e\n        If the new connection is successfully made, the previous\n        connection is closed.\n        If the connection attempt fails (wrong user name, access\n        denied, etc.), the previous connection will be kept if\n        \u003cspan class=\"application\"\u003epsql\u003c/span\u003e is in interactive mode.  But when\n        executing a non-interactive script, the old connection is closed\n        and an error is reported.  That may or may not terminate the\n        script; if it does not, all database-accessing commands will fail\n        until another \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e command is successfully\n        executed.  This distinction was chosen as\n        a user convenience against typos on the one hand, and a safety\n        mechanism that scripts are not accidentally acting on the\n        wrong database on the other hand.\n        Note that whenever a \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e command attempts\n        to re-use parameters, the values re-used are those of the last\n        successful connection, not of any failed attempts made subsequently.\n        However, in the case of a\n        non-interactive \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e failure, no parameters\n        are allowed to be re-used later, since the script would likely be\n        expecting the values from the failed \u003ccode class=\"literal\"\u003e\\connect\u003c/code\u003e\n        to be re-used.\n        \u003c/p\u003e\u003cp\u003e\n        Examples:\n        \u003c/p\u003e\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\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","related":[{"label":"\\connect","url":"/wiki/psql/cmd-63-6f-6e-6e-65-63-74/?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":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"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}
