之前接触的只有mysql,记录一下PostgreSQL以及中文分词器的安装。
安装环境
系统:CentOS 8
PostgreSQL
-
官网选择版本等信息会生成安装命令:
-
安装步骤
-
添加PostgreSQL存储库rpm包
首先下载rpm包安装到系统,我们使用DNF方式(Centos 7以后版本推荐使用,DNF包管理器克服了YUM包管理器的一些瓶颈,提升了用户体验,内存占用,依赖分析,运行速度等方面,DNF使维护软件包组变得容易,并且能够自动解决依赖性问题)。
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
-
安装好之后查看软件包详细信息(非必须)
rpm -qi pgdg-redhat-repo
-
禁用内置的PostgreSQL模块(暂不清楚为啥要禁用)
dnf -qy module disable postgresql
-
删除缓存的无用软件包
在使用 DNF 的过程中,会因为各种原因在系统中残留各种过时的文件和未完成的编译工程。我们可以使用该命令来删除这些没用的垃圾文件。
dnf clean all
-
安装PostgreSQL
dnf install -y postgresql11-server
-
初始化数据库
/usr/pgsql-11/bin/postgresql-11-setup initdb
-
开机自动启动数据库服务
“--now”表示在激活的同时启动服务,若加上则第八步省略。
systemctl enable (--now) postgresql-11
-
启动数据库
systemctl start(stop | restart | status) postgresql-11
-
登录
-
切换成postgres用户
安装完毕后,系统会自动的创建一个用户postgres(既是系统用户也是数据库超级管理员)专门用来管理PostgreSQL数据库,密码为空。
su - postgres
-
登录数据库
psql
-
修改postgres登录密码
alter user postgres with password '密码'
-
退出
\q
-
开启远程访问
-
修改postgresql.conf配置文件
vim /var/lib/pgsql/11/data/postgresql.conf
打开上图两行注释,并将“listen_addresses”内容修改为“*”,保存退出。
-
修改pg_hba.conf配置文件
vim /var/lib/pgsql/11/data/pg_hba.conf
如上图所示,追加host all all 0.0.0.0/0 md5。保存退出,使用DataGrip测试连接成功