官网安装脚本查询:https://www.postgresql.org/download/linux/redhat/
# 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 postgresql10-server # Optionally initialize the database and enable automatic start: sudo /usr/pgsql-10/bin/postgresql-10-setup initdb sudo systemctl enable postgresql-10 sudo systemctl start postgresql-10
使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)
[root@localhost software]# su postgres bash-4.2$
bash-4.2$ psql psql (10.16) 输入 "help" 来获取帮助信息.
create user test_user with password 'abc123'; # 创建用户 create database test_db owner test_user; # 创建数据库 grant all privileges on database test_db to test_user; # 授权
postgres=# \q bash-4.2$
修改/var/lib/pgsql/10/data/postgresql.conf文件,取消 listen_addresses 的注释,将参数值改为“*”
bash-4.2$ vim /var/lib/pgsql/10/data/postgresql.conf
修改/var/lib/pgsql/10/data/pg_hba.conf文件,增加下图红框部分内容
bash-4.2$ vim /var/lib/pgsql/10/data/pg_hba.conf
bash-4.2$ su root 密码: [root@localhost software]# systemctl restart postgresql-10.service
修改默认生成的 postgres 用户密码(此postgres非上面的postgres用户,此为数据库的用户,上面的为操作系统的用户)
su - postgres psql -U postgres alter user postgres with encrypted password '1';
systemctl start postgresql-10.service # 启动服务 systemctl stop postgresql-10.service # 关闭服务 systemctl restart postgresql-10.service # 重启服务 systemctl status postgresql-10.service # 查看状态