This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-31
Channels
- # ai (5)
- # announcements (11)
- # beginners (19)
- # biff (1)
- # calva (8)
- # cider (3)
- # clj-kondo (12)
- # clojure (97)
- # clojure-europe (39)
- # clojure-nl (1)
- # clojure-norway (74)
- # clojure-uk (35)
- # clojurescript (8)
- # component (8)
- # conjure (4)
- # cursive (13)
- # data-science (1)
- # datahike (55)
- # datomic (2)
- # emacs (3)
- # etaoin (6)
- # gratitude (1)
- # hoplon (12)
- # hyperfiddle (54)
- # introduce-yourself (1)
- # lsp (70)
- # missionary (40)
- # music (1)
- # off-topic (79)
- # re-frame (78)
- # releases (4)
- # sql (5)
- # squint (9)
- # tree-sitter (4)
- # xtdb (20)
My managed PostgreSQL went down today for a few hours , but that did not affect my uptime monitoring unfortunately (because the backend still returned HTTP 200).
Now I want to implement an API endpoint to check DB status.
My approach would be to do a SELECT 1 FROM account;
and catch any exception. Or is there some other elegant way to do that?
I think ‘SELECT 1;’ should be enough - you just need to know that the connection is alive and not touch the schemas
Bit late to respond but thought I would anyway just in case it helps someone else. The query SELECT 1 FROM account;
will doubtless work, but PostgreSQL actually has a definitive way of checking your database status called pg_isready
. Is it more elegant than your solution? That depends. I can see a couple of benefits of using it:
1. If the 'accounts' table is dropped, renamed or moved to another schema then your check may no longer work.
2. pg_isready also has a few different return statuses that will give you more information about connection issues than a simple SELECT.
The docs are here: https://www.postgresql.org/docs/current/app-pg-isready.html
That is good to know, thank you!
Btw @U0JEFEZH6 already proposed a better solution by just using SELECT 1;
so that it does not depend on any table.