新聞中心
在linux下安裝Postgresql有二進(jìn)制格式安裝和源碼安裝兩種安裝方式,這里用的是二進(jìn)制格式安裝。各個(gè)版本的Linux都內(nèi)置了Postgresql,所以可直接通過(guò)命令行安裝便可。本文用的是CentOS 6.5。

10年積累的網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有羅莊免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
安裝Postgresql
# 安裝postgresql服務(wù)器
yum
install postgresql-
server
#依賴包是否安裝
Y/
N Y
#第三方貢獻(xiàn)包
yum
install postgresql-
contrib
#依賴包是否安裝
Y/N Y
安裝成功后,數(shù)據(jù)庫(kù)狀態(tài)
[root@localhost Hadoop]# service postgresql status postmaster is stopped
嘗試啟動(dòng)數(shù)據(jù)庫(kù),但報(bào)錯(cuò),需要先初始化數(shù)據(jù)目錄
[root@localhost hadoop]# service postgresql start /var/lib/pgsql/data is missing.Use "service postgresql initdb" to initialize the cluster first.
[root@localhost hadoop]# service postgresql initdb
Initializing database: [OK]
啟動(dòng)數(shù)據(jù)庫(kù)
通過(guò)service命令啟動(dòng)Postgresql,需要注意的是,默認(rèn)在安裝時(shí)會(huì)創(chuàng)建postgres用戶并安裝到此用戶下。而Postgresql 的默認(rèn)數(shù)據(jù)庫(kù)也是用此用戶命名的。
[root@localhost hadoop]# service postgresql start
Starting postgresql service: [ OK ]
[root@localhost hadoop]#
su -
postgres
-bash-
4.1
$ psql
psql (
8.4.
20
)
Type
"
help
"
for
help.
postgres=
# \l
List of databases
Name | Owner | Encoding | Collation | 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=#
Postgresql 的Psql 就等于Oracle的Sqlplus一樣 ,直接用命令Psql登錄等于用操作系統(tǒng)驗(yàn)證登錄,不需要輸入用戶名和密碼。
基本參數(shù)設(shè)置
在Centos下,默認(rèn)的數(shù)據(jù)目錄在 /var/lib/pgsql/data 下 ,配置的參數(shù)文件就在此目錄下。
-bash-
4.1$
ls -
l
total
80
drwx------
5 postgres postgres
4096 Nov
16
07:
43
base
drwx------
2 postgres postgres
4096 Nov
17
23:
51
global
drwx------
2 postgres postgres
4096 Nov
16
07:
43
pg_clog
-rw-------
1 postgres postgres
3533 Nov
17
22:
05
pg_hba.conf
-rw-------
1 postgres postgres
1631 Nov
16
07:
43
pg_ident.conf
drwx------
2 postgres postgres
4096 Nov
18
00:
00
pg_log
drwx------
4 postgres postgres
4096 Nov
16
07:
43
pg_multixact
drwx------
2 postgres postgres
4096 Nov
18
00:
00
pg_stat_tmp
drwx------
2 postgres postgres
4096 Nov
16
07:
43
pg_subtrans
drwx------
2 postgres postgres
4096 Nov
16
07:
43
pg_tblspc
drwx------
2 postgres postgres
4096 Nov
16
07:
43
pg_twophase
-rw-------
1 postgres postgres
4 Nov
16
07:
43
PG_VERSION
drwx------
3 postgres postgres
4096 Nov
16
07:
43
pg_xlog
-rw-------
1 postgres postgres
16877 Nov
17
21:
54
postgresql.conf
-rw-------
1 postgres postgres
57 Nov
17
23:
51
postmaster.opts
-rw-------
1 postgres postgres
45 Nov
17
23:
51 postmaster.pid
配置遠(yuǎn)程登錄數(shù)據(jù)庫(kù)
1. 修改 postgresql.conf 文件,配置PostgreSQL數(shù)據(jù)庫(kù)服務(wù)器的相應(yīng)的參數(shù)
listen_addresses = '*' # PostgreSQL安裝完成后,默認(rèn)是只接受來(lái)在本機(jī)localhost的連接請(qǐng)求,此處將數(shù)據(jù)庫(kù)服務(wù)器的監(jiān)聽(tīng)模式修改為監(jiān)聽(tīng)所有主機(jī)發(fā)出的連接請(qǐng)求 port = 5432 # 默認(rèn)端口,修改后要重啟數(shù)據(jù)庫(kù)
2. 修改 pg_hba.conf 文件,配置對(duì)數(shù)據(jù)庫(kù)的訪問(wèn)權(quán)限
在最后一行加上配置,表示允許網(wǎng)段192.168.191.0上的所有主機(jī)使用所有合法的數(shù)據(jù)??用戶名訪問(wèn)數(shù)據(jù)庫(kù),
24是子網(wǎng)掩碼,表示允許IP范圍在 192.168.191.0--192.168.191.255 的計(jì)算機(jī)訪問(wèn)。
3. 測(cè)試遠(yuǎn)程登錄
首先修改默認(rèn)數(shù)據(jù)庫(kù)用戶登錄密碼
-bash-4.1$ psql psql (8.4.20) Type "help" for help. postgres=# \password
按提示修改密碼。
然后再?gòu)牧硪慌_(tái)局域網(wǎng)機(jī)器上登錄
psql -U postgres -d postgres -h 192.168.191.5 -p 5432 -- 成功
其中 –u 指定用戶,-d 指定數(shù)據(jù)庫(kù)名 ,-h 指定host,-p 端口號(hào),按提示輸入密碼。
另外,可視化客戶端推薦用DBeaver。
-- 感謝您付出的閱讀時(shí)間。
網(wǎng)頁(yè)標(biāo)題:Linux下安裝PostgreSQL并設(shè)置基本參數(shù)
新聞來(lái)源:http://m.fisionsoft.com.cn/article/cdgpgco.html


咨詢
建站咨詢
