Linux 下源码安装PostgreSQL

通过源文件在Linux下安装PostgreSQL。

本示例以目前最新的稳定版本v13.0为例。

操作系统:CentOS Linux release 7.5.1804 (Core)

1,下载PostgreSQL源文件

wget https://ftp.postgresql.org/pub/source/v13.0/postgresql-13.0.tar.gz

2,解压PostgreSQL源文件到指定目标并编译安装

安装依赖

yum install -y readline readline-devel

解压PostgreSQL源码压缩包

tar -xf postgresql-13.0.tar.gz

切换至解压目录

cd postgresql-13.0

配置编译选项

./configure

可以根据自己应用场景,选择相应的配置参数。具体可以参考http://www.postgres.cn/docs/12/install-procedure.html

编译并安装

make

make install

默认安装目录/usr/local/pgsql/

3,设置环境变量

新建文件/etc/profile.d/postgresql.sh

vi  /etc/profile.d/postgresql.sh

加入如下内容:

export POSTGRESQL_PATH=/usr/local/pgsql/

export PATH=$PATH:$POSTGRESQL_PATH\bin

刷新环境变量

source /etc/profile.d/postgresql.sh

4,创建PostgreSQL用户组及用户

groupadd postgres

useradd -g postgres postgres

5,初始化PostgreSQL数据库存储目录

创建数据库存储目录

mkdir /usr/local/pgsql/data

授予postgres用户数据库存储目录权限

chown postgres:postgres /usr/local/pgsql/data

切换至postgres用户

su - postgres

初始化数据库存储目录

initdb -D /usr/local/pgsql/data

6,启动PostgreSQL数据

前台运行方式:

postgres -D /usr/local/pgsql/data

后台运行方式:

postgres -D /usr/local/pgsql/data >logfile 2>&1 &

其中-D参数指定的是数据库的存储目录

7,注册开机启动服务

切换回root用户注册服务

su root

cp 解压目录/postgresql-13.0/contrib/start-scripts/linux /etc/init.d/postgresql

注册服务

chmod +x /etc/init.d/postgresql

然后注册服务

systemctl enable postgresql

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容