Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a layer in GeoServer. It is based on PostGis view. It seems that GeoServer generates random featureIDs. The view has the same columns as the underlying table, including the PK column. But GeoServer ignores the PK column for layers based on the view.

When I created a layers based on the table itself, Geoserver used PK as featureID.

How to make GeoServer to do the same for a view?

Thank you in advance.


I've accepted iant's answer. SQL I used to create the metadata table is below. After I ran it on the PostGis DB, I've restarted GeoServer and recreated the layer. It worked.


CREATE TABLE gt_pk_metadata_table (
  table_schema VARCHAR(32) NOT NULL,
  table_name VARCHAR(32) NOT NULL,
  pk_column VARCHAR(32) NOT NULL,
  pk_column_idx INTEGER,
  pk_policy VARCHAR(32),
  pk_sequence VARCHAR(64),
  unique (table_schema, table_name, pk_column),
  check (pk_policy in ('sequence', 'assigned', 'autoincrement'))

INSERT INTO gt_pk_metadata_table(
            table_schema, table_name, pk_column, pk_column_idx, pk_policy, 
    VALUES (
share|improve this question
up vote 5 down vote accepted

You need to provide a metadata table which contains the view name and the primary key name. The documentation here explains how.

share|improve this answer
It was useful. Thank you! – Maxim Eliseev Jun 20 '13 at 15:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.