Using schema other than public in PostGIS?

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;


  1. One of the possible organizational strategies you can build with schemas is to allow a user to run rampant in one schema, but be unable to foul things up in another. So if you want to use schemas in this way, that can be done in the privileges tab of pgAdmin. But it's not required that you do that, so if you just want to maintain the same privileges across multiple schemas, that's fine.

  2. Based on the articles you linked to, the problem with keeping everything in public is that when you dump data, you're likely to get system tables and relationships mixed in with your data. If you move all your data to a new schema, you don't have to worry about that ever again.

  3. No trouble at all. (For proof, notice that you don't have to specify public.spatial_ref_sys when you want to search the SRS table.)


This is now addressed on the official site in a page titled Move PostGIS extension to a different schema. The correct method is to install the extension into public. This is the only option. The extension no longer supports relocation. The next thing is to run the following commands, (copied from the site),

UPDATE pg_extension 
  SET extrelocatable = TRUE 
    WHERE extname = 'postgis';

ALTER EXTENSION postgis 
  SET SCHEMA postgis;

Tags:

Postgis