postgresql编译安装

postgresql编译安装

一、下载源码和依赖包

step 1:源码包下载地址:https://www.postgresql.org/ftp/source/

源码下载

step 2:依赖下载地址:http://www.rpmfind.net/

依赖包下载
在这里插入图片描述

二、编译安装数据库

step 1:创建用户和目录

mkdir /opt/postgresql/data
groupadd pgsql
useradd -g pgsql -G pgsql -d /opt/postgresql pgsql
chown -R pgsql:pgsql /opt/postgresql
passwd pgsql #修改密码
密码:rofine@123

step 2:上传安装包到服务器

step 3:安装依赖

rpm -ivh ncurses-devel-5.9-14.20130511.el7_4.x86_64.rpm
rpm -Uvh readline-6.2-11.el7.x86_64.rpm
rpm -ivh readline-devel-6.2-11.el7.x86_64.rpm
rpm -ivh mpfr-3.1.1-4.el7.x86_64.rpm 
rpm -ivh libmpc-1.0.1-3.el7.x86_64.rpm
rpm -ivh cpp-4.8.5-44.el7.x86_64.rpm 
rpm -Uvh libgomp-4.8.5-44.el7.x86_64.rpm
rpm -Uvh libgcc-4.8.5-44.el7.x86_64.rpm
rpm -ivh kernel-headers-3.10.0-1160.el7.x86_64.rpm
rpm -Uvh glibc-common-2.17-317.el7.x86_64.rpm glibc-2.17-317.el7.x86_64.rpm
rpm -ivh glibc-headers-2.17-317.el7.x86_64.rpm
rpm -ivh glibc-devel-2.17-317.el7.x86_64.rpm
rpm -ivh gcc-4.8.5-44.el7.x86_64.rpm
rpm -ivh zlib-devel-1.2.7-18.el7.x86_64.rpm

step 4:切换pgsql用户,解压文件到指定目录

su pgsql
tar -zxvf postgresql-14.6.tar.gz -C /opt/postgresql

step 5:编译安装

cd /opt/postgresql/postgresql-14.6
./configure --prefix=/opt/postgresql
make && make install
/opt/postgresql/bin/initdb -D /opt/postgresql/data/
touch /opt/postgresql/logfile 

step 6:配置环境变量

vim ~/.bash_profile
	
		export PGDATA=/opt/postgresql/data
		export PATH=$PATH:$HOME/bin:/opt/postgresql/bin
		export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/postgresql/lib
		export PGDATABASE=postgres
		export PGPORT=5432
source ~/.bash_profile

step 7:使用pgsql用户启动postgres

cd /opt/postgresql
./pgsql/bin/pg_ctl -D ./pgsql/pgsql_data/ -l ./pgsql/logfile start
waiting for server to start.... done
server started
#查看pgsql状态
ps -ef | grep postgres | grep -v grep
pgsql    13912     1  0 15:36 pts/2    00:00:00 /home/postgresql/bin/postgres -D ./pgsql/pgsql_data
pgsql    13914 13912  0 15:36 ?        00:00:00 postgres: checkpointer process   
pgsql    13915 13912  0 15:36 ?        00:00:00 postgres: writer process   
pgsql    13916 13912  0 15:36 ?        00:00:00 postgres: wal writer process   
pgsql    13917 13912  0 15:36 ?        00:00:00 postgres: autovacuum launcher process   
pgsql    13918 13912  0 15:36 ?        00:00:00 postgres: stats collector process   
pgsql    13919 13912  0 15:36 ?        00:00:00 postgres: bgworker: logical replication launcher   
-bash-4.2$ psql
psql.bin (14.6)
Type "help" for help.

postgres=# \q    //退出

step 8:配置postgresql.conf文件

使用pgsql用户执行
打开postgresql.conf文件,修改以下参数

cd /opt/postgresql/pgsql/pgsql_data
vim postgresql.conf #编辑文件
listen_addresses= '*' #地址为*	port = 5432 #修改端口

step 9:配置hosts文件

打开/etc/hosts文件,修改以下参数
vim /etc/hosts #编辑文件
127.0.0.1   postgresql

step 10:修改数据库配置


sed -i -e"s/^#listen_addresses =.*$/listen_addresses = '*'/" $DATADIR/postgresql.conf

sed -i -e"s/^max_connections = 100.*$/max_connections = 1000/" $DATADIR/postgresql.conf

sed -i -e"s/^shared_buffers =.*$/shared_buffers = 2GB/" $DATADIR/postgresql.conf

sed -i -e"s/^#effective_cache_size = 128MB.*$/effective_cache_size = 4GB/" $DATADIR/postgresql.conf

sed -i -e"s/^#work_mem = 1MB.*$/work_mem = 128MB/" $DATADIR/postgresql.conf

echo "host all all 0.0.0.0/0 md5" >> $DATADIR/pg_hba.conf

step 11:添加系统systemd服务启动

cat >> /etc/systemd/system/postgresql.service <<EOF

[Unit]

Description=PostgreSQL database server

After=network.target

[Service]

Type=forking

User=pgsql

Group=pgsql

#Environment=PGDATA=/opt/postgresql/data

#OOMScoreAdjust=-1000

ExecStart=/opt/postgresql/bin/pg_ctl -D /opt/postgresql/data -l /opt/postgresql/logfile start

ExecStop=/opt/postgresql/bin/pg_ctl stop -D /opt/postgresql/data

ExecReload=/opt/postgresql/bin/pg_ctl reload -D /opt/postgresql/data

TimeoutSec=300

[Install]

WantedBy=multi-user.target

EOF

systemctl daemon-reload

systemctl start postgresql.service

systemctl enable postgresql.service

step 12:重启数据库

systemctl restart postgresql.service

EOF

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译安装PostgreSQL的步骤如下: 1. 首先,为PostgreSQL创建一个目录,例如/home/postgres,并确保该目录的所有者是postgres用户,组是postgres组。可以使用以下命令完成此操作: ``` mkdir /home/postgres chown postgres /home/postgres chgrp postgres /home/postgres ``` 2. 下载PostgreSQL的源代码压缩包和对应的MD5校验文件。可以使用以下命令下载: ``` wget https://ftp.postgresql.org/pub/source/v${PG_VERSION_NUM}/postgresql-${PG_VERSION_NUM}.tar.bz2 wget https://ftp.postgresql.org/pub/source/v${PG_VERSION_NUM}/postgresql-${PG_VERSION_NUM}.tar.bz2.md5 ``` 3. 进入下载的源代码目录,并执行编译安装。假设源代码解压后的目录是/root/postgresql-9.2.24(根据实际情况修改),可以使用以下命令完成编译安装: ``` cd /root/postgresql-9.2.24/contrib/pageinspect make make install ``` 这些命令将编译安装Pageinspect扩展,它是PostgreSQL的一个附加模块。安装过程将创建必要的目录和文件,并将Pageinspect扩展安装到适当的位置。 请注意,上述步骤中的路径和版本号可能需要根据实际情况进行修改。此外,在执行编译安装之前,确保已经安装了相关的构建工具和依赖项。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [一、PostgreSQL编译安装](https://blog.csdn.net/yuanyuanstudent/article/details/128239127)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [PostgreSQL 编译安装通用步骤](https://blog.csdn.net/qiuchenjun/article/details/131356450)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值