Re: dumping a password-protected db from a perl script or

From: dima <_pppp(at)mail(dot)ru>
To: Artur Pietruk <arturp(at)plukwa(dot)pdi(dot)net>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: dumping a password-protected db from a perl script or
Date: 2002-11-05 09:24:34
Message-ID: 3DC78E52.9000706@mail.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

>>How can i dump a password-protected database using perl (DBI or pg) or C
>>(using libpq)? I can't pass the password to pg_dump utility (I was
>>trying to pass it via tty also) when running system() from perl.
>
>
> Isn't example below something like what you are trying to do:
>
> ====8<====
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void) {
> system("export PGDATABASE=\"test\"; export PGPASSWORD=\"test\"; export PGUSER=\"test\"; psql");
>
> exit(0);
> }
> ====8<====
>
> ? Here psql should connect to db 'test' as user 'test', password
> 'test'. Check if it works with pg_dump.
>
> I hope that helps! BTW - there are also other ways to do that...
> Check docs of your pg version. $PGPASSWORD is deprecated.

Thanks to Artur! I solved my problem another way using his hint.
I needed to make backups of a non-constant set of DBs as a cron job. I
connected to the main DB the usual way & made "select datname from
pg_database". Then I setup the environment correctly & forked a child
(pg_dump) for every DB in the list i got.
It will be a pity if $PGPASSWORD would dissapear in the future releases
of PostgreSQL since users wouldn't be able to automate some DB
maintainance tasks. I enjoy MySQL allowing to provide password @ the
prompt actually. Maybe this feature would be added to Postgres later.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message geek24@avantel.net 2002-11-05 15:42:59 Re: About lower and uppercase
Previous Message frbn 2002-11-05 08:22:37 Re: [ADMIN] About lower and uppercase