国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > PostgreSQL > 正文

PostgreSql服務(wù)器的配置

2019-09-08 23:34:18
字體:
供稿:網(wǎng)友
PostgreSQL最早是由UC Berkley大學(xué)計(jì)算機(jī)系開發(fā)的,當(dāng)初由 Michael Stonebraker 教授領(lǐng)導(dǎo)的 Postgres 項(xiàng)目,是由高級(jí)防務(wù)研究項(xiàng)目局(Defense Advanced Research Projects Agency) (DARPA) , 陸軍研究處 (ARO ), 國(guó)家科學(xué)基金會(huì)(National Science Foundation)(NSF),和 ESL 公司贊助進(jìn)行的。它的許多先進(jìn)的“對(duì)象-關(guān)系”概念現(xiàn)在已經(jīng)在一些商業(yè)數(shù)據(jù)庫里得到應(yīng)用,PostgreSQL支持SQL92/SQL3,事務(wù)完整性和可擴(kuò)展性。它現(xiàn)在是一個(gè)源于Berkley代碼并公開源代碼的數(shù)據(jù)庫。

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

類/表(classes)
繼承(inheritance)
類型(types)
函數(shù)(functions)

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

約束(constraints)
觸發(fā)器(triggers)
規(guī)則(rules)
事務(wù)完整(transaction integrity)

這些特性將 Postgres置于對(duì)象-關(guān)系 (object-relational) 型數(shù)據(jù)庫的范疇.盡管Postgres有一些面向?qū)ο蟮奶匦裕匀粚儆陉P(guān)系型數(shù)據(jù)庫的范疇, 事實(shí)上,一些商用數(shù)據(jù)庫最近已經(jīng)集成了一些Postgres 所領(lǐng)先的特性.

1.對(duì)系統(tǒng)的要求:

安裝在RedHat Linux 6.0下測(cè)試通過。

要用“root”用戶進(jìn)行安裝。

PostgreSQL的版本是7.0

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

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

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

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

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

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

#rpm -qa|grep egcs

安裝egcs用:

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

2.下載Postgresql源碼包:

Postgresql到本書發(fā)表為止已經(jīng)推出了7.0.2的版本:

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

ftp://ftp.postgresql.org/pub/v7.0.2/postgresql-7.0.2.tar.gz

3.安裝Postgresql:

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

1、解包:

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

2、創(chuàng)建postgresql用戶

以 root,bin 或者其他有特殊權(quán)限的用戶身份運(yùn)行 PostgreSQL 存在安全問題,因而是不允許的。這是運(yùn)行服務(wù)器的用戶。用于生產(chǎn)時(shí)你可以創(chuàng)建一個(gè)獨(dú)立的非特權(quán)的用戶(常用 postgres)

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

修改好postgres用戶的密碼,以postgres用戶登錄系統(tǒng);

3、設(shè)置編譯參數(shù):

$CC="egcs"

進(jìn)入解包后的postgresql源文件目錄:
$ ./configure
configure不加任何選項(xiàng),系統(tǒng)將按默認(rèn)的設(shè)置安裝postgresql,查看configre的相關(guān)選項(xiàng)可以使用:configure -help

一些最常用的如下:

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

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

--enable-multibyte
允許使用多字節(jié)字符編碼。這個(gè)選項(xiàng)主要用于象日語,韓語或中文這樣的語言。

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

--with-odbc
制作 <SPAN title="常規(guī)詞語,單擊這里可以查看解釋" style="BACKGROUND-IMAGE: url(C:PROGRA~1!SUNVDFKC3000
ormmark.gif); BACKGROUND-POSITION: left bottom; BACKGROUND-REPEAT: repeat-x; CURSOR: hand" )>ODBC</SPAN> 驅(qū)動(dòng)包.

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

這些編譯參數(shù)告訴編譯器如何編譯PostgreSQL:

4、編譯源碼

$make

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

#su
#make install

在這里我們架設(shè)postgresql安裝在默認(rèn)的位置/usr/local/

6、配置共享庫:

告訴你的系統(tǒng)如何找到共享庫。如何實(shí)現(xiàn)這些因平臺(tái)而異。看起來可以在任何地方生效的方法是設(shè)置環(huán)境變量 LD_LIBRARY_PATH:
# LD_LIBRARY_PATH=/usr/local/pgsql/lib
# export LD_LIBRARY_PATH

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

/usr/local/pgsql/lib

然后運(yùn)行命令:

#/sbin/ldconfig

7、用postgres數(shù)據(jù)庫超級(jí)用戶完成數(shù)據(jù)庫的安裝:

你必須用 PostgreSQL 超級(jí)用戶帳號(hào)登錄執(zhí)行這一步。以 root 是不能進(jìn)行這一步的;

# 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 選項(xiàng)聲明數(shù)據(jù)存儲(chǔ)的位置。你可以使用任何你想用的路徑,它不必在安裝目錄里。在運(yùn)行 initdb 前只要確保數(shù)據(jù)庫超級(jí)用戶帳戶可以寫(或者創(chuàng)建)那個(gè)目錄就行了。

8、啟動(dòng)postgresql服務(wù);

