You can also set user, password, database, port, etc. as environment variables. So in your batch file:<br>set PGPASSWORD=secret<br>set PGUSER=postgres<br>set PGDATABASE=mydatabase<br>set PGPORT=5432<br><br>Taking it a little further I usually do:<br>
set PGCONN="host=localhost dbname=%PGDATABASE% user=%PGUSER% password=%PGPASSWORD% port=%PGPORT%"<br><br>And then I can use PGCONN with ogr2ogr:<br>ogr2ogr PG:%PGCONN% ...<br><br>Rich<br><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Nov 20, 2012 at 1:34 PM, Mike Toews <span dir="ltr"><<a href="mailto:mwtoews@gmail.com" target="_blank">mwtoews@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Mark,<br>
<br>
Look into the .pgpass file[1], which is used to store a user's<br>
password in plain text in the user's home directory. Several<br>
PostgreSQL applications use the password file, including psql, pgAdmin<br>
III. One notable exception that doesn't yet use the password file is<br>
pgsql2shp [2].<br>
<br>
After you have this file configured for the user/database, the<br>
password will not be required or prompted for your psql command below.<br>
<br>
-Mike<br>
<br>
[1] <a href="http://www.postgresql.org/docs/current/static/libpq-pgpass.html" target="_blank">http://www.postgresql.org/docs/current/static/libpq-pgpass.html</a><br>
[2] <a href="http://trac.osgeo.org/postgis/ticket/398" target="_blank">http://trac.osgeo.org/postgis/ticket/398</a><br>
<div class="HOEnZb"><div class="h5"><br>
On 21 November 2012 08:01, Mark Volz <<a href="mailto:MarkVolz@co.lyon.mn.us">MarkVolz@co.lyon.mn.us</a>> wrote:<br>
> Hello,<br>
><br>
> I am trying to create a batch program that will update postgis from a directory of shapefiles. I came across <a href="http://suite.opengeo.org/opengeo-docs/dataadmin/pgGettingStarted/shp2pgsql.html" target="_blank">http://suite.opengeo.org/opengeo-docs/dataadmin/pgGettingStarted/shp2pgsql.html</a>, which uses psql to load data into postgis. The psql command appears to prompt for a password, which would be fine if I was manually running the batch file. However, I want to set up a scheduled task in windows so that my data gets updated on automatic intervals.<br>
><br>
> Is there a way to store a password in a batch file such as " for %%f in (*.sql) do psql -p 5432 -w -U postgres --password mypassword --dbname postgis20 -f %%f?<br>
> If not is there a way to trick a windows batch file to send the password to psql?<br>
><br>
> Thanks for any help<br>
><br>
> Mark Volz<br>
> GIS Specialist<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Richard Greenwood<br><a href="mailto:richard.greenwood@gmail.com">richard.greenwood@gmail.com</a><br><a href="http://www.greenwoodmap.com">www.greenwoodmap.com</a><br>
</div>