Thread: psql without password prompt
I want to run a SQL script in my crontab job which requires using psql without having to input password every time. I am running postgresql 7.2. What is the trick? Thank you. -- Wei Weng Network Software Engineer KenCast Inc.
Set the PGPASSWORD environment variable or supply it on STDIN. Your user environment may be visible to other users so PGPASSWORD may not be secure. I just don't mount /proc so I don't worry about that (I run OpenBSD which doesn't require /proc like linux tends to). You may also consider sending the password in on STDIN. If that doesn't work then use a scripting language and don't use psql. Joshua b. Jore ; http://www.greentechnologist.org ; 10012 11010 11022 10202 1012 2122 11020 10202 10202 11002 1020 1012 11102 11102 11102 1201 11001 11002 10211 11020 10202 10202 11002 11021 1201 11010 11020 10211 On 29 May 2002, Wei Weng wrote: > I want to run a SQL script in my crontab job which requires using psql > without having to input password every time. I am running postgresql > 7.2. > > What is the trick? > > Thank you. > > > > -- > Wei Weng > Network Software Engineer > KenCast Inc. > > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster >
"Joshua b. Jore" <josh@greentechnologist.org> writes: >> [ how to run batch scripts without embedding a password? ] > Set the PGPASSWORD environment variable or supply it on STDIN. Your user > environment may be visible to other users so PGPASSWORD may not be secure. > I just don't mount /proc so I don't worry about that (I run OpenBSD which > doesn't require /proc like linux tends to). You may also consider sending > the password in on STDIN. An even better answer is to not use password authentication, if possible. If your platform supports IDENT auth for local (Unix-socket) connections, that's a pretty good alternative IMHO. IDENT across loopback (127.0.0.1) connections is also workable if you run an identd daemon; this works on most every platform. I would not recommend IDENT for remote connections though, unless you trust the admin of the remote machine. regards, tom lane
> I want to run a SQL script in my crontab job which requires using psql > without having to input password every time. I am running postgresql > 7.2. > > What is the trick? You may have gotten other replies that I've not noticed in my mail que, but what I do is write my script in perl and use the DBI module to connect to the database. Then use cron to run the script. I'm sure there are other ways, but that's one way. brew