Typically, PostgreSQL can handle hundreds or thousands of concurrent connections when properly configured. However, the optimal number of users for your particular case may require testing and tuning.
In case your database reaches a critical point, there are several strategies you can apply to improve PostgreSQL performance, such as optimizing queries, tuning server resources, horizontal scaling, and using caching.
pgBouncer is a program that helps optimize PostgreSQL performance by reducing the number of server connections. It works as an intermediary between clients and servers, serving connection requests, executing queries, and retrieving results. This reduces the number of connections that directly access PostgreSQL, which can improve performance when there are a large number of clients.
Installation:
apt install pgbouncer.
Configuring userlist.txt:
"prnwatch_user" "prnwatch_password"
Configuring pgbouncer.ini:
[databases] prnwatch_template = host=127.0.0.1 port=5432 dbname=PRNWATCH auth_user=prnwatch_user [pgbouncer] listen_port = 6432 listen_addr = * auth_type = md5 auth_file = d:\PGBouncer\userlist.txt logfile = d:\PGBouncer\pgbouncer.log pidfile = d:\PGBouncer\pgbouncer.pid admin_users = prnwatch_user pool_mode = transaction default_pool_size = 100 max_client_conn = 10000
Section [databases]:
Section [pgbouncer]:
"prnwatch_user" "md5145c741eaed0b9c05ae8444b74d987f0"
Registering pgBouncer as a service:
pgbouncer --regservice pgbouncer.iniAfter that we start the pgBouncer service.
pgbouncer -d pgbouncer.ini
On each O&K Print Watch client, we specify a new database connection via pgBouncer.
Change the database connection string in O&K Print Watch:
Provider=MSDASQL;Driver={PostgreSQL Unicode};Server=PGBOUNCER_HOSTNAME;Port=6432;Database=prnwatch_template;UID=prnwatch_user;PWD=prnwatch_password;C8=0
host=PGBOUNCER_HOSTNAMEport=6432 dbname=prnwatch_template user=prnwatch_user password=prnwatch_password binary_parameters=yes
When using the database connection via pgBouncer, it is necessary to disable it Use serverside prepare. In the Windows version of O&K Print Watch the parameter C8=0 in the connection string is used for this, in the Linux version binary_parameters=yes.
Restart the O&K Print Watch Service:
net stop "O&K Print Watch Service" & sc start "O&K Print Watch Service"
systemctl restart printwatch