PgBouncer config常见错误

简介: PgBouncer config

PgBouncer config

https://www.pgbouncer.org/config.html

[pg10@db01 data]$ psql -h db01 -p5766 -d test01 -U admin
psql: ERROR: no such user: admin

用户名称未配置在密码文件之中(auth_file)。

[pg10@db01 data]$ psql -h db01 -p5766 -d test01 -U test01
Password for user test01:
psql: ERROR: SASL authentication failed //scram-sha-256认证密码错误信息。

[pg10@db01 data]$ psql -h db01 -p5766 -d test01 -U test01
Password for user test01:
psql: ERROR: password authentication failed //md5认证密码错误信息。

密码错误

[pg10@db01 data]$ psql -h db01 -p5766 -d test
psql: ERROR: no such database: test

数据库名称错误,检查pgbouncer.ini查看数据库名称配置信息。

测试用例:

配置文件参考:

[pg10@db01 pgbouncer]$ cat pgbouncer.ini
[databases]
;;; 未设置用户密码,需要使用auth_file密码连接数据。
test01=host=db01 port=5432 dbname=test01
[pgbouncer]
logfile = /home/pg10/pgbouncer/pgbouncer.log
pidfile = /home/pg10/pgbouncer/pgbouncer.pid
auth_type = md5
auth_file = /data/pg
listen_addr = *
listen_port = 5766

密码文件

select usename,passwd from pg_shadow;

[pg10@db01 pgbouncer]$ cat /data/pg
"test01" "123456"

数据库建立test01数据库和用户

5432数据库建立测试用户和数据库:

create user test01 with password '123456';
create database test01 owner test01;
grant all privileges on database test01 to test01;

连接池连接测试:

-h 指定ip地址
-p 连接池端口
-d 数据库连接描述名称
[pg10@db01 data]$ psql -h db01 -p5766 -d test01 -U test01
Password for user test01:
psql (10.14)
Type "help" for help.
test01=>

数据库连接符号*

The database name “pgbouncer” is reserved for the admin console and cannot be used as a key here.

“*” acts as a fallback database: If the exact name does not exist, its value is taken as connection string for the requested database. For example, if there is an entry (and no other overriding entries)

  • = host=foo

then a connection to PgBouncer specifying a database “bar” will effectively behave as if an entry
bar = host=foo dbname=bar
exists (taking advantage of the default for dbname being the client-side database name; see below).
Such automatically created database entries are cleaned up if they stay idle longer than the time specified by the autodb_idle_timeout parameter.

If user= is set, all connections to the destination database will be done with the specified user, meaning that there will be only one pool for this database.
password
If no password is specified here, the password from the auth_file or auth_query will be used.

数据连接的几种方式:
appdb=host=db01 port=5666 dbname=appdb
appdb01=host=db01 port=5666 user=appuser password=1qaz@WSX dbname=appdb01
*=host=db01 port=5432

databases配置比较简单,每行由key=value对组成,其中key为对外数据库名称,value由多个以空格隔开的key=value对的连接串及相关参数对组成。

