栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Postgresql14安装教程(CentOS 7.9.2009)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Postgresql14安装教程(CentOS 7.9.2009)

1、基本步骤
#参考官网:https://www.postgresql.org/download/linux/redhat/
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql14-server
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
2、修改配置文件postgresql.conf
#默认postgreql 安装在/usr/pgsql-14,数据存储目录:/var/lib/pgsql/14/data
vim /var/lib/pgsql/14/data/postgresql.conf
#修改 
listen_addresses = '*'
3、修改配置文件pg_hba.conf
#默认postgreql 安装在/usr/pgsql-14,数据存储目录:/var/lib/pgsql/14/data
vim /var/lib/pgsql/14/data/pg_hba.conf 
#增加一行 
host    all             all             0.0.0.0/0               password
4、重启数据库
sudo systemctl enable postgresql-14
sudo systemctl restart postgresql-14
#start不起效
sudo systemctl start postgresql-14
5、检查数据库状态
systemctl status postgresql-14
6、测试
#创建用户testuser、数据库testdb 并赋给testuser所有的testdb相关的权限。
su - postgres
psql
CREATE USER testuser with PASSWORD '123456';
CREATE DATABASE testdb owner testuser;
GRANT ALL ON DATABASE testdb TO testuser
#直接用testuser登录, 点击回车后,输入密码即可
psql -h 192.168.8.88 -U testuser  -d testdb
#检查数据目录
show data_directory;
#用navicat客户端连接
主机名或ip地址:10.xx.3.xx
端口:5432
初始数据库:testdb
用户名:testuser
密码:123456

7、检查是否能客户端根据ip连接
curl localhost:5432
curl 10.xx.3.xx:5432
8、查询postgresql进程
ps -ef | grep postmaster
9、修改密码
  • #1. 修改linux系统postgres用户的密码
    PostgreSQL会创建一个默认的linux用户postgres,修改该用户密码的方法如下:
    ##步骤一:删除用户postgres的密码
    sudo  passwd -d postgres
    ##步骤二:设置用户postgres的密码
    sudo -u postgres passwd
    ##系统提示输入新的密码
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    ​
    #2. 修改PostgreSQL数据库默认用户postgres的密码
    PostgreSQL数据库创建一个postgres用户作为数据库的管理员,密码随机,所以需要修改密码,方式如下:
    ##步骤一:登录PostgreSQL
    sudo -u postgres psql
    ##步骤二:修改登录PostgreSQL密码
    ALTER USER postgres WITH PASSWORD 'ROOT';
    ​
    注:
    密码postges要用引号引起来
    命令最后有分号

9、其他命令
查询linux内核命令:uname -r
查询centos版本命令:lsb_release -a

10、随后需要完善的地方

默认postgreql 安装在/usr/pgsql-14,数据存储目录:/var/lib/pgsql/版本号/data,在实际生产中/var可能存在硬盘空间不足的问题,我们一般将数据存储目录放在挂载的硬盘如/data下

11、参考网址

官方地址:PostgreSQL: Linux downloads (Red Hat family)

参考网址1:CentOS7.9下安装PostgreSQL14并指定数据目录笔记_guoshfcs的博客-CSDN博客_postgresql 指定数据目录

参考网址2:

修改linux系统用户、PostgreSQL用户的密码 - cnshen - 博客园

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/868657.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号