My PostgreSQL version is -
psql (15.2 (Ubuntu 15.2-1.pgdg22.04+1))
Connect (\c) is used at psql command prompt and the command syntax is -
\connect (or \c) [ dbname [ username ] [ host ] [ port ] ]
this command takes the value from previous connection for all four input values if we don't pass any value. we can understand this as below -
postgres=# \c (if we don't pass anything on this prompt then it will take all values (db name, user name, host and port) from previous connection.)
postgres=# \c test (here we are passing one value and this value be taken as database name, for other values user name, host name and port will be used from previous connection)
postgres=# \c test testuser (here host and port will be inherit from previous connection while first value will be taken as database name while second value will be taken as user name)
postgres=# \c test testuser localhost (here port will be used from previous connection while other three values db name, user name and host will be taken from given three values)
postgres=# \c test testuser localhost 5432 (in this command all four values are passed hence it will pick from here only)
post execute above command the output is -
postgres=# \c testdb testadmin localhost 5432
Password for user testadmin:
You are now connected to database "testdb" as user "testadmin".