为什么我不知道PostgreSQL数据库上是否正确安装了PostGIS?

And*_*ili 0 database postgresql rdbms postgis postgresql-9.6

我在PostgreSQL中绝对是新手,我正在按照本教程检查我的PostgreSQL安装是否安装了PostGIS扩展.

这是教程:https://www.a2hosting.com/kb/developer-corner/postgresql/determining-the-postgresql-and-postgis-versions

我正在使用PostgreSQL 9.6.1.

所以我可以通过命令行访问我的PostgreSQL,并执行了以下命令:

SELECT PostGIS_full_version();
Run Code Online (Sandbox Code Playgroud)

这是获得的输出:

C:\ Users\Andrea> pasql -u admin'pasql'未被识别为内部或外部命令,可运行程序或批处理文件.

C:\Users\Andrea>psql -U postgres
psql (9.6.1)
ATTENZIONE: Il code page della console (850) differisce dal code page
            di Windows (1252). I caratteri a 8-bit potrebbero non
            funzionare correttamente. Vedi le pagine di riferimento
            psql "Note per utenti Windows" per i dettagli.
Digita "help" per avere un aiuto.

postgres=# SELECT PostGIS_full_version();
ERROR:  function postgis_full_version() does not exist
RIGA 1: SELECT PostGIS_full_version();
               ^
NOTA: No function matches the given name and argument types. You might need to add explicit type casts.
postgres=#
Run Code Online (Sandbox Code Playgroud)

所以我用标准用户完成了对数据库的访问,然后我执行了命令,但似乎PostGIS_full_version()函数不存在.

那是什么意思呢?这意味着简单的PoistGIS尚未安装或我做错了什么?(也许让我在特定的数据库上执行它?)

Joh*_*ell 5

你至少有两个问题.首先,

Il code page della console (850) differisce dal code page
        di Windows (1252)
Run Code Online (Sandbox Code Playgroud)

表示您安装了较旧版本的Postgres,因此,当您从某处键入psql时,会找到此旧版本.我不再使用Windows,但我猜测该位置将在您的环境变量的PATH中设置.运行不兼容的客户端和服务器版本通常是个坏主意.您可以通过删除Postgres的旧版本(大概是8.xx)来修复此问题.

第二个问题是,你正在运行

SELECT PostGIS_full_version();

从Postgres数据库中,你可以从中看到

Postgres的=#

在开始时.安装Postgis时,通常是通过

CREATE EXTENSION POSTGIS;

您通常会在要在空间上启用的数据库中执行此操作,而不是在Postgres数据库中执行此操作,而不是用于系统表等.注意,Postgis没有全局安装.另一个选项是将Postgis功能安装到template1 db中,这意味着您创建的所有后续数据库都将自动安装Postgis.