Import OSM file to PostGis on Windows10 - postgresql

can you help me with importing planet.osm file to my PostGist db? I am new in this and I found tutorials only for linux.
There are some commands, but I do not know how use it ... I will be grateful for some step by step tutorial. I'm using GeoServer if it is important information for us to help me. Thanks for advices.
edit:
I used osm2pgsql -s -U postgres -d nameofdatabase name.osm
but unsuccessful because I have error with no database found.

I used OGR2OGR to import osm data in pbf format on Windows (Windows 10, Posgres 9.6 with Postgis 2.3). You can use OGR2OGR from the "OSgeo42 shell", which comes with QGIS or you can get Osgeo4w separately here). The steps are something like this:
Create a new database: create database db_for_osm
Create Postgis extension in your db. In SQL create extension postgis
Now you can run OGR2OGR. Open the "OSGEO4W
shell". This will open a command window with all
the environment variables set. The command will be something like
ogr2ogr -f PostgreSQL PG:"dbname='db_for_osm' host='localhost' port='5432' user='myuser' password='mypassword'" planet.osm.pbf
My large upload took a couple of days to complete, so be prepared for this to take a long time - I suggest you do a test with a small region first - for the test I did for this answer I downloaded a city from Mapzen.

Related

I have error loading data into PostgreSQL database

follow up to the question, this is the command line i used but it could not recognizecommand line my password
The Image
I have a PostGreSQL script that contains table definition and sample data but whenever i tried to run the script, i get the error as shown in the diagram.
Please, does anyone has any idea o what is wrong?
I am new to PostgreSQL
From the image, it looks as if you're using pgAdmin to load a database dump created with pg_dump. I'm not sure whether this will work with pgAdmin's query tool; you should try instead loading it from the command line:
psql -f the_dump_file.sql my_database
Full details here:
https://www.postgresql.org/docs/9.6/static/app-pgdump.html
https://www.postgresql.org/docs/9.6/static/app-psql.html

Creating a mysqldump file

Goal: migrate google-cloud-sql First Generation to second generation
Exporting Data from Cloud SQL is working fine.
https://cloud.google.com/sql/docs/backup-recovery/backing-up
But:
Note: If you are exporting your data for use in a Cloud SQL instance, you must use the instructions provided in Exporting data for Import into Cloud SQL. You cannot use these instructions.
So i get to this page:
Exporting Data for Import into Cloud SQL
https://cloud.google.com/sql/docs/import-export/creating-mysqldump-csv#mysqldump
This pages describes how to create a mysqldump or CSV file from a MySQL database that does not reside in Cloud SQL.
Instructions are not working:
mysqldump --databases [DATABASE_NAME] -h [INSTANCE_IP] -u [USERNAME] -p \
--hex-blob --skip-triggers --set-gtid-purged=OFF --default-character-set=utf8 > [DATABASE_FILE].sql
mysqldump: unknown variable 'set-gtid-purged=OFF
How do I create mysqldump for import in cloud sql second generation?
thanks in advance,
Sander
edit:
Using google cloud sql first generation via google cloud console
removed set-gtid-purged=OFF
result:
Enter password:
mysqldump: Got error: 2013: Lost connection to MySQL server at 'reading initial communication packet', system error: 0 when trying to connect
s#folkloric-alpha-618:~$
For set-gtid-purged. Please verify which mysql-client version you have installed. Many OS come with the MariaDB version which does not support this flag (since their implementation of GTID is different).
I know the Oracle official mysql-client supports this flag since 5.6.9.
To verify your package run:
mysqldump --version
If you get this, you don't have the official client:
mysqldump Ver 10.16 Distrib 10.1.41-MariaDB, for debian-linux-gnu (x86_64)
The official client would be something like this:
mysqldump Ver 10.13 Distrib 5.7.27, for Linux (x86_64)
If you want to change the version, you can use their official repository.

Restore postgis backup from 1.5 to 2.1.2

I have a database backup of a postgres 9.1 and postgis 1.5. Many of the databases were built using a spatial enabled database, created using:
createdb spacial psql -d spacial -f postgis.sql psql -d spacial -f spatial_ref_sys.sql psql -d spacial -f postgis_comments.sql
Now I jave a postgres 9.3 and postgis 2.1. All spatial databases were not restored correctly because my spacial database (created with this new version) is created with only one of the two tables (created with the old version).
Does anyone knows what is going on? Thanks.
I have made the steps I needed, at least I think I've made it. After run: SELECT postgis_full_version(); I've got this result: "POSTGIS="2.1.2 r12389" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.9.1" LIBJSON="UNKNOWN""
As the POSTGIS 2.1.2 is not covered in the link provided, I figured I should run only the script postgis_upgrade_21_minor.sql, as I don't have topology installed. But a few tables were not imported at all. During importing I got a few messages: type "geometry" is undefined.
Any new ideas?
Follow the hard upgrade instructions in the manual. These steps, in brief, are:
Dump the old database to a file
Spatially enable a new empty database (there are several different ways to do this)
Use a special utility postgis_restore.pl that came with your new version of PostGIS to translate the old format to the new format.

How can i check the template for postgis in postgres ubuntu

I am following this tutorial
http://technobytz.com/install-postgis-postgresql-9-3-ubuntu.html
and i created db with this command
createdb test_db -T template_postgis2.1
but i get this error
test_db2=# select postgis_version();
ERROR: function postgis_version() does not exist
LINE 1: select postgis_version();
This works if use
create extension postgis
i want to know that is that ok or i have error. because i made the template before. Didn't that template automatically make the db as postgis
According to the official documentation on the topic, you have to create the extension in each new database you create. Why? This has to do with a change in the way a database is PostGIS-enabled in PostgreSQL-9.1+ and PostGIS-2+. Previously, there were a series of scripts that had to be run to load the functions, types, and other features of PostGIS into a database. Consequently, the best practice was to create a template database (template_postgis, etc.), run all the scripts against that template, and create each new PostGIS-enabled database against that template. In newer versions of PostgreSQL (9.1+), you can enabled PostGIS support within a new database by simply executing the command CREATE EXTENSION postgis; as such, you should skip the template step entirely.
So to sum up:
CREATE EXTENSION postgis; is the way to go for PostgreSQL-9.1+ and PostGIS-2+
Making a template database is the way to go for prior versions of PostgreSQL or PostGIS.
I hope that helps clear it up!

How to import database backed up in commerical version of DB2 8.9 to free DB2 10 ExpressC Edition

Please let me know the steps on importing DB2 database exported from Commerical Version (DB2 8/9 ) to free DB2 ExpressC Edition(10).
As long as you are trying to restore into a DB2 Express C running in the 'same platform'(Same OS and same/higher bit level), you should not face any issue with the normal 'RESTORE' command.
If it is otherwise, it gets a little trickier. You can use the 'db2look' command to copy the schema(DDLs) creation SQLs and then run them in new machine to recreate the schema. Then you should use 'db2move' to move the user data present in the tables.
First of all, in DB2 there is no limitation about database size in free edition. Just CPU limitation exist. So there won't be any issue about porting you database to free edition.
Here is step by step way to do it. On old system:
# db2look -d DBNAME -e -o DBNAME.DDL
# db2move DBNAME export
After moving all generated files to new system, issue these commands on new system:
# db2 CREATE DATABASE DBNAME
# db2 -tvf DBNAME.DDL
# db2move DBNAME IMPORT
That's all.