AlmaLinux9.1编译安装postgresql-15.2数据库
一、查看系统版本:
[root@AlmaLinux9 ~]# cat /etc/redhat-release
AlmaLinux release 9.1 (Lime Lynx)
二、下载安装源码包:
cd /opt
wget https://ftp.postgresql.org/pub/source/v15.2/postgresql-15.2.tar.bz2
tar -jxvf postgresql-15.2.tar.bz2
三、创建数据库用户:
groupadd postgres
useradd -g postgres postgres
echo postgres | passwd --stdin postgres
四、关闭selinux:
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
# 输入 getenforce 返回 Permissive 则是关闭状态
五、创建目录设置权限:
mkdir /data/pgsql -p
mkdir /data/pglog -p
mkdir /usr/local/pgsql
chown -R postgres.postgres /data/pgsql
chown -R postgres.postgres /data/pglog
chown -R postgres.postgres /usr/local/pgsql
chown -R postgres.postgres /opt/postgresql-15.2
六、安装所需包:
yum install epel-release -y
yum install tcl tcl-devel perl-ExtUtils-Embed readline-devel zlib-devel pam pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc gcc* gcc-c++ openssl-devel cmake systemd-devel libtool -y
yum install systemtap-sdt-devel libicu-devel bison flex perl krb5-devel libuuid libuuid-devel lz4-devel libzstd-devel -y
dnf --enablerepo=crb install uuid-devel -y
七、切换用户编译安装:
su - postgres
cd /opt/postgresql-15.2
./configure --prefix=/usr/local/pgsql --with-openssl --with-tcl --with-perl --with-python --with-libxml --with-libxslt --with-ossp-uuid --with-pam --with-ldap --with-zlib --with-systemd --with-readline --with-zstd
make
make all
make check
make install
八、初始化数据库:
#初始化
/usr/local/pgsql/bin/initdb -D /data/pgsql
# 启动数据库
/usr/local/pgsql/bin/pg_ctl -D /data/pgsql -l /data/pglog/pgsql.log start
# 创建数据库 test
/usr/local/pgsql/bin/createdb test
# 连接数据test
/usr/local/pgsql/bin/psql test
九、设置PostgreSQL的环境变量:
echo "export PATH=/usr/local/pgsql/bin:$PATH" >> /home/postgres/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/pgsql/lib" >> /home/postgres/.bashrc
source /home/postgres/.bashrc
十、开启远程登录:
修改 postgresql.conf 文件: vim /data/pgsql/postgresql.conf 修改listen_addresses的值
listen_addresses = '*'
查看配置文件:
grep -v '#' /data/pgsql/postgresql.conf
在 pg_hba.conf 文件最后添加如下内容
echo "host all all 0/0 md5" >> /data/pgsql/pg_hba.conf
十一、创建数据库和用户:
psql
psql (15.3)
Type "help" for help.
postgres=# create user dba with password 'abcd@2023';
CREATE ROLE
postgres=# create database testdb owner dba;
CREATE DATABASE
postgres=# grant all privileges on database testdb to dba;
GRANT
postgres=#
十二、重启数据库:
/usr/local/pgsql/bin/pg_ctl -D /data/pgsql -l /data/pglog/pgsql.log restart #重启服务
/usr/local/pgsql/bin/pg_ctl -D /data/pgsql -l /data/pglog/pgsql.log status #查看服务状态
/usr/local/pgsql/bin/pg_ctl -D /data/pgsql -l /data/pglog/pgsql.log start #启动服务
/usr/local/pgsql/bin/pg_ctl -D /data/pgsql -l /data/pglog/pgsql.log stop #停止服务
十三、测试远程连接数据库:
[postgres@AlmaLinux9 ~]$ psql -h 192.168.188.4 -d testdb -U dba
Password for user dba:
psql (15.2)
Type "help" for help.
testdb=>
十四、查看版本信息:
[postgres@AlmaLinux9 ~]$ psql -V
psql (PostgreSQL) 15.2
[postgres@AlmaLinux9 ~]$ psql
psql (15.2)
Type "help" for help.
postgres=# select version();
version
----------------------------------------------------------------------------------------------------------
PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2), 64-bit
(1 row)
postgres=# show server_version;
server_version
----------------
15.2
(1 row)
postgres=# SHOW server_version_num;
server_version_num
--------------------
150002
(1 row)
Tag标签:「PostgreSQL 编译 AlmaLinux 源码」更新时间:「2024-07-01 10:46:09」阅读次数:「1179」