theory/pgenv

pgenv status option

Closed this issue · 7 comments

I was wondering if is there any specific reason we don't have "status" option in pgenv?
I feel the lacking of this option anyway, we have stop and start, use and even log to see the details, but there is no simple check for current status of the server.

Should I add this option and send a PR?

theory commented

Sure, I like it!

+1 for me too, but it is worth noting that status should also report in the output the version of PostgreSQL selected (not only if it is running or not).

Right, so it should be a combination of current option and the status of the server, like:
16.0 (running)

But wouldn't it make the usage of current option obsolete?
After some time, users being aware of status option will take advantage of it to check for both the current version in use and the status of server instance. It shouldn't be a problem in general though.

If you both confirm on that, I'll put some time on it and make it into a PR.

But wouldn't it make the usage of current option obsolete? After some time, users being aware of status option will take advantage of it to check for both the current version in use and the status of server instance. It shouldn't be a problem in general though.

Good point! I wonder if current should be improved to be more verbose and report back the status, thus removing the need for a status command at all.
One reason I see to keep the commands separated could be when scripting against pgenv, so that status and current could report independent information (with status being your original idea). If we don't mind, I rather be extending current to keep the list of commands short.
@theory has the last word on this.

Right, scripting against pgenv is something I totally missed. Changing that is going to make other scripts to possibly do some undetermined behavior, even though it's commonly known that we should never rely on scraping the output of any program.
Besides that, when I first came out with the word "status" I did it intentionally, because it somehow resonates 'systemctl status' command.

One reason to add "status" option rather than extending "current" is that users mostly have a common sense of having that option on services. I didn't know pgenv doesn't have it and without looking at the help menu I just tried to get the status by running "status".

Now that I'm looking at it from the perspective of someone who's scripting things, having the status of an instance on "current" option might be tempting, as users can get both instance version in use and see if that instance is running, but running two commands to achieve the same results doesn't seem to be hard to do so, and it's not even a resource intensive operation to avoid. So letting options to do one thing and do it well keeps things clear.
This is why 'pgenv status' might be better left printing one word of either 'running', 'inactive', or 'unloaded'.

rethinking about this, I'm convinced that we should keep commands separated, so implement a status (that has to rely on pg_control, not on systemctl!) and may be, later on, improve the current command to accept something like current status to merge the two (leaving current and status separated for scripting purposes).

Great, sure. I'll send a review request soon.