安装:
# sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# sudo dnf -qy module disable postgresql
# sudo dnf install -y postgresql13-server
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
postgresql13-server x86_64 13.3-2PGDG.rhel8 pgdg13 5.5 M
Installing dependencies:
libicu x86_64 60.3-2.el8_1 baseos 8.8 M
postgresql13 x86_64 13.3-2PGDG.rhel8 pgdg13 1.5 M
postgresql13-libs x86_64 13.3-2PGDG.rhel8 pgdg13 413 k
Transaction Summary
================================================================================
Install 4 Packages
[root@centos8 ~]# sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK
[root@centos8 ~]# sudo systemctl enable postgresql-13
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service → /usrrvice.
[root@centos8 ~]# sudo systemctl start postgresql-13
说明:
postgresql-client libraries and client binaries
postgresql-server core database server
postgresql-contrib additional supplied modules
postgresql-devel libraries and headers for C language development
-- 切换用户 创建用户和数据库:
[root@centos8 ~]# su - postgres
[postgres@centos8 ~]$ psql
psql (13.3)
Type "help" for help.
postgres=# create user root with password 'oracle';
CREATE ROLE
postgres=# create database product owner root;
CREATE DATABASE
postgres=# grant all privileges on database product to root;
GRANT
--退出:
postgres=# \q
postgres=# quit
配置postgresql 可以远程访问:
#添加/修改:在所有IP地址上监听,从而允许远程连接到数据库服务器
# vim /var/lib/pgsql/13/data/postgresql.conf
listening_address:'*'
#listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#添加/修改:允许任意用户从任意机器上以密码方式访问数据库,把下行添加为第一条规则:
加入:
# vim /var/lib/pgsql/13/data/pg_hba.conf
host all all 0.0.0.0/0 md5
重启服务器:
# sudo systemctl restart postgresql-13