Linux下安装pgsql

1. 下载

下载上述红框内数据包

postgresql13-13.2-1PGDG.rhel8.x86_64.rpm

postgresql13-libs-13.2-1PGDG.rhel8.x86_64.rpm

postgresql13-server-13.2-1PGDG.rhel8.x86_64.rpm

2. 安装

2.1 拷贝安装包到centos 系统中

#创建文件夹

sudo mkdir /myShare

#挂载共享文件

sudo mount -t cifs -o username="administrator",password="***" //192.168.1.2/temp /myShare

sudo mount -t cifs -o username=administrator,password=*** //192.168.1.2/temp /myShare

 

#拷贝文件

sudo cp postgresql13-server-13.2-1PGDG.rhel8.x86_64.rpm postgresql13-13.2-1PGDG.rhel8.x86_64.rpm postgresql13-libs-13.2-1PGDG.rhel8.x86_64.rpm /usr/local/

 

2.2 安装 postgresql 包

sudo rpm -ivh postgresql13-libs-13.2-1PGDG.rhel8.x86_64.rpm

sudo rpm -ivh postgresql13-13.2-1PGDG.rhel8.x86_64.rpm

sudo rpm -ivh postgresql13-server-13.2-1PGDG.rhel8.x86_64.rpm

 

2.3 执行完以后,postgres安装完毕,初始化postgres并设置自启动

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

systemctl start postgresql-13

systemctl enable postgresql-13.service

 

2.4 修改 postgresql.conf 文件

#切换用户

sudo -i -u postgres

#找到 postgresql.conf文件

cd 13/data/

 

vi postgresql.conf

#找到listen_addresses,将其值修改为 *#取消listen_addresses 和 port注释

i编辑文件    esc,:wq保存

 

2.4 修改 pg_hba.conf 文件

vi pg_hba.conf

#找到 #IPv4 local connections:添加

hosthost all all 127.0.0.1/32 trust

host all all 0.0.0.0/0 md5

 

 

2.5 重启postgres服务

systemctl restart postgresql-13

2.6 关闭防火墙

关闭防火墙:systemctl stop firewalld.service #停止

                      systemctl disable firewalld.service #禁止firewall开机启动

 

2.7 修改postgres 密码

psql

alter user postgres with password '123456';

 

 

其它命令:

sudo -i -u postgres  进入sql编辑(\q退出编辑)

psql 进入脚本 (exit推出脚本)

创建用户 CREATE USER root01 WITH PASSWORD '123456';    //;不可缺失

创建数据库  CREATE DATABASE db_01 OWNER root01;

权限赋予  GRANT ALL PRIVILEGES ON DATABASE db_01 TO root01;

 

posted @ 2021-05-22 14:55  当年小清新  阅读(614)  评论(0编辑  收藏  举报