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
2
3
service postgresql-12 initdb
chkconfig postgresql-12 on
service postgresql-12 start

创建用户

切换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
2
3
4
vi /var/lib/pgsql/12/data/pg_hba.conf

//添加如下:
local testdb test md5

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
2
3
4
5
6
7
8
9
10
11
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local all all trust

# The same using local loopback TCP/IP connections.
#
# TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 trust
# TYPE DATABASE USER ADDRESS METHOD
local sameuser all md5
local all @admins md5
local all +support md5

参考

作者

ovasty

发布于

2021-12-30

更新于

2021-12-30

许可协议

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.