host: 后端数据库的主机名或者IP地址
port: 后端数据库监听端口
dbname: 后端数据库名称
user: 连接后端数据库的用户名
password: 连接后端数据库的密码
pool_size: 配置连接池的大小,如果没有配置此项,连接池大小将使用[pgbouncer]部分中default_pool_size配置的值
connect_query: 在连接使用之前执行一个SQL语句,用于探测此连接是否正常.如果执行该语句出错,则选择另外一个连接
max_db_connections: 配置数据库范围的最大值(即数据库中的所有池都不会有这么多的服务器连接
client_encoding: 制定客户端字符集编码
datestyle: 指定日志类型参数
timezone: 指定时区
注意:如果在连接串中没有指定user和password,那么pgbouncer将使用给客户端连接pgbouncer时的用户名和密码来连接后端数据库,并为每个不同的用户建立一个连接池;
如果连接中指定了user和password,pgbouncer将使用这里设置的用户名和密码来连接后端数据库,这样对使用这项配置的数据库来说,就只有一个连接池了.

[pg10@db01 pgbouncer]$ cat pgbouncer.ini
[databases]
;;; 数据连接符号*,匹配所有数据库。
*=host=db01 port=5432
[pgbouncer]
logfile = /home/pg10/pgbouncer/pgbouncer.log
pidfile = /home/pg10/pgbouncer/pgbouncer.pid
auth_type = md5
auth_file = /data/pg
listen_addr = *
listen_port = 5766

匹配所有数据库,客户端数据库数据库名称和源数据库一致(pgbouncer把数据库信息发送到数据库服务器认证)
[pg10@db01 data]$ psql -h db01 -p5766 -d sadfsdf -U test01
Password for user test01:
psql: ERROR: database "sadfsdf" does not exist
[pg10@db01 data]$ psql -h db01 -p5766 -d sadfsdf -U test01
psql: ERROR: pgbouncer cannot connect to server

需要输入正确数据库名称和用户名:

[pg10@db01 data]$ psql -h db01 -p5766 -d test01 -U test01
Password for user test01:
psql (10.14)
Type "help" for help.
test01=> \q

相关文章
|
关系型数据库 数据库 文件存储
|
安全 关系型数据库 数据库
Postgresql 数据库用户权限授权(用户角色分配模式)
为了更方面和安全地管理数据库用户账号权限安全,实现通过用户角色代理的模式,实现用户账号功能授权的模式
19424 2
Postgresql 数据库用户权限授权(用户角色分配模式)
|
关系型数据库 数据库 PostgreSQL
PostgreSQL 内存表可选项 - unlogged table
标签 PostgreSQL , 内存表 , unlogged table 背景 内存表,通常被用于不需要持久化,变更频繁,访问RT低的场景。 目前社区版本PostgreSQL没有内存表的功能,postgrespro提供了两个插件可以实现类似内存表的功能。
3701 0
|
12月前
|
缓存 搜索推荐 数据挖掘
TPS和QPS是什么?都是什么区别?
TPS和QPS是什么?都是什么区别?
8695 4
|
11月前
|
SQL 关系型数据库 数据库
PostgreSQL性能飙升的秘密:这几个调优技巧让你的数据库查询速度翻倍!
【10月更文挑战第25天】本文介绍了几种有效提升 PostgreSQL 数据库查询效率的方法,包括索引优化、查询优化、配置优化和硬件优化。通过合理设计索引、编写高效 SQL 查询、调整配置参数和选择合适硬件,可以显著提高数据库性能。
1804 2
|
运维 监控 关系型数据库
【一文搞懂PGSQL】7. PostgreSQL + repmgr + witness 高可用架构
该文档介绍了如何构建基于PostgreSQL的高可用架构,利用repmgr进行集群管理和故障转移,并引入witness节点增强网络故障检测能力。repmgr是一款轻量级的开源工具,支持一键部署、自动故障转移及分布式节点管理。文档详细描述了环境搭建步骤,包括配置postgresql参数、安装与配置repmgr、注册集群节点以及配置witness节点等。此外,还提供了故障手动与自动切换的方法及常用命令,确保集群稳定运行。
|
监控 关系型数据库 数据库
RDS PostgreSQL内置连接池PgBouncer
2023年7月,阿里云RDS PostgreSQL支持内置数据库连接池PgBouncer,本篇文章从以下角度探讨PgBouncer:1. PgBouncer是什么;2. 应用场景 ;3. 性能对比;4. 如何使用;5. 总结
|
应用服务中间件 nginx
Nginx的referer参数的用法和原理
总结:referer参数可以用于Nginx配置,以限制或允许特定来源网站的访问,提高安全性或控制流量。它通过valid_referers指令来定义合法的Referer来源,并根据配置对请求进行处理。但需要注意,Referer字段内容可以被伪造,因此不应作为唯一的安全措施。
1294 0
|
消息中间件 监控 Java
Kafka性能调优:高吞吐、低延迟的数据流
Apache Kafka作为一种高性能、分布式流处理平台,对于实时数据的处理至关重要。本文将深入讨论Kafka性能调优的关键策略和技术,通过丰富的示例代码为大家提供实际操作指南,以构建高吞吐、低延迟的数据流系统。