pgbouncer-密码文件

简介: pgbouncer

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

相关文章
|
关系型数据库 数据库 文件存储
|
Linux
Linux添加用户并赋管理员权限
Linux添加用户并赋管理员权限
313 0
|
安全 Go 索引
Go切片循环就用range 有这一篇就够了
Go切片循环就用range 有这一篇就够了
690 0
|
SQL 关系型数据库 MySQL
MySQL主从:延时从库恢复全解
MySQL主从:延时从库恢复全解
|
前端开发 NoSQL 关系型数据库
Nightingale——V6版本部署
Nightingale——V6版本部署
204 1
|
关系型数据库 数据库 PostgreSQL
pg下delete数据后。除了使用VACUUM FULL TABLE 才能释放磁盘空间外的方法。
【8月更文挑战第12天】pg下delete数据后。除了使用VACUUM FULL TABLE 才能释放磁盘空间外的方法。
712 1
|
存储 关系型数据库 分布式数据库
数据管理的艺术:PolarDB开源版详评与实战部署策略(二)
PolarDB-PG是阿里云的一款云原生关系型数据库,100%兼容PostgreSQL,支持Oracle语法,采用Shared-Storage存储计算分离架构,提供极致弹性、毫秒级延迟的HTAP能力。具备高可用、高可靠和弹性扩展特性,支持单机、存储计算分离和X-Paxos三节点等多种部署形态。通过Docker可快速部署实例,包括单节点、一主一备和HTAP(一主两备)实例。此外,文章还介绍了在ECS上使用ESSD云盘搭建PolarDB-PG的详细步骤,适合开发和测试环境。
224686 22
|
Ubuntu Linux 网络安全
|
消息中间件 缓存 NoSQL
硬核!GitHub置顶102W字Redis高手心法笔记,阿里竟第一时间收藏
天下武功,⽆坚不可摧,唯快不破! 学习⼀个技术,通常只接触了零散的技术点,没有在脑海⾥建⽴⼀个完整的知识框架和架构体系,没有系统观。这样会很吃⼒,⽽且会出现⼀看好像⾃⼰会,过后就忘记,⼀脸懵逼。
|
虚拟化 Docker 容器
Minikube - Kubernetes本地实验环境
为了方便大家本地开发和体验Kubernetes,社区提供了可以在本机部署的Minikube。本文介绍利用阿里云的镜像地址在Windows/Mac/Linux上来部署和配置Minikube
239660 71
Minikube - Kubernetes本地实验环境