技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁 > 教程 > 服務(wù)器類 >

centos下編譯安裝PostgreSQL數(shù)據(jù)庫的教程

來源:技術(shù)員聯(lián)盟┆發(fā)布時間:2018-05-21 18:28┆點擊:

PostgreSQL是開源關(guān)系型數(shù)據(jù)庫的首選了,因為現(xiàn)在mysql數(shù)據(jù)庫都給oracle收購了,下面我們來介紹在centos中編譯PostgreSQL數(shù)據(jù)庫的教程.

 


readline是一個開源的跨平臺程序庫,提供了交互式的文本編輯功能。postgresql需要readline的支持。
wget -c https://ftp.postgresql.org/pub/source/v9.3.5/postgresql-9.3.5.tar.gz
[root@rootop postgresql-9.3.5]# yum install readline readline-devel


[root@rootop postgresql-9.3.5]# ./configure --prefix=http://www.3lian.com/usr/local/pgsql
[root@rootop postgresql-9.3.5]# make
[root@rootop postgresql-9.3.5]# make install

添加系統(tǒng)賬戶:

[root@rootop ~]# useradd postgres
[root@rootop ~]# passwd postgres

創(chuàng)建數(shù)據(jù)目錄:

[root@rootop ~]# mkdir /usr/local/pgsql/data
[root@rootop ~]# chown postgres:postgres /usr/local/pgsql/data/

初始化數(shù)據(jù)庫:

[root@rootop ~]# su postgres  #切換到postgres用戶執(zhí)行

[postgres@rootop ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
根據(jù)提示可以通過 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data/
或 /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l logfile start 啟動服務(wù)。

推薦下面的腳本啟動方式,啟動以后會在tcp上監(jiān)聽5432端口。

[postgres@rootop ~]$ lsof -i:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 5140 postgres 3u IPv4 2394876345 0t0 TCP localhost:postgres (LISTEN)

復(fù)制管理腳本(root操作):

[root@rootop postgresql-9.3.5]# cp contrib/start-scripts/linux /etc/init.d/postgresql
[root@rootop postgresql-9.3.5]# chmod o+x /etc/init.d/postgresql

編輯啟動腳本,注意以下部分為實際信息:

#安裝路徑
prefix=http://www.3lian.com/usr/local/pgsql
#數(shù)據(jù)目錄
PGDATA=”/usr/local/pgsql/data”
#啟動用戶
PGUSER=postgres
#日志路徑
PGLOG=”$PGDATA/serverlog”
然后就可以通過service postgresql start|stop|restart|reload|status 管理了。

開機(jī)啟動:

[root@AY131126202614070132Z ~]# chkconfig postgresql on

相關(guān)配置文件:
通過 /usr/local/pgsql/data/postgresql.conf 可以配置監(jiān)聽地址、端口及連接數(shù)等。
listen_addresses =
port =
max_connections =
通過 /usr/local/pgsql/data/pg_hba.conf 可以配置允許遠(yuǎn)程連接的地址。
host all all 127.0.0.1/32 trust

登陸數(shù)據(jù)庫:


[root@AY131126202614070132Z ~]# /usr/local/pgsql/bin/psql -h 127.0.0.1 -d postgres -U postgres
psql (9.3.5)
Type "help" for help.
 
postgres=# \l  #查看已有的數(shù)據(jù)庫
 List of databases
 Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
 | | | | | postgres=CTc/postgres
 template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
 | | | | | postgres=CTc/postgres
(3 rows)
 
postgres=# \q   #退出

psql 支持的參數(shù)可以通過/usr/local/pgsql/bin/psql --help 獲取
安裝完成。