4. 创建空间数据库

4.1. PgAdmin

PostgreSQL has a number of administrative front-ends. The primary one is psql, a command-line tool for entering SQL queries. Another popular PostgreSQL front-end is the free and open source graphical tool pgAdmin. All queries done in pgAdmin can also be done on the command line with psql. pgAdmin also includes a geometry viewer you can use to spatial view PostGIS queries.

  1. 找到安装在电脑上的 pgAdmin 并启动它。

    _images/pgadmin_01.png
  2. 如果你是第一次运行 pgAdmin,有可能没有配置过任何数据库连接。右键单击浏览器面板中的 Servers 项。

    命名服务器为 PostGIS. 在连接选项卡中,输入 Host name/address``(主机名或地址)。如果你用的是本地安装的 PostgreSQL,可以填 ``localhost. 如果用的是云端数据库,你可以登陆上去后找到对应的主机名。

    Port**(端口)设为 ``5432``(默认值),把 **Maintenance databaseUsername 设为 postgres. 密码 是你安装时填写的密码。

    _images/pgadmin_02a.png

4.2. 创建一个数据库

  1. 打开数据库树,查看可用的数据库。名为 postgres 数据库是默认用户 postgres 自己维护的数据库,对我们来说没什么用。

  2. 右键点击 Database 项,选择 New Database.

    _images/pgadmin_02.png
  3. 和下面表格一样填写 Create Database 表单,然后点击 OK.

    名称

    nyc

    拥有者

    postgres

    _images/pgadmin_03.png
  4. 选择新的 nyc 数据库,打开它,会展开树结构。你能看到 public 模式。

    _images/pgadmin_04.png
  5. 单击下面的 SQL 查询按钮(或者菜单项 Tools > Query Tool)。

    _images/pgadmin_05.png
  6. 输入以下 SQL 来加载 PostGIS 扩展:

    CREATE EXTENSION postgis;
    
  7. 单击工具栏的 Play 按钮或者按 F5 来执行查询。

  8. 现在运行 PostGIS 函数确定 PostGIS 已经安装好了:

    SELECT postgis_full_version();
    

恭喜你,你创建好了 PostGIS 空间数据库。

4.3. 函数列表

PostGIS_Full_Version:显示 PostGIS 的完整版本和构建配置信息。