三、 源码安装

3.1. 下载地址:

https://www.postgresql.org/ftp/source/

3.2 环境要求

make 版本 3.80以上

[root@open_source~]#make-versionGNUMake3.82Builtforx86_64-redhat-linux-gnuCopyright(C)2010FreeSoftwareFoundation,Inc.LicenseGPLv3+:GNUGPLversion3orlater<http://gnu.org/licenses/gpl.html>Thisisfreesoftware:youarefreetochangeandredistributeit.ThereisNOWARRANTY,totheextentpermittedbylaw.

gcc 版本4.5以上

[root@open_sourceCentOS_yum]#gcc--versiongcc(GCC)4.8.520150623(RedHat4.8.5-39)Copyright(C)2015FreeSoftwareFoundation,Inc.Thisisfreesoftware;seethesourceforcopyingconditions.ThereisNOwarranty;notevenforMERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.

tar gzip bzip 是否安装

源码包使用的是tar,gzip,bzip2打包压缩的,所以我们需要使用tar gzip bzip这些工具解压

[root@open_sourceCentOS_yum]#tar--versiontar(GNUtar)1.26Copyright(C)2011FreeSoftwareFoundation,Inc.LicenseGPLv3+:GNUGPLversion3orlater<http://gnu.org/licenses/gpl.html>.Thisisfreesoftware:youarefreetochangeandredistributeit.ThereisNOWARRANTY,totheextentpermittedbylaw.WrittenbyJohnGilmoreandJayFenlason.[root@open_sourceCentOS_yum]#gzip--versiongzip1.5Copyright(C)2007,2010,2011FreeSoftwareFoundation,Inc.Copyright(C)1993Jean-loupGailly.Thisisfreesoftware.YoumayredistributecopiesofitunderthetermsoftheGNUGeneralPublicLicense<http://www.gnu.org/licenses/gpl.html>.ThereisNOWARRANTY,totheextentpermittedbylaw.WrittenbyJean-loupGailly.

3.3 安装其它依赖包

yuminstall-y\libicu-devel.x86_64\icu.x86_64\tcl.x86_64\tcl-devel.x86_64\perl-ExtUtils-Embed.noarch\readline-devel.x86_64\zlib-devel\openssl-devel\pam-devel.x86_64\libxml2\libxml2-devel\libxslt-devel\zlib-devel\openldap-devel.x86_64[root@open_source~]#rpm-qa--queryformat"%{NAME}-%{VERSION}-%{RELEASE}(%{ARCH})\n"libicu-devel\>icu\>tcl\>tcl-devel\>perl-ExtUtils-Embed\>readline-devel\>zlib-devel\>openssl-devel\>pam-devel\>libxml2\>libxml2-devel\>libxslt-devel\>zlib-devel\>openldap-develzlib-devel-1.2.7-18.el7(x86_64)perl-ExtUtils-Embed-1.30-294.el7_6(noarch)openldap-devel-2.4.44-21.el7_6(x86_64)libxml2-2.9.1-6.el7_2.3(x86_64)libxml2-devel-2.9.1-6.el7_2.3(x86_64)tcl-devel-8.5.13-8.el7(x86_64)openssl-devel-1.0.2k-19.el7(x86_64)libxslt-devel-1.1.28-5.el7(x86_64)pam-devel-1.1.8-22.el7(x86_64)tcl-8.5.13-8.el7(x86_64)readline-devel-6.2-11.el7(x86_64)libicu-devel-50.2-3.el7(x86_64)

3.3 解压PostgreSQL安装包并进入目录

[root@open_source~]#lspostgresql-10.12.tar.bz2postgresql-10.12.tar.bz2[root@open_source~]#tar-jxfpostgresql-10.12.tar.bz2[root@open_source~]#ls-rldpostgresql-10.12drwxrwxrwx611071107273Feb1017:32postgresql-10.12[root@open_source~]#cdpostgresql-10.12[root@open_sourcepostgresql-10.12]#ls-rtltotal684-rw-r--r--1110711071212Feb1017:19README-rw-r--r--1110711071665Feb1017:19Makefile-rw-r--r--111071107284Feb1017:19HISTORY-rw-r--r--1110711073822Feb1017:19GNUmakefile.in-rw-r--r--1110711071192Feb1017:19COPYRIGHT-rw-r--r--11107110779645Feb1017:19configure.in-rwxr-xr-x111071107507965Feb1017:19configure-rw-r--r--111071107493Feb1017:19aclocal.m4drwxrwxrwx55110711074096Feb1017:31contribdrwxrwxrwx311071107107Feb1017:31docdrwxrwxrwx2110711074096Feb1017:31config-rw-r--r--11107110773124Feb1017:32INSTALLdrwxrwxrwx1611071107328Feb1017:32src

