Linux上怎么安裝PostgreSQL-創(chuàng)新互聯(lián)

本篇內(nèi)容主要講解“Linux上怎么安裝PostgreSQL”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Linux上怎么安裝PostgreSQL”吧!

成都創(chuàng)新互聯(lián)長(zhǎng)期為上千余家客戶(hù)提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為剛察企業(yè)提供專(zhuān)業(yè)的網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)剛察網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。

環(huán)境

此處是從頭學(xué)PG,為了適應(yīng)兩年后趨勢(shì),所以我選擇的都是最新的版本

  • Redhat 7.8

  • PostgreSQL 12.2 源碼

下載

  1. 打開(kāi) PostgreSQL 官網(wǎng) https://www.postgresql.org/,點(diǎn)擊菜單欄上的 Download。

  2. 可以根據(jù)需要點(diǎn)擊自己所需要的的版本,此處為了更好的學(xué)習(xí)PG,不落后其他大咖,我選擇下載最新版本的源碼

    Linux上怎么安裝PostgreSQL

安裝

  1. 上傳并解壓

      [root@node1 soft]# bzip2 -d postgresql-12.2.tar.bz2 
       [root@node1 soft]# tar -xvf postgresql-12.2.tar
       postgresql-12.2/
       postgresql-12.2/.dir-locals.el
       postgresql-12.2/contrib/
       postgresql-12.2/contrib/tcn/
       postgresql-12.2/contrib/tcn/tcn.control
       ... ...(省略輸出)
       [root@node1 soft]# ls -lrt 
       total 131200
       drwxrwxrwx 6 1107 1107       273 Feb 10 17:29 postgresql-12.2
       -rw-r--r-- 1 root root 134348800 Apr 30 05:29 postgresql-12.2.ta
  2. 安裝 yum 包

    yum -y install readline-devel
    yum -y install readline

    避免 ./configure 時(shí)報(bào)錯(cuò)
    Linux上怎么安裝PostgreSQL

  3. configure

    [root@node1 postgresql-12.2]# ./configure 
    checking build system type... x86_64-pc-linux-gnu
    checking host system type... x86_64-pc-linux-gnu
    checking which template to use... linux
    checking whether NLS is wanted... no
    checking for default port number... 5432
    checking for block size... 8kB
    ... ...(省略輸出)
    checking for fop... no
    checking thread safety of required library functions... yes
    checking whether gcc -std=gnu99 supports -Wl,--as-needed... yes
    configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
    configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
    configure: using CPPFLAGS= -D_GNU_SOURCE 
    configure: using LDFLAGS=  -Wl,--as-needed
    configure: creating ./config.status
    config.status: creating GNUmakefile
    config.status: creating src/Makefile.global
    config.status: creating src/include/pg_config.h
    config.status: creating src/include/pg_config_ext.h
    config.status: creating src/interfaces/ecpg/include/ecpg_config.h
    config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
    config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
    config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
    config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
    config.status: linking src/makefiles/Makefile.linux to src/Makefile.por
  4. make && make install

    [root@node1 postgresql-12.2]# make
    make -C ./src/backend generated-headers
    make[1]: Entering directory `/soft/postgresql-12.2/src/backend'
    make -C catalog distprep generated-header-symlinks
    make[2]: Entering directory `/soft/postgresql-12.2/src/backend/catalog'
    ... ...(省略輸出)
    make[2]: Nothing to be done for `all'.
    make[2]: Leaving directory `/soft/postgresql-12.2/src/test/perl'
    make[1]: Leaving directory `/soft/postgresql-12.2/src'
    make -C config all
    make[1]: Entering directory `/soft/postgresql-12.2/config'
    make[1]: Nothing to be done for `all'.
    make[1]: Leaving directory `/soft/postgresql-12.2/config'
    All of PostgreSQL successfully made. Ready to install.
    [root@node1 postgresql-12.2]# make install
    make -C ./src/backend generated-headers
    make[1]: Entering directory `/soft/postgresql-12.2/src/backend'
    make -C catalog distprep generated-header-symlinks
    make[2]: Entering directory `/soft/postgresql-12.2/src/backend/catalog'
    make[2]: Nothing to be done for `distprep'.
    make[2]: Nothing to be done for `generated-header-symlinks'.
    ... ...(省略輸出)
    make -C config install
    make[1]: Entering directory `/soft/postgresql-12.2/config'
    /usr/bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config'
    /usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
    /usr/bin/install -c -m 755 ./missing '/usr/local/pgsql/lib/pgxs/config/missing'
    make[1]: Leaving directory `/soft/postgresql-12.2/config'
    PostgreSQL installation complete
  5. 創(chuàng)建用戶(hù)并配置密碼

    [root@node1 postgresql-12.2]# useradd postgres
    [root@node1 postgresql-12.2]# passwd postgres
    Changing password for user postgres.
    New password: 
    BAD PASSWORD: The password contains the user name in some form
    Retype new password: 
    passwd: all authentication tokens updated successfully
  6. 創(chuàng)建數(shù)據(jù)目錄并授權(quán)

    [root@node1 postgresql-12.2]# mkdir -p /data/pg_data
    [root@node1 postgresql-12.2]# chown postgres:postgres -R /data
    [root@node1 postgresql-12.2]# cd /usr/local
    [root@node1 local]# ll
    total 0
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 bin
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 etc
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 games
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 include
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 lib
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 lib64
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 libexec
    drwxr-xr-x  6 postgres postgres 56 Apr 30 05:53 pgsql
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 sbin
    drwxr-xr-x. 5 root     root     49 Apr 16 12:09 share
    drwxr-xr-x. 2 root     root      6 Dec 14  2017 src
    [root@node1 local]# chown postgres:postgres -R pgsq
  7. 配置 postgres 用戶(hù)

    [postgres@node1 ~]$ cat .bash_profile 
    export PATH=$PATH:/usr/local/pgsql/bin
    export PGDATA=/data/pg_data
    [postgres@node1 ~]$ source .bash_profile
  8. 初始化數(shù)據(jù)庫(kù)

    [postgres@node1 ~]$ initdb -D /data/pg_data/
    The files belonging to this database system will be owned by user "postgres".
    This user must also own the server process.
    The database cluster will be initialized with locale "en_US.UTF-8".
    The default database encoding has accordingly been set to "UTF8".
    The default text search configuration will be set to "english".
    Data page checksums are disabled.
    fixing permissions on existing directory /data/pg_data ... ok
    creating subdirectories ... ok
    selecting dynamic shared memory implementation ... posix
    selecting default max_connections ... 100
    selecting default shared_buffers ... 128MB
    selecting default time zone ... America/New_York
    creating configuration files ... ok
    running bootstrap script ... ok
    performing post-bootstrap initialization ... ok
    syncing data to disk ... ok
    initdb: warning: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the option -A, or
    --auth-local and --auth-host, the next time you run initdb.
    Success. You can now start the database server using:
        pg_ctl -D /data/pg_data/ -l logfile star
  9. 啟動(dòng)數(shù)據(jù)庫(kù)

    [postgres@node1 ~]$ pg_ctl -D /data/pg_data/ start
    waiting for server to start....2020-04-30 06:34:29.841 EDT [53149] LOG:  starting PostgreSQL 12.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
    2020-04-30 06:34:29.841 EDT [53149] LOG:  listening on IPv6 address "::1", port 5432
    2020-04-30 06:34:29.841 EDT [53149] LOG:  listening on IPv4 address "127.0.0.1", port 5432
    2020-04-30 06:34:29.844 EDT [53149] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
    2020-04-30 06:34:29.856 EDT [53150] LOG:  database system was shut down at 2020-04-30 06:29:52 EDT
    2020-04-30 06:34:29.858 EDT [53149] LOG:  database system is ready to accept connections
     done
    server starte
  10. 關(guān)閉數(shù)據(jù)庫(kù)

    [postgres@node1 ~]$ pg_ctl -D /data/pg_data/ stop
    waiting for server to shut down....2020-04-30 06:35:27.573 EDT [53149] LOG:  received fast shutdown request
    2020-04-30 06:35:27.574 EDT [53149] LOG:  aborting any active transactions
    2020-04-30 06:35:27.574 EDT [53149] LOG:  background worker "logical replication launcher" (PID 53156) exited with exit code 1
    2020-04-30 06:35:27.575 EDT [53151] LOG:  shutting down
    2020-04-30 06:35:27.584 EDT [53149] LOG:  database system is shut down
     done
    server stopped

到此,相信大家對(duì)“Linux上怎么安裝PostgreSQL”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!

本文標(biāo)題:Linux上怎么安裝PostgreSQL-創(chuàng)新互聯(lián)
分享鏈接:http://muchs.cn/article36/dcodsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站網(wǎng)站建設(shè)、域名注冊(cè)、品牌網(wǎng)站制作、移動(dòng)網(wǎng)站建設(shè)網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)