023.PGSQL-linux下的安装教程

参考博客  https://www.cnblogs.com/ningy1009/p/14467751.html

官网下载地址

https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

1.下载仓库源

[root@s101 /root]#sudo yum  install  -y  https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
pgdg-redhat-repo-latest.noarch.rpm                                                                            | 7.4 kB  00:00:00
Examining /var/tmp/yum-root-Xd3oez/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-17.1.noarch
Marking /var/tmp/yum-root-Xd3oez/pgdg-redhat-repo-latest.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat-repo.noarch 0:42.0-17.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================
 Package                         Arch                  Version                  Repository                                      Size
=====================================================================================================================================
Installing:
 pgdg-redhat-repo                noarch                42.0-17.1                /pgdg-redhat-repo-latest.noarch                 11 k

Transaction Summary
=====================================================================================================================================
Install  1 Package

Total size: 11 k
Installed size: 11 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pgdg-redhat-repo-42.0-17.1.noarch                                                                                 1/1
  Verifying  : pgdg-redhat-repo-42.0-17.1.noarch                                                                                 1/1

Installed:
  pgdg-redhat-repo.noarch 0:42.0-17.1

Complete!
[root@s101 /root]#

 

2.安装数据库postgresql13 和 扩展包

[root@s101 /root]#sudo yum install -y postgresql13-server postgresql13-contrib postgresql13-devel

 

3.查看安装包和安装地址

[root@s101 /root]#rpm -qa grep postgres


[root@s101 /root]#rpm -qal | grep postgres

 

 4.数据库初始化 ,初始化位置:  /var/lib/pgsql/13/data

初始化前

 

 初始化后

sudo /usr/pgsql-13/bin/postgresql-13-setup initdb

 


 

 

 

 数据库应用程序所在文件

 

 

 

 

5.设置开机自启动
sudo systemctl enable postgresql-13

 


 



6.启动服务
sudo systemctl start postgresql-13

#重新启动
sudo systemctl restart postgresql-13

#停止服务

sudo systemctl stop postgresql-13

#查看服务状态

sudo systemctl status postgresql-13

7.查看服务状态

 

 8.如果防火墙有开启,开启防火墙的5432端口

查看防火墙的状态

firewall-cmd --state

 

 

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

 

 

 查看现有规则 

iptables -nL

 

 

9.修改配置文件,添加允许远程连接IP 

cd   /var/lib/pgsql/13/data 

1)postgresql.conf

添加 

listen_addresses = '*'

 

 

2)pg_hba.conf  

host all all 0.0.0.0/0 trust

 

 

10.重启服务

[root@s101 /var/lib/pgsql/13/data]#sudo systemctl restart postgresql-13

 

11. 修改数据库密码

su - postgres  #注意这里postgers 前后都有空格

# 以postgres 用户进入系统

#登录数据库命令: 
psql -U postgres  #会进入postgres用户的控制台

#\l 查看有哪些数据库
#\c postgresql  选择postgresql 这个数据库,会提示进入连接
#然后就可以用select 等语句查询了

#修改数据库密码
ALTER USER postgres WITH PASSWORD  '123456' ;

#退出数据库
\q

 

 

 

回到顶部
2. 修改linux系统postgres用户的密码
 
PostgreSQL会创建一个默认的linux用户postgres,修改该用户密码的方法如下:
 
步骤一:删除用户postgres的密码
1
 
sudo passwd -d postgres
 
步骤二:设置用户postgres的密码
1
 
sudo -u postgres passwd
 
系统提示输入新的密码
1
2
3
 
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
 
 
 登录数据库
su postgres #注意这里postgers 前后都有空格
psql -U postgres -d postgres -p 5432
 

 

 




posted @ 2021-06-22 17:58  star521  阅读(305)  评论(0编辑  收藏  举报