3.4 理解编译安装

[root@open_sourcepostgresql-10.12]#./configure--help`configure'configuresPostgreSQL10.12toadapttomanykindsofsystems.Usage:./configure[OPTION]...[VAR=VALUE]...Toassignenvironmentvariables(e.g.,CC,CFLAGS...),specifythemasVAR=VALUE.Seebelowfordescriptionsofsomeoftheusefulvariables.Defaultsfortheoptionsarespecifiedinbrackets.Configuration:-h,--helpdisplaythishelpandexit--help=shortdisplayoptionsspecifictothispackage--help=recursivedisplaytheshorthelpofalltheincludedpackages-V,--versiondisplayversioninformationandexit-q,--quiet,--silentdonotprint`checking...'messages--cache-file=FILEcachetestresultsinFILE[disabled]-C,--config-cachealiasfor`--cache-file=config.cache'-n,--no-createdonotcreateoutputfiles--srcdir=DIRfindthesourcesinDIR[configurediror`..']Installationdirectories:--prefix=PREFIXinstallarchitecture-independentfilesinPREFIX[/usr/local/pgsql]--exec-prefix=EPREFIXinstallarchitecture-dependentfilesinEPREFIX[PREFIX]Bydefault,`makeinstall'willinstallallthefilesin`/usr/local/pgsql/bin',`/usr/local/pgsql/lib'etc.Youcanspecifyaninstallationprefixotherthan`/usr/local/pgsql'using`--prefix',forinstance`--prefix=$HOME'.Forbettercontrol,usetheoptionsbelow.Finetuningoftheinstallationdirectories:--bindir=DIRuserexecutables[EPREFIX/bin]--sbindir=DIRsystemadminexecutables[EPREFIX/sbin]--libexecdir=DIRprogramexecutables[EPREFIX/libexec]--sysconfdir=DIRread-onlysingle-machinedata[PREFIX/etc]--sharedstatedir=DIRmodifiablearchitecture-independentdata[PREFIX/com]--localstatedir=DIRmodifiablesingle-machinedata[PREFIX/var]--libdir=DIRobjectcodelibraries[EPREFIX/lib]--includedir=DIRCheaderfiles[PREFIX/include]--oldincludedir=DIRCheaderfilesfornon-gcc[/usr/include]--datarootdir=DIRread-onlyarch.-independentdataroot[PREFIX/share]--datadir=DIRread-onlyarchitecture-independentdata[DATAROOTDIR]--infodir=DIRinfodocumentation[DATAROOTDIR/info]--localedir=DIRlocale-dependentdata[DATAROOTDIR/locale]--mandir=DIRmandocumentation[DATAROOTDIR/man]--docdir=DIRdocumentationroot[DATAROOTDIR/doc/postgresql]--htmldir=DIRhtmldocumentation[DOCDIR]--dvidir=DIRdvidocumentation[DOCDIR]--pdfdir=DIRpdfdocumentation[DOCDIR]--psdir=DIRpsdocumentation[DOCDIR]Systemtypes:--build=BUILDconfigureforbuildingonBUILD[guessed]--host=HOSTcross-compiletobuildprogramstorunonHOST[BUILD]OptionalFeatures:--disable-option-checkingignoreunrecognized--enable/--withoptions--disable-FEATUREdonotincludeFEATURE(sameas--enable-FEATURE=no)--enable-FEATURE[=ARG]includeFEATURE[ARG=yes]--disable-integer-datetimesobsoleteoption,nolongersupported--enable-nls[=LANGUAGES]enableNativeLanguageSupport--disable-rpathdonotembedsharedlibrarysearchpathinexecutables--disable-spinlocksdonotusespinlocks--disable-atomicsdonotuseatomicoperations--disable-strong-randomdonotuseastrongrandomnumbersource--enable-debugbuildwithdebuggingsymbols(-g)--enable-profilingbuildwithprofilingenabled--enable-coveragebuildwithcoveragetestinginstrumentation--enable-dtracebuildwithDTracesupport--enable-tap-testsenableTAPtests(requiresPerlandIPC::Run)--enable-dependturnonautomaticdependencytracking--enable-cassertenableassertionchecks(fordebugging)--disable-thread-safetydisablethread-safetyinclientlibraries--disable-largefileomitsupportforlargefiles--disable-float4-byvaldisablefloat4passedbyvalue--disable-float8-byvaldisablefloat8passedbyvalueOptionalPackages:--with-PACKAGE[=ARG]usePACKAGE[ARG=yes]--without-PACKAGEdonotusePACKAGE(sameas--with-PACKAGE=no)--with-extra-version=STRINGappendSTRINGtoversion--with-template=NAMEoverrideoperatingsystemtemplate--with-includes=DIRSlookforadditionalheaderfilesinDIRS--with-libraries=DIRSlookforadditionallibrariesinDIRS--with-libs=DIRSalternativespellingof--with-libraries--with-pgport=PORTNUMsetdefaultportnumber[5432]--with-blocksize=BLOCKSIZEsettableblocksizeinkB[8]--with-segsize=SEGSIZEsettablesegmentsizeinGB[1]--with-wal-blocksize=BLOCKSIZEsetWALblocksizeinkB[8]--with-wal-segsize=SEGSIZEsetWALsegmentsizeinMB[16]--with-CC=CMDsetcompiler(deprecated)--with-icubuildwithICUsupport--with-tclbuildTclmodules(PL/Tcl)--with-tclconfig=DIRtclConfig.shisinDIR--with-perlbuildPerlmodules(PL/Perl)--with-pythonbuildPythonmodules(PL/Python)--with-gssapibuildwithGSSAPIsupport--with-krb-srvnam=NAMEdefaultserviceprincipalnameinKerberos(GSSAPI)[postgres]--with-pambuildwithPAMsupport--with-bsd-authbuildwithBSDAuthenticationsupport--with-ldapbuildwithLDAPsupport--with-bonjourbuildwithBonjoursupport--with-opensslbuildwithOpenSSLsupport--with-selinuxbuildwithSELinuxsupport--with-systemdbuildwithsystemdsupport--without-readlinedonotuseGNUReadlinenorBSDLibeditforediting--with-libedit-preferredpreferBSDLibeditoverGNUReadline--with-uuid=LIBbuildcontrib/uuid-osspusingLIB(bsd,e2fs,ossp)--with-ossp-uuidobsoletespellingof--with-uuid=ossp--with-libxmlbuildwithXMLsupport--with-libxsltuseXSLTsupportwhenbuildingcontrib/xml2--with-system-tzdata=DIRusesystemtimezonedatainDIR--without-zlibdonotuseZlib--with-gnu-ldassumetheCcompilerusesGNUld[default=no]Someinfluentialenvironmentvariables:CCCcompilercommandCFLAGSCcompilerflagsLDFLAGSlinkerflags,e.g.-L<libdir>ifyouhavelibrariesinanonstandarddirectory<libdir>LIBSlibrariestopasstothelinker,e.g.-l<library>CPPFLAGS(Objective)C/C++preprocessorflags,e.g.-I<includedir>ifyouhaveheadersinanonstandarddirectory<includedir>CPPCpreprocessorPKG_CONFIGpathtopkg-configutilityPKG_CONFIG_PATHdirectoriestoaddtopkg-config'ssearchpathPKG_CONFIG_LIBDIRpathoverridingpkg-config'sbuilt-insearchpathICU_CFLAGSCcompilerflagsforICU,overridingpkg-configICU_LIBSlinkerflagsforICU,overridingpkg-configLDFLAGS_EXextralinkerflagsforlinkingexecutablesonlyLDFLAGS_SLextralinkerflagsforlinkingsharedlibrariesonlyUsethesevariablestooverridethechoicesmadeby`configure'ortohelpittofindlibrariesandprogramswithnonstandardnames/locations.Reportbugsto<pgsql-bugs@postgresql.org>.

