2

I am currently attempting to use OSM Bright to quickly style some OSM data, so I can export tiles without spending hours writing Carto in TileMill.

This is my first time using osm2pgsql to import OSM (.pbf) data into PostgreSQL. It seems that I am running from one issue into the next (missing style file, no hstore, etc. ) and I have just hit a point where I am not sure how to progress anymore.

The following message keeps popping up:

Error: Connection to database failed: FATAL:  database "gis" does not exist

I have nowhere entered that I want to access a database called gis .

Executing the help command and looking at the docs I realize that:

 -d|--database The name of the PostgreSQL database to connect to (default: gis).

Which tells me that it is most likely looking for the default database, which I do not understand, as I have indicated to use my already-created database (ethiopia):

enter image description here

Here is the command I have entered:

F:\randomGISstuff\ethiopia>osm2pgsql -c -G -U postgres -S -hstore F:\randomGISstuff\ethiopia\default.style  -U postgres -d ethiopia ethiopia-latest.osm.pbf

If it is easier for you to look at a cmd screenshot, here it is:

enter image description here

The command that is featured on the OSM Bright page is definitely not sufficient in my case.


EDIT SOLUTION:

Because the solution is all hidden in comments, I will mention here what solved my issue:
1) Create a database and add the hstore to it:

CREATE EXTENSION hstore

2) make sure to set the password, not in the osm2pgsql statement, but before, like:

SET pgpassword=postgres

3) start osm2pgsql

4) Execute the following command:

 osm2pgsql -c -G -U postgres --hstore -S F:\randomGISstuff\ethiopia\default.style -d ethiopia F:\randomGISstuff\ethiopia\et hiopia-latest.osm.pbf
  • Think you need to have a database called 'gis' like here learnosm.org/en/osm-data/setting-up-postgresql – Mapperz Feb 17 '15 at 19:50
  • I have been using that tutorial (until a certain point), but my general understanding is that the database does not have to be named gis. Also, where on that page do you see that? Maybe I missed it, but it looks like their database is called gisdb. – BritishSteel Feb 17 '15 at 19:53
2

There seems to be something wrong with the style file option. Try:

F:\randomGISstuff\ethiopia>osm2pgsql -c -G -U postgres --hstore -S F:\randomGISstuff\ethiopia\default.style  -U postgres -d ethiopia ethiopia-latest.osm.pbf

If the user needs to give a password, you might have to put it on the command line as well.

It might help to always give the full path to the pbf file.

  • My database does use a password. Where and how would I have to insert that? I have tried the -W command before, but it was not accepted. – BritishSteel Feb 17 '15 at 20:14
  • OK, so full path even though I cd'ed to the place where the .pbf is located? – BritishSteel Feb 17 '15 at 20:15
  • This would be my updated statement, with the full path to the OSM data: osm2pgsql -c -G -U postgres -hstore -S F:\randomGISstuff\ethiopia\default.style -U postgres -d ethiopia F:\randomGISstuff\ethiopia\et hiopia-latest.osm.pbf – BritishSteel Feb 17 '15 at 20:22
  • PS: I now keep getting osm2pgsql: illegal option -- t. I have no idea where this would be coming from. – BritishSteel Feb 17 '15 at 20:25
  • 1
    Thank you so much for your great help! I got it to work by first entering the password, thenstarting osm2pqsql and then executing the following: osm2pgsql -c -G -U postgres --hstore -S F:\randomGISstuff\ethiopia\default.style -d ethiopia F:\randomGISstuff\ethiopia\et hiopia-latest.osm.pbf – BritishSteel Feb 18 '15 at 8:53
0

in SQL Editor create db 'gis'

-- Database: gis

-- DROP DATABASE gis;

CREATE DATABASE gis
  WITH OWNER = postgres
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       LC_COLLATE = 'English_United States.1252'
       LC_CTYPE = 'English_United States.1252'
       CONNECTION LIMIT = -1;

enter image description here

  • I have just created this new database, and executed the following command: osm2pgsql -c -G -U postgres -S F:\randomGISstuff\ethi opia\default.style -d gis ethiopia-latest.osm.pbf However, I am now again getting the hstore error message (which I have created after creating the DB). Where do I have to add the -hstore command? – BritishSteel Feb 17 '15 at 20:12
  • You forgot to add hstore extension. Run the querry 'Create extension hstrore;' to add it to your dbase. – nickves Feb 18 '15 at 6:35
0

Your command line is messed up. Breaking it down,

  • You are specifying -U postgres twice. Although it shouldn't cause any errors, there's no reason to do it twice. Importing with the postgres user is also bad practice.

  • -S -hstore F:\randomGISstuff\ethiopia\default.style sets the style to be "-hstore, which isn't what you want unless you have a file named -hstore which contains your style. It then tells it to load the OSM data in F:\randomGISstuff\ethiopia\default.style, which is where the actual style probably is, not the data.

    Alternately, it might tell osm2pgsql to use the options -h, -s, -t, -o, -r, and -e.

If you fix your command line, it should work.

0

I encountered the same error. In my case, it seems to be an issue with older versions of osm2pgsql.

With an older version osm2pgsql SVN version 0.88.1 (64bit id space), I had to specify -d mydatabase explicitly even if it is a default database in PostgreSQL which works with psql. Otherwise, osm2pgsql assumes its own default database and reports the error about database "gis" does not exist.

In a newer version osm2pgsql version 0.96.0 (64 bit id space), osm2pgsql works fine for the default database without needing -d.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.