PostGIS – Using a Schema Other than Public

postgis

I'm currently setting up a fresh install of PostGIS 2.0.2 and PostgreSQL 9.1.6 on Ubuntu. I've recently come across some information indicating that using the public schema to store all data is not a good idea.

For this reason, I've set up a schema called data and made myself the owner, but is it a good idea?

My concerns are:

  1. Besides setting the owner, I may need to pay attention to things on the Privileges tab when creating this new schema (through pgAdmin III);
  2. I may not get the same benefits by storing my data in the public schema and dumping all data into a separate schema before doing a backup/restore (this would save a few keystrokes when using ogr2ogr); and
  3. I may run into trouble by not having the default PostGIS tables and views in my new data schema (they are in the public schema within the same database).

Best Answer

When you spatially-enable a PostGIS database, the relevant functions, SRS table, and views are placed in the public schema, as you state. That does not mean that all or any of your own spatial tables need to be in the same public schema. PostGIS will still work on all spatial data in the "new" schemas.

In fact, I usually place my application-specific tables in a separate schema. That way, if you need to do a major version upgrade to PostGIS, you can keep your application-specific table backups and restores as a separate procedure from the one that replaces the spatial tools.

So, I think you're doing well. Finally, in case you didn't do it already, it's a good idea to add the new schema to the search path:

ALTER DATABASE my_db SET search_path = gc, public;

Related Question