3.5. 安装PostgreSQL 10

[root@open_sourcepostgresql-10.12]#./configure\>--prefix=/data/pgsql10/\>--bindir=/data/pgsql10/bin\>--sysconfdir=/data/pgsql10/etc\>--libdir=/data/pgsql10/lib\>--includedir=/data/pgsql10/include\>--datarootdir=/data/pgsql10/share/\>--datadir=/data/pgsql10/share/\>--localedir=/data/pgsql10/share/locale\>--mandir=/data/pgsql10/share/man\>--docdir=/data/pgsql10/share/doc\>--htmldir=/data/pgsql10/share/html\>--enable-nls\>--with-pgport=5435\>--with-perl\>--with-python\>--with-tcl\>--with-icu\>--with-openssl\>--with-pam\>--with-ldap\>--with-readline\>--with-libxml\>--with-libxslt\>--with-blocksize=8\>--with-wal-segsize=16\>--with-wal-blocksize=8\>--with-zlib\[root@open_sourcepostgresql-10.12]#exportCOPT=”-Werror”[root@open_sourcepostgresql-10.12]#make&&makeinstall……make[1]:Leavingdirectory`/root/postgresql-10.12/src'make-Cconfiginstallmake[1]:Enteringdirectory`/root/postgresql-10.12/config'/usr/bin/mkdir-p'/data/pgsql10/lib/pgxs/config'/usr/bin/install-c-m755./install-sh'/data/pgsql10/lib/pgxs/config/install-sh'/usr/bin/install-c-m755./missing'/data/pgsql10/lib/pgxs/config/missing'make[1]:Leavingdirectory`/root/postgresql-10.12/config'PostgreSQLinstallationcomplete.[root@open_sourcepostgresql-10.12]#ls-rtl/data/pgsql10/total16drwxr-xr-x2rootroot6Mar516:28pgdatadrwxr-xr-x6rootroot4096Mar516:43includedrwxr-xr-x2rootroot4096Mar516:43bindrwxr-xr-x7rootroot4096Mar516:43sharedrwxr-xr-x4rootroot4096Mar516:43lib

