Ubuntu18.04安装postgresql10+postgis2.4(入门,零基础,教程)

这里写自定义目录标题

中二的开场白

已经辗转安装过好多次postgresql数据了,想起自己一开始安装是的窘况,想着记录一下我的安装过程,用来给后来的新手提供一些个帮助。

开发环境简介

现在的系统是Ubuntu18.04,以前装的Ubuntu16.04,从我不下50次的安装经验来说,这俩是一样的。
安装命令也是apt命令安装,一般默认安装的是库里的最新版本。
刚安装的是10.19。
时间紧张,正式开始吧。

开直接上命令行

#这里一如既往的是root身份任性,别的身份的命令需要sudo打头
#首先先更新一下apt的源,确保是安装的最新版本的postgresql
root@iZ8vbd3whsqpuhzrq9w78uZ:/# apt update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu bionic InRelease
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-backports InRelease [74.6 kB]              
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security InRelease [88.7 kB]              
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main Sources [519 kB]             
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 Packages [2,303 kB]               
Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main i386 Packages [1,378 kB]                           
Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/universe i386 Packages [1,589 kB]            
Hit:9 http://ppa.launchpad.net/certbot/certbot/ubuntu bionic InRelease            
Get:10 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/universe amd64 Packages [1,766 kB]
Fetched 7,807 kB in 2s (4,643 kB/s)                                                   
Reading package lists... Done
Building dependency tree       
Reading state information... Done
39 packages can be upgraded. Run 'apt list --upgradable' to see them.

更新完毕下面开始安装

安装命令apt-get install postgresql和apt install postgresql一样,就是前者会把这个数据库的包下载到本机。本着节约开发空间的信息用的apt install postgresql命令。

如果想想安装自己想安装的版本可以运行命令:apt-cache search postgresql进行好找,然后选择需要的版本安装,先默认的安装完,再做指定版本安装的实验。

root@iZ8vbd3whsqpuhzrq9w78uZ:/# apt install postgresql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libpq5 postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common
Suggested packages:
  postgresql-doc locales-all postgresql-doc-10 libjson-perl
The following NEW packages will be installed:
  libpq5 postgresql postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common
0 upgraded, 6 newly installed, 0 to remove and 39 not upgraded.
Need to get 5,014 kB of archives.
After this operation, 19.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

