PostgreSQL 14.2 安装教程

第一章 PostgreSQL安装

1.1 新建 /opt/tools 目录

mkdir -p /opt/tools

1.2 上传postgresql文件

1.3 解压postgresql文件

tar -zxvf postgresql-14.2.tar.gz

1.4 进入 postgresql 并配置

cd postgresql-14.2

mkdir -p /opt/app/postgresql

./configure --prefix=/opt/app/postgresql

注: /opt/app/postgresql/:安装目录

执行配置脚本前需安装gcc、readline-devel、zlib-devel

yum -y install gcc

yum -y install readline-devel

yum install -y zlib-devel

重新再次执行

./configure --prefix=/opt/app/postgresql

1.5 编译安装

make && make install

1.6 配置环境变量

vi /etc/bashrc

在文件末尾添加以下内容

export PATH=$PATH:/opt/app/postgresql/bin

使修改马上生效:

source /etc/bashrc

测试psql命令

psql --help

1.7 初始化数据

1.7. 1 创建psql的用户和密码

useradd postgres

passwd postgres

1.7.2 创建数据目录

cd /opt/app/postgresql

mkdir data

1.7.3 创建日志目录

cd /opt/app/postgresql

mkdir logs

1.7.4 设置postgresql文件夹的所有者和所属组为postgres

chown -R postgres:postgres /opt/app/postgresql

1.7.5 切换到postgres用户来操作数据库,pgsql数据库以postgres为默认用户

su postgres

1.7.6 初始化数据库

bin/initdb -D /opt/app/postgresql/data

1 . 8 启动postgresql数据库

bin/pg_ctl -D /opt/app/postgresql/data -l /opt/app/postgresql/logs/logfile start

1.8.1 登录测试

psql

1.8.2 修改postgre密码

ALTER USER postgres WITH PASSWORD 'Nancal@123'

1.9 停止postgresql数据库

bin/pg_ctl -D /opt/app/postgresql/data stop

1.10 配置系统服务service

1.10.1 进入postgresql源码包的解压目录

cd /opt/tools/postgresql-14.2

1.10.2 复制启动脚本到init.d下

cp contrib/start-scripts/linux /etc/init.d/postgresql

1.10.3 修改postgresql

vi /etc/init.d/postgresql

/opt/app/postgresql

1.10.4 赋予该文件执行权限

chmod +x /etc/init.d/postgresql

1.10.5 设置服务开机自启

chkconfig --add postgresql

1.10.6 启动数据库服务

service postgresql start

第二章 远程访问

默认情况下,pgsql在linux服务器上面,已经是安装和启动成功了,也能连上。但是本地window环境下,是无法连接上pgsql服务器的。

2 .1 修改postgresql.conf

vi /opt/app/postgresql/data/postgresql.conf

取消 listen_addresses 的注释,将参数值改为"*"。

2 .2 修改pg_hba.conf

vi /opt/app/postgresql/data/pg_hba.conf

找到host all all 127.0.0.1/32 trust这行,然后在下面添加一行:host all all 0.0.0.0/0 trust即可。

2.3 重启服务

cd /opt/app/postgresql

su postgres

bin/pg_ctl -D /opt/app/postgresql/data -l /opt/app/postgresql/logs/logfile restart

第三章 配置防火墙

3 .1 开启5432端口

开放5432端口

firewall-cmd --zone=public --add-port=5432/tcp --permanent

#关闭5432端口

firewall-cmd --zone=public --remove-port=5432/tcp --permanent

3.2 配置立即生效

firewall-cmd --reload

3.3 重启防火墙

service firewalld restart

3.4 查看已开放的端口

firewall-cmd --list-ports

相关推荐
RestCloud13 小时前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud13 小时前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence15 小时前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
DemonAvenger1 天前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
AAA修煤气灶刘哥1 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
RestCloud2 天前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术2 天前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
可涵不会debug2 天前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom2 天前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试
IvorySQL2 天前
IvorySQL 4.6:DocumentDB+FerretDB 实现 MongoDB 兼容部署指南
postgresql