avatar

刘刚刚的blog

采菊东篱下,悠然见南山🦥

  • 首页
  • 大模型应用
  • 常用软件/工具
  • Halo
  • 关于
Home PostgreSQL的Yum安装
文章

PostgreSQL的Yum安装

Posted 2021-01-9 Updated 2024-12- 17
By Administrator
17~22 min read

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

数据库
postgresql
License:  CC BY 4.0
Share

Further Reading

Jul 19, 2021

PostgreSQL中的逻辑结构

在postgresql中,数据的组织结构可以分为:数据库、表与索引(relation)、数据行(tuple)。本问主要介绍了相关的:claster、database、schema、tablespace的概念。 cluster 当启动数据库服务时,不同的文件夹参数即代表不同的cluster: 一个PG

Jul 19, 2021

PostgreSQL中的逻辑结构

在postgresql中,数据的组织结构可以分为:数据库、表与索引(relation)、数据行(tuple)。本问主要介绍了相关的:claster、database、schema、tablespace的概念。

Jul 18, 2021

PostgreSQL中的TOAST

toast技术主要用来解决可变长度数据类型的存储问题。 简介 在PostgreSQL中,页面的大小是固定的(通常是8k),而PostgreSQL不允许数据的分页存储,因此当存储一些大字段时,大字段通常会被压缩或者切片称为多行,存到的系统表 (toast)中。 可变类型数据在表中的存储 在可变长度类型

OLDER

<linux就该这么学>第一章 部署虚拟环境安装虚拟化系统

NEWER

<linux就该这么学>第二章 新手必须掌握的Linux命令

Recently Updated

  • 文本切分-语义分割(Semantic Chunking)
  • dify 并发配置优化
  • Typing
  • 大模型返回中json_schema与json_mode的区别
  • Async

Trending Tags

Halo 运维 postgresql 设计模式 linux就该这么学 nas rag odoo python 文本切分

Contents

©2025 刘刚刚的blog. Some rights reserved.

Using the Halo theme Chirpy