前面的步驟應(yīng)該已經(jīng)告訴你如何啟動(dòng)數(shù)據(jù)庫服務(wù)器。現(xiàn)在就做。
$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
這樣將在前臺(tái)啟動(dòng)數(shù)據(jù)庫服務(wù)器。要把它放到后臺(tái),使用 -S。

4.配置Postgresql的腳本文件

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

創(chuàng)建“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.
[ ${NETWORKI<SPAN title="常規(guī)詞語,單擊這里可以查看解釋" style="BACKGROUND-IMAGE: url(C:PROGRA~1!SUNVDFKC3000
ormmark.gif); BACKGROUND-POSITION: left bottom; BACKGROUND-REPEAT: repeat-x; CURSOR: hand" )>NG</SPAN>} = "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

現(xiàn)在讓腳本可執(zhí)行并設(shè)置它的缺省權(quán)限:

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

用下面命令創(chuàng)建“rc.d”目錄下PostgresSQL的符號(hào)鏈接:

[root@Aid]# chkconfig --add postgresql

系統(tǒng)會(huì)在啟動(dòng)時(shí)自動(dòng)把Postgresql后臺(tái)進(jìn)程啟動(dòng),也可以通過

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

進(jìn)行人工控制;

5.Postgresql數(shù)據(jù)庫的用戶管理和存取權(quán)限

和Mysql不同的是,Postgresql的用戶管理和權(quán)限控制,是截然不同的一套體制,有點(diǎn)類似于傳統(tǒng)的關(guān)系數(shù)據(jù)庫;

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

在數(shù)據(jù)庫用戶以及數(shù)據(jù)庫方面postgresql用系統(tǒng)命令進(jìn)行管理:

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

這些命令只影響用戶與 Postgres;而對(duì)用戶的其他操作系統(tǒng)級(jí)的權(quán)限或狀態(tài)沒有影響

用“createuser”命令在數(shù)據(jù)庫中定義一個(gè)新超級(jí)用戶:

# su postgres
$ createuser
Enter name of user to add ---> admin
Enter user's 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 successfully added

用“destroyuser”命令在數(shù)據(jù)庫中刪除用戶:

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

用“createdb”命令創(chuàng)建新的數(shù)據(jù)庫:

# su postgres
$ createdb dbname

用“destorydb”命令刪除數(shù)據(jù)庫:
# su postgres
$ destorydb dbname

6 使用psql操作postgresql數(shù)據(jù)庫

postgresql和mysql一樣擁有一套獨(dú)立的客戶端程序,使用標(biāo)準(zhǔn)的SQL語句對(duì)數(shù)據(jù)庫進(jìn)行操作和管理;

$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

告訴用戶已經(jīng)連接到數(shù)據(jù)庫databasename

7.postgresql數(shù)據(jù)庫的備份

Postgres 提供兩個(gè)工具備份你的系統(tǒng):pg_dump 備份獨(dú)立的數(shù)據(jù)庫以及 pg_dumpall 在一個(gè)步驟里備份你的數(shù)據(jù)庫節(jié)點(diǎn)。

可以用下面的命令備份一個(gè)獨(dú)立的數(shù)據(jù)庫:

$ pg_dump dbname > dbname.pgdump

然后可以用下面命令恢復(fù)

$cat dbname.pgdump | psql dbname

這個(gè)技巧可以用于把數(shù)據(jù)庫移動(dòng)到一個(gè)新位置,然后重新命名現(xiàn)有數(shù)據(jù)庫。

Postgres 允許表的尺寸大于你的系統(tǒng)的最大文件尺寸,可能把表輸出到一個(gè)文件會(huì)有問題,生成的文件很可能比你的系統(tǒng)允許的最大文件大。

使用壓縮的輸出格式:

$ 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

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

PostgreSQL已經(jīng)是不利新聞的一個(gè)犧牲品,被列為一個(gè)學(xué)術(shù)的玩物,為真實(shí)世界使用太復(fù)雜。在過去這可能是對(duì)的,然而不再是。它有一個(gè)遠(yuǎn)遠(yuǎn)超過其他進(jìn)展緩慢的數(shù)據(jù)庫甚至一些企業(yè)數(shù)據(jù)庫的功能集,然而, 它缺乏用來衡量達(dá)到高價(jià)產(chǎn)品的很多管理特征和調(diào)節(jié)能力,這些特征是數(shù)據(jù)庫決不會(huì)一般水平的數(shù)據(jù)庫所要求的,并且甚至他們不會(huì)注意到這很少的缺點(diǎn)。PostgreSQL在Unix數(shù)據(jù)庫競(jìng)技場(chǎng)成為了一個(gè)真正的競(jìng)爭(zhēng)者。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 满洲里市| 富裕县| 三原县| 潞城市| 乌恰县| 全南县| 永仁县| 铜山县| 凤山市| 济阳县| 克拉玛依市| 大石桥市| 凤冈县| 平泉县| 碌曲县| 宁晋县| 栾城县| 鸡东县| 汶川县| 怀柔区| 惠安县| 察雅县| 阿城市| 钟山县| 九台市| 容城县| 万山特区| 石家庄市| 余干县| 嵩明县| 灵丘县| 定日县| 临武县| 冷水江市| 阿拉尔市| SHOW| 贵阳市| 静安区| 郁南县| 西青区| 敦煌市|