到这一步,按键盘上的y继续安装,n是退出安装的。

Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 libpq5 amd64 10.19-0ubuntu0.18.04.1 [108 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 postgresql-client-common all 190ubuntu0.1 [29.6 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 postgresql-client-10 amd64 10.19-0ubuntu0.18.04.1 [942 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 postgresql-common all 190ubuntu0.1 [157 kB]
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 postgresql-10 amd64 10.19-0ubuntu0.18.04.1 [3,772 kB]
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 postgresql all 10+190ubuntu0.1 [5,884 B]
Fetched 5,014 kB in 2s (2,639 kB/s)    
Preconfiguring packages ...
Selecting previously unselected package libpq5:amd64.
(Reading database ... 116227 files and directories currently installed.)
Preparing to unpack .../0-libpq5_10.19-0ubuntu0.18.04.1_amd64.deb ...
Unpacking libpq5:amd64 (10.19-0ubuntu0.18.04.1) ...
Selecting previously unselected package postgresql-client-common.
Preparing to unpack .../1-postgresql-client-common_190ubuntu0.1_all.deb ...
Unpacking postgresql-client-common (190ubuntu0.1) ...
Selecting previously unselected package postgresql-client-10.
Preparing to unpack .../2-postgresql-client-10_10.19-0ubuntu0.18.04.1_amd64.deb ...
Unpacking postgresql-client-10 (10.19-0ubuntu0.18.04.1) ...
Selecting previously unselected package postgresql-common.
Preparing to unpack .../3-postgresql-common_190ubuntu0.1_all.deb ...
Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (190ubuntu0.1) ...
Selecting previously unselected package postgresql-10.
Preparing to unpack .../4-postgresql-10_10.19-0ubuntu0.18.04.1_amd64.deb ...
Unpacking postgresql-10 (10.19-0ubuntu0.18.04.1) ...
Selecting previously unselected package postgresql.
Preparing to unpack .../5-postgresql_10+190ubuntu0.1_all.deb ...
Unpacking postgresql (10+190ubuntu0.1) ...
Setting up libpq5:amd64 (10.19-0ubuntu0.18.04.1) ...
Setting up postgresql-client-common (190ubuntu0.1) ...
Setting up postgresql-common (190ubuntu0.1) ...
Adding user postgres to group ssl-cert

Creating config file /etc/postgresql-common/createcluster.conf with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.
Setting up postgresql-client-10 (10.19-0ubuntu0.18.04.1) ...
update-alternatives: using /usr/share/postgresql/10/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up postgresql-10 (10.19-0ubuntu0.18.04.1) ...
Creating new PostgreSQL cluster 10/main ...
/usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/10/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/10/main ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Asia/Shanghai
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start

Ver Cluster Port Status Owner    Data directory              Log file
10  main    5432 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
update-alternatives: using /usr/share/postgresql/10/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
Setting up postgresql (10+190ubuntu0.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for systemd (237-3ubuntu10.52) ...

到这里postgresql就安装完毕了。

#安装完毕后,会自动的生成postgres用户,以前编译那装的时候老麻烦了,得创建用户组,添加用户什么的,很烦。apt安装就这个好处,自动生成。

切换到postgres账户,进行数据库相关的设置操作。

root@iZ8vbd3whsqpuhzrq9w78uZ:/# su postgres

#psql命令是进入数据库的sql命令页面。

postgres@iZ8vbd3whsqpuhzrq9w78uZ:/$ psql
#这里显示的就是当前数据库的版本了,还有当前系统的版本。
psql (10.19 (Ubuntu 10.19-0ubuntu0.18.04.1))
Type "help" for help.
#数据库sql中前边是#开头的,是注释的意思,哎…… 写个博客也很费劲啊。
#这里已经进入到了默认的数据库postgres。
postgres=# 
#现在设置数据库的密码,就用下面这条语句,记得这属于sql语句,必须得分号结尾。
postgres=#  alter user postgres with password 'mypassword';
#显示这个就是设置成功了。
ALTER ROLE
#然后退出sql命令界面输入:\q回车,就会退出来。
postgres=# \q
postgres@iZ8vbd3whsqpuhzrq9w78uZ:/$ 

postgresql数据库默认是不允许远程访问的,需要进行修改,废话不多上代码。接着上边的代码,

postgres@iZ8vbd3whsqpuhzrq9w78uZ:/$ 
#首先切换用户,我这里还是切换成了root用户。
postgres@iZ8vbd3whsqpuhzrq9w78uZ:/$ su root
Password: 
root@iZ8vbd3whsqpuhzrq9w78uZ:/# 

然后进入配置文件所在的路径:/etc/postgresql/10/main/

root@iZ8vbd3whsqpuhzrq9w78uZ:/# cd /etc/postgresql/10/main/
root@iZ8vbd3whsqpuhzrq9w78uZ:/etc/postgresql/10/main# ll
total 60
drwxr-xr-x 3 postgres postgres  4096 Nov 23 15:00 ./
drwxr-xr-x 3 postgres postgres  4096 Nov 23 15:00 ../
drwxr-xr-x 2 postgres postgres  4096 Nov 23 15:00 conf.d/
-rw-r--r-- 1 postgres postgres   315 Nov 23 15:00 environment
-rw-r--r-- 1 postgres postgres   143 Nov 23 15:00 pg_ctl.conf
-rw-r----- 1 postgres postgres  4686 Nov 23 15:00 pg_hba.conf
-rw-r----- 1 postgres postgres  1636 Nov 23 15:00 pg_ident.conf
-rw-r--r-- 1 postgres postgres 23180 Nov 23 15:00 postgresql.conf
-rw-r--r-- 1 postgres postgres   317 Nov 23 15:00 start.conf
root@iZ8vbd3whsqpuhzrq9w78uZ:/etc/postgresql/10/main# 

修改postgresql.conf文件

文件很长,摘取主要内容大概是34到84的内容是这样的。要修改的东西正好也是在这个位置。

#------------------------------------------------------------------------------
# FILE LOCATIONS
#------------------------------------------------------------------------------

# The default values of these variables are driven from the -D command-line
# option or PGDATA environment variable, represented here as ConfigDir.

data_directory = '/var/lib/postgresql/10/main'          # use data in another directory
                                        # (change requires restart)
hba_file = '/etc/postgresql/10/main/pg_hba.conf'        # host-based authentication file
                                        # (change requires restart)
ident_file = '/etc/postgresql/10/main/pg_ident.conf'    # ident configuration file
                                        # (change requires restart)

# If external_pid_file is not explicitly set, no extra PID file is written.
external_pid_file = '/var/run/postgresql/10-main.pid'                   # write an extra PID file
                                        # (change requires restart)


#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

#listen_addresses = 'localhost'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
                                        # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                        # (change requires restart)
#bonjour = off                          # advertise server via Bonjour
                                        # (change requires restart)
#bonjour_name = ''                      # defaults to the computer name
                                        # (change requires restart)

# - Security and Authentication -

把#listen_addresses = 'localhost’修改成listen_addresses = ‘*’。

其中port = 5432 是数据库的端口号,这个可以随便改,前提是系统中的空闲端口。
这个max_connections = 100是最大连接数,我一般改成1000,因为我都是十好几个项目公用一个库,怕不够。

第一个文件修改完毕。

修改第二个文件pg_hba.conf,直接划到文件最底部,大概是这个样子

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

在下方添加:host all all 0.0.0.0/0 md5

添加完毕后是这样的:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all             all             0.0.0.0/0               md5

然后重启数据库,用远程工具试试。

root@iZ8vbd3whsqpuhzrq9w78uZ:/etc/postgresql/10/main# nano postgresql.conf 
root@iZ8vbd3whsqpuhzrq9w78uZ:/etc/postgresql/10/main# nano pg_hba.conf 
root@iZ8vbd3whsqpuhzrq9w78uZ:/etc/postgresql/10/main# /etc/init.d/postgresql restart
[ ok ] Restarting postgresql (via systemctl): postgresql.service.
root@iZ8vbd3whsqpuhzrq9w78uZ:/etc/postgresql/10/main# 

我一般白嫖Navicat for postgresql

测试一下。
在这里插入图片描述

好了,到此postgresql安装完毕。

说一下指定版本安装

我发现只能指定大版本,比如postgresql-10,postgresql-9.5,postgresql-9.6。这样是可以的。
比如这种类型的小版本是不支持的:postgresql-10.1,postgresql-10.5,postgresql-9.5.16,……这些小版本是不支持的。

接下来安装postgis

#查看最新的版本
root@iZ8vbd3whsqpuhzrq9w78uZ:/# apt-cache search postgresql postgis
imposm - importer for OpenStreetMap data
liblwgeom-2.4-0 - PostGIS "Lightweight Geometry" library
liblwgeom-dev - PostGIS "Lightweight Geometry" library - Development files
libpostgis-java - Geographic objects support for PostgreSQL -- JDBC support
osm2pgsql - OpenStreetMap data to PostgreSQL converter
postgis - Geographic objects support for PostgreSQL
postgis-doc - Geographic objects support for PostgreSQL -- documentation
postgis-gui - Geographic objects support for PostgreSQL -- GUI programs
postgresql-10-pgrouting - Routing functionality support for PostgreSQL/PostGIS
postgresql-10-pgrouting-doc - Routing functionality support for PostgreSQL/PostGIS (Documentation)
postgresql-10-pgrouting-scripts - Routing functionality support for PostgreSQL/PostGIS - SQL scripts
postgresql-10-postgis-2.4 - Geographic objects support for PostgreSQL 10
postgresql-10-postgis-2.4-scripts - Geographic objects support for PostgreSQL 10 -- SQL scripts
postgresql-10-postgis-scripts - transitional dummy package
python-imposm - importer for OpenStreetMap data - Python module
qgis - Geographic Information System (GIS)
tinyows - lightweight and fast WFS-T server
root@iZ8vbd3whsqpuhzrq9w78uZ:/# 

最新版是postgresql-10-postgis-2.4

安装postgis-2.4

root@iZ8vbd3whsqpuhzrq9w78uZ:/# apt install postgresql-10-postgis-2.4
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  gdal-data libaec0 libarmadillo8 libarpack2 libblas3 libdap25 libdapclient6v5 libepsilon1 libfreexl1 libfyba0 libgdal20 libgeos-3.6.2 libgeos-c1v5 libgeotiff2 libgfortran4 libgif7 libhdf4-0-alt libhdf5-100 libkmlbase1
  libkmldom1 libkmlengine1 liblapack3 liblcms2-2 liblwgeom-2.4-0 libminizip1 libnetcdf13 libodbc1 libogdi3.2 libpoppler73 libproj12 libprotobuf-c1 libqhull7 libspatialite7 libsuperlu5 libsz2 liburiparser1 libxerces-c3.2
  odbcinst odbcinst1debian2 poppler-data postgresql-10-postgis-2.4-scripts proj-bin proj-data
Suggested packages:
  geotiff-bin gdal-bin libgeotiff-epsg libhdf4-doc libhdf4-alt-dev hdf4-tools liblcms2-utils libmyodbc odbc-postgresql tdsodbc unixodbc-bin ogdi-bin poppler-utils ghostscript fonts-japanese-mincho | fonts-ipafont-mincho
  fonts-japanese-gothic | fonts-ipafont-gothic fonts-arphic-ukai fonts-arphic-uming fonts-nanum postgis
The following NEW packages will be installed:
  gdal-data libaec0 libarmadillo8 libarpack2 libblas3 libdap25 libdapclient6v5 libepsilon1 libfreexl1 libfyba0 libgdal20 libgeos-3.6.2 libgeos-c1v5 libgeotiff2 libgfortran4 libgif7 libhdf4-0-alt libhdf5-100 libkmlbase1
  libkmldom1 libkmlengine1 liblapack3 liblcms2-2 liblwgeom-2.4-0 libminizip1 libnetcdf13 libodbc1 libogdi3.2 libpoppler73 libproj12 libprotobuf-c1 libqhull7 libspatialite7 libsuperlu5 libsz2 liburiparser1 libxerces-c3.2
  odbcinst odbcinst1debian2 poppler-data postgresql-10-postgis-2.4 postgresql-10-postgis-2.4-scripts proj-bin proj-data
0 upgraded, 44 newly installed, 0 to remove and 39 not upgraded.
Need to get 22.7 MB of archives.
After this operation, 181 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/main amd64 poppler-data all 0.4.8-2 [1,479 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 gdal-data all 2.2.3+dfsg-2 [363 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libaec0 amd64 0.3.2-2 [18.1 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/main amd64 libblas3 amd64 3.7.1-4ubuntu1 [140 kB]
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 libgfortran4 amd64 7.5.0-3ubuntu1~18.04 [492 kB]
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/main amd64 liblapack3 amd64 3.7.1-4ubuntu1 [2,112 kB]
Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libarpack2 amd64 3.5.0+real-2 [89.7 kB]
Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libsuperlu5 amd64 5.2.1+dfsg1-3 [161 kB]
Get:9 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libarmadillo8 amd64 1:8.400.0+dfsg-2 [81.9 kB]
Get:10 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libdap25 amd64 3.19.1-2build1 [426 kB]
Get:11 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libdapclient6v5 amd64 3.19.1-2build1 [88.9 kB]
Get:12 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libepsilon1 amd64 0.9.2+dfsg-2 [41.2 kB]
Get:13 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libfyba0 amd64 4.1.1-3 [110 kB]
Get:14 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libfreexl1 amd64 1.0.5-1 [33.4 kB]
Get:15 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libgeos-3.6.2 amd64 3.6.2-1build2 [476 kB]
Get:16 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libgeos-c1v5 amd64 3.6.2-1build2 [54.9 kB]
Get:17 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 proj-data all 4.9.3-2 [4,020 kB]
Get:18 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libproj12 amd64 4.9.3-2 [159 kB]
Get:19 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libgeotiff2 amd64 1.4.2-2build1 [58.5 kB]
Get:20 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 libgif7 amd64 5.1.4-2ubuntu0.1 [30.9 kB]
Get:21 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libhdf4-0-alt amd64 4.2.13-2 [267 kB]
Get:22 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libsz2 amd64 0.3.2-2 [5,114 B]
Get:23 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libhdf5-100 amd64 1.10.0-patch1+docs-4 [1,256 kB]
Get:24 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libminizip1 amd64 1.1-8build1 [20.2 kB]
Get:25 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 liburiparser1 amd64 0.8.4-1 [38.0 kB]
Get:26 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libkmlbase1 amd64 1.3.0-5 [44.9 kB]
Get:27 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libkmldom1 amd64 1.3.0-5 [165 kB]
Get:28 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libkmlengine1 amd64 1.3.0-5 [73.7 kB]
Get:29 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libnetcdf13 amd64 1:4.6.0-2build1 [333 kB]
Get:30 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/main amd64 libodbc1 amd64 2.3.4-1.1ubuntu3 [183 kB]
Get:31 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libogdi3.2 amd64 3.2.0+ds-2 [213 kB]
Get:32 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 liblcms2-2 amd64 2.9-1ubuntu0.1 [139 kB]
Get:33 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/main amd64 libpoppler73 amd64 0.62.0-2ubuntu2.12 [800 kB]
Get:34 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libqhull7 amd64 2015.2-4 [152 kB]
Get:35 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libspatialite7 amd64 4.3.0a-5build1 [1,224 kB]
Get:36 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libxerces-c3.2 amd64 3.2.0+debian-2 [851 kB]
Get:37 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/main amd64 odbcinst amd64 2.3.4-1.1ubuntu3 [12.4 kB]
Get:38 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/main amd64 odbcinst1debian2 amd64 2.3.4-1.1ubuntu3 [40.4 kB]
Get:39 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libgdal20 amd64 2.2.3+dfsg-2 [5,099 kB]
Get:40 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 liblwgeom-2.4-0 amd64 2.4.3+dfsg-4 [212 kB]
Get:41 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 libprotobuf-c1 amd64 1.2.1-2 [19.0 kB]
Get:42 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 postgresql-10-postgis-2.4 amd64 2.4.3+dfsg-4 [559 kB]
Get:43 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 postgresql-10-postgis-2.4-scripts all 2.4.3+dfsg-4 [547 kB]
Get:44 http://mirrors.cloud.aliyuncs.com/ubuntu bionic/universe amd64 proj-bin amd64 4.9.3-2 [32.3 kB]
Fetched 22.7 MB in 5s (4,183 kB/s)    
Extracting templates from packages: 100%
Selecting previously unselected package poppler-data.
(Reading database ... 116970 files and directories currently installed.)
Preparing to unpack .../00-poppler-data_0.4.8-2_all.deb ...
Unpacking poppler-data (0.4.8-2) ...
Selecting previously unselected package gdal-data.
Preparing to unpack .../01-gdal-data_2.2.3+dfsg-2_all.deb ...
Unpacking gdal-data (2.2.3+dfsg-2) ...
Selecting previously unselected package libaec0:amd64.
Preparing to unpack .../02-libaec0_0.3.2-2_amd64.deb ...
Unpacking libaec0:amd64 (0.3.2-2) ...
Selecting previously unselected package libblas3:amd64.
Preparing to unpack .../03-libblas3_3.7.1-4ubuntu1_amd64.deb ...
Unpacking libblas3:amd64 (3.7.1-4ubuntu1) ...
Selecting previously unselected package libgfortran4:amd64.
Preparing to unpack .../04-libgfortran4_7.5.0-3ubuntu1~18.04_amd64.deb ...
Unpacking libgfortran4:amd64 (7.5.0-3ubuntu1~18.04) ...
Selecting previously unselected package liblapack3:amd64.
Preparing to unpack .../05-liblapack3_3.7.1-4ubuntu1_amd64.deb ...
Unpacking liblapack3:amd64 (3.7.1-4ubuntu1) ...
Selecting previously unselected package libarpack2:amd64.
Preparing to unpack .../06-libarpack2_3.5.0+real-2_amd64.deb ...
Unpacking libarpack2:amd64 (3.5.0+real-2) ...
Selecting previously unselected package libsuperlu5:amd64.
Preparing to unpack .../07-libsuperlu5_5.2.1+dfsg1-3_amd64.deb ...
Unpacking libsuperlu5:amd64 (5.2.1+dfsg1-3) ...
Selecting previously unselected package libarmadillo8.
Preparing to unpack .../08-libarmadillo8_1%3a8.400.0+dfsg-2_amd64.deb ...
Unpacking libarmadillo8 (1:8.400.0+dfsg-2) ...
Selecting previously unselected package libdap25:amd64.
Preparing to unpack .../09-libdap25_3.19.1-2build1_amd64.deb ...
Unpacking libdap25:amd64 (3.19.1-2build1) ...
Selecting previously unselected package libdapclient6v5:amd64.
Preparing to unpack .../10-libdapclient6v5_3.19.1-2build1_amd64.deb ...
Unpacking libdapclient6v5:amd64 (3.19.1-2build1) ...
Selecting previously unselected package libepsilon1:amd64.
Preparing to unpack .../11-libepsilon1_0.9.2+dfsg-2_amd64.deb ...
Unpacking libepsilon1:amd64 (0.9.2+dfsg-2) ...
Selecting previously unselected package libfyba0:amd64.
Preparing to unpack .../12-libfyba0_4.1.1-3_amd64.deb ...
Unpacking libfyba0:amd64 (4.1.1-3) ...
Selecting previously unselected package libfreexl1:amd64.
Preparing to unpack .../13-libfreexl1_1.0.5-1_amd64.deb ...
Unpacking libfreexl1:amd64 (1.0.5-1) ...
Selecting previously unselected package libgeos-3.6.2:amd64.
Preparing to unpack .../14-libgeos-3.6.2_3.6.2-1build2_amd64.deb ...
Unpacking libgeos-3.6.2:amd64 (3.6.2-1build2) ...
Selecting previously unselected package libgeos-c1v5:amd64.
Preparing to unpack .../15-libgeos-c1v5_3.6.2-1build2_amd64.deb ...
Unpacking libgeos-c1v5:amd64 (3.6.2-1build2) ...
Selecting previously unselected package proj-data.
Preparing to unpack .../16-proj-data_4.9.3-2_all.deb ...
Unpacking proj-data (4.9.3-2) ...
Selecting previously unselected package libproj12:amd64.
Preparing to unpack .../17-libproj12_4.9.3-2_amd64.deb ...
Unpacking libproj12:amd64 (4.9.3-2) ...
Selecting previously unselected package libgeotiff2:amd64.
Preparing to unpack .../18-libgeotiff2_1.4.2-2build1_amd64.deb ...
Unpacking libgeotiff2:amd64 (1.4.2-2build1) ...
Selecting previously unselected package libgif7:amd64.
Preparing to unpack .../19-libgif7_5.1.4-2ubuntu0.1_amd64.deb ...
Unpacking libgif7:amd64 (5.1.4-2ubuntu0.1) ...
Selecting previously unselected package libhdf4-0-alt.
Preparing to unpack .../20-libhdf4-0-alt_4.2.13-2_amd64.deb ...
Unpacking libhdf4-0-alt (4.2.13-2) ...
Selecting previously unselected package libsz2:amd64.
Preparing to unpack .../21-libsz2_0.3.2-2_amd64.deb ...
Unpacking libsz2:amd64 (0.3.2-2) ...
Selecting previously unselected package libhdf5-100:amd64.
Preparing to unpack .../22-libhdf5-100_1.10.0-patch1+docs-4_amd64.deb ...
Unpacking libhdf5-100:amd64 (1.10.0-patch1+docs-4) ...
Selecting previously unselected package libminizip1:amd64.
Preparing to unpack .../23-libminizip1_1.1-8build1_amd64.deb ...
Unpacking libminizip1:amd64 (1.1-8build1) ...
Selecting previously unselected package liburiparser1:amd64.
Preparing to unpack .../24-liburiparser1_0.8.4-1_amd64.deb ...
Unpacking liburiparser1:amd64 (0.8.4-1) ...
Selecting previously unselected package libkmlbase1:amd64.
Preparing to unpack .../25-libkmlbase1_1.3.0-5_amd64.deb ...
Unpacking libkmlbase1:amd64 (1.3.0-5) ...
Selecting previously unselected package libkmldom1:amd64.
Preparing to unpack .../26-libkmldom1_1.3.0-5_amd64.deb ...
Unpacking libkmldom1:amd64 (1.3.0-5) ...
Selecting previously unselected package libkmlengine1:amd64.
Preparing to unpack .../27-libkmlengine1_1.3.0-5_amd64.deb ...
Unpacking libkmlengine1:amd64 (1.3.0-5) ...
Selecting previously unselected package libnetcdf13:amd64.
Preparing to unpack .../28-libnetcdf13_1%3a4.6.0-2build1_amd64.deb ...
Unpacking libnetcdf13:amd64 (1:4.6.0-2build1) ...
Selecting previously unselected package libodbc1:amd64.
Preparing to unpack .../29-libodbc1_2.3.4-1.1ubuntu3_amd64.deb ...
Unpacking libodbc1:amd64 (2.3.4-1.1ubuntu3) ...
Selecting previously unselected package libogdi3.2.
Preparing to unpack .../30-libogdi3.2_3.2.0+ds-2_amd64.deb ...
Unpacking libogdi3.2 (3.2.0+ds-2) ...
Selecting previously unselected package liblcms2-2:amd64.
Preparing to unpack .../31-liblcms2-2_2.9-1ubuntu0.1_amd64.deb ...
Unpacking liblcms2-2:amd64 (2.9-1ubuntu0.1) ...
Selecting previously unselected package libpoppler73:amd64.
Preparing to unpack .../32-libpoppler73_0.62.0-2ubuntu2.12_amd64.deb ...
Unpacking libpoppler73:amd64 (0.62.0-2ubuntu2.12) ...
Selecting previously unselected package libqhull7:amd64.
Preparing to unpack .../33-libqhull7_2015.2-4_amd64.deb ...
Unpacking libqhull7:amd64 (2015.2-4) ...
Selecting previously unselected package libspatialite7:amd64.
Preparing to unpack .../34-libspatialite7_4.3.0a-5build1_amd64.deb ...
Unpacking libspatialite7:amd64 (4.3.0a-5build1) ...
Selecting previously unselected package libxerces-c3.2:amd64.
Preparing to unpack .../35-libxerces-c3.2_3.2.0+debian-2_amd64.deb ...
Unpacking libxerces-c3.2:amd64 (3.2.0+debian-2) ...
Selecting previously unselected package odbcinst.
Preparing to unpack .../36-odbcinst_2.3.4-1.1ubuntu3_amd64.deb ...
Unpacking odbcinst (2.3.4-1.1ubuntu3) ...
Selecting previously unselected package odbcinst1debian2:amd64.
Preparing to unpack .../37-odbcinst1debian2_2.3.4-1.1ubuntu3_amd64.deb ...
Unpacking odbcinst1debian2:amd64 (2.3.4-1.1ubuntu3) ...
Selecting previously unselected package libgdal20.
Preparing to unpack .../38-libgdal20_2.2.3+dfsg-2_amd64.deb ...
Unpacking libgdal20 (2.2.3+dfsg-2) ...
Selecting previously unselected package liblwgeom-2.4-0.
Preparing to unpack .../39-liblwgeom-2.4-0_2.4.3+dfsg-4_amd64.deb ...
Unpacking liblwgeom-2.4-0 (2.4.3+dfsg-4) ...
Selecting previously unselected package libprotobuf-c1:amd64.
Preparing to unpack .../40-libprotobuf-c1_1.2.1-2_amd64.deb ...
Unpacking libprotobuf-c1:amd64 (1.2.1-2) ...
Selecting previously unselected package postgresql-10-postgis-2.4.
Preparing to unpack .../41-postgresql-10-postgis-2.4_2.4.3+dfsg-4_amd64.deb ...
Unpacking postgresql-10-postgis-2.4 (2.4.3+dfsg-4) ...
Selecting previously unselected package postgresql-10-postgis-2.4-scripts.
Preparing to unpack .../42-postgresql-10-postgis-2.4-scripts_2.4.3+dfsg-4_all.deb ...
Unpacking postgresql-10-postgis-2.4-scripts (2.4.3+dfsg-4) ...
Selecting previously unselected package proj-bin.
Preparing to unpack .../43-proj-bin_4.9.3-2_amd64.deb ...
Unpacking proj-bin (4.9.3-2) ...
Setting up libminizip1:amd64 (1.1-8build1) ...
Setting up libaec0:amd64 (0.3.2-2) ...
Setting up libdap25:amd64 (3.19.1-2build1) ...
Setting up libqhull7:amd64 (2015.2-4) ...
Setting up libodbc1:amd64 (2.3.4-1.1ubuntu3) ...
Setting up postgresql-10-postgis-2.4-scripts (2.4.3+dfsg-4) ...
Setting up libgfortran4:amd64 (7.5.0-3ubuntu1~18.04) ...
Setting up liblcms2-2:amd64 (2.9-1ubuntu0.1) ...
Setting up poppler-data (0.4.8-2) ...
Setting up libgeos-3.6.2:amd64 (3.6.2-1build2) ...
Setting up libgif7:amd64 (5.1.4-2ubuntu0.1) ...
Setting up libprotobuf-c1:amd64 (1.2.1-2) ...
Setting up libepsilon1:amd64 (0.9.2+dfsg-2) ...
Setting up libfreexl1:amd64 (1.0.5-1) ...
Setting up libfyba0:amd64 (4.1.1-3) ...
Setting up libdapclient6v5:amd64 (3.19.1-2build1) ...
Setting up gdal-data (2.2.3+dfsg-2) ...
Setting up libpoppler73:amd64 (0.62.0-2ubuntu2.12) ...
Setting up libgeos-c1v5:amd64 (3.6.2-1build2) ...
Setting up libblas3:amd64 (3.7.1-4ubuntu1) ...
update-alternatives: using /usr/lib/x86_64-linux-gnu/blas/libblas.so.3 to provide /usr/lib/x86_64-linux-gnu/libblas.so.3 (libblas.so.3-x86_64-linux-gnu) in auto mode
Setting up libhdf4-0-alt (4.2.13-2) ...
Setting up libxerces-c3.2:amd64 (3.2.0+debian-2) ...
Setting up liburiparser1:amd64 (0.8.4-1) ...
Setting up libsz2:amd64 (0.3.2-2) ...
Setting up proj-data (4.9.3-2) ...
Setting up libproj12:amd64 (4.9.3-2) ...
Setting up libhdf5-100:amd64 (1.10.0-patch1+docs-4) ...
Setting up liblwgeom-2.4-0 (2.4.3+dfsg-4) ...
Setting up liblapack3:amd64 (3.7.1-4ubuntu1) ...
update-alternatives: using /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3 to provide /usr/lib/x86_64-linux-gnu/liblapack.so.3 (liblapack.so.3-x86_64-linux-gnu) in auto mode
Setting up libsuperlu5:amd64 (5.2.1+dfsg1-3) ...
Setting up libkmlbase1:amd64 (1.3.0-5) ...
Setting up libogdi3.2 (3.2.0+ds-2) ...
Setting up proj-bin (4.9.3-2) ...
Setting up libgeotiff2:amd64 (1.4.2-2build1) ...
Setting up libnetcdf13:amd64 (1:4.6.0-2build1) ...
Setting up libspatialite7:amd64 (4.3.0a-5build1) ...
Setting up libarpack2:amd64 (3.5.0+real-2) ...
Setting up libkmldom1:amd64 (1.3.0-5) ...
Setting up libarmadillo8 (1:8.400.0+dfsg-2) ...
Setting up libkmlengine1:amd64 (1.3.0-5) ...
Setting up odbcinst1debian2:amd64 (2.3.4-1.1ubuntu3) ...
Setting up odbcinst (2.3.4-1.1ubuntu3) ...
Setting up libgdal20 (2.2.3+dfsg-2) ...
Setting up postgresql-10-postgis-2.4 (2.4.3+dfsg-4) ...
Processing triggers for postgresql-common (190ubuntu0.1) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for fontconfig (2.12.6-0ubuntu2) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
root@iZ8vbd3whsqpuhzrq9w78uZ:/# 

好了,postgis-2.4安装完成。

接下来要把postgis的能力赋予给某个数据库了;

切换到数据库用户,并进入到sql命令界面。

root@iZ8vbd3whsqpuhzrq9w78uZ:/# su postgres
postgres@iZ8vbd3whsqpuhzrq9w78uZ:/$ psql
psql (10.19 (Ubuntu 10.19-0ubuntu0.18.04.1))
Type "help" for help.

postgres=# 

赋予默认的postgres库postgis能力

postgres=# create extension postgis;
CREATE EXTENSION

查看一下数据库的具体信息

postgres=# select version();
                                                               version                                                                
--------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 10.19 (Ubuntu 10.19-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit
(1 row)

查看一下postgis的具体信息

postgres=# select postgis_full_version();
                                                                                           postgis_full_version                                                                                           
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="2.4.3 r16312" PGSQL="100" GEOS="3.6.2-CAPI-1.10.2 4d2925d6" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.2.3, released 2017/11/20" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" RASTER
(1 row)

测试一下postgis的能力

postgres=# select st_point(1,1) as testfirstpoint;
               testfirstpoint               
--------------------------------------------
 0101000000000000000000F03F000000000000F03F
(1 row)

默认的posgres数据库postgis天加成功,再来添加别的数据库,我现在用的库是battery

首先进入battery库,用\c database命令进入数据库battery,这里不用加分号结尾,加也可以啊。

postgres=# \c battery 
You are now connected to database "battery" as user "postgres".
battery=# create extension postgis;
CREATE EXTENSION
battery=# 

测试一下

postgres=# \c battery 
You are now connected to database "battery" as user "postgres".
battery=# create extension postgis;
CREATE EXTENSION
battery=# select st_point(1,1) as testfirstpoint;
               testfirstpoint               
--------------------------------------------
 0101000000000000000000F03F000000000000F03F
(1 row)

battery=# 

OK完成

后边儿我会记录一下数据库文件怎么移动。大概场景就是数据库太大了,本来的数据盘装不了,需要吧数据库文件诺动到新挂载的硬盘上。

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值