官网地址:https://www.postgresql.org/
下载地页面:https://www.postgresql.org/download/linux/redhat/
使用yum命令添加PostgreSQL软件源。
[root@localhost ~] yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
使用yum命令安装PostgreSQL。
[root@localhost ~] yum install postgresql12
[root@localhost ~] yum install postgresql12-server
[root@localhost ~] yum install postgresql12-contrib
初始化数据库。
[root@localhost ~] /usr/pgsql-12/bin/postgresql-12-setup initdb
配置开机启动与启动
[root@localhost ~] systemctl enable postgresql-12
[root@localhost ~] systemctl start postgresql-12
首先,切换到postgres用户。然后执行修改用户密码SQL语句。其中“postgres”为要修改密码的用户,“123456”为用户的密码。
[root@localhost ~] su - postgres
bash-4.2$ psql -c "alter user postgres with password '123456'"
打开并编辑文件“/var/lib/pgsql/12/data/postgresql.conf”。将“#listen_addresses = 'localhost'”改为“listen_addresses = '*'”
打开并编辑文件“/var/lib/pgsql/12/data/pg_hba.conf”。在文件的末尾添加“host all all 0.0.0.0/0 md5”。
如果不需要数据库Python3支持,则忽略该步骤。
[root@localhost ~] yum install postgresql12-plpython3
要使用python扩展,需要打开数据库,执行如下SQL语句。
CREATE extension plpython3u;