1.postgresql官网地址 https://www.postgresql.org/
2.下载地址 https://www.postgresql.org/download/linux/redhat/
选择对应的操作系统及安装版本,下面以9.6为例
# 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 postgresql96-server # Optionally initialize the database and enable automatic start: sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb sudo systemctl enable postgresql-9.6 sudo systemctl start postgresql-9.6
到这里安装及启动完成
3.修改配置文件,改为md5 密码登录
vi /var/lib/pgsql/9.6/data/pg_hba.conf #host all all 127.0.0.1/32 ident host all all 127.0.0.1/32 md5
4.配置用户及数据库
passwd postgres su - postgres createuser testpost # 登录数据库 psql # 创建数据库testpost CREATE DATAbase testpost WITH ENCODING 'UTF8' OWNER testpost TEMPLATE=template0; #设置testpost用户密码 alter user testpost with password 'testpost'; #给testpost授权 alter role testpost createdb; alter role testpost superuser; alter role testpost createrole; #更改test数据库拥有者 alter database testpost owner to testpost; #进入命令行 psql #指定用户 psql -U testdb -h 127.0.0.1 #查看库情况 l #查看用户 du # 退出 q



