溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

在Linux上如何安裝PostgreSQL

發(fā)布時間:2021-08-26 09:55:47 來源:億速云 閱讀:191 作者:小新 欄目:系統(tǒng)運維

這篇文章主要介紹了在Linux上如何安裝PostgreSQL,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

PostgreSQL 的官方下載地址為:
ftp://ftp.postgresql.org/pub/v7.1.3/postgresql-7.1.3.tar.gz
http://www.postgresql.org/
如果下載最新的開發(fā)版本,你需要下載并安裝 flex(版本號大于 2.5.4) 以及 bison (版本號大于 1.28)
設(shè)計人員為了安全考慮,PostgreSQL 不能以 root 用戶運行,所以必須建立對應(yīng)的用戶和組。
# useradd postgre (自動建立 postgre 組)
安裝的過程并不復(fù)雜和其他源碼版本的安裝方法類似:
解壓到 /usr/local/src:
# tar xvfz postgresql-7.1.3.tar.gz
# cd postgresql-7.1.3
# ./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
建立數(shù)據(jù)庫目錄:
$ mkdir data
啟動數(shù)據(jù)庫引擎:
$ 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 &
[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 的數(shù)據(jù)庫,允許 Internet 用戶的連接( -i ) ,并在后臺運行。
建立數(shù)據(jù)庫
$createdb mydb
PostgreSQL 會返回 “ CREATED DATABASE”的信息,表明數(shù)據(jù)庫建立完成。
$psql mydb
進入交互 psql 工具,建立表:
CREATE TABLE mytable (
id varchar(20),
name varchar(30));
建立完成后,會得到一條 “CREATED” 的信息,表示建立成功?,F(xiàn)在插入一條數(shù)據(jù):
INSERT INTO mytable values('Author', 'Xu Yongjiu');
psql 返回 INSERT 18732 1,查詢插入是否成功:
SELECT * FROM MYTABLE;
退出 psql ,用 \q 命令

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“在Linux上如何安裝PostgreSQL”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI