zoukankan      html  css  js  c++  java
  • ubuntu18.04安装上安装 PostgreSQL10并开启远程访问

    首先更新本地包索引

    sudo apt update
    

    安装PostgreSQL服务器和PostgreSQL contrib包,它为PostgreSQL数据库提供了额外的功能

    sudo apt install postgresql postgresql-contrib
    

    安装完成后,PostgreSQL服务将自动启动。 要验证安装,我们将使用psql实用程序连接到PostgreSQL数据库服务器并打印服务器版本

    sudo -u postgres psql -c "SELECT version();"
    

    输出内容:  

      

    安装完成后切换到postgres下

    sudo -u postgres psql  

    使用q退出psql,然后切换到root用户下,修改postgres的密码 sudo passwd root修改成功后

    使用createdb命令创建名为johndb的新数据库:
    sudo su - postgres -c "createdb johndb"
    

    授权给postgres

    grant all privileges on database johndb to postgres;
    

     启用对PostgreSQL服务器的远程访问

    修改配置文件postgresql.conf

    sudo vim /etc/postgresql/10/main/postgresql.conf
    

      修改listen_addresses = '*' 

    #------------------------------------------------------------------------------
    # CONNECTIONS AND AUTHENTICATION
    #------------------------------------------------------------------------------
    
    # - Connection Settings -
    
    listen_addresses = '*'     # what IP address(es) to listen on;
    

    修改pg_hba.conf文件,配置用户的访问权限(#开头的行是注释内容)

    sudo vim /etc/postgresql/10/main/postgresql.conf
    
    修改如下添加 host    all             all             0.0.0.0/0                  trust
    # "local" is for Unix domain socket connections only
    local   all             all                                     trust
    # IPv4 local connections:
    host    all             all             127.0.0.1/32             trust
    host    all             all             0.0.0.0/0                  trust
            
    

    保存文件并重启PostgreSQL服务:

    sudo service postgresql restart
    

    在客户端登陆账户就是postgresql密码就是sudo passwd root修改的密码

  • 相关阅读:
    CLR(Common Language Runtime)
    六个经典的英语面试问题
    XML基本知识(三)
    vc++中各种字符串(转载)
    winform窗体间传值
    jQuery实现按比例缩放图片
    .net中几个名词解释
    XML Schema 定义
    C#中TreeView组件使用方法初步
    微软电话面试题
  • 原文地址:https://www.cnblogs.com/axyls/p/13742572.html
Copyright © 2011-2022 走看看