Pg_dump options

Started by Campano, Troyabout 24 years ago10 messagesgeneral
Jump to latest
#1Campano, Troy
Troy.Campano@LibertyMutual.com

Is there a way to supply a username and password in one command using
pg_dump?

For example is it possible to do this so it doesn't prompt you for a
username/password:

pg_dump mydb --username=dbuser --password=dbpass > myfile.out

Thank you!

[:==> Troy Campano <==:]

#2Gurudutt
guru@indvalley.com
In reply to: Campano, Troy (#1)
Re: Pg_dump options

Hello Troy,

You could use one of these things to get it working..

Create one txt file, input the username and password in different
lines like

Username
Password

save the file(user.txt)...

Give this file as input to the pg_dump it should work

pg_dump dummy_db < user.txt > /tmp/dummy_db.sql

Hope it solves the problem, it worked for me...

Gurudutt

Tuesday, January 29, 2002, 12:38:07 AM, you wrote:

TCLc> Is there a way to supply a username and password in one command using
TCLc> pg_dump?

TCLc> For example is it possible to do this so it doesn't prompt you for a
TCLc> username/password:

TCLc> pg_dump mydb --username=dbuser --password=dbpass > myfile.out

TCLc> Thank you!

[:==>> Troy Campano <==:]

--
Best regards,
Gurudutt mailto:guru@indvalley.com

Life is not fair - get used to it.
Bill Gates

#3Dmitry Alyabyev
dimitry@al.org.ua
In reply to: Gurudutt (#2)
Re: Pg_dump options

Tuesday, January 29, 2002, 7:34:17 AM, Gurudutt wrote:

Hello Troy,

You could use one of these things to get it working..

Create one txt file, input the username and password in different
lines like

Username
Password

save the file(user.txt)...

Give this file as input to the pg_dump it should work

pg_dump dummy_db < user.txt > /tmp/dummy_db.sql

Hope it solves the problem, it worked for me...

yes, it works BUT you will have lines "Username:" and "Password:" in
your dump file. I think better to have these options in pg_dump (like
mysql_dump has) instead of doing this work around.

--
Dimitry

#4Gurudutt
guru@indvalley.com
In reply to: Dmitry Alyabyev (#3)
Re: Pg_dump options

Hello Dmitry,

Yes!! I fully agree with what you say, the option should've been there
in pg_dump just the way it is in mysql_dump. But Username: & Password:
won't be there in the dump file if u write the pg_dump command in a
shell script and execute it inside the shell.

Tuesday, January 29, 2002, 1:10:06 PM, you wrote:

DA> Tuesday, January 29, 2002, 7:34:17 AM, Gurudutt wrote:

Hello Troy,

You could use one of these things to get it working..

Create one txt file, input the username and password in different
lines like

Username
Password

save the file(user.txt)...

Give this file as input to the pg_dump it should work

pg_dump dummy_db < user.txt > /tmp/dummy_db.sql

Hope it solves the problem, it worked for me...

DA> yes, it works BUT you will have lines "Username:" and "Password:" in
DA> your dump file. I think better to have these options in pg_dump (like
DA> mysql_dump has) instead of doing this work around.

--
Best regards,
Gurudutt mailto:guru@indvalley.com

Life is not fair - get used to it.
Bill Gates

#5Karl DeBisschop
kdebisschop@range.infoplease.com
In reply to: Gurudutt (#4)
Re: Pg_dump options

On Tue, 2002-01-29 at 03:27, Gurudutt wrote:

Hello Dmitry,

Yes!! I fully agree with what you say, the option should've been there
in pg_dump just the way it is in mysql_dump.

IIRC, it has been discussed, but was rejected because passing a password
on a command line cannot generally be made secure.

Responding to a propmt can. A variety of other methods can. But command
lines are sniffable in many (most? all?) environments.

--
Karl

#6Dmitry Alyabyev
dimitry@al.org.ua
In reply to: Karl DeBisschop (#5)
Re: Pg_dump options

Yes, you're right. But why do not make it like --user and
--read-password-from-stdin-without-promtp options ?

--
Dimitry

Tuesday, January 29, 2002, 11:16:21 AM, Karl DeBisschop wrote:

Show quoted text

On Tue, 2002-01-29 at 03:27, Gurudutt wrote:

Hello Dmitry,

Yes!! I fully agree with what you say, the option should've been there
in pg_dump just the way it is in mysql_dump.

IIRC, it has been discussed, but was rejected because passing a password
on a command line cannot generally be made secure.

Responding to a propmt can. A variety of other methods can. But command
lines are sniffable in many (most? all?) environments.

--
Karl

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

#7Karl DeBisschop
kdebisschop@range.infoplease.com
In reply to: Dmitry Alyabyev (#6)
Re: Pg_dump options

On Tue, 2002-01-29 at 04:45, Dmitry Alyabyev wrote:

Yes, you're right. But why do not make it like --user and
--read-password-from-stdin-without-promtp options ?

In the man page for pg_dump in7.2:

-U username
Connect as the given user.

-W Force a password prompt. This should happen auto-
matically if the server requires password authenti-
cation.

And the password prompt does not write into your dump file.

--
Karl

#8Dmitry Alyabyev
dimitry@al.org.ua
In reply to: Karl DeBisschop (#7)
Re: Pg_dump options

Sorry, I didn't check it for 7.1 branch - but it definitely happened
for 7.0

--
Dimitry

Tuesday, January 29, 2002, 12:30:16 PM, Karl DeBisschop wrote:

Show quoted text

On Tue, 2002-01-29 at 04:45, Dmitry Alyabyev wrote:

Yes, you're right. But why do not make it like --user and
--read-password-from-stdin-without-promtp options ?

In the man page for pg_dump in7.2:

-U username
Connect as the given user.

-W Force a password prompt. This should happen auto-
matically if the server requires password authenti-
cation.

And the password prompt does not write into your dump file.

--
Karl

#9Devrim GUNDUZ
devrim@oper.metu.edu.tr
In reply to: Campano, Troy (#1)
Re: Pg_dump options

Hi,

YOu could do it by using expect:
Here is a sample code:

---------------
1. backup.sh

#!/usr/bin/expect -f
set env(SHELL) /bin/sh
set env(HOME) /usr/sbin/

spawn /usr/sbin/createdbbackups.sh

expect Username:
send postgres\r
expect Password:
send YourPasswdHere\r

2.createdbbackups.sh

pg_dump mydb > mydb.pgdump -p 5456 -u;

---------------

If you are having a backup for more than one database, you should write
their names in the second file, and write the last four lines in the first
file (beginning with expect, ending with the passwd line) as many as the
number of your databases.

Regards and best wishes,

--

Devrim G�ND�Z

devrim@oper.metu.edu.tr
devrim.gunduz@linux.org.tr
devrimg@tr.net

Phone : +90-535-328-9594 (cellular)-
Phone : +90-312-295-9595 (work)
Phone : +90-312-286-5906 (home)

Web : http://devrim.oper.metu.edu.tr
------------------------------------------------------------------

On Mon, 28 Jan 2002 Troy.Campano@LibertyMutual.com wrote:

Show quoted text

Is there a way to supply a username and password in one command using
pg_dump?

For example is it possible to do this so it doesn't prompt you for a
username/password:

pg_dump mydb --username=dbuser --password=dbpass > myfile.out

Thank you!

[:==> Troy Campano <==:]

#10Achilleus Mantzios
rnd@gatewaynet.com
In reply to: Devrim GUNDUZ (#9)
Re: Pg_dump options

Also you could create a protected file
eg pgCONFIDENTIAL
with the lines

yourusername
yourpasswd

and do

cat pgCONFIDENTIAL | pg_dump -u yourdb > dbdump.sql