PostgreSQL安装配置参考文档
1.安装
Centos安装包链接 : https://yum.postgresql.org/rpmchart/
然后选择系统版本及PostgreSQL版本
举例
- [postgresql10-libs-10.13-1PGDG.rhel7] 为 运行库
- [postgresql10-server-10.13-1PGDG.rhel7] 为 服务端
- [postgresql10-10.13-1PGDG.rhel7] 为 客户端
以上三个为主要安装包,其余安装包可是视情况安装
#进入下载目录,使用如下命令进行安装
sudo rpm -ivh post*.rpm
安装完毕后,系统会创建一个数据库超级用户 postgres,密码为空
#更改postgres用户密码 用于远程链接
sudo passwd postgres
#修改psql密码
ALTER USER postgres WITH PASSWORD 'password';
#错误示范
[user@localhost ~]$ passwd postgres
passwd: Only root can specify a user name.
重启PostgreSQL服务
#查看服务状态 服务为 postgresql-版本号
systemctl status postgresql-10
#启动 / 重启服务状态
systemctl start/restart postgresql-10
#停止服务
systemctl stop postgresql-10
查看是否安装成功 如有问题 请先观看 2.1配置相关文件
-
最大权限
#进入用户 并输入超级用户密码 sudo -i -u postgres #进入数据库 [user@localhost ~]$ sudo -i -u postgres [sudo] password for user: -bash-4.2$ psql psql (10.13) Type "help" for help. postgres=# #登出 postgres=# \q -bash-4.2$ exit logout
-
普通权限
#登入 [user@localhost ~]$ su postgres Password: bash-4.2$
2.配置及视图化工具
1.配置相关文件
PostgreSQL
在维护 PostgreSQL 库时,有两个配置文件修改的情况比较多,第一是认证文件 pg_hba.conf,另一个是配置文件 postgresql.conf
#使用以下命令寻找到
find \ -name 文件名
以便允许远程访问
# pg_hba.conf 文件
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
# 主要是 将 ipv4 local connections 修改为 md5验证
#postgresql.conf 文件
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# 将listen_addresses参数修改为 listen_addresses = '*'
2.视图化工具
Web端 pgAdmin4
#yum下载软件
sudo yum install pgadmin4
#使用 第一次使用 可能会输入邮箱 及密码 用于登陆网址
find / -name pgAdmin4.py
python3 pgAdmin4.py
# 网页输入网址
http://127.0.0.1:5050
# 输入数据库网址,用户名,密码
客户端
#下载
yum install pgadmin3
#运行
pgadmin3
3.SpringBoot链接PostgreSQL
数据源依赖
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.12</version>
</dependency>
yaml配置文件
spring:
datasource:
url: jdbc:postgresql://127.0.0.1:5432/postgres
username: name
password: password
platform: postgres
driver-class-name: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
接下来使用 Mybaits 进行 CRUD