1

Using psql, how can I disconnect from an established connection without logging out?

To be more specific: Assuming the database server runs on localhost, I connect to the db server using

psql -U <user>

after that I am in the PSQL console. From there I can connect to one of the databases using

<user>=# \connect <database>

Now here is the question: How can I disconnect from this session without logging of from PSQL Console? I tried \disconnect but without any luck and using \q not only closes the session but kicks me out of PSQL entirely.

So is there a command which allows me to disconnect from one database and to reconnect to another database (using \connect <another_database>) without logging of from/ shutting down PSQL?

Ueli Hofstetter
  • 2,409
  • 4
  • 29
  • 52
  • 1
    Have a look at http://stackoverflow.com/questions/17963348/how-to-disconnect-from-a-database-and-go-back-to-the-default-database-in-postgre – Barbara Laird Jan 01 '16 at 00:44

1 Answers1

1

According to the POSTGRESQL docs at Postgres Manual, there is no meta command which will only close the current connection (without closing the PSQL application using \q). The only way to close the current connection is to connect to another database using \connect, as described in the docs mentioned above:

If the new connection is successfully made, the previous connection is closed.

Similiar information is also provided in the second answer to How to Disconnect from a database and go back to the default database in PostgreSQL? (thanks to @Barbara Laird for pointing this out)

Community
  • 1
  • 1
Ueli Hofstetter
  • 2,409
  • 4
  • 29
  • 52