源码编译怎么安装PostgresSQL

发布时间:2021-11-04 17:46:54 作者:iii
来源:亿速云 阅读:229

这篇文章主要讲解了“源码编译怎么安装PostgresSQL”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“源码编译怎么安装PostgresSQL”吧!

一、环境准备

1、安装依赖包

yum -y install gcc*
yum -y install python python-devel
yum -y install perl-ExtUtils-Embed
yum -y install zlib-devel
yum -y install readline*

2、创建用户组、目录

groupadd -g 1001 postgres #新增用户组
useradd -g 1001 -u 1001 postgres #新增用户
[root@pg11 ~]# id postgres
uid=1001(postgres) gid=1001(postgres) groups=1001(postgres)
passwd postgres #为用户设置密码

3、创建目录

mkdir -p /usr/local/pgsql11.5
chown -R postgres:postgres /usr/local/pgsql11.5/

mkdir -p /home/osdata/pgdata
chown -R postgres:postgres /home/osdata/
chmod 0700 /home/osdata/pgdata

4、修改环境变量(postgres用户)

export PATH=/usr/local/pgsql11.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/pgsql11.5/lib
export PGDATA=/home/osdata/pgdata

5、上传软件包,并且解压缩(root)

[root@pg11 pgsql11.5]# ll
total 19312
-rw-r–r--. 1 root root 19773087 Oct 30 20:05 postgresql-11.5.tar.bz2
[root@pg11 pgsql11.5]#chown -R postgres:postgres /usr/local/pgsql11.5/
[root@pg11 pgsql11.5]# ll
total 19312
-rw-r–r--. 1 postgres postgres 19773087 Oct 30 20:05 postgresql-11.5.tar.bz2

tar -xvf postgresql-11.5.tar.bz2

6、生成链接

ln -sf /usr/local/pgsql11.5 /usr/local/pgsql

二、安装postgresql

1、编译

cd postgresql-11.5/
./configure --prefix=/usr/local/pgsql11.5 --with-perl --with-python

2、安装

一次性把文档及附加模块全部进行编译和安装
gmake world
出现“PostgreSQL, contrib, and documentation successfully made. Ready to install.”说明编译成功

gmake install-world
出现“PostgreSQL, contrib, and documentation installation complete.”说明安装成功

查看版本
[postgres@pg11 postgresql-11.5]$ postgres --version
postgres (PostgreSQL) 11.5

3、初始化数据库

initdb -D /home/osdata/pgdata/ -W

4、启动数据库

pg_ctl -D $PGDATA -l logfile start

5、查看实例进程

[postgres@pg ~]$ ps -ef|grep postgres
postgres 56625 1 0 Mar04 ? 00:00:03 /usr/local/pgsql11.5/bin/postgres -D /home/osdata/pgdata
postgres 56627 56625 0 Mar04 ? 00:00:00 postgres: checkpointer
postgres 56628 56625 0 Mar04 ? 00:00:01 postgres: background writer
postgres 56629 56625 0 Mar04 ? 00:00:01 postgres: walwriter
postgres 56630 56625 0 Mar04 ? 00:00:05 postgres: autovacuum launcher
postgres 56631 56625 0 Mar04 ? 00:00:10 postgres: stats collector
postgres 56632 56625 0 Mar04 ? 00:00:00 postgres: logical replication launcher
root 76758 76699 0 11:01 pts/0 00:00:00 su - postgres
postgres 76759 76758 0 11:01 pts/0 00:00:00 -bash
postgres 76797 76759 0 11:01 pts/0 00:00:00 psql
postgres 76801 56625 0 11:01 ? 00:00:00 postgres: postgres test [local] idle
root 77192 77145 0 11:21 pts/1 00:00:00 su - postgres
postgres 77193 77192 0 11:21 pts/1 00:00:00 -bash
postgres 79582 77193 0 13:45 pts/1 00:00:00 ps -ef
postgres 79583 77193 0 13:45 pts/1 00:00:00 grep --color=auto postgres

查看数据库状态
[postgres@pg11 ~]$ pg_ctl -D /home/osdata/pgdata/ status
pg_ctl: server is running (PID: 23588)
/usr/local/pgsql11.5/bin/postgres “-D” “/home/osdata/pgdata”

6、设置开机自启动

1、配置脚本服务
在源码包的contrib目录中有linux、freebsd、macos适用的服务脚本
[root@pg11 ~]# cd /usr/local/pgsql/postgresql-11.5/contrib/start-scripts
[root@pg11 start-scripts]# ll
total 8
-rw-r–r--. 1 postgres postgres 1467 Aug 6 2019 freebsd
-rw-r–r--. 1 postgres postgres 3552 Aug 6 2019 linux
drwxrwxr-x. 2 postgres postgres 84 Aug 6 2019 macos
把名为linux的脚本拷贝到/etc/init.d目录,并且重命名为postgresql11
[root@pg11 ~]# cp /usr/local/pgsql/postgresql-11.5/contrib/start-scripts/linux /etc/init.d/postgresql11
[root@pg11 init.d]# chmod +x postgresql-11
[root@pg11 init.d]# chkconfig postgresql-11 on
[root@pg11 init.d]# chkconfig --list |grep postgresql-11
postgresql-11 0:off 1:off 2:on 3:on 4:on 5:on 6:off

7、登录数据库

[postgres@pg ~]$ psql
psql (11.5)
Type “help” for help.

postgres=#

感谢各位的阅读,以上就是“源码编译怎么安装PostgresSQL”的内容了,经过本文的学习后,相信大家对源码编译怎么安装PostgresSQL这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. 源码编译安装LAMP
  2. 源码编译安装LNMP

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

postgressql

上一篇:df -h无响应或者卡住该怎么办

下一篇:初始化参数REMOTE_LOGIN_PASSWORDFILE设置Oracle数据库的密码验证方式是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》