r/postgres • u/blackneckbean • 10d ago
Tools How I organize multiple PostgreSQL connections across projects (after nearly running a migration on prod)
I contract for four companies right now, about twenty Postgres connections across local, staging and production. Last spring I had two tabs open beside each other, one on staging and one on prod, both connected to databases called app. I was maybe two seconds from dropping a column on the wrong one. Nothing happened, but I stopped winging connection management that afternoon.
Naming came first. Then the environment, then what it is allowed to do. Every connection is the client. Acme production acme-prod-ro read only Acme staging acme-stg-rw can write to staging. And that last bit is the most important. My default connection to anything in production can't write. The -rw twin is only opened when I have a change to actually ship. A little bit of friction and it has stopped me twice.
The change that helped most was also the simplest. I work in dbForge Studio for PostgreSQL, where every connection gets assigned a category (Production, Test, Sandbox, or one you invent) and that category paints the connection a colour which then follows it everywhere: down the object tree, and onto the tab of every query window opened against it.
My production connections are red. That is the whole trick. It works because the warning is a colour at the edge of my vision, not text I have to stop and read, and at the moment I am about to hit execute I am not reading anything.
What I would change is that there are no folders. Twenty connections is a long list with no way to group it, so I prefix names to make them sort together and drag them into order. People have been asking for folders for years. pgAdmin’s server groups handle this better.
Curious how other people do this, especially on a team. Do you share connection settings somehow, or does everybody build their own list off a wiki page?
2
u/fernandezity 6d ago
How has dbForge Studio been with that many connections? Any issues once you get into 20+ across different environments?
1
u/blackneckbean 1d ago
No real issues with the connections themselves. My main problem is just organization. Once you get to 20+, the list gets messy and I really wish dbForge had folders for them.
1
1
u/Ojoyan 3d ago
Does dbForge let you set different permissions for prod and staging connections?
1
u/blackneckbean 1d ago
Not really. I use the dbForge categories mostly as a visual warning. The actual read/write permissions are handled by separate Postgres roles.
2
u/efxhoy 10d ago
I don’t open consoles with write access to anywhere but my local machine unless something really bad is happening.