Edb Postgres™ Pgbouncer Guide
Edb Postgres™ Pgbouncer Guide
1 Installation 2
1.1 Installing PgBouncer on a CentOS Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Installing PgBouncer on a Debian or Ubuntu Host . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Installing PgBouncer on a Windows Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 Installing PgBouncer on an SLES 12 Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3 Uninstallation 24
3.1 Uninstalling PgBouncer on a CentOS Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2 Uninstalling PgBouncer on a Debian or Ubuntu Host . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3 Uninstalling PgBouncer on an SLES 12 Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4 Uninstalling PgBouncer on a Windows Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Index 28
i
PgBouncer Guide
When a client application connects to a Postgres server, it negotiates a connection; that negotiation takes time. Pg-
Bouncer saves time by maintaining a pool of pre-established connections to the server. Instead of connecting directly
to the server, the client connects to PgBouncer, minimizing the connection negotiation time by using a previously
established connection made available to the client in the PgBouncer pool.
PgBouncer is a lightweight connection pooling utility for Postgres and Advanced Server installations that is based on
the openSource PgBouncer project.
EnterpriseDB enhancements for the PgBouncer project are available via RPM Packages, deb packages, or a graphical
installer that you can download with StackBuilder Plus. The enhancements allow PgBouncer to service clients that are
using EDB Connectors that require compatible out parameter handling.
For more information about PgBouncer, including reference and usage information, please visit the PgBouncer project
site.
Contents 1
CHAPTER 1
Installation
This section walks you through installing PgBouncer on a CentOS, Debian/Ubuntu, or a Windows host.
The following table lists the latest PgBouncer versions, their supported corresponding Advanced Server versions, and
the supported platforms for each PgBouncer version.
The PgBouncer version required by your Advanced Server installation is version-specific, but the documented and
supported functionality of each version is the same. The information in this guide applies to each version listed in the
table below.
2
PgBouncer Guide
3
PgBouncer Guide
If you have previously used an RPM package to install Advanced Server, you have probably already created the
repository configuration file and have EnterpriseDB credentials. If that is the case, you can install PgBouncer with the
following command:
On RHEL/CentOS 6 and 7:
On a RHEL/CentOS 8 host, you can use the dnf package manager to install PgBouncer:
On CentOS/RHEL 8:
[edb]
name=EnterpriseDB RPMs $releasever - $basearch
baseurl=https://<username>:<password>@yum.enterprisedb.com/edb/redhat/
˓→rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/ENTERPRISEDB-GPG-KEY
3. Save your changes to the configuration file and exit the editor.
yum makecache
5. Before installing PgBouncer, execute the following command to install the Extra Packages for Enterprise Linux
(EPEL) release package:
On RHEL/CentOS 6 and 7:
On RHEL/CentOS 8:
Note: You may need to enable the [extras] repository definition in the CentOS-Base.repo file (located in
/etc/yum.repos.d).
On RHEL/CentOS 8:
When you install an RPM package that is signed by a source that is not recognized by your system, yum may ask
for your permission to import the key to your local server. If prompted, and you are satisfied that the packages
come from a trustworthy source, enter y, and press Return to continue.
During the installation, yum may encounter a dependency that it cannot resolve. If it does, it will provide a list
of the required dependencies that you must manually resolve. PgBouncer will be installed in the /usr/edb/
pgbouncer<x.x> directory.
You must install Advanced Server before installing PgBouncer. For details about installing and configuring Advanced
Server, see the EDB Postgres Advanced Server Installation Guide available at the EDB website. To install a package
on a Debian or Ubuntu host, you must have credentials to access the EnterpriseDB repository. See the EDB repository
access instructions to request the EnterpriseDB credentials.
The following steps will walk you through using the EnterpriseDB repository to install a DEB package. When using
the commands, replace the username and password with the credentials provided by EnterpriseDB.
Please note that if you are using the pdf version of this document, using cut/paste to copy command may result in extra
spaces or carriage returns in the pasted command. If a command fails, check the command carefully for additional
characters.
1. Assume superuser privileges:
sudo su -
˓→$(lsb_release -cs).list'
wget -q -O - https://<username>:<password>@apt.enterprisedb.com/edb-deb.
˓→gpg.key | apt-key add -
apt-get update
Graphical installers for PgBouncer are available via StackBuilder Plus (for Advanced Server hosts) or Stack Builder
(for PostgreSQL hosts).
The following steps walk you through installing PgBouncer 1.14.0.1 by accessing StackBuilder Plus through Windows
start menu
1. Access StackBuilder Plus through the Windows start menu; on the Welcome window, select your Advanced
Server installation from the drop-down list. Click Next to continue to the application selection page.
2. Expand the Add-ons, tools and utilities node, and check the box next to the PgBouncer v1.
14.0.1-1. Click Next to continue.
3. The selected packages and the default download directory where the package will be installed are displayed;
change the download directory location if required. Click Next.
4. Once you have downloaded the installation files, a confirmation message is displayed. Click Next to start the
PgBouncer installation.
7. Use the Installation Directory field to specify the directory in which you wish to install PgBouncer
(the default installation directory is C:\Program Files\edb) Then, click Next to continue.
8. Use fields on the EDB Postgres Advanced Server Installation Details window to provide
connection information for the Advanced Server host:
• Use the Host field to identify the system on which Advanced Server resides.
• Provide the name of the role that PgBouncer will use for connections to the server in the User
Name field.
• Provide the password associated with the role in the Password field.
• Use the Port field to identify the listener port that Advanced Server monitors for client connections.
Then, click Next to continue.
9. Use fields on the PgBouncer Configurations window to provide your preferences for the PgBouncer
installation:
• Use the Listening Port field to specify the port that PgBouncer monitors for connections.
• Use the Operating System User field to specify the name of the Linux operating system user that Pg-
Bouncer will change to after startup. This option is not supported on Windows hosts.
10. The Ready to Install window notifies you when the installer has all of the information needed to install
PgBouncer on your system. Click Next to install PgBouncer. Progress bars inform you as the installation
progresses.
11. The installer notifies you when the setup wizard has completed the installation. Click Finish to exit the
installer.
Perform the following steps to install PgBouncer on a SLES 12 SP4 host using the zypper package manager.
1. Assume superuser privileges and use the following command to add the EnterpriseDB repository configuration
file to your SLES host:
This command creates a repository configuration file named edb.repo in the /etc/zypp/repos.d direc-
tory.
2. Invoke the following command to refresh the repository.
zypper refresh
This section walks you through how to configure and use PgBouncer.
When the PgBouncer service is running, any Postgres client connecting to the PgBouncer listener port specified in the
configuration file will use connection pooling.
PgBouncer connection and configuration information is stored in the .ini file, located in the following directory:
On Linux:
/etc/edb/pgbouncer<x.x>/edb-pgbouncer-<x.x>.ini
Where <x.x> is the PgBouncer version.
On Debian:
/etc/edb/pgbouncer<x.x>/pgbouncer.ini
Where <x.x> is the PgBouncer version.
On SLES 12 SP4:
/etc/edb/pgbouncer1.14/edb-pgbouncer-<x.x>.ini
Where <x.x> is the PgBouncer version.
On Windows:
C:\Program Files\edb\pgbouncer<x.x>\share\pgbouncer.ini
Where <x.x> is the PgBouncer version.
The PgBouncer configuration file is divided into two sections: [databases] and [pgbouncer].
The [databases] section of the configuration file contains a list of databases and the associated connection infor-
mation. In an Advanced Server installation, the configuration file contains an entry for the installation of Advanced
Server that installed PgBouncer:
19
PgBouncer Guide
Parameter Description
name The name of the database to which the client application will connect.
host The IP address of the host.
port The port on which the host is listening.
dbname The (optional) database name.
user A username (if different than the information specified by the connecting client ).
password A password (if different than the information specified by the connecting client).
The following example demonstrates the syntax allowed in the [databases] section of the configuration file:
[databases]
edb = host=127.0.0.1 port=5444
acctg = host=192.168.10.101 port=5432 user=bob password=XXXXXX
Include the dbname parameter to map the connection name to an alternate database name. For example:
hr = host=127.0.0.1 port=5445 dbname=humanresources
When the client provides authentication information, that information is used to connect to PgBouncer, which in
turn uses the information specified in the PgBouncer configuration file to connect to the database server. The user
information provided in the configuration file must match a role defined in the Postgres database cluster.
Note: If you do not specify user details in pgbouncer.ini, the username and password will be authenticated by
the database server and PgBouncer. As such, the username and password should be included in the userlist.txt
file and the database cluster.
The [pgbouncer] section of the configuration file contains configuration details specific to PgBouncer:
Parameter Description
admin_users A comma-delimited list of users that are allowed to access the Ad-
min Console (for management and monitoring purposes). By de-
fault, PgBouncer is installed with an admin_users = enterprisedb.
auth_file The path to the authentication file that contains username and pass-
words of clients that may connect to PgBouncer. The authenti-
cation file (userlist.txt) is located in /opt/edb/pgbouncer-<x.x>/etc,
and contains username/password pairs that specify the identities
that clients may use to access PgBouncer. Within the authentication
file, the username and password must be specified within double-
quotes, as shown below:
“user_name” “password”
To make changes to the identities that can access PgBouncer, you
can edit the existing authentication file, or specify an alternate au-
thentication file with the auth_file parameter.
auth_type
auth_type The authentication method used by PgBouncer. May be: md5,
crypt, plain, trust or any. The default value is md5.
default_pool_size The amount of user connections that are allowed to access the
server. The default is 20 active connections.
group_connections Clients providing the same application_name will be grouped to use
the same connection. The default is 0.
ignore_startup_parameters A comma-delimited list of application startup packets that Pg-
Bouncer should ignore. The default is application_name .
listen_addr The IP address on which PgBouncer listens for client connections.
If omitted, only Unix socket connections are allowed; the client
must also reside on the same host as PgBouncer and may not specify
a host IP address when connecting to PgBouncer.
listen_port The port that PgBouncer monitors for client connections. By de-
fault, PgBouncer listens on port 6432.
logfile The path to the PgBouncer log file.
max_client_conn The maximum number of connections allowed. The default is 100.
pidfile The path to the process ID file.
pool_mode The value of pool_mode specifies when the server connection can be
made available to the connection pool. May be: session, transaction
or statement. The default value is session.
server_reset_query The default is DISCARD ALL which instructs PgBouncer to clean
any changes made to a database session.
stats_users A comma delimited list of users who are allowed to connect and run
read-only queries. The default is stats_users = enterprisedb.
The following example demonstrates the syntax allowed in the [pgbouncer] section of the configuration file for
edb-pgbouncer-1.14 version:
[pgbouncer]
logfile = /var/log/edb/pgbouncer1.14/edb-pgbouncer-1.14.log
pidfile = /var/run/edb/pgbouncer1.14/edb-pgbouncer-1.14.pid
listen_addr = *
listen_port = 6432
auth_type = md5
auth_file = /opt/edb/pgbouncer-1.14/etc/userlist.txt
admin_users = enterprisedb
stats_users = enterprisedb
pool_mode = session
server_reset_query = DISCARD ALL
ignore_startup_parameters = application_name
max_client_conn = 100
default_pool_size = 20
group_connections = 0
For more information about the settings used in the pgbouncer.ini file, click here.
After editing the PgBouncer configuration file to reflect your environment, you must restart the PgBouncer service for
the changes to take effect. The name of the PgBouncer service is edb-pgbouncer-1.14; use platform specific
commands to stop, start, or restart the service as needed.
The Admin Console allows you to retrieve statistical information about PgBouncer activity, and to control the Pg-
Bouncer process. You can use the edb-psql client to access the PgBouncer Admin Console by connecting to the
pgbouncer database. The following example connects to the pgbouncer database with the edb-psql client on a
Linux system. PgBouncer is listening on port 6432, with a user name of enterprisedb:
Enter following command after navigating to the bin directory under your Advanced Server installation:
# ./edb-psql -p 6432 -U enterprisedb pgbouncer
Please note that the required connection information will vary according to the connecting client, platform and authen-
tication information required by the server.
After connecting to the pgbouncer database, you can use the SHOW CLIENTS command to retrieve client-related
information:
# SHOW CLIENTS;
The SHOW CLIENTS command returns:
You can use other variations of the SHOW command to retrieve information about PgBouncer:
SHOW STATS
SHOW SERVERS
SHOW POOLS
SHOW LISTS
SHOW USERS
SHOW DATABASES
SHOW FDS
SHOW CONFIG
You can use the following commands to control the PgBouncer process:
PAUSE
Use the PAUSE command to disconnect all servers after waiting for current queries to complete.
SUSPEND
Use the SUSPEND command to flush the socket buffers and suspend the PgBouncer process.
RESUME
Use the RESUME command to resume work after a PAUSE or SUSPEND command.
SHUTDOWN
Use the SHUTDOWN command to stop the PgBouncer process and exit.
RELOAD
Use the RELOAD command to reload the PgBouncer configuration files.
For more information about using PgBouncer, see the PgBouncer project site.
Uninstallation
To uninstall PgBouncer on a CentOS host, assume identity of the root user and invoke the following command:
On RHEL/CentOS 6 and 7:
On RHEL/CentOS 8:
24
PgBouncer Guide
To uninstall PgBouncer on an SLES 12 host, assume the identity of the root user and invoke the following command:
C
Configuration and Usage, 19
Configuring PgBouncer, 19
I
Installation, 2
Installing PgBouncer on a CentOS Host,
4
Installing PgBouncer on a Debian or
Ubuntu Host, 6
Installing PgBouncer on a Windows
Host, 7
Installing PgBouncer on an SLES 12
Host, 18
U
Uninstallation, 24
Uninstalling PgBouncer on a CentOS
Host, 24
Uninstalling PgBouncer on a Debian or
Ubuntu Host, 25
Uninstalling PgBouncer on a Windows
Host, 27
Uninstalling PgBouncer on an SLES 12
Host, 26
Using the PgBouncer Admin Console, 22
28