Skip to content

Commit db840d0

Browse files
committed
Add List Databases Available For Connecting as a Postgres til
1 parent 53f82df commit db840d0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1182 TILs and counting..._
13+
_1183 TILs and counting..._
1414

1515
---
1616

@@ -609,6 +609,7 @@ _1182 TILs and counting..._
609609
- [List All Versions Of A Function](postgres/list-all-versions-of-a-function.md)
610610
- [List Available Schemas](postgres/list-available-schemas.md)
611611
- [List Connections To A Database](postgres/list-connections-to-a-database.md)
612+
- [List Databases Available For Connecting](postgres/list-databases-available-for-connecting.md)
612613
- [List Database Objects With Disk Usage](postgres/list-database-objects-with-disk-usage.md)
613614
- [List Database Users](postgres/list-database-users.md)
614615
- [List Various Kinds Of Objects](postgres/list-various-kinds-of-objects.md)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# List Databases Available For Connecting
2+
3+
I tend to have a couple different versions of Postgres installed on my
4+
development machine. Each server version tends to have a different set of
5+
databases. As I switch between projects and Postgres versions, it can be hard
6+
to remember the name of the database to which I want to connect when using
7+
`psql`.
8+
9+
I usually connect to one of the defaults, which is either named `postgres` or
10+
named after the machine user.
11+
12+
There is a better way. I can first ask `psql` to list all the available
13+
databases.
14+
15+
```
16+
❯ psql --list
17+
Timing is on.
18+
List of databases
19+
Name | Owner | Encoding | Collate | Ctype | Access privileges
20+
--------------------------------+------------+----------+-------------+-------------+---------------------------
21+
jbranchaud | jbranchaud | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
22+
postgres | jbranchaud | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
23+
thirty_days_server_development | jbranchaud | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
24+
thirty_days_server_test | jbranchaud | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
25+
(4 rows)
26+
```
27+
28+
Then I know before connecting which one I'm looking for or if it must be in the
29+
data directory of another Postgres server version.

0 commit comments

Comments
 (0)