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

pgmoon connect to wrong postgresql scheme which is last used when turn keepalive on #68

Closed
gzliudan opened this issue Mar 31, 2018 · 1 comment

Comments

@gzliudan
Copy link

gzliudan commented Mar 31, 2018

my application connects to several PostgreSQL scheme or database according to client's choice. If I used pg:keepalive() in my codes, and client visit different scheme almost at the same time, pgmoon does not switch to right scheme, still connect to last scheme.

below is some of my config(different user use differnt scheme which is decided by postgresql database):
{
"id": 1,
"host": "127.0.0.1",
"port": "5432",
"database": "mydb",
"user": "develop",
"password": "123456"
},
{
"id": 2,
"host": "127.0.0.1",
"port": "5432",
"database": "mydb",
"user": "test",
"password": "123456"
}

below is my code:

`local g_vars = require("global_vars")

local pg_conf = g_vars.get_server_unit(ngx.var.db_id)
if not pg_conf then
ngx.say([[{"return_code": -1, "error_message": "db_id is wrong"}]])
return
end

local pgmoon = require("pgmoon")
local pg = pgmoon.new(pg_conf)

if not pg:connect() then
ngx.say([[{"return_code": -2, "error_message": "fail to connect database"}]])
return
end

local result_obj = pg:query("SELECT get_classes() AS result")
pg:keepalive()

local json = require "cjson.safe"
local result_str = json.encode(result_obj[1].result)
ngx.say(result_str)`

@gzliudan gzliudan changed the title keepalive() connect to wrong scheme which is last used pgmoon connect to wrong scheme which is last used when turn keepalive on Mar 31, 2018
@gzliudan gzliudan changed the title pgmoon connect to wrong scheme which is last used when turn keepalive on pgmoon connect to wrong postgresql scheme which is last used when turn keepalive on Mar 31, 2018
leafo added a commit that referenced this issue Apr 3, 2018
@leafo
Copy link
Owner

leafo commented Apr 3, 2018

Thanks for the report, the pool wasn't using the user, but it is now.

You can pull latest version to get the fix

@leafo leafo closed this as completed Apr 3, 2018
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