美文网首页
Linux下postgres的安装

Linux下postgres的安装

作者: 轴儿 | 来源:发表于2018-03-18 00:21 被阅读0次

    1.下载postgres安装包:

    wget http://p5osdejt4.bkt.clouddn.com/postgresql-9.6.1.tar.gz

    2.解压安装包:

    tar -zxvf postgresql-9.6.1.tar.gz

    3.安装依赖:

    yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake

    4.编译与安装:

    cd /usr/postgresql-9.6.1

    ./configure --prefix=/usr/local/postgreSQL --with-perl --with-python --with-libxml --with-libxslt

    make && make install

    5.创建数据库数据存储目录:

    mkdir -p /usr/local/postgreSQL/data

    chown postgres:postgres /usr/local/postgreSQL/data (赋权限给postgres用户)

    6.切换用户:

    su - postgres

    7.初始化数据:

    /usr/local/postgreSQL/bin/initdb --no-locale -U postgres -E utf8 -D /usr/local/postgreSQL/data

    备注:

    initdb [选项]... [DATADIR]

    -D, --pgdata=DATADIR       当前数据库簇的位置

    -E, --encoding=ENCODING   为新数据库设置默认编码

    --locale=LOCALE      为新数据库设置默认语言环境

    -U, --username=NAME       数据库超级用户名

    8.复制PostgreSQL执行脚本:

    cp /usr/postgresql-9.6.1/contrib/start-scripts/linux /etc/init.d/postgresql

    chmod +x /etc/init.d/postgresql

    修改/etc/init.d/postgresql

    把PGDATA改成PGDATA=/usr/local/postgreSQL/data

    9.加入开机启动:

    chkconfig --add postgresql

    chkconfig postgresql on

    管理PG服务时也可以直接用上面启动脚本

    启动:service postgresql start

    停止:service postgresql stop

    重启:service postgresql restart

    加载:service postgresql reload

    状态:service postgresql status

    10.postgres用户下配置环境变量(这样就可以直接使用psql命令):

    vim /home/postgres/.bash_profile

    在此文件的最后加上:export PATH=$PATH:/usr/local/postgreSQL/bin

    连接数据库

    psql -h 127.0.0.1 -U postgres -p 5432 -d postgres -W

    -d 指定数据库 ,-W 输入密码 , -U 指定用户,-p 指定端口,-h 指定IP

    11.配置使得其他计算机也可以访问数据库

    vim /usr/local/postgreSQL/data/postgresql.conf

    将postgresql.conf文件中的listen_addresses=’localhost’修改为listen_addresses=’*'

    vim /usr/local/postgreSQL/data/pg_hba.conf

    pg_hba.conf文件添加ipv4的可访问ip即可。例如:host all all 112.5.168.65/32 trust

    11.配置tcp连接心跳等参数,防止远程电脑时间长了自动断开连接

    tcp_keepalives_idle = 30 #间歇性发送TCP心跳包, 防止连接被网络设备中断.

    tcp_keepalives_interval = 15 # TCP_KEEPINTVL, in seconds;

    tcp_keepalives_count = 10  # TCP_KEEPCNT;

    12.错误分析:

    max_connections值太大,导致启动失败。

    max_connections是最大连接数,即允许客户端连接的最大连接数,增大连接可以允许接入更多的客户端,但设置过大同样会造成DB启动失败。

    FATAL: could not create semaphores: No space left on device

    日志查看:/usr/local/postgreSQL/data/serverlog

    相关文章

      网友评论

          本文标题:Linux下postgres的安装

          本文链接:https://www.haomeiwen.com/subject/kwssqftx.html