• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

linux怎么安装postgresql

mysql 搞java代码 3年前 (2022-05-21) 18次浏览 已收录 0个评论

linux安装postgresql

配置用户和组

groupadd postgres
useradd postgres -g postgres

www#gaodaima.com来源gao*daima.com搞@代#码网搞代码

环境准备

yum install -y perl-ExtUtils-Embed readline-<a href="https://www.gaodaima.com/tag/devel" title="查看更多关于devel的文章" target="_blank">devel</a> zlib-devel pam-devel libxml2-devel libxslt-devel 
openldap-devel 
 python-devel gcc-c++ openssl-devel cmake gcc* readline-devel

权限配置

mkdir /opt/postgres
chown -R postgres:postgres /opt/postgres/

配置环境变量

vi /etc/profile

#在文件末尾将以下环境变量添加进去
export PATH=/opt/postgres/bin:$PATH
export PGHOME=/opt/postgres
export PGDATA=/opt/postgres/data/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib/
export PATH=$PGHOME/bin:$PATH:$HOME/bin

安装过程

安装数据库

cd 下载好的压缩包存放路径#解压文件tar -zxvf postgresql-9.6.3.tar.gz

cd  postgresql-9.6.3#参数根据自己需求配置./configure --prefix=/opt/postgres/ --with-python --with-libxml 
--with-libxslt
make
make install****,安装过程内容太长就不截图了,从屏显的信息最后看到PostgreSQL installation complete. 就说明安装好了,
如果报错大多数都是安装包问题或者依赖没下载,看下错误信息基本都能解决****

2.初始化数据库

su postgres

#初始化数据库的参数也是根据自己需要添加 ,可以通过--help查看
/opt/postgres/bin/initdb -D $PGDATA  -E  UTF8  

#如果出现以下message就说明初始化成功了
*********************************************************************

    creating directory /opt/postgres/data ... ok
    creating subdirectories ... ok
    selecting default max_connections ... 100
    selecting default shared_buffers ... 128MB
    selecting dynamic shared memory implementation ... posix
    creating configuration files ... ok
    running bootstrap script ... ok
    performing post-bootstrap initialization ... ok
    syncing data to disk ... ok
    
    WARNING: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the option -A, or
    --auth-local and --auth-host, the next time you run initdb.
    
    Success. You can now start the database server using:
    
        /opt/postgres/bin/pg_ctl -D /opt/postgres/data -l logfile start
    
********************************************************************
#启动数据库服务

#数据文件和日志文件的路径根据自己需求指定。
/opt/postgres/bin/pg_ctl -D $PGDATA -l /opt/postgres/server.log start

到此postgres服务就安装完毕了。

使用数据库

进入数据库

su postgres

#进入数据库

[postgres@localhost postgres]$ psql
psql (9.6.3)
Type "help" for help.

postgres=#

修改数据库配置,允许其他服务器连接

#postgres安装好以后需要修改2个配置文件才能允许别的服务器访问。
cd /opt/postgres/data

vi postgresql.conf
#找到listen_addresses和port参数,修改如下,也可根据自己需求修改
listen_addresses = '*'
port = 5432

#根据自己的网段设置下放行的ip规则
vi pg_hba.conf

# IPv4 local connections:
host    all             all             192.168.0.0/16            md5

推荐学习《Python教程》。

来源:搞代码网:原文地址:https://www.gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:linux怎么安装postgresql

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址