安装
# 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 postgresql11-server
启动
# Optionally initialize the database and enable automatic start:
初始化:sudo /usr/pgsql-11/bin/postgresql-11-setup initdb sudo systemctl enable postgresql-11
sudo systemctl start postgresql-11
修改密码:
安装完PostgreSQL数据库以后,默认会创建一个名为postgres的Linux登录用户名,这里需要进行密码修改
注意:这里修改的是Linux系统登录的账号密码,不是PostgreSQL数据库的密码,后面会修改PostgreSQL数据库的密码。
使用下面的命令修改postgres用户的登录密码:
passwd postgres
设置允许远程连接:
cd /var/lib/pgsql/11/data
vim postgresql.conf
把listen_addresses前面的#去掉,然后将localhost修改为*,修改后的内容如下:
最好保存退出。
还是在同样目录下,对pg_hba.conf文件进行编辑:
vim pg_hba.conf
如下图所示:
这里对IPv4内容进行修改,修改前文件内容:
修改为文件内容:
最后保存退出。
重启
systemctl restart postgresql-11
修改数据库密码
ssh postgres@node1 -p 22
psql -U postgres \password