1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58: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

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1182 TILs and counting..._
_1183 TILs and counting..._
---
@@ -609,6 +609,7 @@ _1182 TILs and counting..._
- [List All Versions Of A Function](postgres/list-all-versions-of-a-function.md)
- [List Available Schemas](postgres/list-available-schemas.md)
- [List Connections To A Database](postgres/list-connections-to-a-database.md)
- [List Databases Available For Connecting](postgres/list-databases-available-for-connecting.md)
- [List Database Objects With Disk Usage](postgres/list-database-objects-with-disk-usage.md)
- [List Database Users](postgres/list-database-users.md)
- [List Various Kinds Of Objects](postgres/list-various-kinds-of-objects.md)

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.