centos環境源碼安裝postgresql9.4

來源:互聯網
上載者:User

centos環境源碼安裝postgresql9.4
源碼安裝簡要步驟

  • 下載PostgreSQL 源碼包
    下載根目錄地址:http://ftp.postgresql.org/
    本人選擇的是當前最新版本v9.4.1:http://ftp.postgresql.org/pub/source/v9.4.1/
    本人下載的源碼壓縮包地址如下:
$ /usr/local/postgresql
  • 1
  • 解壓源碼包
$ tar -zxvf postgresql-9.4.1.tar.gz
  • 1
  • 進入解壓後的目錄
$ cd postgresql-9.4.1
  • 1

  • 開始編譯安裝PostgreSQL 資料庫
$ ./configure
  • 1
  • 執行gmake
$ gmake
  • 1

- 執行gmake install

$ gmake install
  • 1

- 設定環境變數

$ vi .bash_profile#### 把 PATH=$PATH:$HOME/bin 改成下面內容 ####$ PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
  • 1
  • 2
  • 3
  • 讓環境變數生效
$ source .bash_profile
  • 1
  • 添加使用者postgres
$ adduser postgres
  • 1

- 更改使用者目錄(可選操作)

$ vi /etc/passwd#### 把 postgres:x:528:528::/home/postgres:/bin/bash 改成下面內容 ####$ postgres:x:528:528::/usr/local/pgsql:/bin/bash#### 將.bash_profile 移動到新的使用者目錄並修改許可權 ####$ cp /home/postgres/.bash_profile /usr/local/pgsql/$ chown postgres.postgres .bash_profile#### 刪除使用者目錄 ####$ rm -rf postgres/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 建立資料目錄
$ mkdir /usr/local/pgsql/data
  • 1
  • 更改許可權
$ chown postgres /usr/local/pgsql/data
  • 1
  • 切換到postgres 使用者
$ su - postgres
  • 1

- 初始化資料庫

$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
  • 1

- 回到root 使用者

$ exit
  • 1
  • 複製安裝目錄下的linux檔案到/etc/init.d/
$ cd postgresql-9.4.1$ cp contrib/start-scripts/linux /etc/init.d/postgresql
  • 1
  • 2

- 添加執行許可權

$ chmod +x /etc/init.d/postgresql
  • 1
  • 啟動資料庫
$ service postgresql restart
  • 1

- 讓資料庫開機啟動

$ chkconfig --add postgresql $ chkconfig postgresql on
  • 1
  • 2
  • 測試使用
$ su - postgres$ createdb test$ psql testtest=$ create table test(id int);
  • 1
  • 2
  • 3
  • 4

源碼安裝相關問題及解決方案
  • ./configure時,提示error: readline library not found 該情況,一般是未安裝readline-devel,雖然提示中有建議使用 –without readline,但是裝下又何妨,萬一後面出點亂子,找個問題都難找,還是裝一下吧。
yum install readline-devel
  • 1
  • 直接執行gmake install,預設安裝在哪?
$ /usr/local/pgsql
  • 1
  • 執行postgresql命令、修改postgresql設定檔(postgresql.conf、pg_hba.conf),檔案和目錄在哪?
$ /usr/local/pgsql/data
  • 1
  • postgresql預設只允許本機訪問,需要遠端連線、外網訪問,如何配置? 先配置監聽地址
$ vi /usr/local/pgsql/data/postgresql.conf#### 取消掉下面一行的前面的#注釋,並將值改為* ####$ listen_addresses = '*'
  • 1
  • 2
  • 3

再配置支援遠端連線

$ vi /usr/local/pgsql/data/pg_hba.conf#### 直接配置為不限制IP,即0.0.0.0,注意:/後面也必須為0!!! ####$ 將 127.0.0.1/8 改為 0.0.0.0/0

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.