Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 002AE4763A2 for ; Tue, 5 Nov 2002 04:24:37 -0500 (EST) Received: from mx10.mail.ru (mx10.mail.ru [194.67.57.20]) by postgresql.org (Postfix) with ESMTP id D6639476226 for ; Tue, 5 Nov 2002 04:24:36 -0500 (EST) Received: from drweb by mx10.mail.ru with drweb-scanned (Exim MX.A) id 188zwr-0007Xw-00; Tue, 05 Nov 2002 12:24:37 +0300 Received: from [213.128.193.142] (helo=mail.ru) by mx10.mail.ru with esmtp (Exim SMTP.A) id 188zwr-0007WT-00; Tue, 05 Nov 2002 12:24:37 +0300 Message-ID: <3DC78E52.9000706@mail.ru> Date: Tue, 05 Nov 2002 12:24:34 +0300 From: dima <_pppp@mail.ru> User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.0.0) Gecko/20020816 X-Accept-Language: ru, en-us, en MIME-Version: 1.0 To: Artur Pietruk Cc: pgsql-admin@postgresql.org Subject: Re: dumping a password-protected db from a perl script or References: <3DC676F6.9060900@mail.ru> <20021104151205.GK3354@yoda.plukwa.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/53 X-Sequence-Number: 6241 >>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 > #include > > 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.