Linux下安裝PostgreSQL-8.1.5

來源:互聯網
上載者:User
由於工作的需要,在新的項目中需要使用PostgreSQL-8.1.5;雖然以前也配置過,但是這次配置卻發現新的版本和原來的有很多不一樣的地方.
這裡不再闡述那裡不一樣,只是把這次配置的過程記錄下在,方便以後再配置的時候忘記了.

    PostgreSQL 的官方為:http://www.postgresql.org/
  下載postgresql-8.1.5.tar.gz版本.

  設計人員為了安全考慮,PostgreSQL 不能以 root 使用者運行,所以必須建立對應的使用者和組。

  # useradd postgre (自動建立 postgre 組)

  安裝的過程並不複雜和其他源碼版本的安裝方法類似:
  解壓到 /usr/local/src:
  # tar xvfz postgresql-8.1.5.tar.gz
  # cd postgresql-8.1.5
  # ./configure --prefix=/usr/local/pgsql
  # make
  # make install
  # chown -R postgre.postgre /usr/local/pgsql

  這樣安裝完畢後,並不是萬事大吉了,還有一些收尾工作要做:
  # vi ~postgre/.bash_profile
  添加:

  PGLIB=/usr/local/pgsql/lib
  PGDATA=$HOME/data
  PATH=$PATH:/usr/local/pgsql/bin
  MANPATH=$MANPATH:/usr/local/pgsql/man
  export PGLIB PGDATA PATH MANPATH

  以 postgres 使用者登入,
  # su - postgre
  建立資料庫目錄:
  $ mkdir data

  啟動資料庫引擎:

  $ initdb
  [postgre@www postgre]$ initdb
  This database system will be initialized with username "postgre".
  This user will own all the data files and must also own the server process.

  Fixing permissions on pre-existing data directory /home/postgre/data
  Creating database system directory /home/postgre/data/base
  Creating database XLOG directory /home/postgre/data/pg_xlog
  Creating template database in /home/postgre/data/base/template1
  Creating global relations in /home/postgre/data/base
  Adding template1 database to pg_database

  Creating view pg_user.
  Creating view pg_rules.
  Creating view pg_views.
  Creating view pg_tables.
  Creating view pg_indexes.
  Loading pg_description.
  Vacuuming database.

  Success. You can now start the database server using:

  /usr/local/pgsql/bin/postmaster -D /home/postgre/data
  or
  /usr/local/pgsql/bin/pg_ctl -D /home/postgre/data start
  $  postmaster -i -D data  ($ postmaster -i -D ~/data &)
  [1] 22603
  [postgre@www postgre]$ DEBUG: Data Base System is starting up at Thu Jan 31 02:00:44 2002
  DEBUG: Data Base System was shut down at Thu Jan 31 01:57:58 2002
  DEBUG: Data Base System is in production state at Thu Jan 31 02:00:44 2002

  這樣 PostgreSQL 使用位於 /usr/local/pgsql/data 的資料庫,允許 Internet 使用者的串連( -i ) ,並在後台運行。

  建立資料庫
  $createdb mydb
  PostgreSQL 會返回 “ CREATED DATABASE”的資訊,表明資料庫建立完成。
  $psql mydb
  進入互動 psql 工具,建立表:

  CREATE TABLE mytable (
  id varchar(20),
  name varchar(30));

  建立完成後,會得到一條 “CREATED” 的資訊,表示建立成功。現在插入一條資料:

  INSERT INTO mytable values('Author', 'Xu Yongjiu');

  psql 返回 INSERT 18732 1,查詢插入是否成功:

  SELECT * FROM MYTABLE;

  退出 psql ,用 \q 命令。
--------------------------------------
如果僅僅這樣配置,那麼在本機測試是沒有問題的,但是其他機子就會無法串連.
需要修改pg_hba.conf,和postgresql.conf檔案.
由於檔案比較大我就不全部寫出來了.我把檔案直接放上來,以供大家參考.
希望對大家有所協助.(由於無法上傳.conf檔案,所以大家下載後把.pdf改為.conf)

http://files.cnblogs.com/matildawaltzer/pg_hba.pdf
http://files.cnblogs.com/matildawaltzer/postgresql.pdf

相關文章

聯繫我們

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