请在Centos8上安装PostgreSQL12

首先

由于以前只有接触过Mysql,所以按照Postgresql官方网站上的安装方法安装了它进行验证。
这次预计使用本地postgres用户进行无需验证的连接。

环境

    • CentOS8

 

    Postgresql12

安装

dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install -y postgresql12-server
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12

请在以下官方网站选择要安装的项目并进行安装:
https://www.postgresql.org/download/linux/redhat/

更改设置

事前准备 (shì

用户更改

安装后,已添加了postgres用户,因此需要更改用户。
基本上都是使用postgres用户进行操作。

su - postgres

切换目录

移动到设置文件所在的目录。

cd /var/lib/pgsql/12/data

添加路径

可以通过相对路径来使用pg_ctl。
也可以将其追加到.bash_profile文件中。

export PATH=$PATH:/usr/pgsql-12/bin/

Postgresql配置文件

進行基本配置的文件。根據需要適時更改配置。
由於此次是進行驗證,所以保留默認配置。

pg_hba.conf 的含义是 PostgreSQL 数据库集群中的一个配置文件。

设置连接网络的文件。
通过将ident更改为trust,可以使本地主机无需进行身份验证即可进行连接。
由于postgresql.conf默认情况下可能会使用ipv6进行连接,因此还需更改ipv6。

    • 変更前

 

    • # IPv4 local connections:

 

    • host all all 127.0.0.1/32 ident

 

    • # IPv6 local connections:

 

    • host all all ::1/128 ident

変更後
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust

設定的應用

通过以下命令应用设置。

pg_ctl reload

确认

登录确认

请确保能够通过以下命令登录。

psql -h localhost

更改密码(可选)

在连接之后,更改postgres用户的密码。

alter role postgres with password 'パスワード';

概要

我根据官方网站的指引进行了安装。
我忘记了进行IPv6设置更改,也不知道postgres用户的初始密码,导致遇到了意外的问题。
而且,直到现在我仍然不知道postgres用户的初始密码。

文献引用

    • https://www.postgresql.org/download/linux/redhat/

 

    データベース初心者のためのPostgreSQL教室
bannerAds