openEuler 22.03 LTS 上源码安装 PostgreSQL 15

安装PostgreSQL 15

1 安装必要的依赖

#yum install -y readline-devel zlib-devel gcc

2、下载源码

# wget https://ftp.postgresql.org/pub/source/v15.6/postgresql-15.6.tar.gz
# tar -xzvf postgresql-15.6.tar.gz

3 配置

# cd postgresql-15.6/
# ./configure

4 编译安装

# ./configure
# make
# make install

5 创建用户和用户组

# groupadd postgres
# useradd -g postgres postgres
# passwd postgres
更改用户 postgres 的密码 。
新的密码: 
重新输入新的密码: 
passwd:所有的身份验证令牌已经成功更新。

6 初始化数据库

6.1 创建数据目录

# mkdir /usr/local/pgsql/data
# chown postgres /usr/local/pgsql/data

6.2 切换到 postgres 操作系统用户

# su - postgres

6.3 初始化数据库

[postgres@localhost ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
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".
The default database encoding has accordingly been set to "UTF8".
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.

fixing permissions on existing directory /usr/local/pgsql/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

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

6.4 启动数据库

[postgres@localhost ~]$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
waiting for server to start.... done
server started
[postgres@localhost ~]$ 

把 start 改为 stop 就是停止。

7 安装后的操作系统配置

7.1 以管理员的身份配置/etc/profile

在/etc/profile.d 目录下新增 postgresql.sh 文件,内容如下

[root@localhost profile.d]# cat postgresql.sh 
export PATH=$PATH:/usr/local/pgsql/bin

7.2 设置开机自动启动

(1)创建启动文件

在/usr/lib/systemd/system 下创建文件 postgresql.service,内容如下:

# vim postgresql.service
[Unit]
Description=PostgreSQL database server
After=network.target
[Service]
Type=forking

User=postgres
Group=postgres
OOMScoreAdjust=-1000
Environment=PGDATA=/usr/local/pgsql/data
Environment=PGPORT=5432

ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -l ${PGDATA}/logfile -s -o "-p ${PGPORT}" -w -t 300 
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -l ${PGDATA}/logfile -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -l ${PGDATA}/logfile -s

TimeoutSec=300

[Install]
WantedBy=multi-user.target

(2)设置自动启动

# chmod a+x postgresql.service 
# systemctl enable postgresql.service
# systemctl start postgresql.service

7.3 设置远程访问

PostgreSQL安装后,默认是只接受本地机器连接访问。如果想在其他主机上访问PostgreSQL数据库服务器,就需要进行相应的配置。以下是我配置远程连接PostgreSQL数据库方式:

(1)pg_hba.conf 配置PostgreSQL数据库的访问权限

修改配置文件:(PostgreSQL安装路径下的data,也是安装时data的默认路径)data目录下的 pg_hba.conf 和 postgresql.conf。

# cd /usr/local/pgsql/data
# vim pg_hba.conf

找到“# IPv4 local connections:“后,回车另起一行,添加参数行如下,保存。
host all all 0.0.0.0/0 trust
其中0.0.0.0/0表示运行任意ip地址访问

image

(2)postgresql.conf 配置PostgreSQL数据库服务器的相应的参数

找到“listen_addresses“参数后,设置listen_addresses = ‘*’,保存。

# vim postgresql.conf

image

设置好后重启服务即可被远程连接。

8 问题

8.1 远程连接失败解决方案

一般服务器端防火窗入站规则打开后,如果外部物理机远程连接失败。 建议在服务器端安装Navicat检查是否能够连接成功。如果可以连接成功,请在服务器进行安全组端口开放。

开放端口

# systemctl start firewalld.service(开启防火墙)
# systemctl stop firewalld.service(关闭防火墙)
# systemctl status firewalld(查看防火墙是否开启)

如需要开放80和443端口,如下:

# firewall-cmd --zone=public --permanent --add-port=80/tcp
# firewall-cmd --zone=public --permanent --add-port=443/tcp
# firewall-cmd --reload

查看所有开启的端口:

# firewall-cmd --list-ports

常用命令介绍:

firewall-cmd --state ##查看防火墙状态,是否是running
firewall-cmd --reload ##重新载入配置,比如添加规则之后,需要执行此命令
firewall-cmd --get-zones ##列出支持的zone
firewall-cmd --get-services ##列出支持的服务,在列表中的服务是放行的
firewall-cmd --query-service ftp ##查看ftp服务是否支持,返回yes或者no
firewall-cmd --add-service=ftp ##临时开放ftp服务
firewall-cmd --add-service=ftp --permanent ##永久开放ftp服务
firewall-cmd --remove-service=ftp --permanent ##永久移除ftp服务
firewall-cmd --add-port=80/tcp --permanent ##永久添加80端口
iptables -L -n ##查看规则,这个命令是和iptables的相同的


http://www.niftyadmin.cn/n/5378875.html

相关文章

2024年华为OD机试真题-多段线数据压缩-Java-OD统一考试(C卷)

题目描述: 下图中,每个方块代表一个像素,每个像素用其行号和列号表示。 为简化处理,多段线的走向只能是水平、竖直、斜向45度。 上图中的多段线可以用下面的坐标串表示:(2, 8), (3, 7), (3, 6), (3, 5), (4, 4), (5, 3), (6, 2), (7, 3), (8, 4), (7, 5)。 但可以发现,这…

读十堂极简人工智能课笔记04_计算机视觉

1. 仙女蜂 1.1. Megaphragma mymaripenne 1.2. 一种微小的蜂类 1.3. 人类已知第三小的昆虫 1.4. 大脑仅由7400个神经元组成,比大型昆虫的大脑小了好几个数量级 1.5. 微小的身体里没有空间容纳这些神经元,所以在生长的最后阶段,它把每个神…

数据结构与算法:双向链表

朋友们大家好啊,在上节完成单链表的讲解后,我们本篇文章来对带头循环双向链表进行讲解 双向链表 双向链表、头节点和循环的介绍构建双向链表节点的构建初始化双向循环链表(空链表)销毁双向链表 链表的打印双向链表头尾的插与删尾插…

Git 初学

目录 一、需求的产生 二、版本控制系统理解 1. 认识版本控制系统 2. 版本控制系统分类 (1)集中式版本控制系统 缺点: (2)分布式版本控制系统 三、初识 git 四、git 的使用 例:将 “ OLED文件夹 ”…

wayland(xdg_wm_base) + egl + opengles 使用FBO渲染到纹理实例(六)

文章目录 前言一、FBO介绍1. FBO 简介2. FBO的关键组成部分3. FBO的基本工作流程4. FBO 实现渲染到纹理5. FBO 实现离屏渲染二、FBO 实现渲染到纹理的代码实例1. egl_wayland_texture3_2.c2. xdg-shell-client-protocol.h 和 xdg-shell-protocol.c3. 编译4. 运行总结参考资料前…

深度学习主流开源框架:Caffe、TensorFlow、Pytorch、Theano、Keras、MXNet、Chainer

2.6 深度学习主流开源框架 表2.1 深度学习主流框架参数对比 框架关键词总结 框架关键词基本数据结构(都是高维数组)Caffe“在工业中应用较为广泛”,“编译安装麻烦一点”BlobTensorFlow“安装简单pip”TensorPytorch“定位:快…

函数递归与迭代附n的阶乘+顺序打印一个整数的每一位数+求第n个斐波那契数

1. 什么是递归&#xff1f; 递归其实是一种解决问题的方法&#xff0c;在C语言中&#xff0c;递归就是函数自己调用自己。 下面是一个最简单的C语言递归代码&#xff1a; #include <stdio.h> int main() {printf("hehe\n");main();//main函数中⼜调⽤了main函数…

【C语言相关问题】C语言中关于大小写字母转换的问题

大家好&#xff0c;这里是争做图书馆扫地僧的小白。非常感谢各位的支持&#xff0c;也期待着您的关注。 目前博主有着C语言、C、linux以及数据结构的专栏&#xff0c;内容正在逐步的更新。 希望对各位朋友有所帮助同时也期望可以得到各位的支持&#xff0c;有任何问题欢迎私信与…