Centos7 postgresql安装全过程

悠悠 2022-02-21 17:16 366阅读 0赞

安装

安装 存储库RPM

  1. yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

安装客户端软件包

  1. yum install postgresql10

安装服务器包

  1. yum install postgresql10-server

只下载 不安装

  1. yum install --downloadonly --downloaddir=/root/ postgresql10 postgresql10-server
  2. --downloadonly #只下载
  3. --downloaddir=/root/ #rpm的下载保存地址

安装

  1. yum install ./*.rpm

初始化数据库并启用自动启动

  1. # 初始化数据库
  2. /usr/pgsql-10/bin/postgresql-10-setup initdb
  3. systemctl enable postgresql-10
  4. systemctl start postgresql-10

配置用户名密码+远程登录

允许远程登录

  1. # 编辑配置文件 listen_address=’localhost’ 改为 "*",去掉注释
  2. vim /var/lib/pgsql/10/data/postgresql.conf
  3. # 修改
  4. vim /var/lib/pgsql/10/data/pg_hba.conf
  5. # 添加 24是子网掩码 password ,将127 也改为password
  6. host all all 192.168.56.0/24 password
  7. #重启服务
  8. systemctl restart postgresql-10

从系统中进入数据库进行操作:

  1. su postgres
  2. psql -U postgres # 登录命令 会进入postgres用户的控制台
  3. # psql -U postgres # 再次执行 进入数据库
  4. \c postgres # \c 数据库 ,选择一个数据库进入
  5. \l 是查看有哪些数据库

创建用户名和密码

  1. create user username with login password 'password';
  2. # 如,用户名sun,密码123456
  3. create user sun with login password '123456';
  4. # 创建数据库 dbname,dbname小写
  5. CREATE DATABASE dbname;
  6. # 给用户权限, 给用户某个schema的所有权限,如果有
  7. grant all on all tables in schema postgres to sun;

data目录迁移

  1. https://blog.csdn.net/wk1134314305/article/details/79054248

发表评论

表情:
评论列表 (有 0 条评论,366人围观)

还没有评论,来说两句吧...

相关阅读