Skip to content
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

db_postgres: added connection parameters #2622

Merged
merged 3 commits into from Feb 9, 2021

Conversation

korayvt
Copy link
Contributor

@korayvt korayvt commented Feb 4, 2021

Pre-Submission Checklist

  • Commit message has the format required by CONTRIBUTING guide
  • Commits are split per component (core, individual modules, libs, utils, ...)
  • Each component has a single commit (if not, squash them into one commit)
  • 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)
  • New feature (non-breaking change which adds new functionality)
  • Breaking change (fix or feature that would change existing functionality)

Checklist:

  • PR should be backported to stable branches
  • Tested changes locally
  • Related to issue #XXXX (replace XXXX with an open issue number)

Description

New configuration parameter is added to set postgres connection parameters.

korayvt and others added 2 commits February 4, 2021 08:32
Updating my repo 04.02.2021
- new config parameter ("con_param") is added to set pg connection parameters
@korayvt korayvt changed the title korayvt/db postgres con params db_postgres: added connection parameters Feb 4, 2021
@henningw
Copy link
Contributor

henningw commented Feb 4, 2021

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).

@korayvt
Copy link
Contributor Author

korayvt commented Feb 4, 2021

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?

@miconda
Copy link
Member

miconda commented Feb 4, 2021

@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().

@amessina
Copy link
Contributor

amessina commented Feb 5, 2021

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
Copy link
Contributor Author

korayvt commented Feb 5, 2021

@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.

@korayvt
Copy link
Contributor Author

korayvt commented Feb 5, 2021

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.

@amessina
Copy link
Contributor

amessina commented Feb 5, 2021

@korayvt, thank you for that detail. I look forward to this pull request.

	- connection param style changed.
	- timeout param is used if connect_timeout is not set explicitly.
	- function renamed
	- unused variable deleted
	- doc updated
@miconda miconda merged commit 1466425 into kamailio:master Feb 9, 2021
@miconda
Copy link
Member

miconda commented Feb 9, 2021

Thanks!

NGSegovia pushed a commit to NGSegovia/kamailio that referenced this pull request Aug 26, 2021
- new config parameter ("con_param") is added to set pg connection parameters
- timeout param is used if connect_timeout is not set explicitly.

Co-authored-by: KORAY VATANSEVER <koray.vatansever@turkcell.com.tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants