PostgreSQL 10 Administration Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it…

Each database is completely identified by its connection string. PgBouncer will read this information from its configuration file. The steps to be done are as follows:

  1. All you need to do is to set up PgBouncer as you did in the previous recipe, replacing the databases section of pgbouncer.ini with the following:
[databases] 
myfirstdb = port=5432 host=localhost
anotherdb = port=5437 host=localhost
sparedb = port=5435 host=localhost
  1. Once you have started PgBouncer, you can connect to the first database:
$ psql -p 6432 -h 127.0.0.1 -U postgres myfirstdb
psql (9.6.1)
Type "help" for help.

myfirstdb=# show port;
port
------
5432
(1 row)

myfirstdb=# show server_version;
server_version
----------------
10.1
(1 row)
  1. Now you can connect to the anotherdb database as if it were on the same server:
myfirstdb=# \c anotherdb
psql (10.1, server 9.6.5)
You are now connected to database "anotherdb" as user "postgres".
  1. The server's greeting message suggests that we have landed on a different server, so we check the port and version:
anotherdb=# show port;
port
------
5437
(1 row)

anotherdb=# show server_version;
server_version
----------------
9.5.5
(1 row)