Linux上怎么安装PostgreSQL
本篇内容主要讲解“Linux上怎么安装PostgreSQL”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux上怎么安装PostgreSQL”吧!
环境此处是从头学PG,为了适应两年后趋势,所以我选择的都是最新的版本
Redhat 7.8
PostgreSQL 12.2 源码
下载打开 PostgreSQL 官网 https://www.postgresql.org/,点击菜单栏上的 Download。
可以根据需要点击自己所需要的的版本,此处为了更好的学习PG,不落后其他大咖,我选择下载最新版本的源码
上传并解压
[root@node1soft]#bzip2-dpostgresql-12.2.tar.bz2[root@node1soft]#tar-xvfpostgresql-12.2.tarpostgresql-12.2/postgresql-12.2/.dir-locals.elpostgresql-12.2/contrib/postgresql-12.2/contrib/tcn/postgresql-12.2/contrib/tcn/tcn.control......(省略输出)[root@node1soft]#ls-lrttotal131200drwxrwxrwx611071107273Feb1017:29postgresql-12.2-rw-r--r--1rootroot134348800Apr3005:29postgresql-12.2.ta
安装 yum 包
yum-yinstallreadline-develyum-yinstallreadline
避免 ./configure 时报错
configure
[root@node1postgresql-12.2]#./configurecheckingbuildsystemtype...x86_64-pc-linux-gnucheckinghostsystemtype...x86_64-pc-linux-gnucheckingwhichtemplatetouse...linuxcheckingwhetherNLSiswanted...nocheckingfordefaultportnumber...5432checkingforblocksize...8kB......(省略输出)checkingforfop...nocheckingthreadsafetyofrequiredlibraryfunctions...yescheckingwhethergcc-std=gnu99supports-Wl,--as-needed...yesconfigure:usingcompiler=gcc(GCC)4.8.520150623(RedHat4.8.5-39)configure:usingCFLAGS=-Wall-Wmissing-prototypes-Wpointer-arith-Wdeclaration-after-statement-Werror=vla-Wendif-labels-Wmissing-format-attribute-Wformat-security-fno-strict-aliasing-fwrapv-fexcess-precision=standard-O2configure:usingCPPFLAGS=-D_GNU_SOURCEconfigure:usingLDFLAGS=-Wl,--as-neededconfigure:creating./config.statusconfig.status:creatingGNUmakefileconfig.status:creatingsrc/Makefile.globalconfig.status:creatingsrc/include/pg_config.hconfig.status:creatingsrc/include/pg_config_ext.hconfig.status:creatingsrc/interfaces/ecpg/include/ecpg_config.hconfig.status:linkingsrc/backend/port/tas/dummy.stosrc/backend/port/tas.sconfig.status:linkingsrc/backend/port/posix_sema.ctosrc/backend/port/pg_sema.cconfig.status:linkingsrc/backend/port/sysv_shmem.ctosrc/backend/port/pg_shmem.cconfig.status:linkingsrc/include/port/linux.htosrc/include/pg_config_os.hconfig.status:linkingsrc/makefiles/Makefile.linuxtosrc/Makefile.por
make && make install
[root@node1postgresql-12.2]#makemake-C./src/backendgenerated-headersmake[1]:Enteringdirectory`/soft/postgresql-12.2/src/backend'make-Ccatalogdistprepgenerated-header-symlinksmake[2]:Enteringdirectory`/soft/postgresql-12.2/src/backend/catalog'......(省略输出)make[2]:Nothingtobedonefor`all'.make[2]:Leavingdirectory`/soft/postgresql-12.2/src/test/perl'make[1]:Leavingdirectory`/soft/postgresql-12.2/src'make-Cconfigallmake[1]:Enteringdirectory`/soft/postgresql-12.2/config'make[1]:Nothingtobedonefor`all'.make[1]:Leavingdirectory`/soft/postgresql-12.2/config'AllofPostgreSQLsuccessfullymade.Readytoinstall.[root@node1postgresql-12.2]#makeinstallmake-C./src/backendgenerated-headersmake[1]:Enteringdirectory`/soft/postgresql-12.2/src/backend'make-Ccatalogdistprepgenerated-header-symlinksmake[2]:Enteringdirectory`/soft/postgresql-12.2/src/backend/catalog'make[2]:Nothingtobedonefor`distprep'.make[2]:Nothingtobedonefor`generated-header-symlinks'.......(省略输出)make-Cconfiginstallmake[1]:Enteringdirectory`/soft/postgresql-12.2/config'/usr/bin/mkdir-p'/usr/local/pgsql/lib/pgxs/config'/usr/bin/install-c-m755./install-sh'/usr/local/pgsql/lib/pgxs/config/install-sh'/usr/bin/install-c-m755./missing'/usr/local/pgsql/lib/pgxs/config/missing'make[1]:Leavingdirectory`/soft/postgresql-12.2/config'PostgreSQLinstallationcomplete
创建用户并配置密码
[root@node1postgresql-12.2]#useraddpostgres[root@node1postgresql-12.2]#passwdpostgresChangingpasswordforuserpostgres.Newpassword:BADPASSWORD:ThepasswordcontainstheusernameinsomeformRetypenewpassword:passwd:allauthenticationtokensupdatedsuccessfully
创建数据目录并授权
[root@node1postgresql-12.2]#mkdir-p/data/pg_data[root@node1postgresql-12.2]#chownpostgres:postgres-R/data[root@node1postgresql-12.2]#cd/usr/local[root@node1local]#lltotal0drwxr-xr-x.2rootroot6Dec142017bindrwxr-xr-x.2rootroot6Dec142017etcdrwxr-xr-x.2rootroot6Dec142017gamesdrwxr-xr-x.2rootroot6Dec142017includedrwxr-xr-x.2rootroot6Dec142017libdrwxr-xr-x.2rootroot6Dec142017lib64drwxr-xr-x.2rootroot6Dec142017libexecdrwxr-xr-x6postgrespostgres56Apr3005:53pgsqldrwxr-xr-x.2rootroot6Dec142017sbindrwxr-xr-x.5rootroot49Apr1612:09sharedrwxr-xr-x.2rootroot6Dec142017src[root@node1local]#chownpostgres:postgres-Rpgsq
配置 postgres 用户
[postgres@node1~]$cat.bash_profileexportPATH=$PATH:/usr/local/pgsql/binexportPGDATA=/data/pg_data[postgres@node1~]$source.bash_profile
初始化数据库
[postgres@node1~]$initdb-D/data/pg_data/Thefilesbelongingtothisdatabasesystemwillbeownedbyuser"postgres".Thisusermustalsoowntheserverprocess.Thedatabaseclusterwillbeinitializedwithlocale"en_US.UTF-8".Thedefaultdatabaseencodinghasaccordinglybeensetto"UTF8".Thedefaulttextsearchconfigurationwillbesetto"english".Datapagechecksumsaredisabled.fixingpermissionsonexistingdirectory/data/pg_data...okcreatingsubdirectories...okselectingdynamicsharedmemoryimplementation...posixselectingdefaultmax_connections...100selectingdefaultshared_buffers...128MBselectingdefaulttimezone...America/New_Yorkcreatingconfigurationfiles...okrunningbootstrapscript...okperformingpost-bootstrapinitialization...oksyncingdatatodisk...okinitdb:warning:enabling"trust"authenticationforlocalconnectionsYoucanchangethisbyeditingpg_hba.conforusingtheoption-A,or--auth-localand--auth-host,thenexttimeyouruninitdb.Success.Youcannowstartthedatabaseserverusing:pg_ctl-D/data/pg_data/-llogfilestar
启动数据库
[postgres@node1~]$pg_ctl-D/data/pg_data/startwaitingforservertostart....2020-04-3006:34:29.841EDT[53149]LOG:startingPostgreSQL12.2onx86_64-pc-linux-gnu,compiledbygcc(GCC)4.8.520150623(RedHat4.8.5-39),64-bit2020-04-3006:34:29.841EDT[53149]LOG:listeningonIPv6address"::1",port54322020-04-3006:34:29.841EDT[53149]LOG:listeningonIPv4address"127.0.0.1",port54322020-04-3006:34:29.844EDT[53149]LOG:listeningonUnixsocket"/tmp/.s.PGSQL.5432"2020-04-3006:34:29.856EDT[53150]LOG:databasesystemwasshutdownat2020-04-3006:29:52EDT2020-04-3006:34:29.858EDT[53149]LOG:databasesystemisreadytoacceptconnectionsdoneserverstarte
关闭数据库
[postgres@node1~]$pg_ctl-D/data/pg_data/stopwaitingforservertoshutdown....2020-04-3006:35:27.573EDT[53149]LOG:receivedfastshutdownrequest2020-04-3006:35:27.574EDT[53149]LOG:abortinganyactivetransactions2020-04-3006:35:27.574EDT[53149]LOG:backgroundworker"logicalreplicationlauncher"(PID53156)exitedwithexitcode12020-04-3006:35:27.575EDT[53151]LOG:shuttingdown2020-04-3006:35:27.584EDT[53149]LOG:databasesystemisshutdowndoneserverstopped
到此,相信大家对“Linux上怎么安装PostgreSQL”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。