1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add List Databases Available For Connecting as a Postgres til

This commit is contained in:
jbranchaud
2022-01-25 12:26:26 -06:00
parent 53f82df5b1
commit db840d05c1
2 changed files with 31 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
# 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.