Creating a spatial database¶
This section describes the process of creating a new spatially enabled PostGIS database.
This section uses the command line utility createdb and optionally the graphical utility pgAdmin. These tools may not be automatically present, depending on the type of installation of OpenGeo Suite. Please see the Installation section for information on how to install these tools for your platform.
Expand the Databases item in the Object browser to reveal the available databases.
Right-click Databases and select New Database.
Complete the New database form with the following information:
- Name—<user-defined database name>
Either click Execute arbitrary SQL queries on the pgAdmin toolbar or click Tools ‣ Query tool to open the Query dialog box.
Enter the following query into the SQL editor input box and click the Execute query button, or press F5, to run the query.
CREATE EXTENSION postgis;
Verify the database was created correctly by running the management function postgis_full_version() in the SQL editor. It should return version and build configuration information.
If the command runs successfully the PostGIS database is setup correctly and ready to use.
Double-click the new database item in the Object browser to display the contents. Inside the public schema, you will see one PostGIS-specific metadata table, spatial_ref_sys (for further information, see the section on OpenGIS metadata).
If you don’t see this table, your database was not created correctly.
Creating a spatial database from the command line¶
You can also create a PostGIS database from the command line with the createdb and psql commands.
createdb -U postgres <DATABASENAME> psql -U postgres -d <DATABASENAME> -c 'CREATE EXTENSION postgis'