Fork Me On GitLab

psql Tips

Psql Tip #061

In interactive mode, you can connect to another database, host, port or with another user by using the following metacommand \c dbname username host port.
laetitia:~$ psql
psql (14devel)
Type "help" for help.

laetitia=# \conninfo
You are connected to database "laetitia" as user "laetitia" via socket in "/tmp" at port "5432".
laetitia=# \c laetitia laetitia localhost 5432
You are now connected to database "laetitia" as user "laetitia" on host "localhost" (address "::1") at port "5432".
laetitia=#
This feature is available since at Postgres 7.1 for \c dbname username and since Postgres 8.2 for \c dbname username host port.
See Postgres documentation for more information.
Try a new tipSee them all