[postgis-users] loading sql files using batch commands - psql
Richard Greenwood
richard.greenwood at gmail.com
Tue Nov 20 14:15:00 PST 2012
You can also set user, password, database, port, etc. as environment
variables. So in your batch file:
set PGPASSWORD=secret
set PGUSER=postgres
set PGDATABASE=mydatabase
set PGPORT=5432
Taking it a little further I usually do:
set PGCONN="host=localhost dbname=%PGDATABASE% user=%PGUSER%
password=%PGPASSWORD% port=%PGPORT%"
And then I can use PGCONN with ogr2ogr:
ogr2ogr PG:%PGCONN% ...
Rich
On Tue, Nov 20, 2012 at 1:34 PM, Mike Toews <mwtoews at gmail.com> wrote:
> Hi Mark,
>
> Look into the .pgpass file[1], which is used to store a user's
> password in plain text in the user's home directory. Several
> PostgreSQL applications use the password file, including psql, pgAdmin
> III. One notable exception that doesn't yet use the password file is
> pgsql2shp [2].
>
> After you have this file configured for the user/database, the
> password will not be required or prompted for your psql command below.
>
> -Mike
>
> [1] http://www.postgresql.org/docs/current/static/libpq-pgpass.html
> [2] http://trac.osgeo.org/postgis/ticket/398
>
> On 21 November 2012 08:01, Mark Volz <MarkVolz at co.lyon.mn.us> wrote:
> > Hello,
> >
> > I am trying to create a batch program that will update postgis from a
> directory of shapefiles. I came across
> http://suite.opengeo.org/opengeo-docs/dataadmin/pgGettingStarted/shp2pgsql.html,
> 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.
> >
> > 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?
> > If not is there a way to trick a windows batch file to send the password
> to psql?
> >
> > Thanks for any help
> >
> > Mark Volz
> > GIS Specialist
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
--
Richard Greenwood
richard.greenwood at gmail.com
www.greenwoodmap.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20121120/ea5766ea/attachment.html>
More information about the postgis-users
mailing list