刘刚刚的个人博客

PostgreSQL的Yum安装

创建时间:2021-01-09 09:51:46
更新时间:2021-07-07 13:43:34

Yum 安装中可以自动处理依赖,操作更加的简单

环境准备

本文章中操作的环境信息:

操作系统:centos7.5

数据库版本:12.1

# 查看系统版本的方式
more /etc/redhat-release

关闭SELinux

vi /etc/selinux/config

# 关闭
SELINUX=disabled

image-20210105233753375

安装

在centos7中postgreSQL的版本默认为9.2,我们可以通过如下命令查看

yum list postgresql --showduplicates | sort -r 

image-20210108163229509

我们可以使用官方提供的仓库进行安装:

# 使用pg官方RPM仓库:
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# 安装服务端:
yum install -y postgresql12-server

# 初始化
/usr/pgsql-12/bin/postgresql-12-setup initdb

# 加入系统启动项
systemctl enable postgresql-12

# 启动数据库
systemctl start postgresql-12

# 将目录加入环境变量
root@postgresql ~]# vim ~/.bash_profile
export PGHOME=/opt/pg12
export PATH=$PGHOME/bin:$PATH

# 查看数据库版本
[postgres@postgresql bin]$ pg_ctl  -V
pg_ctl (PostgreSQL) 12.1

安装好后,系统自动会为我们创建一个postgres的用户组和用户,启动的时候默认使用该用户启动。

# 查看postgres相关的进程,可以看到使用的是postgres用户
ps -ef |grep postgres

image-20210108154104725

配置文件

这里只介绍配置文件的位置

# 使用如下命令可以看到yum安装时使用到的一些目录
rpm -ql postgresql12-server

# 输出如下
/etc/pam.d/postgresql
/etc/sysconfig/pgsql
/usr/bin/postgresql-12-setup
/usr/lib/systemd/system/postgresql-12.service
/usr/lib/tmpfiles.d/postgresql-12.conf
/usr/pgsql-12/bin/initdb
/usr/pgsql-12/bin/pg_checksums
/usr/pgsql-12/bin/pg_controldata
/usr/pgsql-12/bin/pg_ctl
/usr/pgsql-12/bin/pg_resetwal
/usr/pgsql-12/bin/postgres
/usr/pgsql-12/bin/postgresql-12-check-db-dir
/usr/pgsql-12/bin/postgresql-12-setup
/usr/pgsql-12/bin/postmaster
/usr/pgsql-12/lib
... 
/var/lib/pgsql
/var/lib/pgsql/12
/var/lib/pgsql/12/backups
/var/lib/pgsql/12/data
/var/run/postgresql

其中,postgresql.conf 的内容在/var/lib/pgsql/12/data文件夹下

cd /var/lib/pgsql/12/data
ls 

image-20210108160928843

其他说明

安装其他版本的方式

  1. 进入网站 https://www.postgresql.org/download/
  2. 选择系统

    image-20210108161159564

  3. 选择安装的版本及系统的版本,选择好后,就会显示对应的安装命令

    image-20210108161240739

Yum安装会自动增加系统服务

cd /usr/lib/systemd/system
cat postgresql-12.service 

# 可以看到如下内容
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  It is recommended to use systemd
# "dropin" feature;  i.e. create file with suffix .conf under
# /etc/systemd/system/postgresql-12.service.d directory overriding the
# unit's defaults. You can also use "systemctl edit postgresql-12"
# Look at systemd.unit(5) manual page for more info.

# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.

# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 12 database server
Documentation=https://www.postgresql.org/docs/12/static/
After=syslog.target
After=network.target

[Service]
Type=notify

User=postgres
Group=postgres

# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory
Environment=PGDATA=/var/lib/pgsql/12/data/

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-12/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
 

# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0

[Install]
WantedBy=multi-user.target
我的名片

昵称:shuta

职业:后台开发(python、php)

邮箱:648949076@qq.com

站点信息

建站时间: 2020/2/19
网站程序: ANTD PRO VUE + TP6.0
晋ICP备18007778号