0

I know that I can use \c to switch databases using psql.

Does PostgreSQL have a command that I can use in a different client? In my case I’m using SQLPro on a Mac, and I can easily switch databases from a menu. I wondered whether there’s a command to do that.

Manngo
  • 14,066
  • 10
  • 88
  • 110
  • Does this answer your question? ["use database\_name" command in PostgreSQL](https://stackoverflow.com/questions/10335561/use-database-name-command-in-postgresql) – David Jones Mar 29 '23 at 11:00
  • @DavidJones Thanks, I saw that, but its very old, and the answers all dwell on either psql or a gui. – Manngo Mar 29 '23 at 23:16
  • Yes fair enough, if you are looking for a definitive answer for SqlPro on a Mac. May I suggest you perhaps try reaching out to the software vendor directly? – David Jones Mar 30 '23 at 00:02

2 Answers2

1

\c connects to a different server.

No, a Postgres server cannot connect you to another Postgres server. That is the client's job.

A client may have its own equivalent of \c.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • 1
    Actually this incorrect, both [dblink](https://www.postgresql.org/docs/current/dblink.html) and [postgres_fdw](https://www.postgresql.org/docs/current/dblink.html) allow you to connect from one database or server to another from within the server. Delete your answer or fix it. – Adrian Klaver Mar 29 '23 at 04:18
  • @AdrianKlaver Interesting, clients embedded in the server to do cross-server queries. Of course. Not quite what the op is looking for (or likely overkill) but worth an answer. I'm not familiar with those extensions. How about you write up an answer? – Schwern Mar 29 '23 at 19:00
1

What psql does if you use \c is to open a new database connection and close the old one. Whether a different client program has a facility like that or not depends entirely on the implementation of that client program. It cannot be a function of the PostgreSQL server.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263