CentOS安装postgresql9.1

本文介绍了在 CentOS 5.5 上安装 PostgreSQL 9.1 的详细步骤,包括下载安装包、配置 YUM 源、安装相关组件等,并提供了在遇到 initdb 失败时的解决方案。

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

以下是在CentOS5.5上安装postgresql9.1的相关记录

(1) 从http://yum.pgrpms.org/repopackages.php 下载postgresql9.1 rpm安装包
   [root@server1 ~]# wget http://yum.pgrpms.org/9.1/redhat/rhel-5-i386/pgdg-centos91-9.1-4.noarch.rpm
(2)安装pgdg-centos91-9.1-4.noarch.rpm
  [root@server1 ~]# rpm -i pgdg-centos91-9.1-4.noarch.rpm 
(3)更改CentOS-Base.repo
  为方便通过yum安装postgresql9.1的相关软件,所以需要更改CentOS-Base.repo,以便于yum list postgresql* 能找到postgresql9.1的相关软件包
  只需要在 CentOS-Base.repo的[base] and [updates]中增加'exclude=postgresql*'即可
  具体操作如下:
    [root@server1 ~]# cd /etc/yum.repos.d 
    [root@server1 yum.repos.d]# vi CentOS-Base.repo  
      [base]
      name=CentOS-$releasever - Base
      mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
      #baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/
      gpgcheck=1
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
      exclude=postgresql*
      #released updates
      [updates]
      name=CentOS-$releasever - Updates
      mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
      #baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/updates/$basearch/
      gpgcheck=1
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
      exclude=postgfesql*
      #packages used/produced in the build but not released
(4)通过yum list postgres*来检测相关的安装包
  [root@server1 yum.repos.d]# yum list postgres*
    Available Packages 
    postgresql91.x86_64                         9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-contrib.x86_64                 9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-debuginfo.x86_64               9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-devel.i686                     9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-devel.x86_64                   9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-docs.x86_64                    9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-jdbc.x86_64                    9.1.901-1PGDG.rhel6           pgdg91 
    postgresql91-jdbc-debuginfo.x86_64          9.1.901-1PGDG.rhel6           pgdg91 
    postgresql91-libs.i686                      9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-libs.x86_64                    9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-odbc.x86_64                    09.00.0200-1PGDG.rhel6        pgdg91 
    postgresql91-odbc-debuginfo.x86_64          09.00.0200-1PGDG.rhel6        pgdg91 
    postgresql91-plperl.x86_64                  9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-plpython.x86_64                9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-pltcl.x86_64                   9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-python.x86_64                  4.0-2PGDG.rhel6               pgdg91 
    postgresql91-python-debuginfo.x86_64        4.0-2PGDG.rhel6               pgdg91 
    postgresql91-server.x86_64                  9.1.1-1PGDG.rhel6             pgdg91 
    postgresql91-tcl.x86_64                     1.9.0-1.rhel6                 pgdg91 
    postgresql91-tcl-debuginfo.x86_64           1.9.0-1.rhel6                 pgdg91 
    postgresql91-test.x86_64                    9.1.1-1PGDG.rhel6             pgdg91 
    postgresql_autodoc.noarch                   1.40-1.rhel6                  pgdg91 
    [root@server1 yum.repos.d]# 
(6)使用yum安装postgresql9.1以及相关软件包
  [root@server1 yum.repos.d]# yum install postgresql91 postgresql91-devel postgresql91-server postgresql91-libs postgresql91-contrib 
(7)初始化并启动postgresql
  [root@server1 yum.repos.d]# service postgresql-9.1 initdb 
  Initializing database:                                     [  OK  ] 
  [root@server1 yum.repos.d]# 
  [root@server1 yum.repos.d]# service postgresql-9.1 initdb 
  Initializing database:                                     [  OK  ] 
  [root@server1 yum.repos.d]# 


安装postgresql注意事项:
(1)如果在initdb时失败,则很有可能是因为系统默认字符编码和postgresql所认可的不一致所导致的,这时可以通过/var/lib/pgsql/9.1/pgstartup.log的相关出错信息来确认
  如果确定是编码的问题导致initdb失败,则可以通过在initdb时指定--no-locale来解决,具体方法如下
  1.1 [root@GJZ bin]# su - postgres
  1.2 -bash-3.2$ /usr/local/pgsql/bin/initdb --no-locale
    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 C.
    The default database encoding has accordingly been set to SQL_ASCII.
    The default text search configuration will be set to "english".
    fixing permissions on existing directory /var/lib/pgsql/9.1/data ... ok
(2) 注意修改/var/lib/pgsql/9.1/data中的postgresql.conf和pg_hba.conf文件,根据需要配置相关的访问策略

参考资料:
(1)http://www.davidghedini.com/pg/entry/install_postgresql_9_on_centos
(2)http://www.linuxfly.org/post/88/
(3)



### 如何在 CentOS 上从源码安装 PostgreSQL #### 准备工作 为了确保顺利编译和安装,需要先确认系统已经安装了必要的开发工具和库。可以通过以下命令来安装这些依赖项: ```bash sudo yum groupinstall "Development Tools" sudo yum install readline-devel zlib-devel bzip2-devel openssl-devel libxml2-devel libxslt-devel ``` #### 下载源代码包 访问官方网站获取最新版本的PostgreSQL源文件并解压。 ```bash cd /usr/src sudo wget https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.bz2 sudo tar jxf postgresql-13.3.tar.bz2 cd postgresql-13.3 ``` #### 配置构建环境 进入解压缩后的目录后,运行`configure`脚本来设置编译参数。这里可以根据实际需求调整配置选项,比如指定安装路径等。 ```bash ./configure --prefix=/opt/pgsql --with-python --with-perl --with-tcl --with-libraries=/usr/lib64 --with-includes=/usr/include ``` #### 编译与测试 完成上述准备工作之后就可以开始编译过程了,在这一步也可以顺便执行一些基本的功能检测以验证编译结果是否正常。 ```bash make world make check ``` #### 安装软件 当所有的单元测试都通过以后,则可以正式安装PostgreSQL到目标位置去了。 ```bash sudo make install-world ``` #### 初始化数据库集群 首次启动之前还需要创建一个新的数据存储区域,并对其进行初始化处理。 ```bash /opt/pgsql/bin/initdb -D /opt/pgsql/data/ ``` #### 启动服务 最后就是让新安装的服务能够自动开机自启以及手动开启它来进行初次连接尝试。 ```bash cp contrib/start-scripts/linux /etc/rc.d/init.d/postgresql chmod +x /etc/rc.d/init.d/postgresql chkconfig --add postgresql service postgresql start ``` 以上就是在CentOS操作系统上基于官方发布的tarball形式分发版进行完全本地化部署的方法[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值