1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00
Files
til/postgres/list-databases-available-for-connecting.md

30 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# List Databases Available For Connecting
I tend to have a couple different versions of Postgres installed on my
development machine. Each server version tends to have a different set of
databases. As I switch between projects and Postgres versions, it can be hard
to remember the name of the database to which I want to connect when using
`psql`.
I usually connect to one of the defaults, which is either named `postgres` or
named after the machine user.
There is a better way. I can first ask `psql` to list all the available
databases.
```
psql --list
Timing is on.
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------------------------+------------+----------+-------------+-------------+---------------------------
jbranchaud | jbranchaud | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | jbranchaud | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
thirty_days_server_development | jbranchaud | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
thirty_days_server_test | jbranchaud | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)
```
Then I know before connecting which one I'm looking for or if it must be in the
data directory of another Postgres server version.