CentOS7安装PostgreSQL12
PostgreSQL安装
参考如下链接:
https://www.postgresql.org/download/linux/redhat/
安装PostgreSQL的yum源
执行如下操作
1 | yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm |
安装PostgreSQL
执行
1 | yum install postgresql12-server |
安装完成后,初始化数据库并启动
1 | service postgresql-12 initdb |
创建用户
切换postgre用户,执行
1 | su - postgre |
进行psql
1 | psql |
创建用户,如test
1 | create user test with password 'FkE3@5PU5jf9L'; |
创建数据库testdb,owner为test
1 | create database testdb owner test; |
授权
1 | grant all privileges on database testdb to test; |
启动md5加密,修改pg_hba.conf文件。PG的客户认证,是通过该文件进行管理的。
1 | vi /var/lib/pgsql/12/data/pg_hba.conf |
pg_hba.conf文件说明
The general format of the pg_hba.conf
file is a set of records, one per line. Blank lines are ignored, as is any text after the #
comment character. Records cannot be continued across lines. A record is made up of a number of fields which are separated by spaces and/or tabs. Fields can contain white space if the field value is double-quoted. Quoting one of the keywords in a database, user, or address field (e.g., all
or replication
) makes the word lose its special meaning, and just match a database, user, or host with that name.
Each record specifies a connection type, a client IP address range (if relevant for the connection type), a database name, a user name, and the authentication method to be used for connections matching these parameters. The first record with a matching connection type, client address, requested database, and user name is used to perform authentication. There is no “fall-through” or “backup”: if one record is chosen and the authentication fails, subsequent records are not considered. If no record matches, access is denied.
文件格式如下:
1 | # TYPE DATABASE USER ADDRESS METHOD |
参考
CentOS7安装PostgreSQL12