【PostgreSQL】从零开始:(二)PostgreSQL下载与安装
Winodws环境下载与安装PostgreSQL
下载PostgreSQL
也可以直接丁路到EDB网站直接下载 【下载地址】
安装PostgreSQL
安装完成后,如果勾选:Stack Builder may be used to download and install additional tools,drivers and applications to complement your PostgreSQL installation. 在Finish之后会运行Stack Builder,可用于下载和安装附加的工具、驱动程序和应用程序,以补充PostgreSQL安装。可以不勾选,勾选了会运行 Stack Builder安装插件。(本次安装不附带Stack Builder安装,附录可以了解Stack Builder安装插件相关内容)
1.登录数据库
2.查看下我们已有的数据库
Liunx环境下载与安装PostgreSQL
使用YUM下载安装PostgreSQL
下面我们来演示一下
1.下载PostgreSQL安装包
https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
执行结果:
[root@postgre-sql ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
已加载插件:fastestmirror
pgdg-redhat-repo-latest.noarch.rpm |8.6 kB 00:00:00
正在检查 /var/tmp/yum-root-rFo7Yw/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-32.noarch
/var/tmp/yum-root-rFo7Yw/pgdg-redhat-repo-latest.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 pgdg-redhat-repo.noarch.0.42.0-32 将被 安装
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================================================================================================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================================================================================================================================================================================================================
正在安装:
pgdg-redhat-repo noarch 42.0-32 /pgdg-redhat-repo-latest.noarch 13 k
事务概要
============================================================================================================================================================================================================================================================================================================================================
安装 1 软件包
总计:13 k
安装大小:13 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : pgdg-redhat-repo-42.0-32.noarch 1/1
验证中 : pgdg-redhat-repo-42.0-32.noarch 1/1
已安装:
pgdg-redhat-repo.noarch 0:42.0-32
完毕!
[root@postgre-sql ~]#
2.安装PostgreSQL
折腾了半天,发现centos7的yum只有PostgreSQL15版本:见附录,那我们就以15作为演示
yum install-y postgresql15-server
执行结果:
[root@postgre-sql ~]# yum install -y postgresql15-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 postgresql15-server.x86_64.0.15.5-1PGDG.rhel7 将被 安装
--> 正在处理依赖关系 postgresql15-libs(x86-64)=15.5-1PGDG.rhel7,它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 postgresql15(x86-64)=15.5-1PGDG.rhel7,它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 libzstd.so.1()(64bit),它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 libpq.so.5()(64bit),它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 libicuuc.so.50()(64bit),它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 libicui18n.so.50()(64bit),它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在检查事务
---> 软件包 libicu.x86_64.0.50.2-4.el7_7 将被 安装
---> 软件包 postgresql15.x86_64.0.15.5-1PGDG.rhel7 将被 安装
--> 正在处理依赖关系 libzstd >=1.4.0,它被软件包 postgresql15-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 libzstd.so.1()(64bit),它被软件包 postgresql15-15.5-1PGDG.rhel7.x86_64 需要
---> 软件包 postgresql15-libs.x86_64.0.15.5-1PGDG.rhel7 将被 安装
---> 软件包 postgresql15-server.x86_64.0.15.5-1PGDG.rhel7 将被 安装
--> 正在处理依赖关系 libzstd.so.1()(64bit),它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 解决依赖关系完成
错误:软件包:postgresql15-server-15.5-1PGDG.rhel7.x86_64 (pgdg15)
需要:libzstd.so.1()(64bit)
错误:软件包:postgresql15-15.5-1PGDG.rhel7.x86_64 (pgdg15)
需要:libzstd.so.1()(64bit)
错误:软件包:postgresql15-15.5-1PGDG.rhel7.x86_64 (pgdg15)
需要:libzstd >=1.4.0
您可以尝试添加 --skip-broken 选项来解决该问题
您可以尝试执行:rpm -Va--nofiles--nodigest[root@postgre-sql ~]#
提示我们缺少包libzstd.so.1,libzstd >= 1.4.0
执行:
yum install epel-release.noarch -y
yum install libzstd.x86_64 -y
执行结果:
[root@postgre-sql ~]# yum install epel-release.noarch -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 epel-release.noarch.0.7-11 将被 安装
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================================================================================================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================================================================================================================================================================================================================
正在安装:
epel-release noarch 7-11 extras 15 k
事务概要
============================================================================================================================================================================================================================================================================================================================================
安装 1 软件包
总下载量:15 k
安装大小:24 k
Downloading packages:
epel-release-7-11.noarch.rpm |15 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : epel-release-7-11.noarch 1/1
验证中 : epel-release-7-11.noarch 1/1
已安装:
epel-release.noarch 0:7-11
完毕!
[root@postgre-sql ~]# yum install libzstd.x86_64 -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink |7.0 kB 00:00:00
* epel: mirror.nyist.edu.cn
epel |4.7 kB 00:00:00
(1/3): epel/x86_64/group_gz |99 kB 00:00:00
(2/3): epel/x86_64/updateinfo |1.0 MB 00:00:00
(3/3): epel/x86_64/primary_db |7.0 MB 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 libzstd.x86_64.0.1.5.5-1.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================================================================================================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================================================================================================================================================================================================================
正在安装:
libzstd x86_64 1.5.5-1.el7 epel 292 k
事务概要
============================================================================================================================================================================================================================================================================================================================================
安装 1 软件包
总下载量:292 k
安装大小:775 k
Downloading packages:
警告:/var/cache/yum/x86_64/7/epel/packages/libzstd-1.5.5-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY 0% []0.0 B/s |0 B --:--:-- ETA
libzstd-1.5.5-1.el7.x86_64.rpm 的公钥尚未安装
libzstd-1.5.5-1.el7.x86_64.rpm |292 kB 00:00:00
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 检索密钥
导入 GPG key 0x352C64E5:
用户ID :"Fedora EPEL (7) <[email protected]>"
指纹 : 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
软件包 : epel-release-7-11.noarch (@extras)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : libzstd-1.5.5-1.el7.x86_64 1/1
验证中 : libzstd-1.5.5-1.el7.x86_64 1/1
已安装:
libzstd.x86_64 0:1.5.5-1.el7
完毕!
[root@postgre-sql ~]#
再次执行
yum install-y postgresql15-server
执行结果:
[root@postgre-sql ~]# yum install -y postgresql15-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirror.nyist.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 postgresql15-server.x86_64.0.15.5-1PGDG.rhel7 将被 安装
--> 正在处理依赖关系 postgresql15-libs(x86-64)=15.5-1PGDG.rhel7,它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 postgresql15(x86-64)=15.5-1PGDG.rhel7,它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 libpq.so.5()(64bit),它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 libicuuc.so.50()(64bit),它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在处理依赖关系 libicui18n.so.50()(64bit),它被软件包 postgresql15-server-15.5-1PGDG.rhel7.x86_64 需要
--> 正在检查事务
---> 软件包 libicu.x86_64.0.50.2-4.el7_7 将被 安装
---> 软件包 postgresql15.x86_64.0.15.5-1PGDG.rhel7 将被 安装
---> 软件包 postgresql15-libs.x86_64.0.15.5-1PGDG.rhel7 将被 安装
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================================================================================================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================================================================================================================================================================================================================
正在安装:
postgresql15-server x86_64 15.5-1PGDG.rhel7 pgdg15 5.8 M
为依赖而安装:
libicu x86_64 50.2-4.el7_7 base 6.9 M
postgresql15 x86_64 15.5-1PGDG.rhel7 pgdg15 1.6 M
postgresql15-libs x86_64 15.5-1PGDG.rhel7 pgdg15 284 k
事务概要
============================================================================================================================================================================================================================================================================================================================================
安装 1 软件包 (+3 依赖软件包)
总下载量:15 M
安装大小:58 M
Downloading packages:
(1/4): libicu-50.2-4.el7_7.x86_64.rpm |6.9 MB 00:00:01
warning: /var/cache/yum/x86_64/7/pgdg15/packages/postgresql15-15.5-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY 52% [=========================================================================]3.3 MB/s |7.6 MB 00:00:02 ETA
postgresql15-15.5-1PGDG.rhel7.x86_64.rpm 的公钥尚未安装
(2/4): postgresql15-15.5-1PGDG.rhel7.x86_64.rpm |1.6 MB 00:00:03
(3/4): postgresql15-server-15.5-1PGDG.rhel7.x86_64.rpm |5.8 MB 00:00:00
(4/4): postgresql15-libs-15.5-1PGDG.rhel7.x86_64.rpm |284 kB 00:00:07
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 1.9 MB/s |15 MB 00:00:07
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG 检索密钥
导入 GPG key 0x442DF0F8:
用户ID :"PostgreSQL RPM Building Project <[email protected]>"
指纹 : 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
软件包 : pgdg-redhat-repo-42.0-32.noarch (@/pgdg-redhat-repo-latest.noarch)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : libicu-50.2-4.el7_7.x86_64 1/4
正在安装 : postgresql15-libs-15.5-1PGDG.rhel7.x86_64 2/4
正在安装 : postgresql15-15.5-1PGDG.rhel7.x86_64 3/4
正在安装 : postgresql15-server-15.5-1PGDG.rhel7.x86_64 4/4
验证中 : postgresql15-15.5-1PGDG.rhel7.x86_64 1/4
验证中 : postgresql15-server-15.5-1PGDG.rhel7.x86_64 2/4
验证中 : postgresql15-libs-15.5-1PGDG.rhel7.x86_64 3/4
验证中 : libicu-50.2-4.el7_7.x86_64 4/4
已安装:
postgresql15-server.x86_64 0:15.5-1PGDG.rhel7
作为依赖被安装:
libicu.x86_64 0:50.2-4.el7_7 postgresql15.x86_64 0:15.5-1PGDG.rhel7 postgresql15-libs.x86_64 0:15.5-1PGDG.rhel7
完毕!
[root@postgre-sql ~]#
3.初始化数据
[root@postgre-sql ~]# /usr/pgsql-15/bin/postgresql-15-setup initdb
Initializing database ... OK
[root@postgre-sql ~]#
4.设置为开机启动
[root@postgre-sql ~]# systemctl enable postgresql-15
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-15.service to /usr/lib/systemd/system/postgresql-15.service.
[root@postgre-sql ~]#
5.启动数据库
[root@postgre-sql ~]# systemctl start postgresql-15[root@postgre-sql ~]
6.查看进程
[root@postgre-sql ~]# ps -ef | grep postgres
postgres 33741012:38 ? 00:00:00 /usr/pgsql-15/bin/postmaster -D /var/lib/pgsql/15/data/
postgres 33763374012:38 ? 00:00:00 postgres: logger
postgres 33773374012:38 ? 00:00:00 postgres: checkpointer
postgres 33783374012:38 ? 00:00:00 postgres: background writer
postgres 33803374012:38 ? 00:00:00 postgres: walwriter
postgres 33813374012:38 ? 00:00:00 postgres: autovacuum launcher
postgres 33823374012:38 ? 00:00:00 postgres: logical replication launcher
root 34113049012:41 pts/1 00:00:00 grep--color=auto postgres
[root@postgre-sql ~]#
7.登录数据库
[root@postgre-sql ~]# su - postgres
bash-4.2$ psql
psql (15.5)
输入 "help" 来获取帮助信息.
postgres=#
注意:默认用户是postgres,密码是没有的 需要进入数据后修改密码
postgres=# \du
角色列表
角色名称 | 属性 | 成员属于
----------+--------------------------------------------+----------
postgres | 超级用户, 建立角色, 建立 DB, 复制, 绕过RLS |{}postgres=# alter user postgres with password '12345678ab';
ALTER ROLE
postgres=#
验证密码是否正确
bash-4.2$ psql -h127.0.0.1-U postgres postgres
用户 postgres 的口令:
psql (15.5)
输入 "help" 来获取帮助信息.
postgres=#
下载源码包编译安装
可以通过官网下载也可以使用wget下载
通过官网下载
使用wget
1.安装规划
数据库用户 POSTGRESQL_USER=postgres
数据库用户组 POSTGRESQL_GROUP=postgres
数据库安装文件路径 POSTGRESQL_INSTALL_PATH=/root/postgresql_install
数据库版本号 POSTGRESQL_VERSION=16.1
数据库安装路径 POSTGRESQL_PATH=/opt/postgresql-
P
O
S
T
G
R
E
S
Q
L
V
E
R
S
I
O
N
数据库端口号
P
O
S
T
G
R
E
S
Q
L
P
O
R
T
=
5432
数据库
D
A
T
A
存放路径
P
O
S
T
G
R
E
S
Q
L
D
A
T
A
=
/
d
a
t
a
/
{POSTGRESQL_VERSION} 数据库端口号 POSTGRESQL_PORT=5432 数据库DATA存放路径 POSTGRESQL_DATA=/data/
POSTGRESQLVERSION数据库端口号POSTGRESQLPORT=5432数据库DATA存放路径POSTGRESQLDATA=/data/{POSTGRESQL_VERSION}/data
2.创建用户组及用户并修改密码
[root@postgre-sql ~]# groupadd postgres[root@postgre-sql ~]# useradd -g postgres postgres[root@postgre-sql ~]# passwd postgres
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@postgre-sql ~]#
3.修改root用户配置参数,并让其生效
[root@postgre-sql ~]# vi .bash_profile [root@postgre-sql ~]# cat .bash_profile # .bash_profile# Get the aliases and functionsif[-f ~/.bashrc ];then. ~/.bashrc
fi# User specific environment and startup programsPATH=$PATH:$HOME/bin
# 新增的Postgre自定义配置exportPOSTGRESQL_USER=postgres
exportPOSTGRESQL_GROUP=postgres
exportPOSTGRESQL_INSTALL_PATH=/root/postgresql_install
exportPOSTGRESQL_VERSION=16.1exportPOSTGRESQL_PATH=/opt/postgresql-${POSTGRESQL_VERSION}exportPOSTGRESQL_PORT=5432exportPOSTGRESQL_DATA=/data/${POSTGRESQL_VERSION}/data
N}/data
exportPATH[root@postgre-sql ~]# source .bash_profile [root@postgre-sql ~]# echo ${POSTGRESQL_VERSION}16.1[root@postgre-sql ~]#
4.创建相关目录并授权
[root@postgre-sql ~]# mkdir -p ${POSTGRESQL_INSTALL_PATH}[root@postgre-sql ~]# mkdir -p ${POSTGRESQL_PATH}[root@postgre-sql ~]# mkdir -p ${POSTGRESQL_DATA}[root@postgre-sql ~]# chown -R postgres:postgres /data[root@postgre-sql ~]# chown -R postgres:postgres /root/postgresql_install[root@postgre-sql ~]# chown -R postgres:postgres /opt/postgresql-16.1/
5.安装相关依赖
yum -yinstallbzip2 gcc gcc-c++ epel-release llvm5.0 llvm5.0-devel clang libicu-devel perl-ExtUtils-Embed zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel openldap-devel systemd-devel tcl-devel python-devel
6.下载PostgreSQL源码文件
[root@postgre-sql ~]# cd postgresql_install/[root@postgre-sql postgresql_install]# wget https://ftp.postgresql.org/pub/source/v16.1/postgresql-16.1.tar.bz2 --no-check-certificate
--2023-12-13 15:11:38-- https://ftp.postgresql.org/pub/source/v16.1/postgresql-16.1.tar.bz2
正在解析主机 ftp.postgresql.org (ftp.postgresql.org)... 147.75.85.69, 217.196.149.55, 72.32.157.246, ...
正在连接 ftp.postgresql.org (ftp.postgresql.org)|147.75.85.69|:443... 失败:拒绝连接。
正在连接 ftp.postgresql.org (ftp.postgresql.org)|217.196.149.55|:443... 已连接。
警告: 无法验证 ftp.postgresql.org 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:
颁发的证书已经过期。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:24605482 (23M) [application/octet-stream]
正在保存至: “postgresql-16.1.tar.bz2”
100%[==================================================================================================================================================================================================================================================================================================>] 24,605,482 5.53MB/s 用时 4.2s
2023-12-13 15:12:05 (5.53 MB/s) - 已保存 “postgresql-16.1.tar.bz2” [24605482/24605482])
[root@postgre-sql postgresql_install]# wget https://ftp.postgresql.org/pub/source/v16.1/postgresql-16.1.tar.bz2.md5 --no-check-certificate
--2023-12-13 15:12:18-- https://ftp.postgresql.org/pub/source/v16.1/postgresql-16.1.tar.bz2.md5
正在解析主机 ftp.postgresql.org (ftp.postgresql.org)... 217.196.149.55, 72.32.157.246, 87.238.57.227, ...
正在连接 ftp.postgresql.org (ftp.postgresql.org)|217.196.149.55|:443... 已连接。
警告: 无法验证 ftp.postgresql.org 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:
颁发的证书已经过期。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:58 [text/plain]
正在保存至: “postgresql-16.1.tar.bz2.md5”
100%[==================================================================================================================================================================================================================================================================================================>]58 --.-K/s 用时 0s
2023-12-13 15:12:20 (7.99 MB/s) - 已保存 “postgresql-16.1.tar.bz2.md5” [58/58])[root@postgre-sql postgresql_install]# ls -l
总用量 24036
-rw-r--r--. 1 root root 2460548211月 7 06:19 postgresql-16.1.tar.bz2
-rw-r--r--. 1 root root 5811月 7 06:19 postgresql-16.1.tar.bz2.md5
[root@postgre-sql postgresql_install]#
2.校验文件
[root@postgre-sql postgresql_install]# md5sum postgresql-16.1.tar.bz2
9cbfb9076ed06384471802b850698a6d postgresql-16.1.tar.bz2
[root@postgre-sql postgresql_install]# cat postgresql-16.1.tar.bz2.md5
9cbfb9076ed06384471802b850698a6d postgresql-16.1.tar.bz2
[root@postgre-sql postgresql_install]#
两个MD5值一致就代表包是完整的
3.解压源码文件
[root@postgre-sql postgresql_install]# tar -xjvf postgresql-16.1.tar.bz2[root@postgre-sql postgresql_install]# ls -l
总用量 24040
drwxrwxrwx. 611071107409611月 7 06:18 postgresql-16.1
-rw-r--r--. 1 root root 2460548211月 7 06:19 postgresql-16.1.tar.bz2
-rw-r--r--. 1 root root 5811月 7 06:19 postgresql-16.1.tar.bz2.md5
[root@postgre-sql postgresql_install]#
7.进入数据库源文件目录,给configure加运行权限
[root@postgre-sql postgre_install]# cd postgresql-16.1/[root@postgre-sql postgresql-16.1]# chmod +x configure
8.执行以下语句开始编译PostgreSQL
./configure --prefix=${POSTGRESQL_PATH} --with-pgport=${POSTGRESQL_PORT}makemakeinstall
然后再执行
9.查看数据库文件
[root@postgre-sql postgresql-16.1]# cd /opt/postgresql-16.1/[root@postgre-sql postgresql-16.1]# ls -l
总用量 16
drwxr-xr-x. 2 root root 409612月 1314:15 bin
drwxr-xr-x. 6 root root 409612月 1314:15 include
drwxr-xr-x. 4 root root 409612月 1314:15 lib
drwxr-xr-x. 6 root root 409612月 1314:15 share
[root@postgre-sql postgresql-16.1]#
这里我们已经编译成功了
10.配置postgres用户环境变量
[postgres@postgre-sql ~]$ vi .bash_profile
[postgres@postgre-sql ~]$ cat .bash_profile
# .bash_profile# Get the aliases and functionsif[-f ~/.bashrc ];then. ~/.bashrc
fi# User specific environment and startup programsPATH=$PATH:$HOME/.local/bin:$HOME/bin
## 新添加配置exportPOSTGRESQL_USER=postgres
exportPOSTGRESQL_GROUP=postgres
exportPOSTGRESQL_INSTALL_PATH=/root/postgresql_install
exportPOSTGRESQL_VERSION=16.1exportPOSTGRESQL_PATH=/opt/postgresql-${POSTGRESQL_VERSION}exportPOSTGRESQL_PORT=5432exportPOSTGRESQL_DATA=/data/${POSTGRESQL_VERSION}/data
exportLD_LIBRARY_PATH=${POSTGRESQL_PATH}/lib:/usr/local/lib:$LD_LIBRARY_PATHexportPATH=${POSTGRESQL_PATH}/bin:$PATHexportPGDATA=${POSTGRESQL_DATA}exportPATH[postgres@postgre-sql ~]$ source .bash_profile
[postgres@postgre-sql ~]$ echo$PGDATA
/data/16.1/data
[postgres@postgre-sql ~]$
11.创建数据库实例
[postgres@postgre-sql ~]$ initdb -A md5 -D$PGDATA-E'UTF8'--pwfile=<(printf"%s""12345678ab")
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "zh_CN.UTF-8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
creating directory /data/16.1/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /data/16.1/data -l logfile start
[postgres@postgre-sql ~]$
12.启动数据库
[postgres@postgre-sql ~]$ pg_ctl -D /data/16.1/data start
waiting for server to start....2023-12-13 15:51:24.695 CST [28517] LOG: starting PostgreSQL 16.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC)4.8.5 20150623(Red Hat 4.8.5-44), 64-bit
2023-12-13 15:51:24.698 CST [28517] LOG: listening on IPv6 address "::1", port 54322023-12-13 15:51:24.698 CST [28517] LOG: listening on IPv4 address "127.0.0.1", port 54322023-12-13 15:51:24.701 CST [28517] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2023-12-13 15:51:24.707 CST [28520] LOG: database system was shut down at 2023-12-13 15:51:14 CST
2023-12-13 15:51:24.710 CST [28517] LOG: database system is ready to accept connections
done
server started
[postgres@postgre-sql ~]$
13.登陆数据库
[postgres@postgre-sql ~]$ psql -U postgres -d postgres
Password for user postgres:
psql (16.1)
Type "help"for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
postgres | postgres | UTF8 | libc | zh_CN.UTF-8 | zh_CN.UTF-8 |||
template0 | postgres | UTF8 | libc | zh_CN.UTF-8 | zh_CN.UTF-8 |||=c/postgres +
||||||||postgres=CTc/postgres
template1 | postgres | UTF8 | libc | zh_CN.UTF-8 | zh_CN.UTF-8 |||=c/postgres +
||||||||postgres=CTc/postgres
(3 rows)postgres=#
登陆数据库并查看到了数据库列表,到这里部署已经完成了
14.设置开机自起
[root@postgre-sql ~]# cat >/usr/lib/systemd/system/postgresql.service <<-EOF[Unit]Description=PostgreSQL v${POSTGRESQL_VERSION} database server
Documentation=https://www.postgresql.org
Requires=network.target local-fs.target
After=network.target local-fs.target
[Service]Type=forking
User=postgres
Group=postgres
Environment=PGDATA=/data/${POSTGRESQL_VERSION}/data
OOMScoreAdjust=-1000
ExecStart=${POSTGRESQL_PATH}/bin/pg_ctl start -D\${PGDATA}ExecStop=${POSTGRESQL_PATH}/bin/pg_ctl stop -D\${PGDATA}ExecReload=${POSTGRESQL_PATH}/bin/pg_ctl reload -D\${PGDATA}ExecRestart=${POSTGRESQL_PATH}/bin/pg_ctl restart -D\${PGDATA}TimeoutSec=0[Install]WantedBy=multi-user.target
EOF
[root@postgre-sql ~]# systemctl daemon-reload[root@postgre-sql ~]# systemctl enable --now postgresql.service
Postgis 是数据库地理信息位图的插件,用户开启GIS拓展
pem-httpd 是http服务工具
[root@postgre-sql ~]# yum search postgresql1
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
========================================================================================================================================================= N/S matched: postgresql1 =========================================================================================================================================================
postgresql12-odbc-debuginfo.x86_64 : Debug information for package postgresql12-odbc
postgresql11.x86_64 : PostgreSQL client programs and libraries
postgresql11-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql11-devel.x86_64 : PostgreSQL development header files and libraries
postgresql11-docs.x86_64 : Extra documentation for PostgreSQL
postgresql11-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql11-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql11-odbc.x86_64 : PostgreSQL ODBC driver
postgresql11-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql11-plpython.x86_64 : The Python procedural language for PostgreSQL
postgresql11-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql11-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql11-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql11-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql11-test.x86_64 : The test suite distributed with PostgreSQL
postgresql12.x86_64 : PostgreSQL client programs and libraries
postgresql12-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql12-devel.x86_64 : PostgreSQL development header files and libraries
postgresql12-docs.x86_64 : Extra documentation for PostgreSQL
postgresql12-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql12-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql12-odbc.x86_64 : PostgreSQL ODBC driver
postgresql12-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql12-plpython.x86_64 : The Python procedural language for PostgreSQL
postgresql12-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql12-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql12-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql12-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql12-test.x86_64 : The test suite distributed with PostgreSQL
postgresql13.x86_64 : PostgreSQL client programs and libraries
postgresql13-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql13-devel.x86_64 : PostgreSQL development header files and libraries
postgresql13-docs.x86_64 : Extra documentation for PostgreSQL
postgresql13-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql13-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql13-odbc.x86_64 : PostgreSQL ODBC driver
postgresql13-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql13-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql13-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql13-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql13-test.x86_64 : The test suite distributed with PostgreSQL
postgresql14.x86_64 : PostgreSQL client programs and libraries
postgresql14-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql14-devel.x86_64 : PostgreSQL development header files and libraries
postgresql14-docs.x86_64 : Extra documentation for PostgreSQL
postgresql14-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql14-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql14-odbc.x86_64 : PostgreSQL ODBC driver
postgresql14-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql14-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql14-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql14-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql14-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql14-test.x86_64 : The test suite distributed with PostgreSQL
postgresql15.x86_64 : PostgreSQL client programs and libraries
postgresql15-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql15-devel.x86_64 : PostgreSQL development header files and libraries
postgresql15-docs.x86_64 : Extra documentation for PostgreSQL
postgresql15-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql15-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql15-odbc.x86_64 : PostgreSQL ODBC driver
postgresql15-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql15-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql15-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql15-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql15-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql15-test.x86_64 : The test suite distributed with PostgreSQL
名称和简介匹配 only,使用“search all”试试。
[root@postgre-sql ~]#
版权归原作者 DBA圈小圈 所有, 如有侵权,请联系我们删除。