使用 perl 应用程序(rt 5 - 请求跟踪器)连接到 Postgres 数据库时出现数据库连接错误

使用 perl 应用程序(rt 5 - 请求跟踪器)连接到 Postgres 数据库时出现数据库连接错误

在 CentOS 9 系统上,我通过 dnf 安装了 postgres

    # dnf info postgresql
Last metadata expiration check: 3:26:33 ago on Tue 21 Nov 2023 12:13:48 PM PST.
Installed Packages
Name         : postgresql
Version      : 13.11

然后我编辑了 pg_hba.conf 以允许 md5 密码

    # TYPE  DATABASE        USER            ADDRESS                 METHOD
    
    # "local" is for Unix domain socket connections only
    #local   all             all                                     peer
    local   all             all                                     md5
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            ident
    # IPv6 local connections:
    host    all             all             ::1/128                 ident
    # Allow replication connections from localhost, by a user with the
    # replication privilege.
    local   replication     all                                     peer
    host    replication     all             127.0.0.1/32            ident
    host    replication     all             ::1/128                 ident
host  rt5  rt_user   all  md5
host  rt5  rt_admin  all  md5

然后我为我的 perl 应用程序创建了一个用户,以便使用 sql 进行连接:

 $ sudo -u postgres psql



postgres=# CREATE USER rt_user WITH PASSWORD 'foobar';
CREATE ROLE

postgres=# ALTER USER rt_user with SUPERUSER;

postgres=# ALTER USER rt_user with CREATEDB;

然后我可以看到权限设置正确:rt_user | 超级用户,创建数据库

我将我的连接详细信息添加到我的 perl 应用程序配置中(在本例中,perl 应用程序是请求跟踪器 5:https://rt-wiki.bestpractical.com/wiki/ManualInstallation#Red_Hat_Enterprise_Linux

# DatabaseUser is the name of the database account RT uses to read and store
# data. 'rt_user' is the default but you can change it if you like.
# DO NOT use the 'rt_admin' superuser created in the instructions above.
Set($DatabaseUser, 'rt_user');
# DatabasePassword is the password for DatabaseUser.
Set($DatabasePassword, 'foobar');
# DatabaseHost is the hostname of the database server RT should use.
# Change 'localhost' if it lives on a different server.
Set($DatabaseHost, 'localhost');
# DatabasePort is the port number of the database server RT should use.
# `undef` means the default for that database. Change it if you're not
# using the standard port.
Set($DatabasePort, undef);
# DatabaseName is the name of RT's database hosted on DatabaseHost.
# 'rt5' is the default but you can change it if you like.
Set($DatabaseName, 'rt5');
# DatabaseAdmin is the name of the user in the database used to perform
# major administrative tasks. Change 'rt_admin' if you're using a user
# besides the one created in this guide.
Set($DatabaseAdmin, 'rt_admin');

尽管连接详细信息看起来正确,但它仍然无法与该用户连接:

# make initialize-database
/usr/bin/env -S perl -I/opt/rt5/local/lib/perl5 -I/opt/rt5/local/lib -I/opt/rt5/lib sbin/rt-setup-database --action init --prompt-for-dba-password
In order to create or update your RT database, this script needs to connect to your  Pg instance on localhost (port '') as rt_admin
Please specify that user's database password below. If the user has no database
password, just press return.

Password: 
Working with:
Type:   Pg
Host:   localhost
Port:   
Name:   rt5
User:   rt_user
DBA:    rt_admin
Failed to connect to dbi:Pg:dbname=template1;host=localhost;client_encoding=UTF8 as user 'rt_admin': FATAL:  Ident authentication failed for user "rt_admin"make: *** [Makefile:390: initialize-database] Error 255
[root@localhost rt-5.0.3]# 

答案1

通过确保在数据库中创建具有适当权限的用户并按如下方式编辑 pga_hba.conf,解决了该问题:

# "local" is for Unix domain socket connections only
local   all             all                                     trust

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust

# IPv6 local connections:
host    all             all             ::1/128                 trust

# Allow password authentication for the user rt_admin from a specific IP range
host    all             rt_admin        192.168.1.0/24          md5
host    all             rt_user        192.168.1.0/24          md5

相关内容