Configuring and usage¶
使用する前にEDB PgBouncerを設定します。
EDB PgBouncerの設定¶
EDB PgBouncerサービスの実行中、構成ファイルで指定されたEDB
PgBouncerリスナーポートに接続するPostgresクライアントは接続プーリングを使用します。
EDB PgBouncerの接続と構成情報は.ini ファイルに保存されます。
RedHat/Centos、Debian、およびSLES 12 SP5では、.ini
ファイルは次のディレクトリにあります。
/etc/edb/pgbouncer<x.x>/
<x.x> EDB PgBouncerバージョンです。
Windowsでは、 .ini ファイルは次のディレクトリにあります。
C:\Program Files\edb\pgbouncer<x.x>\share\
<x.x> EDB PgBouncerバージョンです。
EDB PgBouncer構成ファイルは、 [databases] と[pgbouncer]
の2つのセクションに分かれています。
構成ファイルの [databases]
セクションには、データベースのリストと関連する接続情報が含まれています。構成ファイルには、EDB
PgBouncerをインストールしたEDB Postgres Advanced
Serverをインストールするためのエントリが含まれています。
edb = host=127.0.0.1 port=5444
PostgreSQLサーバーの場合、次の例に示すように、PostgreSQLサーバーの詳細を入力する必要があります。
postgres = host=127.0.0.1 port=5432
構成ファイルにkeyword=value
ペアの形式で、より多くのデータベース接続情報を指定できます。表に示されているパラメーターを含めることができます。
Parameter |
Description |
|---|---|
host |
The IP address of the host |
port |
The port on which the host is listening |
dbname |
The (optional) database name |
user |
A user name (if different from the information specified by the connecting client) |
password |
A password (if different from the information specified by the connecting client) |
次の例は、構成ファイルの[databases]
セクションで使用できる構文を示しています。
[databases]
edb = host=127.0.0.1 port=5444
postgres = host=127.0.0.1 port=5432
acctg = host=192.168.10.101 port=5432 user=bob password=XXXXXX
dbname
パラメーターを含めて、接続名を代替データベース名にマップします。例:
hr = host=127.0.0.1 port=5445 dbname=humanresources
クライアントが認証情報を提供すると、その情報を使用してEDB PgBouncerに接続します。 EDB PgBouncerは、EDB PgBouncer構成ファイルで指定された情報を使用してデータベースサーバーに接続します。構成ファイルで提供されるユーザー情報は、Postgresデータベースクラスターで定義されたロールと一致する必要があります。
注釈
If you don't specify user details in pgbouncer.ini , the user name and password are authenticated by the database server and EDB PgBouncer. As such, include the user name and password in the userlist.txt file and the database cluster.
構成ファイルの[pgbouncer] セクションには、EDB
PgBouncerに固有の構成の詳細が含まれています。
Parameter |
Description |
|---|---|
admin_users |
A comma-delimited list of users that are allowed to access the Admin console (for management and monitoring purposes). By default, EDB PgBouncer is installed with admin_users = enterprisedb. For the PostgreSQL server, set this value as admin_users = postgres. |
auth_file |
The path to the authentication file that contains user name and passwords of clients that can connect to EDB PgBouncer. The authentication file (userlist.txt) is located in /etc/edb/pgbouncer<x.x>/, and contains username/password pairs that specify the identities that clients can use to access EDB PgBouncer. In the authentication file, specify the user name and password in double quotes. To make changes to the identities that can access EDB PgBouncer, you can edit the existing authentication file or specify an alternative authentication file with the auth_file parameter. |
auth_type |
The authentication method used by EDB PgBouncer. Can 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. |
ignore_startup_parameters |
A comma-delimited list of application startup packets for EDB PgBouncer to ignore. The default is application_name. |
listen_addr |
The IP address on which EDB PgBouncer listens for client connections. If omitted, only Unix socket connections are allowed. The client must also reside on the same host as EDB PgBouncer and can't specify a host IP address when connecting to EDB PgBouncer. |
listen_port |
The port that EDB PgBouncer monitors for client connections. By default, EDB PgBouncer listens on port 6432. |
logfile |
The path to the EDB 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. Can be session, transaction, or statement. The default value is session. |
server_reset_query |
The default is DISCARD ALL, which instructs EDB 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. For the PostgreSQL server, set this value as stats_users = postgres. |
次の例は、 EDB Postgres Advanced ServerのEDB PgBouncer
1.16の構成ファイルの[pgbouncer]
セクションで使用できる構文を示しています。
[pgbouncer]
logfile = /var/log/edb/pgbouncer1.16/edb-pgbouncer-1.16.log
pidfile = /var/run/edb/pgbouncer1.16/edb-pgbouncer-1.16.pid
listen_addr = *
listen_port = 6432
auth_type = md5
auth_file = /etc/edb/pgbouncer-1.16/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
pgbouncer.ini ファイルで使用される設定の詳細については、
pgbouncer.iniを参照してください。
環境のEDB PgBouncer構成ファイルを編集した後、EDB
PgBouncerサービスを再起動して変更を有効にします。 CentOS、Rocky
Linux、AlmaLinux、RHEL、SUSE、およびWindowsプラットフォームの場合、EDB
PgBouncerサービス名はedb-pgbouncer-1.16 です。
Debパッケージの場合、EDB PgBouncerサービス名はedb-pgbouncer116
です。プラットフォーム固有のコマンドを使用して、必要に応じてサービスを停止、開始、または再起動します。
EDB PgBouncer管理コンソールの使用¶
管理コンソールでは、EDB
PgBouncerアクティビティに関する統計情報を取得したり、EDB
PgBouncerプロセスを制御したりできます。 edb-psqlクライアントを使用して、
pgbouncer データベースに接続することにより、EDB
PgBouncer管理コンソールにアクセスできます。
次の例では、Linuxシステムでedb-psqlクライアントを使用してpgbouncerデータベースに接続します。 EDB PgBouncerは、enterprisedbのユーザー名でポート6432でリッスンしています。
EDB Postgres Advanced Serverインストールの下のbinディレクトリに移動した後、次のコマンドを入力します。必要な接続情報は、接続するクライアント、プラットフォーム、およびサーバーが必要とする認証情報によって異なります。
$ ./edb-psql -p 6432 -U enterprisedb pgbouncer
PostgreSQLサーバーの場合、コマンドは次のとおりです。
$ ./edb-psql -p 6432 -h /tmp -U postgres pgbouncer
pgbouncerデータベースに接続した後、 SHOW CLIENTS
コマンドを使用してクライアント関連の情報を取得できます。
SHOW CLIENTS;¶
SHOW CLIENTS コマンドは次を返します。
__OUTPUT__
- -[ RECORD 1]-+--------------------
type | C
user | enterprisedb
database | pgbouncer
state | active
addr | unix
port | 6432
local_addr | unix
local_port | 6432
connect_time | 2010-05-25 05:26:20
request_time | 2010-05-25 05:39:46
ptr | 0x8655d20
link |
SHOW コマンドの他のバリエーションを使用して、EDB
PgBouncerに関する情報を取得できます。
SHOW STATS SHOW SERVERS SHOW POOLS SHOW LISTS
SHOW USERS SHOW DATABASES SHOW FDS SHOW CONFIG
次のコマンドを使用して、EDB PgBouncerプロセスを制御できます。 PgBouncerの使用の詳細については、 PgBouncer project site を参照してください。
PAUSE
現在のクエリが完了するのを待った後、 PAUSE
コマンドを使用してすべてのサーバーを切断します。
SUSPEND
SUSPEND コマンドを使用して、ソケットバッファーをフラッシュし、EDB
PgBouncerプロセスを一時停止します。
RESUME
RESUME コマンドを使用して、 PAUSE またはSUSPEND
コマンドの後で作業を再開します。
SHUTDOWN
SHUTDOWN コマンドを使用して、EDB
PgBouncerプロセスを停止して終了します。
RELOAD
RELOAD コマンドを使用して、EDB
PgBouncer構成ファイルをリロードします。