- PostgreSQL 10 Administration Cookbook
- Simon Riggs Gianni Ciolli
- 178字
- 2021-06-25 22:04:20
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:
- 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
- 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)
- 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".
- 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)