1.PostgreSQL下载安装

本文详细介绍了在Linux系统中下载并安装PostgreSQL 10.1的步骤,包括解决缺少gcc和readline库的问题,配置环境变量,初始化数据库,创建用户,启动服务以及访问和管理数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载地址:https://www.postgresql.org/ftp/source/v10.1/
想看详细介绍请看官方文档 : http://www.postgres.cn/docs/9.5/install-procedure.html


1. 安装:
[root@mysqltest1 postgresql-10.1]# ./configure --prefix=/usr/local/pgsql
......
configure: error: in `/usr/local/postgresql-10.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details


缺少 gcc包, 安装gcc包
[root@mysqltest1 postgresql-10.1]# yum -y install gcc

configure: error: readline library not found</span>

据提示,应该是没有安装 readline包。

3 检查系统是否安装 readline 包
[root@mysqltest1 postgresql-10.1]# rpm -qa | grep readline
readline-6.2-10.el7.x86_64</span>


4 通过 yum 搜索相关的readline 包
[root@mysqltest1 postgresql-10.1]# yum search readline

已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
================================================================ N/S matched: readline ================================================================
readline-devel.i686 : Files needed to develop programs which use the readline library
readline-devel.x86_64 : Files needed to develop programs which use the readline library
readline-static.i686 : Static libraries for the readline library
readline-static.x86_64 : Static libraries for the readline library
perl-Term-UI.noarch : Term::ReadLine user interface made easy
readline.i686 : A library for editing typed command lines
readline.x86_64 : A library for editing typed command lines


5. 安装 readline-devel 包
[root@mysqltest1 postgresql-10.1]# yum -y install -y readline-devel

6.编译安装
make 编译
make install 安装

7.配置共享库:
LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH</span>


8. 环境变量

[root@mysqltest1 pgsql]# su - pgsql
[root@mysqltest1 pgsql]# vim .bash_profile

export PGHOME=/usr/local/pgsql  
export PGDATA=/usr/local/pgsql/data  
export PGLIB=/usr/local/pgsql/lib  
export PATH=$PGHOME/bin:$PATH  

source /home/pgsql/.bash_profile


9.查看环境变量是否生效

[root@mysqltest1 /]# psql -V
psql (PostgreSQL) 10.1


9. 创建用户,跟oracle一样,pgsql需要单独创建一个用户进行管理

useradd pgsql
chown pgsql:pgsql /usr/local/pgsql -R 


10. 初始化数据库
由于配置了环境变量,所以此处我们直接执行initdb即可完成db初始化,但在这之前可以通过initdb --help看一下初始化相关的帮助信息: 

初始化
initdb -D /usr/local/pgsql/data/  

启动服务

pg_ctl -D /usr/local/pgsql/data/ -l /usr/local/pgsql/logs/logfile start 

11.启动失败,log文件报错信息:

could not open lock file "/tmp/.s.PGSQL.5432.lock": 权限不够

解决办法:
chown pgsql:pgsql /tmp/.s.PGSQL.5432.lock

12.创建数据库
[pgsql@mysqltest1 data]$ createdb mydb
[pgsql@mysqltest1 data]$ dropdb mydb


13. 访问数据库:

[pgsql@mysqltest1 data]$ psql mydb
psql (10.1)
Type "help" for help.
mydb=# 


14. 查看版本
mydb=# select version();'
                                              version                                                
---------------------------------------------------------------------------------------------------------
PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
(1 row)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值