这篇文章主要介绍“PostgreSQL 10.12本地RPM安装的方法是什么”,在日常操作中,相信很多人在PostgreSQL 10.12本地RPM安装的方法是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”PostgreSQL 10.12本地RPM安装的方法是什么”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

二、 本地RPM安装

本地RPM包下载地址:

https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7.7-x86_64/

找到如下两个包下载即可:

postgresql10-10.12-1PGDG.rhel7.x86_64.rpm

postgresql10-server-10.12-1PGDG.rhel7.x86_64.rpm

创建用于管理PG的用户和组:

[root@open_source~]#groupaddpostgres[root@open_source~]#useradd-gpostgrespostgres[root@open_source~]#passwdpostgresChangingpasswordforuserpostgres.Newpassword:BADPASSWORD:ThepasswordcontainstheusernameinsomeformRetypenewpassword:passwd:allauthenticationtokensupdatedsuccessfully.

本地安装PostgreSQL 10.12:

[root@open_source~]#ls-rtltotal6632-rw-r--r--1rootroot6048Feb2315:47pgdg-redhat-repo-latest.noarch.rpm-rw-r--r--1rootroot1657936Feb2316:14postgresql10-10.12-1PGDG.rhel7.x86_64.rpm-rw-r--r--1rootroot4753176Feb2316:14postgresql10-server-10.12-1PGDG.rhel7.x86_64.rpm-rw-r--r--1rootroot365156Feb2316:23postgresql10-libs-10.12-1PGDG.rhel7.x86_64.rpm[root@open_source~]#rpm-ivhpostgresql10-libs-10.12-1PGDG.rhel7.x86_64.rpmwarning:postgresql10-libs-10.12-1PGDG.rhel7.x86_64.rpm:HeaderV4DSA/SHA1Signature,keyID442df0f8:NOKEYPreparing...#################################[100%]Updating/installing...1:postgresql10-libs-10.12-1PGDG.rhe#################################[100%][root@open_source~]#rpm-ivhpostgresql10-10.12-1PGDG.rhel7.x86_64.rpmwarning:postgresql10-10.12-1PGDG.rhel7.x86_64.rpm:HeaderV4DSA/SHA1Signature,keyID442df0f8:NOKEYPreparing...#################################[100%]Updating/installing...1:postgresql10-10.12-1PGDG.rhel7#################################[100%][root@open_source~]#rpm-ivhpostgresql10-server-10.12-1PGDG.rhel7.x86_64.rpmwarning:postgresql10-server-10.12-1PGDG.rhel7.x86_64.rpm:HeaderV4DSA/SHA1Signature,keyID442df0f8:NOKEYPreparing...#################################[100%]Updating/installing...1:postgresql10-server-10.12-1PGDG.r#################################[100%]检查安装是否成功:[root@open_source~]#rpm-qa|greppostgresql10postgresql10-10.12-1PGDG.rhel7.x86_64postgresql10-libs-10.12-1PGDG.rhel7.x86_64postgresql10-server-10.12-1PGDG.rhel7.x86_64

初始化数据库:

[root@open_source~]#/usr/pgsql-10/bin/postgresql-10-setupinitdbInitializingdatabase...OK

检查配置:

[root@open_source~]#cat/usr/lib/systemd/system/postgresql-10.service|egrep-v"^$|^#"[Unit]Description=PostgreSQL10databaseserverDocumentation=https://www.postgresql.org/docs/10/static/After=syslog.targetAfter=network.target[Service]Type=notifyUser=postgresGroup=postgresEnvironment=PGDATA=/var/lib/pgsql/10/data/OOMScoreAdjust=-1000Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adjEnvironment=PG_OOM_ADJUST_VALUE=0ExecStartPre=/usr/pgsql-10/bin/postgresql-10-check-db-dir${PGDATA}ExecStart=/usr/pgsql-10/bin/postmaster-D${PGDATA}ExecReload=/bin/kill-HUP$MAINPIDKillMode=mixedKillSignal=SIGINTTimeoutSec=0[Install]WantedBy=multi-user.target

启动数据库方法一:

