• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • PostgreSql服務器的配置

    發表于:2007-07-02來源:作者:點擊數: 標簽:
    Postgre SQL 最早是由UC Berkley大學計算機系 開發 的,當初由 Michael Stonebraker 教授領導的 Postgre 項目,是由高級防務研究項目局(Defense Advanced Research Projects Agency) (DARPA) , 陸軍研究處 (ARO ), 國家科學基金會(National Science

    PostgreSQL最早是由UC Berkley大學計算機系開發的,當初由 Michael Stonebraker 教授領導的 Postgre 項目,是由高級防務研究項目局(Defense Advanced Research Projects Agency) (DARPA) , 陸軍研究處 (ARO ), 國家科學基金會(National Science Foundation)(NSF),和 ESL 公司贊助進行的。它的許多先進的“對象-關系”概念現在已經在一些商業數據庫里得到應用,PostgreSQL支持SQL92/SQL3,事務完整性和可擴展性。它現在是一個源于Berkley代碼并公開源代碼的數據庫。

    Postgres 通過一種讓用戶可以很容易擴展系統的方法整合了下面四種基本概念,使其能提供可觀的附加功能:

     


    類/表(classes)

    繼承(inheritance)

    類型(types)

    函數(functions)


    其他特性還提供了附加的功能和靈活性:

    約束(constraints)
    觸發器(triggers)
    規則(rules)
    事務完整(transaction integrity)

    這些特性將 Postgres置于對象-關系 (object-relational) 型數據庫的范疇.盡管Postgres有一些面向對象的特性,它仍然屬于關系型數據庫的范疇, 事實上,一些商用數據庫最近已經集成了一些Postgres 所領先的特性.

    1.對系統的要求:

    安裝在RedHat Linux 6.0下測試通過。

    要用“root”用戶進行安裝。

    PostgreSQL的版本是7.0

    而且一定要先安裝egcs-c++-1.1.2-24.i386.rpm軟件包。

    盡管運行 PostgreSQL 的最小內存需求少到只有 8MB,如果我們把內存增加到96MB,可以看到顯著的性能改善。

    檢查你有足夠的磁盤空間。你需要為源代碼樹準備大約30M字節的空間,為安裝目錄準備大約5M字節。為一個空數據庫準備約 1 M字節,否則包含同樣數目數據的平面文件將大約是這個數目的五倍。在回歸測試過程中,你會暫時需要約 20 M字節.

    檢查你有足夠的磁盤空間。你需要為源代碼樹準備大約30M字節的空間,為安裝目錄準備大約5M字節。為一個空數據庫準備約 1 M字節,否則包含同樣數目數據的平面文件將大約是這個數目的五倍。在回歸測試過程中,你會暫時需要約 20 M字節.

    在編譯PostgreSQL之前。首先看一下“egcs-c++-1.1.2-24.i386.rpm”是不是已經安裝。沒有的話,那就趕緊裝吧?!癳gcs-c++-1.1.2-24.i386.rpm”直接可從Redhat的光盤里獲得,在“RedHat/RPMS”下。

    驗證egcs-c++-1.1.2-24.i386.rpm是否安裝,用命令:

    #rpm -qa|grep egcs

    安裝egcs用:

    # rpm -Uvh egcs-c++-version.i386.rpm

    2.下載Postgresql源碼包:

    Postgresql到本書發表為止已經推出了7.0.2的版本:

    由于postgres7.0.2不支持RPM安裝格式,故我們只介紹源碼方式的安裝

    3.安裝Postgresql:

    由于postgres7.0.2不支持RPM安裝格式,故我們只介紹源碼方式的安裝;

    1、解包:

    #tar xzvf postgresql-7.0.2.tar.gz
    #cd postgresql-7.0.2

    2、創建postgresql用戶

    以 root,bin 或者其他有特殊權限的用戶身份運行 PostgreSQL 存在安全問題,因而是不允許的。這是運行服務器的用戶。用于生產時你可以創建一個獨立的非特權的用戶(常用 postgres)

    #useradd -M -o -r -d /var/lib/pgsql -s /bin/bash -c "PostgreSQL Server" -u 40 postgres

    修改好postgres用戶的密碼,以postgres用戶登錄系統;

    3、設置編譯參數:

    $CC="egcs"

    進入解包后的postgresql源文件目錄:
    $ ./configure
    configure不加任何選項,系統將按默認的設置安裝postgresql,查看configre的相關選項可以使用:configure -help

    一些最常用的如下:

    --prefix=BASEDIR
    為安裝 PostgreSQL 選擇一個不同的基礎路徑。缺省是 /usr/local/pgsql。

    --enable-locale
    如果你想用本地化支持。

    --enable-multibyte
    允許使用多字節字符編碼。這個選項主要用于象日語,韓語或中文這樣的語言。

    --with-perl
    添加 Perl 模塊接口。請注意 Perl 接口將安裝到 Perl 模塊的常用位置(典型的是在 /usr/lib/perl),所以要成功使用這個選項,你必須有 root 權限。

    --with-odbc
    制作 ODBC 驅動包.

    --with-tcl
    制作 Tcl/Tk 需要的接口庫和程序,包括 libpgtcl,pgtclsh,和 pgtksh。

    這些編譯參數告訴編譯器如何編譯PostgreSQL:

    4、編譯源碼:

    $make

    5、按照ocnfigure的配置按照程序:

    #su
    #make install

    在這里我們架設postgresql安裝在默認的位置/usr/local/

    6、配置共享庫:

    告訴你的系統如何找到共享庫。如何實現這些因平臺而異??雌饋砜梢栽谌魏蔚胤缴У姆椒ㄊ窃O置環境變量 LD_LIBRARY_PATH:
    # LD_LIBRARY_PATH=/usr/local/pgsql/lib
    # export LD_LIBRARY_PATH

    你可能把這些放到一個 shell 啟動文件里,象 ~/.bash_profile。
    在一些系統里,下面的方法是最好的方法,但是你必須有 root 權限。編輯文件 /etc/ld.so.conf,增加一行

    /usr/local/pgsql/lib

    然后運行命令:

    #/sbin/ldconfig

    7、用postgres數據庫超級用戶完成數據庫的安裝:

    你必須用 PostgreSQL 超級用戶帳號登錄執行這一步。以 root 是不能進行這一步的;

    # mkdir /usr/local/pgsql/data
    # chown postgres /usr/local/pgsql/data
    #su postgres
    $ /usr/local/pgsql/initdb -D /usr/local/pgsql/data
    We are initializing the database system with username postgres (uid=40).
    This user will own all the files and must also own the server process.
    Creating Postgres database system directory /var/lib/pgsql/base
    Creating template database in /var/lib/pgsql/base/template1
    Creating global classes in /var/lib/pgsql/base
    Adding template1 database to pg_database...
    Vacuuming template1
    Creating public pg_user view
    Creating view pg_rules
    Creating view pg_views
    Creating view pg_tables
    Creating view pg_indexes
    Loading pg_description

    -D 選項聲明數據存儲的位置。你可以使用任何你想用的路徑,它不必在安裝目錄里。在運行 initdb 前只要確保數據庫超級用戶帳戶可以寫(或者創建)那個目錄就行了。

    8、啟動postgresql服務;

    前面的步驟應該已經告訴你如何啟動數據庫服務器?,F在就做。
    $ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
    這樣將在前臺啟動數據庫服務器。要把它放到后臺,使用 -S。

    4.配置Postgresql的腳本文件

    配置“/etc/rc.d/ini.d/postgresql”腳本文件,用來啟動和停止PostgreSQL服務器。

    創建“postgresql”腳本文件(touch /etc/rc.d/init.d/postgresql)并加入:

    #! /bin/sh
    # postgresql This is the init script for starting up the PostgreSQL
    # server
    # chkconfig: 345 85 15
    # description: Starts and stops the PostgreSQL backend daemon that handles
    # all database requests.
    # processname: postmaster
    # pidfile: /var/run/postmaster.pid
    #
    # Source function library.
    . /etc/rc.d/init.d/functions
    # Get config.
    . /etc/sysconfig.network
    # Check that networking is up.
    # Pretty much need it for postmaster.
    [ ${NETWORKING} = "no" ] && exit 0
    [ -f /usr/bin/postmaster ]@# @#exit 0
    # This script is slightly unusual in that the name of the daemon (postmaster)
    # is not the same as the name of the subsystem (postgresql)
    # See how we were called.
    case "$1" in
    start)
    echo -n "Checking postgresql installation: "
    # Check for the PGDATA structure
    if [ -f /var/lib/pgsql/PG_VERSION ] && [ -d /var/lib/pgsql/base/template1 ]
    then
    # Check version of existing PGDATA
    if [ `cat /var/lib/pgsql/PG_VERSION` != 6.5 ]
    then
    echo "old version. Need to Upgrade."
    echo "See /usr/doc/postgresql-6.5.2/README.rpm for more information."
    exit 1
    else
    echo "looks good!"
    fi
    # No existing PGDATA! Initdb it.
    else
    echo "no database files found."
    if [ ! -d /var/lib/pgsql ]
    then
    mkdir -p /var/lib/pgsql
    chown postgres.postgres /var/lib/pgsql
    fi
    su -l postgres -c /usr/bin/initdb --pglib=/usr/lib/pgsql --pgdata=/var/lib/pgsql
    fi
    # Check for postmaster already running...
    pid=`pidof postmaster`
    if [ $pid ]
    then
    echo "Postmaster already running."
    else
    #all systems go -- remove any stale lock files
    rm -f /tmp/.s.PGSQL.* > /dev/null
    echo -n "Starting postgresql service: "
    su -l postgres -c /usr/bin/postmaster -i -S -D/var/lib/pgsql
    sleep 1
    pid=`pidof postmaster`
    if [ $pid ]
    then
    echo -n "postmaster [$pid]"
    touch /var/lock/subsys/postgresql
    echo $pid > /var/run/postmaster.pid
    echo
    else
    echo "failed."
    fi
    fi
    ;;
    stop)
    echo -n "Stopping postgresql service: "
    killproc postmaster
    sleep 2
    rm -f /var/run/postmaster.pid
    rm -f /var/lock/subsys/postgresql
    echo
    ;;
    status)
    status postmaster
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    *)
    echo "Usage: postgresql {start|stop|status|restart}"
    exit 1
    esac
    exit 0

    現在讓腳本可執行并設置它的缺省權限:

    [root@Aid]# chmod 700 /etc/rc.d/init.d/postgresql

    用下面命令創建“rc.d”目錄下PostgresSQL的符號鏈接:

    [root@Aid]# chkconfig --add postgresql

    系統會在啟動時自動把Postgresql后臺進程啟動,也可以通過

    /etc/rc.d/init.d/postgresql start|stop|restart

    進行人工控制;

    5.Postgresql數據庫的用戶管理和存取權限

    和Mysql不同的是,Postgresql的用戶管理和權限控制,是截然不同的一套體制,有點類似于傳統的關系數據庫;

    在"pg_hba.conf"文件的PG_DATA段可以用ip地址和用戶名限制對能數據庫的連接,這里你可以指定什么樣的IP地址能夠連接數據庫,什么樣的IP地址是不允許使用數據庫資源的;

    在數據庫用戶以及數據庫方面postgresql用系統命令進行管理:

    createuser 允許聲明可訪問 Postgres的用戶.destroyuser刪除用戶以及拒絕他們訪問Postgres。

    這些命令只影響用戶與 Postgres;而對用戶的其他操作系統級的權限或狀態沒有影響

    用“createuser”命令在數據庫中定義一個新超級用戶:

    # su postgres
    $ createuser
    Enter name of user to add ---> admin
    Enter users postgres ID or RETURN to use unix user ID: 500 ->
    Is user "admin" allowed to create databases (y/n) y
    Is user "admin" a superuser? (y/n) y
    createuser: admin was suclearcase/" target="_blank" >ccessfully added

    用“destroyuser”命令在數據庫中刪除用戶:

    # su postgres
    $ destroyuser
    Enter name of user to delete ---> admin
    destroyuser: delete of user admin was successful.

    用“createdb”命令創建新的數據庫:

    # su postgres
    $ createdb dbname

    用“destorydb”命令刪除數據庫:
    # su postgres
    $ destorydb dbname

    6 使用psql操作postgresql數據庫

    postgresql和mysql一樣擁有一套獨立的客戶端程序,使用標準的SQL語句對數據庫進行操作和管理;

    $psql databasename
    Welcome to the POSTGRESQL interactive sql monitor:
    Please read the file COPYRIGHT for copyright terms of POSTGRESQL
    [PostgreSQL 6.5.3 on i686-pc-linux-gnu, compiled by egcs ]
    type ? for help on slash commands
    type q to quit
    type g or terminate with semicolon to execute query
    You are currently connected to the database: databasename

    告訴用戶已經連接到數據庫databasename

    7.postgresql數據庫的備份

    Postgres 提供兩個工具備份你的系統:pg_dump 備份獨立的數據庫以及 pg_dumpall 在一個步驟里備份你的數據庫節點。

    可以用下面的命令備份一個獨立的數據庫:

    $ pg_dump dbname > dbname.pgdump

    然后可以用下面命令恢復

    $cat dbname.pgdump | psql dbname

    這個技巧可以用于把數據庫移動到一個新位置,然后重新命名現有數據庫。

    Postgres 允許表的尺寸大于你的系統的最大文件尺寸,可能把表輸出到一個文件會有問題,生成的文件很可能比你的系統允許的最大文件大。

    使用壓縮的輸出格式:

    $ pg_dump dbname | gzip > filename.dump.gz

    重載:

    $ createdb dbname
    $ gunzip -c filename.dump.gz | psql dbname

    $ cat filename.dump.gz | gunzip | psql dbname

    使用分割(split):

    $ pg_dump dbname | split -b 1m - filename.dump.

    重載:

    $createdb dbname
    $ cat filename.dump.* | pgsql dbname

    當然,文件名(filename)和 pg_dump 輸出的內容不必與數據庫名一樣。同樣,重載的數據庫可以有任意新的名稱,所以這個機制還適用于給數據庫改名。

    PostgreSQL已經是不利新聞的一個犧牲品,被列為一個學術的玩物,為真實世界使用太復雜。在過去這可能是對的,然而不再是。它有一個遠遠超過其他進展緩慢的數據庫甚至一些企業數據庫的功能集,然而, 它缺乏用來衡量達到高價產品的很多管理特征和調節能力,這些特征是數據庫決不會一般水平的數據庫所要求的,并且甚至他們不會注意到這很少的缺點。PostgreSQL在Unix數據庫競技場成為了一個真正的競爭者。

    (作者:wing)

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>