So I have a list of(lot many) scrapers which push lot many data into one of my database location. Unfortunately I have a requirement that my database location have to be changed for some performance issues. Rather than changing my so many scripts config can I have some mechanism implemented in my db server so that database requests coming from certain IP(machines) I would redirect them to other database/server?
-
2pgBouncer can do that: pgbouncer.github.iouser1822– user18222016-10-12 08:04:17 +00:00Commented Oct 12, 2016 at 8:04
-
Thanks @a_horse_with_no_name! can you give some good documentation links?MD. Mohiuddin Ahmed– MD. Mohiuddin Ahmed2016-10-12 09:08:58 +00:00Commented Oct 12, 2016 at 9:08
-
1pgbouncer.github.io/faq.htmluser1822– user18222016-10-12 09:10:47 +00:00Commented Oct 12, 2016 at 9:10
1 Answer
As @horse_with_no_name already comment: you can use pgbouncer to do that.
Basically you need to create a pool configuration, and during your maintenance you ajust the pool config to a new server or database.
Take a look at the session [databases]
on /etc/pgbouncer.ini
file:
[databases]
; no connection info enforces unix socket
foodb =
; bardb config
bardb = host=127.0.0.1 dbname=bardb
So, if you want to redirect the connections for the database bardb
for another database, what you need to do is edit the dbname
and reload de pgbouncer service. E.G.:
; bardb config
bardb = host=127.0.0.1 dbname=maintenancedb
Please, take a look at the documentation[1] for more details.
You can do the same with the pgpool[2].
Hope it helps.
References:
-
Hi Sebastian! Thanks for quick response! :) I had a question like can we configure / reload it via psql!MD. Mohiuddin Ahmed– MD. Mohiuddin Ahmed2016-10-12 19:48:12 +00:00Commented Oct 12, 2016 at 19:48