postgresql安装

一、从源码安装

安装过程大致如下:

第一步:下载源代码

第二步:编译安装

./configure

make 

make install

第三步:编译安装完成后执行如下步骤。

使用initdb命令初始化数据库簇

启动数据库实例

创建一个应用使用的数据库。

(数据库簇是指数据库实例管理的系统文件和各个数据库文件的一个集合)

1)下载安装包

https://www.postgresql.org/

download-->source-->选择版本

一般选择bz2的压缩包(这种压缩包格式体积比较小)

2)解压安装包 

useradd pgsql     (管理数据库的账号,好像不能用root账号)

cd /tmp

tar -xvf postgresql-14.1.tar.bz2

chown -R pgsql:pgsql  postgresql-14.1

3)编译

mkdir -p /usr/local/pgsql0104/pgsql14.1

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

su - pgsql

cd /tmp/postgresql-14.1
 ./configure --prefix=/usr/local/pgsql0104/pgsql14.1 --with-perl --with-python
 

编译报错一:

checking for flags to link embedded Perl... Can't locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/loc                                                                                                                              al/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/                                                                                                                              perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.
no
configure: error: could not determine flags for linking embedded Perl.
This probably means that ExtUtils::Embed or ExtUtils::MakeMaker is not
installed.

解决方法:

yum install perl-ExtUtils-Embed

编译报错二:

configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

解决方法:

yum install perl-ExtUtils-Embed

编译报错三:

checking for inflate in -lz... no
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.

解决方法:
yum install zlib zlib-devel

编译报错四:
checking for Python.h... no
configure: error: header file <Python.h> is required for Python
解决方法:
yum install python python-devel

4)make && make install 

使用make命令后,其版本要在gmake3.8以上

[root@easha1 postgresql-14.1]# make --version   --查看gmake版本
GNU Make 3.82

su - pgsql

make && make install

补充说明:

--prefix设置的路径为/usr/local/pgsql0104/pgsql14.1, 如果不设置这个路径,默认的路径是/usr/local,加上PostgreSQL的版本号的好处是升级方便,make install命令运行完之后,还有进入/usr/local目录下,为/usr/local/pgsql0104/pgsql14.1建立一个/usr/loca/pgsql的链接:

ln -sf /usr/local/pgsql0104/pgsql14.1  /usr/local/pgsql
 

如果PostgreSQL14.2发布了,在编译PostgreSQL14.2之后,只需把现有的数据库停掉,然后把链接/usr/local/pgsql执行先前的版本/usr/local/pgsql14.2即可完成升级。

5)安装完成后配置
export PATH=/usr/local/pgsql/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATHexport PGDATA=/kingdee/pgsql      (存放数据文件)

可以加到/etc/profile文件中

6)创建数据库簇

su - pgsql

 initdb

[pgsql@easha1 ~]$ initdb
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /kingdee/pgsql ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /kingdee/pgsql -l logfile start

7)安装contrib目录下的工具

 cd /tmp/postgresql-14.1/contrib/

make $$ make install 
 



 



 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值