pgsql 之 centos 7下安装 15.2

发布时间 2023-04-27 10:16:49作者: 一贴灵

1、下载网址:PostgreSQL: Linux downloads (Red Hat family)

    因为RedHat 与 CentOs内核是一样的。

# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql15-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15

 安装时会提示,依赖 libzstd包,可以去这个地方下载

如果,指定的地址不存在,可以自己进去https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/这个目录下找下现有的版本;然后安装 ;

https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libzstd-1.5.5-1.el7.x86_64.rpm
rpm -ivh libzstd-1.5.5-1.el7.x86_64.rpm

然后再次安装 PostgreSQL:

sudo yum install -y postgresql15-server

 3、初始化数据库

/usr/pgsql-15/bin/postgresql-15-setup initdb

4、设置数据库开机自动启动后启动数据库

systemctl enable postgresql-15
systemctl start    postgresql-15

 

2 登录数据库及数据库的简单使用

检查postgresql数据库的操作系统用户,并切换至postgres用户

cat /etc/passwd
    postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
su -  postgres

启动PGSQL 

 psql

如果启动成功,系统 会提示"

psql (15.2)
输入 "help" 来获取帮助信息.

显示现有数据库(注意:postgres=# 是系统提示符,只用输入 \l 就可以,注意是小写的字母L ,不是数字1  ),

下一步是退出到操作系统 下, top -b -u postgres -d 1 -n 1 -c看下后台进程

 postgres=# \l

[root@localhost ~]# top -b -u postgres -d 1 -n 1 -c
top - 09:50:05 up  9:41,  1 user,  load average: 0.05, 0.06, 0.11
Tasks:  99 total,   1 running,  98 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us, 11.1 sy,  0.0 ni, 83.3 id,  0.0 wa,  0.0 hi,  5.6 si,  0.0 st
KiB Mem :  3865284 total,  1684160 free,   964360 used,  1216764 buff/cache
KiB Swap:  3145724 total,  3145724 free,        0 used.  2600184 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 12118 postgres  20   0  399532  17376  15932 S  0.0  0.4   0:00.04 /usr/pgsql-15/bin/postmaster -D /var/lib/pgsql/15/data/
 12121 postgres  20   0  250736   2128    712 S  0.0  0.1   0:00.00 postgres: logger
 12122 postgres  20   0  399684   4408   2876 S  0.0  0.1   0:00.02 postgres: checkpointer
 12123 postgres  20   0  399668   3364   1868 S  0.0  0.1   0:00.05 postgres: background writer
 12125 postgres  20   0  399668   6268   4776 S  0.0  0.2   0:00.02 postgres: walwriter
 12126 postgres  20   0  401152   3348   1588 S  0.0  0.1   0:00.00 postgres: autovacuum launcher
 12127 postgres  20   0  401136   3092   1372 S  0.0  0.1   0:00.00 postgres: logica

(96条消息) CentOS 7下安装PostgreSQL 15版本数据库(图文详细)_战·后风!!的博客-CSDN博客

参考网址;Postgresql15的安装及简单使用-阿里云开发者社区 (aliyun.com)