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

postgres_pass Inheritance in nested locations #28

Open
msva opened this issue Aug 4, 2014 · 3 comments
Open

postgres_pass Inheritance in nested locations #28

msva opened this issue Aug 4, 2014 · 3 comments

Comments

@msva
Copy link

msva commented Aug 4, 2014

Hello there!
I think, it would be great to make default behaviour to inherit postgres_pass setting from top-level location to it's nested locations.

For example, I assume that to work fine, instead of throwing 404:

location /db {
  postgres_pass   db;
  internal;
  location /db/test {
    postgres_query "SELECT id,name from users";
  }
}

Thanks a lot!

@agentzh
Copy link
Contributor

agentzh commented Aug 5, 2014

@msva Will you provide a patch?

@msva
Copy link
Author

msva commented Aug 5, 2014

I'm afraid, no 😞 At least, not now...

I'm almost not familiar with NginX API (not more than it needs for maintain a package and port some patches from old versions).

I tried to fix it myself in the way like it already done in rds_json module (where rds_json directive inherits to the nested locations just fine):

     { ngx_string("postgres_pass"),
       NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
       ngx_postgres_conf_pass,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_postgres_loc_conf_t, upstream),
       NULL },

but I still can't get it to work 😕

I also noticed, that postgress_output inherits fine too, but I can't realize the thing (except it provides a filter, just like rds_json) that makes them (with rds_json directive) works, while do not work for postgress_pass.

Maybe you can advice me, if I missed something else? 😇
Thanks! 😊

@msva
Copy link
Author

msva commented Jul 24, 2016

By the way, I found strange thing. ngx_postgres_module.c contains following in ngx_postgres_merge_loc_conf function:

 358     if ((conf->upstream.upstream == NULL) && (conf->upstream_cv == NULL)) {
 359         conf->upstream.upstream = prev->upstream.upstream;
 360         conf->upstream_cv = prev->upstream_cv;
 361     }

And as I looked in ngx_postgres_conf_pass, it (postgresql_pass) sets either conf->upstream.upstream or conf->upstream_cv based of value type (is it complex or not), so if one of them set in the location, another should be NULL. And if neither set in the location, then code quoted above should (?) merge the ones that set on previous nesting level location (and so on for the top level). But somewhy it does not do that.

// by the way, it'd be nice to also allow _pass on server{} level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants