小编给大家分享一下linux安装postgresql的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

linux安装postgresql

配置用户和组

groupaddpostgresuseraddpostgres-gpostgres

环境准备

yuminstall-yperl-ExtUtils-Embedreadline-develzlib-develpam-devellibxml2-devellibxslt-developenldap-develpython-develgcc-c++openssl-develcmakegcc*readline-devel

权限配置

mkdir/opt/postgreschown-Rpostgres:postgres/opt/postgres/

配置环境变量

vi/etc/profile#在文件末尾将以下环境变量添加进去exportPATH=/opt/postgres/bin:$PATHexportPGHOME=/opt/postgresexportPGDATA=/opt/postgres/data/exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib/exportPATH=$PGHOME/bin:$PATH:$HOME/bin

安装过程

安装数据库

cd下载好的压缩包存放路径#解压文件tar-zxvfpostgresql-9.6.3.tar.gzcdpostgresql-9.6.3#参数根据自己需求配置./configure--prefix=/opt/postgres/--with-python--with-libxml--with-libxsltmakemakeinstall****,安装过程内容太长就不截图了,从屏显的信息最后看到PostgreSQLinstallationcomplete.就说明安装好了,如果报错大多数都是安装包问题或者依赖没下载,看下错误信息基本都能解决****

2.初始化数据库

supostgres#初始化数据库的参数也是根据自己需要添加,可以通过--help查看/opt/postgres/bin/initdb-D$PGDATA-EUTF8#如果出现以下message就说明初始化成功了*********************************************************************creatingdirectory/opt/postgres/data...okcreatingsubdirectories...okselectingdefaultmax_connections...100selectingdefaultshared_buffers...128MBselectingdynamicsharedmemoryimplementation...posixcreatingconfigurationfiles...okrunningbootstrapscript...okperformingpost-bootstrapinitialization...oksyncingdatatodisk...okWARNING:enabling"trust"authenticationforlocalconnectionsYoucanchangethisbyeditingpg_hba.conforusingtheoption-A,or--auth-localand--auth-host,thenexttimeyouruninitdb.Success.Youcannowstartthedatabaseserverusing:/opt/postgres/bin/pg_ctl-D/opt/postgres/data-llogfilestart********************************************************************#启动数据库服务#数据文件和日志文件的路径根据自己需求指定。/opt/postgres/bin/pg_ctl-D$PGDATA-l/opt/postgres/server.logstart

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

使用数据库

进入数据库

supostgres#进入数据库[postgres@localhostpostgres]$psqlpsql(9.6.3)Type"help"forhelp.postgres=#

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

#postgres安装好以后需要修改2个配置文件才能允许别的服务器访问。cd/opt/postgres/datavipostgresql.conf#找到listen_addresses和port参数,修改如下,也可根据自己需求修改listen_addresses='*'port=5432#根据自己的网段设置下放行的ip规则vipg_hba.conf#IPv4localconnections:hostallall192.168.0.0/16md5

看完了这篇文章,相信你对linux安装postgresql的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!