源码安装Postgresql9.5

前端之家收集整理的这篇文章主要介绍了源码安装Postgresql9.5前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Postgresql简介:

Postgresql是一个功能强大,开源对象关系型数据库系统。它拥有超过15年的持续开发和经验证的体系结构,赢得了良好的声誉:可靠性,数据完整性和正确性

官方号称:

Postgresql: The world's most advanced open source database

官网下载地址:https://www.postgresql.org/download/

Postgresql部署:

环境:

[root@node-01~]#cat/etc/redhat-release
CentOSLinuxrelease7.2.1511(Core)

下载包:

[root@node-01~]#wgethttps://ftp.postgresql.org/pub/source/v9.5.4/postgresql-9.5.4.tar.gz

安装依赖包:

[root@node-01~]#yuminstallgccgcc-c++automakeautoconflibtoolmakereadline-develzlib-devel-y
[root@node-01~]#yuminstall-yperl-ExtUtils-Embedperl-ExtUtils-MakeMakeperl-ExtUtils-MakeMaker-Coveragereadlinereadline-develpampam-devellibxml2libxml-devellibxml2-pythonlibxml2-staticlibxsltlibxslt-develtcltcl-develpython-developensslopenssl-devel

创建postgresql用户及设置密码(postgresql默认不允许root用户启动):

[root@node-01~]#useradd-u6233-p123456postgres
[root@node-01~]#idpostgres
uid=6233(postgres)gid=6233(postgres)groups=6233(postgres)

编译安装postgresql:

[root@node-01~]#tar-xfpostgresql-9.5.4.tar.gz
[root@node-01~]#cdpostgresql-9.5.4
[root@node-01postgresql-9.5.4]#./configure--prefix=/usr/local/postgresql--with-pgport=1921--with-perl--with-tcl--with-python--with-openssl--with-pam--with-libxml--with-libxslt--enable-thread-safety--with-wal-blocksize=16--with-blocksize=16
编译安装有两种方式:make和gmake,这里推荐gmake
方法1:gmakeworld&&gmakeinstall-world
方法2:make-j4&&makeinstall
[root@node-01postgresql-9.5.4]#gmakeworld&&gmakeinstall-world
[root@node-01postgresql-9.5.4]#ls/usr/local/postgresql/
binincludelibshare

设置数据库目录及权限:

[root@node-01~]#mkdir-p/data/postgresql
[root@node-01~]#chown-Rpostgres.postgres/data/postgresql/

添加系统环境变量:

[root@node-01~]#echo'exportPATH=$PATH:/usr/local/postgresql/bin/'>>/etc/profile
[root@node-01~]#psql-V
psql(Postgresql)9.5.4

初始化数据库

[root@node-01~]#su-postgres
[postgres@node-01~]$initdb-D/data/postgresql/-Upostgres-EUTF8--locale=C-W
Thefilesbelongingtothisdatabasesystemwillbeownedbyuser"postgres".
Thisusermustalsoowntheserverprocess.

Thedatabaseclusterwillbeinitializedwithlocale"C".
Thedefaulttextsearchconfigurationwillbesetto"english".

Datapagechecksumsaredisabled.

fixingpermissionsonexistingdirectory/data/postgresql...ok
creatingsubdirectories...ok
selectingdefaultmax_connections...100
selectingdefaultshared_buffers...128MB
selectingdynamicsharedmemoryimplementation...posix
creatingconfigurationfiles...ok
creatingtemplate1databasein/data/postgresql/base/1...ok
initializingpg_authid...ok
Enternewsuperuserpassword:设置超级用户的密码
Enteritagain:
settingpassword...ok
initializingdependencies...ok
creatingsystemviews...ok
loadingsystemobjects'descriptions...ok
creatingcollations...ok
creatingconversions...ok
creatingdictionaries...ok
settingprivilegesonbuilt-inobjects...ok
creatinginformationschema...ok
loadingPL/pgsqlserver-sidelanguage...ok
vacuumingdatabasetemplate1...ok
copyingtemplate1totemplate0...ok
copyingtemplate1topostgres...ok
syncingdatatodisk...ok

WARNING:enabling"trust"authenticationforlocalconnections
Youcanchangethisbyeditingpg_hba.conforusingtheoption-A,or
--auth-localand--auth-host,thenexttimeyouruninitdb.

Success.Youcannowstartthedatabaseserverusing:

pg_ctl-D/data/postgresql/-llogfilestart

参数:
-Upostgres:指定的数据库超级管理员自定义
-W:设置密码
-D:数据存放目录
-E:设置编译

修改验证方式简单的配置:

[postgres@node-01~]$vim/data/postgresql/pg_hba.conf
hostallall127.0.0.1/32md5MD5验证方式需要输入用户密码
[postgres@node-01~]$vim/data/postgresql/postgresql.conf
port=1236#(changerequiresrestart)
max_connections=100
unix_socket_directories='/dev/shm/'

添加服务管理脚本:

[root@node-01~]#cdpostgresql-9.5.4
[root@node-01postgresql-9.5.4]#cpcontrib/start-scripts/linux/etc/init.d/postgresql
[root@node-01postgresql-9.5.4]#chmod+x/etc/init.d/postgresql
[root@node-01postgresql-9.5.4]#chkconfigpostgresqlon
[root@node-01postgresql-9.5.4]#vim/etc/init.d/postgresql
prefix=/usr/local/postgresql
PGDATA="/data/postgresql"
PGUSER=postgres
PGLOG="$PGDATA/serverlog"

启动postgresql:

[root@node-01postgresql-9.5.4]#/etc/init.d/postgresqlstart
[root@node-01postgresql-9.5.4]#lsof-i:1236
COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAME
postmaste16232postgres3uIPv6532560t0TCPlocalhost:bvcontrol(LISTEN)
postmaste16232postgres4uIPv4532570t0TCPlocalhost:bvcontrol(LISTEN)

登陆postgresql:

[root@node-01~]#psql-h127.0.0.1-p1236-Upostgres-dpostgres
Passwordforuserpostgres:
psql(9.5.4)
Type"help"forhelp.

postgres=#

安装所有的扩展包:

[root@node-01~]#cdpostgresql-9.5.4/contrib/
[root@node-01contrib]#ls-d*/|xargs-n1-P0sh-c'cd{};make;makeinstall;'c

猜你在找的Postgre SQL相关文章