Thread: How to automate password requests?
Hello, I'm trying to automate some postgresql scripts, but I cannot find a way to pass a password directly to commands like pg_dump psql and so on. Even a echo "password" | psql doesn't work, the password prompt of psql is still waiting. mysql has the -p option. What would be the postgresql equivalent? I don't want to enter passwords dozend times. Regards Marten
Marten Lehmann wrote: > Hello, > > I'm trying to automate some postgresql scripts, but I cannot find a > way to pass a password directly to commands like pg_dump psql and so on. > Even a > > echo "password" | psql > > doesn't work, the password prompt of psql is still waiting. > > mysql has the -p option. What would be the postgresql equivalent? I > don't want to enter passwords dozend times. > > Regards > Marten > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings Read about something called the .pgpass file. There's a way to set a file that contains the password (pgAdmin will create one autmoatically) that pgsql will look for before it asks for your password. It's stored in ~/ The solution I use is a bat file that redefines an environment variable (PGPASSFILE) that points to the file, then runs pg_dumpall. -- Tom Hart IT Specialist Cooperative Federal 723 Westcott St. Syracuse, NY 13210 (315) 471-1116 ext. 202 (315) 476-0567 (fax)
On Wednesday 28 November 2007, Marten Lehmann <lehmann@cnm.de> wrote: > Hello, > > I'm trying to automate some postgresql scripts, but I cannot find a way > to pass a password directly to commands like pg_dump psql and so on. > Even a > > echo "password" | psql > > doesn't work, the password prompt of psql is still waiting. > > mysql has the -p option. What would be the postgresql equivalent? I > don't want to enter passwords dozend times. > create a .pgpass file. -- The global consumer economy can best be described as the most efficient way to convert natural resources into waste.
Hello, >> TIP 5: don't forget to increase your free space map settings > Read about something called the .pgpass file. There's a way to set a > file that contains the password (pgAdmin will create one autmoatically) > that pgsql will look for before it asks for your password. It's stored > in ~/ > > The solution I use is a bat file that redefines an environment variable > (PGPASSFILE) that points to the file, then runs pg_dumpall. is there no way to specify the password directly? I don't like to create a separate file because all config is done in a shell script. I could set a certain environment variable with the password, but does pgadmin read a password from such a variable? If yes, what is its name? Regards Marten
On 11/01/2008, Marten Lehmann <lehmann@cnm.de> wrote: > is there no way to specify the password directly? I don't like to create > a separate file because all config is done in a shell script. I could > set a certain environment variable with the password, but does pgadmin > read a password from such a variable? If yes, what is its name? This is generally a bad idea, because on many systems one can see the environment variables with which a process was started in ps' output. It shouldn't be too hard for your config-script to echo the proper parameters into ~/.pgpass . You best forget about the thought of having a shell variable with the password ;} > Regards > Marten Cheers, Andrej -- Please don't top post, and don't use HTML e-Mail :} Make your quotes concise. http://www.american.edu/econ/notes/htmlmail.htm
the name of env var is PGPASSWORD http://www.network-theory.co.uk/docs/postgresql/vol2/EnvironmentVariables1.h tml Viel Gluck Martin- ----- Original Message ----- From: "Marten Lehmann" <lehmann@cnm.de> To: <pgsql-general@postgresql.org> Sent: Thursday, January 10, 2008 6:48 PM Subject: Re: [GENERAL] How to automate password requests? > Hello, > > >> TIP 5: don't forget to increase your free space map settings > > Read about something called the .pgpass file. There's a way to set a > > file that contains the password (pgAdmin will create one autmoatically) > > that pgsql will look for before it asks for your password. It's stored > > in ~/ > > > > The solution I use is a bat file that redefines an environment variable > > (PGPASSFILE) that points to the file, then runs pg_dumpall. > > is there no way to specify the password directly? I don't like to create > a separate file because all config is done in a shell script. I could > set a certain environment variable with the password, but does pgadmin > read a password from such a variable? If yes, what is its name? > > Regards > Marten > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings >