zoukankan      html  css  js  c++  java
  • 023.PGSQL-linux下的安装教程

    参考博客  https://www.cnblogs.com/ningy1009/p/14467751.html

    官网下载地址

    https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

    1.下载仓库源

    [root@s101 /root]#sudo yum  install  -y  https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    Loaded plugins: fastestmirror
    Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
    pgdg-redhat-repo-latest.noarch.rpm                                                                            | 7.4 kB  00:00:00
    Examining /var/tmp/yum-root-Xd3oez/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-17.1.noarch
    Marking /var/tmp/yum-root-Xd3oez/pgdg-redhat-repo-latest.noarch.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package pgdg-redhat-repo.noarch 0:42.0-17.1 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =====================================================================================================================================
     Package                         Arch                  Version                  Repository                                      Size
    =====================================================================================================================================
    Installing:
     pgdg-redhat-repo                noarch                42.0-17.1                /pgdg-redhat-repo-latest.noarch                 11 k
    
    Transaction Summary
    =====================================================================================================================================
    Install  1 Package
    
    Total size: 11 k
    Installed size: 11 k
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : pgdg-redhat-repo-42.0-17.1.noarch                                                                                 1/1
      Verifying  : pgdg-redhat-repo-42.0-17.1.noarch                                                                                 1/1
    
    Installed:
      pgdg-redhat-repo.noarch 0:42.0-17.1
    
    Complete!
    [root@s101 /root]#

     

    2.安装数据库postgresql13 和 扩展包

    [root@s101 /root]#sudo yum install -y postgresql13-server postgresql13-contrib postgresql13-devel

     

    3.查看安装包和安装地址

    [root@s101 /root]#rpm -qa grep postgres


    [root@s101 /root]#rpm -qal | grep postgres

     

     4.数据库初始化 ,初始化位置:  /var/lib/pgsql/13/data

    初始化前

     

     初始化后

    sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
    
    
    
     

     

     数据库应用程序所在文件

    5.设置开机自启动
    sudo systemctl enable postgresql-13

    
    
    


    6.启动服务
    sudo systemctl start postgresql-13
    
    #重新启动
    sudo systemctl restart postgresql-13
    
    #停止服务
    
    sudo systemctl stop postgresql-13
    
    #查看服务状态
    
    sudo systemctl status postgresql-13

    7.查看服务状态

     

     8.如果防火墙有开启,开启防火墙的5432端口

    查看防火墙的状态

    firewall-cmd --state

     

     

    firewall-cmd --permanent --add-port=5432/tcp   

     

     

     查看现有规则 

    iptables -nL

     

     

    9.修改配置文件,添加允许远程连接IP 

    cd   /var/lib/pgsql/13/data 

    1)postgresql.conf

    添加 

    listen_addresses = '*'

     

     

    2)pg_hba.conf  

    host all all 0.0.0.0/0 trust

     

     

    10.重启服务

    [root@s101 /var/lib/pgsql/13/data]#sudo systemctl restart postgresql-13

     

    11. 修改数据库密码

    su - postgres  #注意这里postgers 前后都有空格
    
    # 以postgres 用户进入系统
    
    #登录数据库命令: 
    psql -U postgres  #会进入postgres用户的控制台
    
    #l 查看有哪些数据库
    #c postgresql  选择postgresql 这个数据库,会提示进入连接
    #然后就可以用select 等语句查询了
    
    #修改数据库密码
    ALTER USER postgres WITH PASSWORD  '123456' ;
    
    #退出数据库
    q

     

     

     

    回到顶部
    2. 修改linux系统postgres用户的密码
     
    PostgreSQL会创建一个默认的linux用户postgres,修改该用户密码的方法如下:
     
    步骤一:删除用户postgres的密码
    1
     
    sudo passwd -d postgres
     
    步骤二:设置用户postgres的密码
    1
     
    sudo -u postgres passwd
     
    系统提示输入新的密码
    1
    2
    3
     
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
     
     
     登录数据库
    su postgres #注意这里postgers 前后都有空格
    psql -U postgres -d postgres -p 5432
     

     

     




  • 相关阅读:
    Delphi 的字符及字符串[4] 字符串、字符指针与字符数组
    Delphi 的字符及字符串[5] 字符串与 Windows API
    WinAPI: FindWindow、FindWindowEx 查找窗口
    java LookAndFeel 美化 Substance使用
    持久化和对象关系映射ORM技术
    java 更换皮肤问题Cannot refer to a nonfinal variable inside an inner class defined in a different method
    java Swing可视化开发工具
    php ORM 持久层框架与简单代码实现
    生成Substance皮肤Menu项的代码
    三层架构实现
  • 原文地址:https://www.cnblogs.com/star521/p/14919711.html
Copyright © 2011-2022 走看看