sql >> Database teknologi >  >> RDS >> PostgreSQL

Perl - DBI og .pgpass

JA! Der ER en bedre måde.

Skift nemt mellem test- og liveservere.

  • opbevar adgangskoder i ~/.pgpass (for psql &pg_dump )
  • andre konfigurationsoplysninger i ~/.pg_service.conf (eller /etc/pg_service.conf )

f.eks.:

#!/usr/bin/perl -T
use strict;
use warnings;
use DBI;

my $dbh = DBI->connect
(
    #"dbi:Pg:service=live",
    "dbi:Pg:service=test",
    undef,
    undef,
    {
        AutoCommit => 0,
        RaiseError => 1,
        PrintError => 0
    }
) or die DBI->errstr;

~/.pg_service.conf:

# http://www.postgresql.org/docs/9.2/static/libpq-pgservice.html
# /usr/local/share/postgresql/pg_service.conf.sample
# http://search.cpan.org/dist/DBD-Pg/Pg.pm
#

[test]
dbname=hotapp_test
user=hotusr_test
# localhost, no TCP nonsense needed:
host=/tmp

[live]
dbname=hotapp_live
user=hotusr_live
host=pgsql-server.example.org

~/.pgpass:

# http://www.postgresql.org/docs/9.2/static/libpq-pgpass.html
# hostname:port:database:username:password
localhost:5432:hotapp_test:hotusr_test:kq[O2Px7=g1
pgsql-server.example.org:5432:hotapp_live:hotusr_live:Unm£a7D(H


  1. Omdøbning af pluggbar database

  2. Initialiseringsafsnit af pakken

  3. Hvad er forskellen mellem JOIN og CROSS JOIN i SQL?

  4. Indlejrede aggregatfunktioner