zoukankan      html  css  js  c++  java
  • CentOS安装PostgreSQL

    版本信息:

        CentOS版本:CentOS-7-x86_64-Minimal-1810

        PostgreSQL版本: PostgreSQL 10.10, 64-bit 

    第一部分:PostgresSQL的安装

    1、安装rpm文件

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

    异常处理:Error:Nothing to do,这个表示yum需要更新,运行 yum -y update

     也可以参考该文章:https://www.cnblogs.com/dijia478/p/11796936.html

    2、安装客户端

    yum install postgresql10

    3、安装服务端

    yum install postgresql10-server

    4、初始化

    /usr/pgsql-10/bin/postgresql-10-setup initdb

    5、设置自动启动并且启动postgresql服务

    systemctl enable postgresql-10
    systemctl start postgresql-10

    postgresql的安装比较简单,官网上有明确的操作步骤

    如果遇到执行 postgresql-10-setup initdb 报  Data directory is not empty!

    cd /var/lib/pgsql/10 
    
    move data datatemp (centos8 命令是mv data datatemp 具体的根据系统来操作)
    
    然后再次执行执行#
    /usr/psql-10/bin/postgresql-10-setup initdb
    其中postgresql由于版本的问题路径也不一样,请根据实际配置
    
    参考链接:https://www.cnblogs.com/starof/p/4773364.html?tdsourcetag=s_pctim_aiomsg

    第二部分:创建用户和数据库

    1、使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)

    su  postgres
    //执行
    psql

    2、修改默认数据库生成的 postgres 用户密码(此postgres非上面的postgres用户,此为数据库的用户,上面的为操作系统的用户)

    alter user postgres with encrypted password '1';

      

    3、创建用户和数据库并授权(如果需要,不需要跳过该步骤)

    create user test_user with password 'abc123';            // 创建用户
    create database test_db owner test_user;                 // 创建数据库
    grant all privileges on database test_db to test_user;   // 授权

    4、退出psql(输入 q 再按回车键即可)

    q

    第三部分:开启远程访问

    1、修改/var/lib/pgsql/10/data/postgresql.conf文件,取消 listen_addresses 的注释,将参数值改为“*”

     2、修改/var/lib/pgsql/10/data/pg_hba.conf文件,增加下图红框部分内容

    3、切换到root用户,重启postgresql服务

    systemctl restart postgresql-10.service

    4、使用数据库连接工具测试连接

     

    2、服务启动、关闭、重启、查看状态命令

    systemctl start postgresql-10.service     // 启动服务
    systemctl stop postgresql-10.service      // 关闭服务
    systemctl restart postgresql-10.service   // 重启服务
    systemctl status postgresql-10.service    // 查看状态
  • 相关阅读:
    【255】◀▶IEW-Unit20
    【254】◀▶IEW-Unit19
    【253】◀▶IEW-Unit18
    【252】◀▶IEW-Unit17
    [LeetCode] Restore IP Address
    1030
    (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))
    新知识的遗忘数度真是可怕
    【自由谈】城域网IPv6过渡技术——4v6场景技术总结(1)
    Graph Databases—The NOSQL Phenomenon阅读笔记
  • 原文地址:https://www.cnblogs.com/whitebai/p/12122240.html
Copyright © 2011-2022 走看看