第一:安装
进入网址:
https://www.postgresql.org/download/linux/redhat/
选项:
1、Select version:13
2、Select platform:centos7
3、Select architecture:x86_64
安装命令
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL:
sudo yum install -y postgresql13-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
第二:创建用户和数据库
1、使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)
su - postgres
create user test_user with password 'abc123'; // 创建用户
create database test_db owner test_user; // 创建数据库
grant all privileges on database test_db to test_user; // 授权
第三:开启远程访问
1、修改/var/lib/pgsql/10/data/postgresql.conf文件,取消 listen_addresses 的注释,将参数值改为“*”
2、修改/var/lib/pgsql/10/data/pg_hba.conf文件,增加一行
host all all 0.0.0.0/0 md5
第四:额外补充
1、修改默认生成的 postgres 用户密码(此postgres非上面的postgres用户,此为数据库的用户,上面的为操作系统的用户)
su - postgres
psql -U postgres
alter user postgres with encrypted password 'newpassword';
第五:安装扩展
1,更新yum
sudo yum update
2,查找 yum list 里的 “contrib”
yum search contrib
3,安装指定 contrib
yum install postgresql13-contrib.x86_64
4,进入系统的psql 环境
sudo -u postgres psql
5,启用插件
6、选择数据库
c your_db
create extension pg_trgm;
7,验证是否己装好
dT



