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 列出当前数据库和连接的信息。

发布了57 篇原创文章 · 获赞 73 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_40450867/article/details/102671979