CentOS7 minimal postgresql 切换数据库和角色 远程登录 登录

注:postgresql角色就是用户

  • 远程登录配置(以postgresql95为例)
  1. 配置
    vi /var/lib/pgsql/9.5/data/pg_hba.conf
host    all             all             192.168.0.102/24            password

192.168.0.102是允许远程登录的ip

  1. 配置
    vi /var/lib/pgsql/9.5/data/postgresql.conf
listen_addresses='*'
  1. 重启服务
    systemctl restart postgresql-9.5.service
    注:如果不能登录,应该是没有登录权限
    alter user root login;
  2. 用角色engine登录数据库engine
    配置远程登录,用engine 登录engine数据库
    CentOS7 minimal postgresql 切换数据库和角色 远程登录 登录_第1张图片
    image.png
  • postgres-client登录数据库
  1. 更改centos7的用户postgres密码为postgres,第二个步骤
  2. 用角色postgres登录postgresql
    su root
    su postgres
    psql
  3. 更改数据库中postgres用户的密码为postgres
    ALTER USER postgres WITH PASSWORD 'postgres';
  4. 配置
    vi /var/lib/pgsql/9.5/data/pg_hba.conf
local   all             all                                     password
  1. 重启数据库服务
    systemctl restart postgresql-9.5.service
  2. 登录数据库,输入密码


    image.png
  3. 切换数据库
    \c databaseName
  4. 切换角色
    \c - userName
    image.png

你可能感兴趣的:(CentOS7 minimal postgresql 切换数据库和角色 远程登录 登录)