I can successfully create a connection to db Postgres using the following:
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;
But I still have valuable login credentials (yes, I changed them) in my Perl module. I am currently using psql to interactively query queries. And to save on remembering my username / password, I put the credentials in a file (~ / .pgpass) with 600 permissions. The file looks like this:
# host:port:database:user:passwd myhost:5432:mydb:myuser:mypasswd
How can I safely use this file ( "$ENV{HOME}/.pgpass" ) and DBI to hide my credentials? It can be done? What is the practice?
source share