3.6 配置postgresql用户环境变量

[root@open_source~]#echo"exportLD_LIBRARY_PATH=/data/pgsql10/lib">>/home/postgres/.bash_profile[root@open_source~]#echo"exportPATH=/data/pgsql10/bin:/usr/bin:/usr/sbin:/sbin:\$PATH">>/home/postgres/.bash_profile[root@open_source~]#echo"exportMANPATH=/data/pgsql10/share/man/:\$MANPATH">>/home/postgres/.bash_profile

3.7 创建数据目录

[root@open_source~]#mkdir-p/data/pgsql10/pgdata

3.8 初始化数据库

[postgres@open_source~]$initdb-D/data/pgsql10/pgdataThefilesbelongingtothisdatabasesystemwillbeownedbyuser"postgres".Thisusermustalsoowntheserverprocess.Thedatabaseclusterwillbeinitializedwithlocale"en_US.utf8".Thedefaultdatabaseencodinghasaccordinglybeensetto"UTF8".Thedefaulttextsearchconfigurationwillbesetto"english".Datapagechecksumsaredisabled.fixingpermissionsonexistingdirectory/data/pgsql10/pgdata...okcreatingsubdirectories...okselectingdefaultmax_connections...100selectingdefaultshared_buffers...128MBselectingdefaulttimezone...America/New_Yorkselectingdynamicsharedmemoryimplementation...posixcreatingconfigurationfiles...okrunningbootstrapscript...okperformingpost-bootstrapinitialization...oksyncingdatatodisk...okWARNING:enabling"trust"authenticationforlocalconnectionsYoucanchangethisbyeditingpg_hba.conforusingtheoption-A,or--auth-localand--auth-host,thenexttimeyouruninitdb.Success.Youcannowstartthedatabaseserverusing:pg_ctl-D/data/pgsql10/pgdata-llogfilestart

3.9 启动数据库

[postgres@open_source~]$pg_ctlstart-D/data/pgsql10/pgdata/-l/tmp/logfilewaitingforservertostart....doneserverstarted


3.10 登录到数据库

[postgres@open_source~]$psqlpsql(10.12)Type"help"forhelp.postgres=#[postgres@open_source~]$psql-Upostgres-dpostgres-p5435psql(10.12)Type"help"forhelp.postgres=#[postgres@open_source~]$psql-Upostgres-dpostgres-h127.0.0.1-p5435psql(10.12)Type"help"forhelp.postgres=#selectversion();version----------------------------------------------------------------------------------------------------------PostgreSQL10.12onx86_64-pc-linux-gnu,compiledbygcc(GCC)4.8.520150623(RedHat4.8.5-39),64-bit