-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
postgresql_ping: return conn error message #177
Conversation
I'm fairly certain we'd make regular use of it at work in our roles/playbooks
I'd say always. |
Well, from a PostgreSQL point of view this ping feature purpose is not to evaluate DB presence and connection. So here it looks we're translating psycopg2 (the current python driver) behavior as to be able to connect to a DB or not. But I strongly suggest to look at psycopg3 driver to make sure it'll still work the same. Because when the collection will move to psycopg3 (which I hope will happen sometime in the future), we won't have to maintain this feature which may require additional code because it's not aligned with upstream feature. |
This feature uses the |
Again, assuming that this module purpose is to evaluate if a DB exists or if we can connect to it is a bad idea, it is not the purpose of the upstream feature, it is explicit in the PostgreSQL documentation. -1 from me for such a change. |
Okay, let's vote |
Why not? Like I said in a comment on #174, we can use PG PING to do multiple things: evaluate a PG cluster that you can connect to (not providing a DBName that will default to postgres db), and/or a specific database within that cluster (specifying a DBName). |
My 2cents on this is to make it fail if we cannot connect to a cluster FOR ANY REASON. This can easily be achieved by changing one line in postgresql_ping.py: Or add variables to task to see result parm, is_available:
|
@MichaelDBA so, you're +1 for this ret val? |
+1 for ret val, but even better if it fails on ANY CONNECT ERROR |
I agree with @MichaelDBA. Retval is a good idea, but |
I am unsure of the goal for the proposed change. Please be careful not to over-engineer what the upstream project is doing:
|
You're right about About whether it should fail or not, as we've put a way how to make it failing in the doc #176, I think a new bool parameter, |
Rebased. Green. @marcosdiez after that we could create another PR to use the returned error message in the |
@Andersson007 will it work the same with psycopg3 ? |
@klando I don't know, I didn't test it. If psycopg3 returns error messages when errors occur, it should work the same. If it does not (though I think it does), we'll have to refactor things unrelated to this PR anyway. |
That's why I added the documentation from psycopg3: what has been done with psycopg2 probably won't work the same with psycopg3. Because psycopg3 offers native support to the feature provided by PostgreSQL... |
What do you mean when saying |
psycopg3 test shows how connection and ping are tested: https://github.com/psycopg/psycopg/blob/master/tests/pq/test_pgconn.py
It's distinct, ping test uses |
I believe the next version of the connector will continue to support exception throwing with messages anyway (as this is conventional). We can also use this code change with |
Could anyone please review the code? |
I am unsure I understood which connector you're talking about:
|
@klando , you asked whether this functionality (introduced by this patch) will work the same with psycopg3 |
and it won't. Or the motivation of Maybe this is the motivation for this special ansible postgresql_ping which I don't have. |
We have what we have. And we still don't have psycopg3 released. Could you elaborate a bit more on what you're suggesting? Will the introduction of the ret var be harmful? Anyway, I don't think psycopg2 support will be dropped soon after psycopg3 is released and I hope the collection will continue to support it. The community finds this ret var useful. |
psycopg3 has been released: https://www.psycopg.org/articles/2021/10/13/psycopg-30-released/ PostgreSQL provides special functions for ping which are distinct from the usual connection functions. Psycopg2 does not have such distinction, but psycopg3 does. As a consequence, implementation of PQping in postgresql_ping with psycopg2 does use an usual connection function, but it should switch to using the native ping implementation of psycopg3 (i.e. it won't use a |
to complete: in order to achieve what this patch is doing for |
Thanks for the information:)
|
changelogs/fragments/177-postgresql_ping_add_conn_err_msg_ret_val.yml
Outdated
Show resolved
Hide resolved
Co-authored-by: Felix Fontein <felix@fontein.de>
…val.yml Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
@felixfontein all committed, PTAL |
Regarding the discussion earlier in this PR:
Both these points do not affect the PR though. Having a return value with the error message (or at least that indicates that an error happened) is IMO a very good idea (and I hope someone will implement 1 as well soon :) ). I also don't see how continuing on the current approach (connecting to the DB and executing a command) would cause any problems with |
@felixfontein thank you for the ideas, sound interesting! I'll think them over and will come up with something soon (I hope). |
@hunleyd @klando @MichaelDBA @marcosdiez thanks for reviewing! |
SUMMARY
Relates to #174
@tcraxs @ @klando @MichaelDBA @hunleyd @marcosdiez , needs your opinion on this:
@marcosdiez maybe we could use the related change in
connect_to_db
to fill up messages in #173See the integration tests i added to
tests/integration/targets/postgresql_ping/tasks/postgresql_ping_initial.yml
to see how it can be used.ISSUE TYPE
COMPONENT NAME
postgresql_ping