You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)`
The text was updated successfully, but these errors were encountered:
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
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
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)`
The text was updated successfully, but these errors were encountered: