1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add Check If The Local Server Is Running as a Postgres til

This commit is contained in:
jbranchaud
2021-03-11 16:58:50 -06:00
parent f5328c55d0
commit 82d1bd0741
2 changed files with 45 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://tinyletter.com/jbranchaud).
_1082 TILs and counting..._
_1083 TILs and counting..._
---
@@ -507,6 +507,7 @@ _1082 TILs and counting..._
- [Between Symmetric](postgres/between-symmetric.md)
- [Capitalize All The Words](postgres/capitalize-all-the-words.md)
- [Change The Current Directory For psql](postgres/change-the-current-directory-for-psql.md)
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
- [Check Table For Any Oprhaned Records](postgres/check-table-for-any-orphaned-records.md)
- [Checking Inequality](postgres/checking-inequality.md)
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)

View File

@@ -0,0 +1,43 @@
# Check If The Local Server Is Running
An install of PostgreSQL comes with a number of utilities including the
`pg_isready` command. This command can be used to check if the local PostgreSQL
server is up, running, and ready to receive connections.
If the server has not yet been started, running the command will result in a
`no response` response.
```bash
$ pg_isready
localhost:5432 - no response
```
In this case, the `pg_ctl` command can be used to start the server.
```bash
$ pg_ctl -D $HOME/.asdf/installs/postgres/12.3/data start
waiting for server to start....
...
done
server started
```
It tells us that the server is started and we can confirm that by again running
`pg_isready`.
```bash
$ pg_isready
localhost:5432 - accepting connections
```
This command is most useful as part of a script, such as in a CI environment.
In that case, you may not want it writing to `stdout`, you just want to use the
command's exit code. For that, you can tack on the `--quiet` flag.
```
$ pg_isready --quiet
```
[source](https://www.postgresql.org/docs/current/app-pg-isready.html)