我可以使用以下方法成功地创建到Postgres数据库的连接:
my $settings = {
host => 'myhost',
db => 'mydb',
user => 'myuser',
passwd => 'mypasswd'
};
my $connection = DBI->connect(
'DBI:Pg:dbname=' . $settings->{'db'} . ';host=' . $settings->{'host'},
$settings->{'user'},
$settings->{'passwd'},
{
RaiseError => 1,
ShowErrorStatement => 0,
AutoCommit => 0
}
) or die DBI->errstr;
然而,我的Perl模块中暴露了有价值的登录凭据(是的,我已经更改了它们)。目前,我使用psql
进行交互式查询。为了节省记住用户名/密码的麻烦,我将凭据放在了一个文件(~/.pgpass)中,并设置了600的权限。文件看起来像这样:
# host:port:database:user:passwd
myhost:5432:mydb:myuser:mypasswd
如何安全地使用此文件("$ENV{HOME}/.pgpass"
)以及DBI
模块来隐藏我的凭据?这可行吗?最佳实践是什么?
export PGSERVICE=test
连接到my $dbh = DBI->connect("dbi:Pg:", undef, undef);
。 - Craig R. Skinner~/.pg_service.conf
文件,但是我收到了错误消息:ERROR: service file "/etc/sysconfig/pgsql/pg_service.conf" not found
。有没有办法强制连接查看~/.pg_service.conf
呢? - Steve$ENV{'PGSYSCONFDIR'}
。谢谢! - Steve