<!-- Kamailio Pull Request Template -->
<!-- IMPORTANT: - for detailed contributing guidelines, read: https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md - pull requests must be done to master branch, unless they are backports of fixes from master branch to a stable branch - backports to stable branches must be done with 'git cherry-pick -x ...' - code is contributed under BSD for core and main components (tm, sl, auth, tls) - code is contributed GPLv2 or a compatible license for the other components - GPL code is contributed with OpenSSL licensing exception -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [x] Commit message has the format required by CONTRIBUTING guide - [x] Commits are split per component (core, individual modules, libs, utils, ...) - [x] Each component has a single commit (if not, squash them into one commit) - [x] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [ ] Small bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: <!-- Go over all points below, and after creating the PR, tick the checkboxes that apply --> - [ ] PR should be backported to stable branches - [x] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description <!-- Describe your changes in detail --> New configuration parameter is added to set postgres connection parameters. You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2622
-- Commit Summary --
* Merge pull request #1 from kamailio/master * db_postgres: added connection parameters
-- File Changes --
M src/modules/db_postgres/doc/db_postgres_admin.xml (21) M src/modules/db_postgres/km_pg_con.c (17) M src/modules/db_postgres/pg_con.c (18) M src/modules/db_postgres/pg_mod.c (101) M src/modules/db_postgres/pg_mod.h (6)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2622.patch https://github.com/kamailio/kamailio/pull/2622.diff
Thanks for the pull request. It seems that you are removing the timeout parameter. This is fine, as it can be replaced with the newly introduced connection parameters. But should be also reflected in the module XML docs (removal of the timeout parameter docs, and addition of a remark that it can be replaced with the new parameter).
ut should be also reflected in the module XML docs (removal of the timeout parameter docs, and addition of a remark that it can be replaced with the new parameter).
Hi Henning,
Timeout parameter is used in two different places: First one is like connect timeout which is replaced with my commit. The other one is like query timeout which we need to keep in the code. Therefore I decided not to remove the timeout parameter. Maybe it's better to change the name and definition of the timeout parameter in xml doc. What do you think?
@korayvt - a variant that keeps also the backward compatibility is to go over the list of connections parameters and if `connect_timeout` is missing, then add it like it is done now, when `pg_timeout>0`.
On another aspect, I would suggest to go for the style of 'param_name=param_value", it seems that the postgres param names are compatible with sip param names, as I can see at the link you provided:
* https://www.postgresql.org/docs/12/libpq-connect.html#LIBPQ-PARAMKEYWORDS
So instead of:
``` modparam("db_postgres", "con_param", "name=connect_timeout;value=15") modparam("db_postgres", "con_param", "name=tcp_user_timeout;value=5000") ```
It can be:
``` modparam("db_postgres", "con_param", "connect_timeout=15") modparam("db_postgres", "con_param", "tcp_user_timeout=5000") ```
And the above can also be compacted to:
``` modparam("db_postgres", "con_param", "connect_timeout=15;tcp_user_timeout=5000") ```
It would require some changes in function `postgres_con_param()`.
Purely as an observer and a db_postgres user, wouldn't it be easier just to pass entire connection strings or connection URIs? That way, Kamailio doesn't need to worry about parsing the params, just to rebuild them for input to libpq https://www.postgresql.org/docs/12/libpq-connect.html#LIBPQ-CONNSTRING
@korayvt - a variant that keeps also the backward compatibility is to go over the list of connections parameters and if `connect_timeout` is missing, then add it like it is done now, when `pg_timeout>0`.
On another aspect, I would suggest to go for the style of 'param_name=param_value", it seems that the postgres param names are compatible with sip param names, as I can see at the link you provided:
So instead of:
modparam("db_postgres", "con_param", "name=connect_timeout;value=15") modparam("db_postgres", "con_param", "name=tcp_user_timeout;value=5000")
It can be:
modparam("db_postgres", "con_param", "connect_timeout=15") modparam("db_postgres", "con_param", "tcp_user_timeout=5000")
And the above can also be compacted to:
modparam("db_postgres", "con_param", "connect_timeout=15;tcp_user_timeout=5000")
It would require some changes in function `postgres_con_param()`.
Hi Daniel,
I will consider your suggestions and make a new commit.
Thanks.
Purely as an observer and a db_postgres user, wouldn't it be easier just to pass entire connection strings or connection URIs? That way, Kamailio doesn't need to worry about parsing the params, just to rebuild them for input to libpq https://www.postgresql.org/docs/12/libpq-connect.html#LIBPQ-CONNSTRING
Thanks for your suggestion. Currently PQconnectdbParams function is used to make connections. This function takes two char arrays as keywords and values. So we need to parse parameters.
@korayvt, thank you for that detail. I look forward to this pull request.
@korayvt pushed 1 commit.
bdb7d3168d1af058c7a34023d68490f902e7ac4e db_postgres: changes based on the reviews
Merged #2622 into master.
Thanks!