[root@open_source~]#systemctlstartpostgresql-10.service[root@open_sourcebin]#systemctlstatuspostgresql-10*postgresql-10.service-PostgreSQL10databaseserverLoaded:loaded(/usr/lib/systemd/system/postgresql-10.service;disabled;vendorpreset:disabled)Active:active(running)sinceSun2020-02-2317:07:19EST;55minagoDocs:https://www.postgresql.org/docs/10/static/Process:12481ExecStartPre=/usr/pgsql-10/bin/postgresql-10-check-db-dir${PGDATA}(code=exited,status=0/SUCCESS)MainPID:12486(postmaster)CGroup:/system.slice/postgresql-10.service|-12486/usr/pgsql-10/bin/postmaster-D/var/lib/pgsql/10/data/|-12488postgres:loggerprocess|-12490postgres:checkpointerprocess|-12491postgres:writerprocess|-12492postgres:walwriterprocess|-12493postgres:autovacuumlauncherprocess|-12494postgres:statscollectorprocess`-12495postgres:bgworker:logicalreplicationlauncherFeb2317:07:19open_sourcesystemd[1]:StartingPostgreSQL10databaseserver...Feb2317:07:19open_sourcepostmaster[12486]:2020-02-2317:07:19.702EST[12486]LOG:listeningonIPv6address"::1",port5432Feb2317:07:19open_sourcepostmaster[12486]:2020-02-2317:07:19.702EST[12486]LOG:listeningonIPv4address"127.0....t5432Feb2317:07:19open_sourcepostmaster[12486]:2020-02-2317:07:19.703EST[12486]LOG:listeningonUnixsocket"/var/ru....5432"Feb2317:07:19open_sourcepostmaster[12486]:2020-02-2317:07:19.704EST[12486]LOG:listeningonUnixsocket"/tmp/.s....5432"Feb2317:07:19open_sourcepostmaster[12486]:2020-02-2317:07:19.710EST[12486]LOG:redirectinglogoutputtologging...rocessFeb2317:07:19open_sourcepostmaster[12486]:2020-02-2317:07:19.710EST[12486]HINT:Futurelogoutputwillappearin..."log".Feb2317:07:19open_sourcesystemd[1]:StartedPostgreSQL10databaseserver.Hint:Somelineswereellipsized,use-ltoshowinfull.[root@open_source~]#ps-ef|grep-ipostgres|grep-vgreppostgres124861017:07?00:00:00/usr/pgsql-10/bin/postmaster-D/var/lib/pgsql/10/data/postgres1248812486017:07?00:00:00postgres:loggerprocesspostgres1249012486017:07?00:00:00postgres:checkpointerprocesspostgres1249112486017:07?00:00:00postgres:writerprocesspostgres1249212486017:07?00:00:00postgres:walwriterprocesspostgres1249312486017:07?00:00:00postgres:autovacuumlauncherprocesspostgres1249412486017:07?00:00:00postgres:statscollectorprocesspostgres1249512486017:07?00:00:00postgres:bgworker:logicalreplicationlauncher

启动数据库方法二:

[postgres@open_source~]$cd/usr/pgsql-10/bin/[postgres@open_sourcebin]$./pg_ctlstartwaitingforservertostart....2020-02-2318:04:33.686EST[12823]LOG:listeningonIPv4address"127.0.0.1",port54322020-02-2318:04:33.687EST[12823]LOG:listeningonUnixsocket"/var/run/postgresql/.s.PGSQL.5432"2020-02-2318:04:33.688EST[12823]LOG:listeningonUnixsocket"/tmp/.s.PGSQL.5432"2020-02-2318:04:33.693EST[12823]LOG:redirectinglogoutputtologgingcollectorprocess2020-02-2318:04:33.693EST[12823]HINT:Futurelogoutputwillappearindirectory"log".doneserverstarted[postgres@open_sourcebin]$./pg_ctlstatuspg_ctl:serverisrunning(PID:12823)/usr/pgsql-10/bin/postgres[postgres@open_sourcebin]$ps-ef|greppostgre|grep-vgreproot128009637018:04pts/000:00:00su-postgrespostgres1280112800018:04pts/000:00:00-bashpostgres128231018:04pts/000:00:00/usr/pgsql-10/bin/postgrespostgres1282412823018:04?00:00:00postgres:loggerprocesspostgres1282612823018:04?00:00:00postgres:checkpointerprocesspostgres1282712823018:04?00:00:00postgres:writerprocesspostgres1282812823018:04?00:00:00postgres:walwriterprocesspostgres1282912823018:04?00:00:00postgres:autovacuumlauncherprocesspostgres1283012823018:04?00:00:00postgres:statscollectorprocesspostgres1283112823018:04?00:00:00postgres:bgworker:logicalreplicationlauncherpostgres1283712801018:05pts/000:00:00ps-ef

