passing passords to pgsql/pg_create/pg_dump programmatically

F

filippo

Hello,

I have written a program perl/Tkprogram, based on postgres. For
maintenance reasons in my program I use these commands:

`dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;

my @psqlOutput = `psql -l -U postgres -h $_`;


my program has a graphic interface but whenever I use these command,
postgres ask for passord in the command line. How can I give these
commands the right passowrd programmatically or how can I interact
with these to give the passwords by a graphic box?

Thanks and best refards,

Filippo
 
J

J. Gleixner

filippo said:
Hello,

I have written a program perl/Tkprogram, based on postgres. For
maintenance reasons in my program I use these commands:

`dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;

my @psqlOutput = `psql -l -U postgres -h $_`;


my program has a graphic interface but whenever I use these command,
postgres ask for passord in the command line. How can I give these
commands the right passowrd programmatically or how can I interact
with these to give the passwords by a graphic box?

Read the documentation for those commands to determine how the user
name and/or password is passed, then add the options and values to your
program. Since you wrote the above code, you should be able to figure
out how to add another option and value.
 
F

Filippo

Read the documentation for those commands to determine how the user
name and/or password is passed, then add the options and values to your
program. Since you wrote the above code, you should be able to figure
out how to add another option and value.

these commands don't accept password command line options, just put on
standard output the string "passord:" and read the standard input for
the value from user. I want to interact with them to pass the
information programmatically (redirect std input/output?).

Thanks,

Filippo
 
J

Josef Moellers

Filippo said:
these commands don't accept password command line options, just put on
standard output the string "passord:" and read the standard input for
the value from user. I want to interact with them to pass the
information programmatically (redirect std input/output?).

Have a look at Expect. Originally it's Tcl based, but a Perl port also
exists on CPAN.
 
B

Ben Morrow

[pgsql.general trimmed: it doesn't exist]

Quoth "filippo said:
Hello,

I have written a program perl/Tkprogram, based on postgres. For
maintenance reasons in my program I use these commands:

`dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;

my @psqlOutput = `psql -l -U postgres -h $_`;


my program has a graphic interface but whenever I use these command,
postgres ask for passord in the command line. How can I give these
commands the right passowrd programmatically or how can I interact
with these to give the passwords by a graphic box?

Read the manpages for those commands to find the appropriate equivalent
SQL (which exists, in every case: the commands just connect to the DB
and send SQL); then send that using DBI.

Ben
 
F

Filippo

[pgsql.general trimmed: it doesn't exist]

Quoth "filippo" <[email protected]>:


I have written a program perl/Tkprogram, based on postgres. For
maintenance reasons in my program I use these commands:
`dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
my @psqlOutput = `psql -l -U postgres -h $_`;
my program has a graphic interface but whenever I use these command,
postgres ask for passord in the command line. How can I give these
commands the right passowrd programmatically or how can I interact
with these to give the passwords by a graphic box?

Read the manpages for those commands to find the appropriate equivalent
SQL (which exists, in every case: the commands just connect to the DB
and send SQL); then send that using DBI.

thanks Ben,
the problem for me with this strategy is to re-create this

pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;

it is a dump (sql command) plus a pipe into another SQL command. I
don't figure out how to implement into simple SQL. By the way, thanks
for the hint.

BR,

Filippo
 
L

Lars Haugseth

* "filippo said:
Hello,

I have written a program perl/Tkprogram, based on postgres. For
maintenance reasons in my program I use these commands:

`dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;

my @psqlOutput = `psql -l -U postgres -h $_`;


my program has a graphic interface but whenever I use these command,
postgres ask for passord in the command line. How can I give these
commands the right passowrd programmatically or how can I interact
with these to give the passwords by a graphic box?

$ dropdb --help
$ createdb --help
$ pg_dump --help

As you can see, all of these command line utilities accept the -W
parameter followed by the password.

Alternatively you can configure PostgreSQL to allow connections
from certain clients without password authentication:

http://www.postgresql.org/docs/8.2/static/client-authentication.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top