Postgresql源碼安裝

來源:互聯網
上載者:User

標籤:

 

以在64位CentOS6.5作業系統上源碼安裝postgresql-9.6beta1為例

 

一.進入官網下載代碼(postgresql-9.6beta1.tar.gz)

https://www.postgresql.org

 

二.將源碼上傳到伺服器/home/alian目錄下

可以在windows安裝ssh或xftp工具,也可以在CentOS安裝lrzsz的rpm包(使用rz,sz命令)上傳或下載檔案。

 

三.將源碼在目前的目錄下解壓

[[email protected] alian]# tar xzvf postgresql-9.6beta1.tar.gz

 

四.進入解壓後的目錄postgresql-9.6beta1,使用configure工具查看編譯協助

[[email protected] postgresql-9.6beta1]# ./configure --help

 

五.根據協助中各配置描述選擇適合自己的配置選項

如下命令中

--prefix=/opt/pg9.6

pg軟體的安裝路徑

 

以下4個配置不是必須的,但如果想修改必須要重新initdb

--with-segsize=1

表在作業系統上物理檔案大小,單位GB,預設值為1,如果表大於1GB,將在作業系統上分割成多個1GB的檔案。

--with-blocksize=32

塊大小,單位KB,預設值為8,是表資料I/O和儲存的單元,範圍1-32,且必須是2的N次方。

--with-wal-segsize=32

WAL在作業系統上物理檔案大小,單位MB,預設值16,範圍1-64,且必須是2的N次方。

--with-wal-blocksize=64

WAL塊大小,單位KB,是WAL I/O和儲存的單元,範圍1-64,且必須是2的N次方。

[[email protected] postgresql-9.6beta1]# ./configure --prefix=/opt/pg9.6 --with-segsize=1 --with-blocksize=32 --with-wal-segsize=32 --with-wal-blocksize=64checking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnuchecking which template to use... linuxchecking whether to build with 64-bit integer date/time support... yeschecking whether NLS is wanted... nochecking for default port number... 5432checking for block size... 32kBchecking for segment size... 1GBchecking for WAL block size... 64kBchecking for WAL segment size... 32MBchecking for gcc... gcc..............

 

 

configure過程中可能會出現下面的錯誤,原因是缺少對應的庫,安裝對應的庫即可。

configure: error: readline library not found[[email protected] postgresql-9.6beta1]# yum install readline-devel configure: error: zlib library not found[[email protected] postgresql-9.6beta1]# yum install zlib-devel

 

 

六.configure成功後,可以直接執行make命令進行簡單編譯,也可以執行make world將contrib目錄下的擴充工具一起編譯,當然也可以先進行簡單編譯,然後進入contrib下對某一工具進行單獨編譯

方法一:簡單安裝

1.執行命令

[[email protected] postgresql-9.6beta1]# make && make install

命令執行完之後,pg軟體就被安裝到/opt/pg9.6路徑下

[[email protected]localhost postgresql-9.6beta1]# ls /opt/pg9.6/bin include lib share

 

2.如果想安裝contrib下的某一擴充工具,以檢測資料庫啟動並執行pg_stat_statements為例

進入contrib/pg_stat_statements目錄下(前提是已在主目錄下執行了configure)

[[email protected] postgresql-9.6beta1]# cd contrib/pg_stat_statements/

 

執行命令

[[email protected] pg_stat_statements]# make && make install

 

方法二、全部安裝(contrib下所有的擴充工具)

[[email protected] postgresql-9.6beta1]# make world && make install-world

 

七、軟體安裝完成後,進行初始化

1.建立一個使用者postgres

[[email protected] postgresql-9.6beta1]# groupadd postgres[[email protected] postgresql-9.6beta1]# useradd postgres

 

2.建立PGDATA目錄

[[email protected] postgresql-9.6beta1]# mkdir -p /mnt/pgdata[[email protected] postgresql-9.6beta1]# chown postgres:postgres /mnt/pgdata/

 

3.使用postgres使用者初始化

[[email protected] postgresql-9.6beta1]# su postgres[[email protected] postgresql-9.6beta1]$ /opt/pg9.6/bin/initdb -D /mnt/pgdata -E UTF8 --locale=C

 

4.使用postgres使用者啟停資料庫

[[email protected] postgresql-9.6beta1]$ /opt/pg9.6/bin/pg_ctl -D /mnt/pgdata/ startserver starting[[email protected] postgresql-9.6beta1]$ /opt/pg9.6/bin/pg_ctl -D /mnt/pgdata/ stopwaiting for server to shut down....LOG: database system is shut downdoneserver stopped

 

5.修改設定檔,使用用戶端訪問資料庫

初始化完成後,會自動為資料庫建立一個超級使用者postgres(執行initdb的使用者),但是資料庫還沒有給該使用者佈建訪問密碼,所以啟動資料庫後,執行下面的命令,給該使用者配置一個密碼

[[email protected] postgresql-9.6beta1]$ /opt/pg9.6/bin/psql -U postgrespsql (9.6beta1)Type "help" for help.postgres=# alter user postgres with password ‘password‘;ALTER ROLEpostgres=# \q

 

另外,在PGDATA目錄下組建組態檔案pg_hba.conf和postgresql.conf,

postgresql.conf中配置#listen_addresses = ‘localhost‘,表示只監聽本地串連,將此配置改成*用來監聽所有IP的訪問,也可以指定特定的IP(注意前面的注釋符#刪掉)

listen_addresses = ‘*‘

 

pg_hba.conf主要內容如下

# "local" is for Unix domain socket connections onlylocal all all trust# IPv4 local connections:host all all 127.0.0.1/32 trust# IPv6 local connections:host all all ::1/128 trust

 

其中trust表示允許無密碼訪問,這是不安全的,將其改為md5,使用密碼訪問。

# "local" is for Unix domain socket connections onlylocal all all md5# IPv4 local connections:host all all 127.0.0.1/32 md5# IPv6 local connections:host all all ::1/128 md5

 

修改完密碼和設定檔後重啟服務再次訪問資料庫時就會提示輸入密碼

[[email protected] postgresql-9.6beta1]$ /opt/pg9.6/bin/psql -U postgresPassword for user postgres: psql (9.6beta1)Type "help" for help.postgres=#

 

 

Postgresql源碼安裝

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.