---
title: "安装Postgresql数据库+Postgis插件"
author: "wang5598"
date: "2013-04-02T13:58:57Z"
tags: ["PostgreSQL", "postgis"]
categories: ["数据库"]
slug: "postgresql-postgis"
draft: false
lastmod: "2013-04-11T15:56:49Z"
id: 1840718
url: "https://wang5598.iteye.com/blog/1840718"
---

postgresql（版本8.4）

下载页面：

http://www.enterprisedb.com/products-services-training/pgdownload

下载地址：

http://get.enterprisedb.com/postgresql/postgresql-8.4.10-1-linux-x64.run

 

postgis（适合于8.4版本）

下载地址：

sbp.enterprisedb.com/getfile.jsp?fileid=2048  （64位操作系统）

 

1、首先下载完两份文件后，设置执行权限：

chmod u+x postgresql-8.4.10-1-linux-x64.run

chmod u+x postgis-pg84-1.4.2-1-linux-x64.bin

2、ubuntu下面如果是非管理员用户，需要获取管理员权限进行操作

sudo -i 然后输入密码

3、接下来先执行postgresql安装，然后再进行postgis安装；

4、安装完成后，需要需改postgresql的配置参数，使其可以接收来自于外面的链接：

1）.备份配置文件

cd /opt/PostgreSQL/8.4/data/

cp pg\_hba.conf pg\_hba.confbak20130402

2）.修改配置文件

vi pg\_hba.conf 添加如下配置

host all all 192.168.1.0/24 md5 

5、重启数据库

 service postgresql-8.4 restart

 

6、安装之前注意要先在操作系统中装好中文字体和编码，这块可以参看具体的操作系统配置，就我的经验而讲，centos基本不用配置，ubuntu要配置很多东西，比较麻烦；在安装postgresql的过程中选择字符编码的时候注意选择zh\_CN.UTF-8的字符编码，不然后续的数据库中的中文会出现乱码；

 

7、个别时候会出现安装postgis失败或者没有创建postgis\_template数据库模板的情况，此时要把数据库卸载掉，找出所有和postgresql相关的配置文件全部删除掉，最主要的就是删除掉一个 postgres-reg.ini 的文件，不然下次还是会出现安装失败的情况。

1、执行卸载：./opt/PostgreSQL/8.4/uninstall-postgresql

2、删除遗留的文件：rm -rf /opt/postgresql-8.4

3、删除配置信息：rm /etc/postgres-reg.ini