\c
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.
当前阅读 PG 18·选择有来源记录的版本
此版本暂无所选语言的定义,以下显示原始英文内容。
- Client
- psql 18.6
- Case-sensitive spelling
- \c
- command
- \c
- manual path
- app-psql.html#APP-PSQL-META-COMMAND-C-LC
- modifiers
- 未知
- signature
- \c or \connect [ -reuse-previous= on|off ] [ dbname [ username ] [ host ] [ port ] | conninfo ]
- spellings
- \c, \connect
版本定义 PG 18
\cor\connect [ -reuse-previous=on|off] [dbname[username] [host] [port] |conninfo]-
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
conninfoconnection 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,hostorportas-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 aconninfostring is given. Passing a first argument of-reuse-previous=onor-reuse-previous=offoverrides that default. If parameters are re-used, then any parameter not explicitly specified as a positional parameter or in theconninfostring is taken from the existing connection's parameters. An exception is that if thehostsetting is changed from its previous value using the positional syntax, anyhostaddrsetting 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
\connectcommand 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\connectcommand 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\connectfailure, no parameters are allowed to be re-used later, since the script would likely be expecting the values from the failed\connectto be re-used.Examples:
=> \c mydb myuser host.dom 6432 => \c service=foo => \c "host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable" => \c -reuse-previous=on sslmode=require -- changes only sslmode => \c postgresql://tom@localhost/mydb?application_name=myapp
精确保留大小写的命令写法
\c\connect
Spellings in this manual definition
比较版本
来源引用
定义来源
center · PostgreSQL 18 · ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8
正文语言: en · ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8