centos7.5安装postgresql和postgis

亲测可用,屡试不爽,多次失败教训的总结。

 

下载较慢时更新yum源

备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 

下载

 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

更新缓存

yum makecache

postgresql安装

参考

https://www.postgresql.org/download/linux/redhat/

centos7 选择安装10版本

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Install the client packages:

yum install postgresql10 -y

Optionally install the server packages:

yum install postgresql10-server

Optionally initialize the database and enable automatic start:

初始化数据库,开机启动并启动数据库

/usr/pgsql-10/bin/postgresql-10-setup initdb 
systemctl enable postgresql-10 
systemctl start postgresql-10

 

 

安装postgis过程中报错需要安装的

 

sudo yum install -y postgresql10-devel.x86_64 

sudo yum install -y libxml2-devel 

sudo yum install -y geos

 

安装postgis

 

yum list postgis*列出可用的postgis包

sudo yum -y install epel-release

sudo yum install -y postgis25_10 postgis25_10-client postgis25_10-debuginfo postgis25_10-devel postgis25_10-docs postgis25_10-gui postgis25_10-utils

sudo yum install -y ogr_fdw10 ogr_fdw10-debuginfo pgrouting_10 pgrouting_10-debuginfo

 

查看端口

sudo netstat -ntlp | grep post

 

psql 角色不存在

删除postgres的密码并重置,密码要复杂一些,否则设置不成功,例如wcg12345W!

sudo passwd -d postgres sudo -u postgres passwd

切回postgres

su - postgres

在root用户下

vim /var/lib/pgsql/10/data/pg_hba.conf

将下面一行的最后一个peer改为trust

local all all peer

改为

local all all trust

在root用户下 重新启动服务

systemctl stop postgresql-10 && systemctl start postgresql-10
su - postgres

安装完成,开始使用

输入psql进入数据库

psql

创建名称为geo的数据库

create database geo;

切换数据库

\c geo;

查看数据库

\l

加载postgis扩展

CREATE EXTENSION postgis;

查看扩展是否被正确加载

SELECT name , default_version FROM pg_available_extensions WHERE name ~ 'gis';

 

查看postgis完整版本

SELECT postgis_full_version() ;

一些命令

\password 设置密码。

\q 退出。

\h 查看SQL命令的解释,比如\h select。

\? 查看psql命令列表。

\l 列出所有数据库。

\c [database_name] 连接其他数据库。

\d 列出当前数据库的所有表格。

\d [table_name] 列出某一张表格的结构。

\du 列出所有用户。

\e 打开文本编辑器。

\conninfo 列出当前数据库和连接的信息。

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

独孤尚亮dugushangliang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值