postgis不适用于所有postgres用户

时间:2018-01-23 17:31:50

标签: postgresql postgis qgis postgresql-9.6

在启用Potgis的数据库上创建新用户时,我遇到了一个奇怪的问题,即新用户无法访问postgis扩展,而早期创建的用户可以使用。

使用我的用户帐户,我得到以下输出:

mydb => SELECT postgis_version();
postgis_version
---------------------------------------
 2.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

使用新用户,我得到以下内容:

mydb => SELECT postgis_version()
mydb-> ;
ERROR:  function postgis_version() does not exist
LINE 1: SELECT postgis_version()
           ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

此外,QGIS正在暗示postgis不活跃:

2018-01-23T16:38:13 1   No PostGIS support in the database.

我正在连接到完全相同的数据库。 用户可以访问公共模式和geometry_columns表。

我在这里有点迷失,因为根据我的信息,Postgis是数据库级别的扩展,它应该适用于所有用户。

1 个答案:

答案 0 :(得分:1)

PostGIS扩展必须安装在必须也位于用户搜索路径中的架构中。

您可以使用命令

检查安装位置
select e.extname,n.* 
from pg_extension e, pg_namespace n 
where e.extnamespace = n.oid and e.extname='postgis';

您可以通过发出

来检查安装它的架构是否在用户搜索路径中
show search_path;

如果没有,您可以通过更改用户来永久添加路径。

ALTER USER username SET search_path TO "$user", public, postgis_schema;

由于上一个命令仅在下次登录时生效,您可以通过应用

立即应用它
SET search_path TO "$user", public, postgis_schema;