Skip to content

support postgresql other port number #915

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

Open
wants to merge 6 commits into
base: next
Choose a base branch
from

Conversation

lionelbargeot
Copy link

Closes #

What has been done to verify that this works as intended?

We have configured an external database server that uses another port (5434)
We tested ODK Central succesfully.

Why is this the best possible solution? Were any other approaches considered?

We added DB_PORT environment variable support in docker-compose.yaml and in scripts that uses this en var.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

users can use a postgresql db server that listen another port than default.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

Not specialy.

Before submitting this PR, please make sure you have:

  • [] branched off and targeted the next branch OR only changed documentation/infrastructure (master is stable and used in production)
  • [] verified that any code or assets from external sources are properly credited in comments or that everything is internally sourced

@matthew-white matthew-white changed the base branch from master to next March 13, 2025 05:09
Copy link
Member

@matthew-white matthew-white left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @lionelbargeot! We've talked about wanting to add this port option: #494 (comment). It's nice that that's something that will be easy for users to set.

@@ -3,6 +3,7 @@
"database": {
"host": "${DB_HOST}",
"user": "${DB_USER}",
"port": "${DB_PORT}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quotes around ${DB_PORT} shouldn't be needed, since ${DB_PORT} will be a number. Central Backend will pass this port option as-is to Knex.js, and from the Knex.js docs, it looks like Knex.js is expecting a number, not a string. Then again, if it's working for you with these quotes, it probably doesn't really matter either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to add to this, I noticed that ${DB_SSL} works similarly in this file. Since it will be either true or false, it doesn't need quotes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Matthew, thanks for your feedback. Is there anything else I can help with ?

@github-project-automation github-project-automation bot moved this to 🕒 backlog in ODK Central Mar 19, 2025
@matthew-white matthew-white moved this from 🕒 backlog to ✏️ in progress in ODK Central Mar 19, 2025
@matthew-white
Copy link
Member

I seem to remember @lognaturel saying that in lieu of a DB_PORT option, some users today include the port in DB_HOST. Is that right?

If so, I think the approach in this PR would actually end up breaking things for those users. This PR always specifies the port config in config.json.template. If DB_PORT is unset, it defaults to 5432. But that won't work out if a user is also specifying a port in DB_HOST. In that case, Central Backend would end up getting two ports: 5432 in the port config and another port via the host config.

Rather than defaulting to 5432, it'd be preferable to specify the port config in config.json.template only if DB_PORT is set to a nonempty string. I'm not sure we have an easy way to do that right now though.

Alternatively, I see in the Central Backend code that specifying null for port is equivalent to omitting port entirely. I think we can leverage that and change the default here from 5432 to null. I'll go ahead and do that now.

@matthew-white
Copy link
Member

I think we can leverage that and change the default here from 5432 to null.

It looks like there's some precedence for this: we do something similar for the ssl config.

@matthew-white
Copy link
Member

I see in the Central Backend code that specifying null for port is equivalent to omitting port entirely.

Ah I was looking at how Central Backend connects to Slonik, but I'm not so sure that this is true when Backend connects to Knex. I'm looking at knexConnection() in lib/util/db.js. In that case, I think we would end up specifying a null port to Knex. Knex might very well be fine with that, but I'm not sure. I think I'd prefer to make a change to Central Backend so that it filters out a null port before passing the rest of the config to Knex.

@matthew-white
Copy link
Member

I searched the codebase for DB_HOST to see if anything else would need to change. Based on that, I'm wondering whether this line would need to incorporate the new DB_PORT variable. I think so.

command: [ "wait-for-it", "${DB_HOST:-postgres14}:5432", "--", "./start-odk.sh" ]

The existence of that line and the hard-coded 5432 in it makes me question whether it really would work to include the port in DB_HOST. If we don't know of anyone specific who's taking that strategy, then maybe we should simply default to 5432 instead of null. We could also make a note of all this in release notes in case anyone is taking that approach.

@matthew-white matthew-white self-assigned this May 15, 2025
@matthew-white matthew-white added the ops Docker, nginx, ops to deploy Central label May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ops Docker, nginx, ops to deploy Central
Projects
Status: ✏️ in progress
Development

Successfully merging this pull request may close these issues.

2 participants