<div dir="ltr"><div><div>[ please keep it in the list ]<br></div><div><br>On Thu, Feb 15, 2018 at 8:52 AM, Vilem Ded <<a href="mailto:Ded.V@seznam.cz">Ded.V@seznam.cz</a>> wrote:<br>><br>> Hi,<br>> now it works!<br>> Can you please briefly elaborate, why setting dbname, dbschema by db.connect + user,password by db.login does not work?<br><br></div><div>I don't know really, maybe no write permissions? Maybe something collides when trying to read from and write to the same db + schema at the same time?<br></div><div><br>> The v.in.ogr is working now, but it doesnt seem very safe to leave password in input string in the script (it is not so serious with only SELECT priviledges though)<br><br></div>you can add a .pgpass <span class="gmail-il">file</span> entry as such:<br>
<br>
thehost:5432:thedb:theuser:the<wbr>passwd<br>
<br></div>then you don't need to provide username and password in the script, the PG client library will fetch them from the .pgpass file.<br><div><div><br>Markus M<br><br>> Thank you very much<br>> Vil<br>> ---------- Původní e-mail ----------<br>> Od: Markus Metz <<a href="mailto:markus.metz.giswork@gmail.com">markus.metz.giswork@gmail.com</a>><br>> Komu: Vilem Ded <<a href="mailto:Ded.V@seznam.cz">Ded.V@seznam.cz</a>><br>> Datum: 14. 2. 2018 18:01:11<br>><br>> Předmět: Re: [GRASS-user] load vector map from PostGIS<br>><br>><br>><br>> On Wed, Feb 14, 2018 at 4:44 PM, Vilem Ded <<a href="mailto:Ded.V@seznam.cz">Ded.V@seznam.cz</a>> wrote:<br>> ><br>> > Thank you a lot. I have managed to move forward, but i am not there yet:/<br>> > I can definitely reach the database since the command:<br>> >  v.in.ogr -l input= "PG:host=172.21.3.20 dbname=mydb user=dbusername password=passwd"<br>> > prints out names of my tables in database.<br>> > But command<br>> > v.in.ogr input= "PG:host=172.21.3.20 dbname=mydb user=dbusername password=passwd" output=outpoint  layer=myschema.mytable<br>> > prints an error about "missing '=' after 'mydb' in connection info string" (at the end). This seems maybe like pg error than grass.script, doesnt it?<br>><br>> Try to reset the default GRASS db connection to the default (sqlite) with<br>><br>> db.connect -d<br>><br>> and test again<br>><br>> Markus M<br>> ><br>> > Thx.<br>> > Vil<br>> ><br>> > DBMI-PostgreSQL driver error:<br>> > Connection failed.<br>> > missing "=" after "mydb" in connection info string<br>> ><br>> > DBMI-PostgreSQL driver error:<br>> > Connection failed.<br>> > missing "=" after "mydb" in connection info string<br>> ><br>> > WARNING: Unable to open database <dbname=mydb schema=myschema> by<br>> >          driver <pg><br>> > WARNING: Unable open database <dbname=mydb schema=myschema> by<br>> >          driver <pg><br>> > WARNING: Unable to find table <outputpoint> linked to vector map<br>> >          <outputpoint><br>> > Creating attribute table for layer <myschema.mytable>...<br>> > DBMI-PostgreSQL driver error:<br>> > Connection failed.<br>> > missing "=" after "mydb" in connection info string<br>> ><br>> > DBMI-PostgreSQL driver error:<br>> > Connection failed.<br>> > missing "=" after "mydb" in connection info string<br>> ><br>> > WARNING: Unable to open database <dbname=mydb schema=myschema> by<br>> >          driver <pg><br>> > ERROR: Unable to open database <dbname=mydb schema=myschema> by<br>> >        driver <pg><br>> ><br>> ><br>> ><br>> > ---------- Původní e-mail ----------<br>> > Od: Moritz Lennert <<a href="mailto:mlennert@club.worldonline.be">mlennert@club.worldonline.be</a>><br>> > Komu: Vilem Ded <<a href="mailto:Ded.V@seznam.cz">Ded.V@seznam.cz</a>><br>> > Datum: 13. 2. 2018 14:58:22<br>> > Předmět: Re: [GRASS-user] load vector map from PostGIS<br>> ><br>> > Le Tue, 13 Feb 2018 14:09:31 +0100 (CET),<br>> > "Vilem Ded" <<a href="mailto:Ded.V@seznam.cz">Ded.V@seznam.cz</a>> a écrit :<br>> ><br>> > > Hi,<br>> > > is there any possibility to download data  into local grass database<br>> > > (topologcal) from remote postgis server? (without getting error)<br>> > > Or is the issue still pending?<br>> > > (<a href="http://osgeo-org.1560.x6.nabble.com/Unable-">http://osgeo-org.1560.x6.nabble.com/Unable-</a><br>> > > to-link-to-postgis-postgresql-td5285313.html) I am using Python to<br>> > > work with GRASS. And honestly, I got lost in outputs of db.*<br>> > > functions:<br>> ><br>> > AFAIK, you should not need to go through all the db.* functions to<br>> > import your data. Not much time to look any further into this, but check<br>> > this thread:<br>> > <a href="https://lists.osgeo.org/pipermail/grass-dev/2017-May/085032.html/">https://lists.osgeo.org/pipermail/grass-dev/2017-May/085032.html/</a><br>> ><br>> > In brief, you should be able to import your data with a simple v.in.ogr<br>> > call, without any db.connect/db.login magic.<br>> ><br>> > Moritz<br>> ><br>> > ><br>> > > #set database and login<br>> > > gscript.run_command('db.connect',<br>> > > database="host=172.21.3.20,dbname=mydb", driver="pg",  verbose = True)<br>> > > gscript.run_command('db.login', user="dbusername", password="passwd",<br>> > > overwrite = True)<br>> > ><br>> > > #verifying connection<br>> > > gscript.run_command('db.connect', flags='p')<br>> > > output:<br>> > > driver: pg<br>> > > database: host=172.21.3.20,dbname=mydb<br>> > > schema:<br>> > > group:<br>> > > #so everything looks fine so far<br>> > ><br>> > > #here comes the trouble - simple list tables in db<br>> > > gscript.run_command('db.tables', flags='p', verbose = True)<br>> > > output:<br>> > > DBMI-PostgreSQL driver error:<br>> > > Connection failed.<br>> > > could not connect to server: No such file or directory<br>> > >     Is the server running locally and accepting<br>> > >     connections on Unix domain socket<br>> > > "/var/run/postgresql/.s.PGSQL.5432"?<br>> > ><br>> > > DBMI-PostgreSQL driver error:<br>> > > Connection failed.<br>> > > could not connect to server: No such file or directory<br>> > >     Is the server running locally and accepting<br>> > >     connections on Unix domain socket<br>> > > "/var/run/postgresql/.s.PGSQL.5432"?<br>> > ><br>> > > ERROR: Unable to open database <host=172.21.3.20,dbname=mydb><br>> > ><br>> > > #but for example:<br>> > > gscript.run_command('v.external',<br>> > >                     input="PG:dbname=mydb host=172.21.3.20",<br>> > >                     flags='l', overwrite =  True)<br>> > > output:<br>> > > --actuall list of all tables in mydb - so i CAN connect to the server!<br>> > ><br>> > > #same for mapping external link - following will create external link<br>> > > gscript.run_command('v.external',<br>> > >                     input="PG:dbname=mydb host=172.21.3.20<br>> > > user=dbusername password=password",<br>> > >                     layer="myschema.mytable", output='outpoints,<br>> > > overwrite = True)<br>> > > output:<br>> > > WARNING: No key column detected.<br>> > > WARNING: Feature table <outpoints> has no primary key defined. Unable<br>> > > to define DB links.<br>> > > WARNING: Feature table <outpoints> has no primary key defined<br>> > > WARNING: Random read is not supported for this layer. Unable to build<br>> > >          topology.<br>> > > v.external complete. Link to vector map <outpoints> created.<br>> > ><br>> > > #weird, because i have primary key defined in the table, following is<br>> > > printing description of that external link<br>> > > gscript.vector_info("outpoints")<br>> > ><br>> > > #if i try to load data from database<br>> > > gscript.run_command('v.in.ogr',<br>> > >                     input="PG:dbname=mydb host=172.21.3.20",<br>> > >                     layer='myschema.mytable',geometry="mygeomcolumn",<br>> > > output = "outpoints2", overwrite =  True, type="point")<br>> > > output:<br>> > > Check if OGR layer <myschema.mytable> contains polygons...<br>> > >  100%�����<br>> > > WARNING: Vector map <outpoints2> already exists and will be<br>> > > overwritten DBMI-PostgreSQL driver error:<br>> > > Connection failed.<br>> > > could not connect to server: No such file or directory<br>> > >     Is the server running locally and accepting<br>> > >     connections on Unix domain socket<br>> > > "/var/run/postgresql/.s.PGSQL.5432"?<br>> > ><br>> > > DBMI-PostgreSQL driver error:<br>> > > Connection failed.<br>> > > could not connect to server: No such file or directory<br>> > >     Is the server running locally and accepting<br>> > >     connections on Unix domain socket<br>> > > "/var/run/postgresql/.s.PGSQL.5432"?<br>> > ><br>> > > WARNING: Unable to open database <host=172.21.3.20,dbname=macfishdb><br>> > > by driver <pg><br>> > > WARNING: Unable open database <host=172.21.3.20,dbname=macfishdb> by<br>> > > driver <pg><br>> > > WARNING: Unable to find table <outpoints2> linked to vector map<br>> > > <lp_grass> Creating attribute table for layer<br>> > > <at_macfish.loggerpos>... DBMI-PostgreSQL driver error:<br>> > > Connection failed.<br>> > > could not connect to server: No such file or directory<br>> > >     Is the server running locally and accepting<br>> > >     connections on Unix domain socket<br>> > > "/var/run/postgresql/.s.PGSQL.5432"?<br>> > ><br>> > > DBMI-PostgreSQL driver error:<br>> > > Connection failed.<br>> > > could not connect to server: No such file or directory<br>> > >     Is the server running locally and accepting<br>> > >     connections on Unix domain socket<br>> > > "/var/run/postgresql/.s.PGSQL.5432"?<br>> > ><br>> > > WARNING: Unable to open database <host=172.21.3.20,dbname=mydb> by<br>> > >          driver <pg><br>> > > ERROR: Unable to open database <host=172.21.3.20,dbname=mydb> by<br>> > >        driver <pg><br>> > ><br>> > > My version of grass:<br>> > > GRASS version:<br>> > > 7.4.0<br>> > > GRASS SVN revision:<br>> > > exported<br>> > > Build date:<br>> > > 2018-01-26<br>> > > Build platform:<br>> > > x86_64-pc-linux-gnu<br>> > > GDAL:<br>> > > 2.2.2<br>> > > PROJ.4:<br>> > > 4.9.2<br>> > > GEOS:<br>> > > 3.5.1<br>> > > SQLite:<br>> > > 3.11.0<br>> > > Python:<br>> > > 2.7.12<br>> > > wxPython:<br>> > > 3.0.2.0<br>> > > Platform: Linux-4.4.0-112-generic-x86_64-with-Ubuntu-16.04-xenial  <br>> > ><br>> > > Version of python:<br>> > ><br>> > > Python 2.7.12 64bits<br>> > ><br>> > > Content of my .grass7/dblogin:<br>> > > pg|host=172.21.3.20, dbname=mydb|dbusername|passwd||<br>> > > sqlite|$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db|dbusername|passwd||<br>> > > pg|macfishdb|dbusername|passwd||<br>> > > pg|host=172.21.3.20,dbname=mydb|dbusername|passwd||<br>> > ><br>> > > Thank you for any comment<br>> > > Dead Vil<br>> > ><br>> > ><br>> ><br>> ><br>> > _______________________________________________<br>> > grass-user mailing list<br>> > <a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>> > <a href="https://lists.osgeo.org/mailman/listinfo/grass-user">https://lists.osgeo.org/mailman/listinfo/grass-user</a><br>><br></div></div></div>