配置用户环境变量:

[postgres@open_source~]$vi.bash_profileexportPGPORT=5432exportPGHOST=open_sourceexportPGHOME=/usr/pgsql-10/exportPGDATA=/home/postgres/dataexport.utf8exportLD_LIBRARY_PATH=/usr/pgsql-10/libexportPATH=$PGHOME/bin:/usr/bin:/usr/sbin:/sbin:$PATHexportMANPATH=$PGHOME/share/man:$MANPATHexportPGUSER=postgresexportPGDATABASE=postgres

创建数据库:

[postgres@open_source~]$initdb-D$PGDATAThefilesbelongingtothisdatabasesystemwillbeownedbyuser"postgres".Thisusermustalsoowntheserverprocess.Thedatabaseclusterwillbeinitializedwithlocale"en_US.utf8".Thedefaultdatabaseencodinghasaccordinglybeensetto"UTF8".Thedefaulttextsearchconfigurationwillbesetto"english".Datapagechecksumsaredisabled.fixingpermissionsonexistingdirectory/home/postgres/data...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/home/postgres/data-llogfilestart

登录数据库:

[postgres@open_source~]$psqlpsql:couldnotconnecttoserver:ConnectionrefusedIstheserverrunningonhost"open_source"(192.168.84.30)andacceptingTCP/IPconnectionsonport5432?[postgres@open_source~]$cd/var/lib/pgsql/10/data[postgres@open_sourcedata]$ls-rtltotal56drwx------2postgrespostgres6Feb2316:51pg_commit_ts-rw-------1postgrespostgres3Feb2316:51PG_VERSIONdrwx------2postgrespostgres6Feb2316:51pg_twophasedrwx------2postgrespostgres6Feb2316:51pg_tblspcdrwx------2postgrespostgres6Feb2316:51pg_snapshotsdrwx------2postgrespostgres6Feb2316:51pg_serialdrwx------2postgrespostgres6Feb2316:51pg_replslotdrwx------4postgrespostgres36Feb2316:51pg_multixactdrwx------2postgrespostgres6Feb2316:51pg_dynshmem-rw-------1postgrespostgres22992Feb2316:51postgresql.conf-rw-------1postgrespostgres88Feb2316:51postgresql.auto.conf-rw-------1postgrespostgres1636Feb2316:51pg_ident.conf-rw-------1postgrespostgres4269Feb2316:51pg_hba.confdrwx------2postgrespostgres18Feb2316:51pg_xactdrwx------3postgrespostgres60Feb2316:51pg_waldrwx------2postgrespostgres18Feb2316:51pg_subtransdrwx------2postgrespostgres4096Feb2316:51globaldrwx------5postgrespostgres41Feb2316:51base-rw-------1postgrespostgres58Feb2317:07postmaster.optsdrwx------2postgrespostgres18Feb2317:07pg_notifydrwx------2postgrespostgres32Feb2317:07log-rw-------1postgrespostgres30Feb2317:07current_logfilesdrwx------4postgrespostgres68Feb2318:03pg_logicaldrwx------2postgrespostgres6Feb2318:03pg_stat_tmpdrwx------2postgrespostgres25Feb2318:03pg_stat[postgres@open_sourcedata]$echolisten_addresses="'*'">>postgresql.conf[postgres@open_sourcedata]$echo"hostallall192.xxx.xxx.xxx/32trust">>pg_hba.conf[postgres@open_sourcedata]$pg_ctlstartwaitingforservertostart....2020-02-2318:40:17.588EST[13271]LOG:listeningonIPv4address"0.0.0.0",port54322020-02-2318:40:17.588EST[13271]LOG:listeningonIPv6address"::",port54322020-02-2318:40:17.589EST[13271]LOG:listeningonUnixsocket"/var/run/postgresql/.s.PGSQL.5432"2020-02-2318:40:17.589EST[13271]LOG:listeningonUnixsocket"/tmp/.s.PGSQL.5432"2020-02-2318:40:17.595EST[13271]LOG:redirectinglogoutputtologgingcollectorprocess2020-02-2318:40:17.595EST[13271]HINT:Futurelogoutputwillappearindirectory"log".doneserverstarted[postgres@open_sourcedata]$psqlpsql(10.12)Type"help"forhelp.postgres=#

到此,关于“PostgreSQL 10.12本地RPM安装的方法是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!