Thursday, 14 November 2019

postgresql - How to create a new 'gis' database in PostGIS?



I'd like to create a new database in PostGIS, so I can load stuff into it while the current database is being used. According to the docs



Some packaged distributions of PostGIS (in particular the Win32 installers for PostGIS >= 1.1.5) load the PostGIS functions into a template database called template_postgis. If the template_postgis database exists in your PostgreSQL installation then it is possible for users and/or applications to create spatially-enabled databases using a single command.



In my case this appears not to be so:


$ createdb -T template_postgis my_spatial_db
createdb: database creation failed: ERROR: template database "template_postgis" does not exist

In the past I have messed around with copying the primary gis database, then deleting the contents of all the tables. There must be a better way. What do you do if you accidentally drop it?



Answer




Following @novicegis's link, this worked for me with postgis 1.5:


db=gis
sudo -su postgres <createdb --encoding=UTF8 --owner=ubuntu $db
psql -d $db -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
psql -d $db -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql
psql -d $db -f /usr/share/postgresql/9.1/contrib/postgis_comments.sql
psql -d $db -c "GRANT SELECT ON spatial_ref_sys TO PUBLIC;"
psql -d $db -c "GRANT ALL ON geometry_columns TO ubuntu;"
psql -d $db -c 'create extension hstore;'

EOF

(The linked instructions didn't include the 'hstore' extension.)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...