ERROR: function postgis_lib_version() does not exist when matching a postgis custom schema

ERROR: function postgis_lib_version() does not exist when matching a postgis custom schema

我有一个 rails 应用程序,在 docker 容器中包含一个 PostGIS 数据库 运行。我正在使用 apartment for multitenancy and activerecord-postgis-adapter 从 ActiveRecord 访问 PostGIS 地理空间数据库功能。按照公寓文档的建议,我在 shared_extentions 模式中安装了 PostGIS。当我尝试在地理服务器中配置数据存储时,出现以下错误:

Error creating data store, check the parameters. Error message: Unable to obtain connection: ERROR: function postgis_lib_version() does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 8

地理服务器数据存储连接参数:

host: app-db
port: 5432
database: app_development
schema: shared_extensions
user: 
passwd:

database.yml:

default: &default
  adapter: postgis
  postgis_schema: shared_extensions
  schema_search_path: public, shared_extensions
  encoding: unicode
  database: app_development
  host: app-db
  username:
  password:

lib/tasks/db_enhancements.rake:

namespace :db do
  desc 'Also create shared_extensions Schema'
  task :extensions => :environment  do
    # Create Schema
    ActiveRecord::Base.connection.execute 'CREATE SCHEMA IF NOT EXISTS shared_extensions;'
    # Enable Hstore
    ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS HSTORE SCHEMA shared_extensions;'
    # Enable Postgis
    ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS postgis SCHEMA shared_extensions;'
    # Enable UUID-OSSP
    ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA shared_extensions;'
    # Grant usage to public
    ActiveRecord::Base.connection.execute 'GRANT usage ON SCHEMA shared_extensions to public;'
  end
end

我也在 pgAdmin 上用 SELECT shared_extensions.postgis_version() 试过了,效果很好:

2.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

当然,当我 运行 SELECT postgis_version() 我得到:

ERROR:  function postgis_version() does not exist
LÍNEA 1: SELECT postgis_version()
                ^
SUGERENCIA:  No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Character: 8

GeoServer 希望 PostGIS 安装在 public 模式中,而不是将 shared_extensions 添加到它的 postgis 函数中。如果你想这样做,那么你需要将 shared_extensions 添加到搜索路径,以便 GeoServer 可以找到它需要的功能。

ALTER DATABASE mydb SET 'search_path' = public,shared_extension;

有关如何将 postgis 移动到不同架构的详细信息,请参阅此 note