PostgreSQL的安裝和啟動(dòng)方法-創(chuàng)新互聯(lián)

這篇文章主要介紹“PostgreSQL的安裝和啟動(dòng)方法”,在日常操作中,相信很多人在PostgreSQL的安裝和啟動(dòng)方法問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”P(pán)ostgreSQL的安裝和啟動(dòng)方法”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

成都服務(wù)器托管,創(chuàng)新互聯(lián)提供包括服務(wù)器租用、多線BGP機(jī)房、帶寬租用、云主機(jī)、機(jī)柜租用、主機(jī)租用托管、CDN網(wǎng)站加速、空間域名等業(yè)務(wù)的一體化完整服務(wù)。電話(huà)咨詢(xún):028-86922220

官方文檔

二進(jìn)制安裝和啟動(dòng):

https://www.postgresql.org/download/linux/redhat/

源碼安裝和啟動(dòng):

https://www.postgresql.org/docs/11/install-procedure.html

https://www.postgresql.org/docs/11/creating-cluster.html

https://www.postgresql.org/docs/11/server-start.html

https://www.postgresql.org/docs/current/kernel-resources.html

兩種方法

1、二進(jìn)制安裝(linux是rpm包,windows是exe安裝文件)

2、源碼安裝,推薦安裝方式

二進(jìn)制安裝

示例:centos7_64平臺(tái),數(shù)據(jù)庫(kù)postgresql11,使用yum安裝

不使用yum的話(huà)可以直接使用rpm包安裝,rpm包下載地址https://yum.postgresql.org/rpmchart.php

1、安裝RPM的yum源,其實(shí)就是下載一個(gè)postgresql的yum源pgdg-redhat-all.repo文件到/etc/yum.repos.d目錄下,有了這個(gè)yum源后,就可以直接yum install postgresql11安裝postgresql數(shù)據(jù)庫(kù)了

yum install

https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2、安裝客戶(hù)端,先執(zhí)行search看有哪些PostgreSQL client可供安裝

yum search 'PostgreSQL client'

yum install postgresql11

3、安裝服務(wù)端,先執(zhí)行search看有哪些PostgreSQL server可供安裝,以下步驟安裝好后,會(huì)自動(dòng)創(chuàng)建用戶(hù)postgres,自動(dòng)創(chuàng)建目錄/usr/pgsql-11

yum search 'PostgreSQL server'

yum install postgresql11-server

4、初始化數(shù)據(jù)庫(kù)并啟用開(kāi)機(jī)自動(dòng)啟動(dòng)

/usr/pgsql-11/bin/postgresql-11-setup initdb

systemctl enable postgresql-11

systemctl start postgresql-11

5、查看postgresql的進(jìn)程

[root@zabbixtest2 ~]# ps -ef|grep postgres

postgres  1527     1  0 01:13 ?        00:00:00 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/

6、連接postgresql數(shù)據(jù)庫(kù)

su - postgres

psql -l

psql -d postgres

源碼安裝

1、建立postgresql用戶(hù)、內(nèi)核資源的配置,主要涉及/etc/security/limits.conf、/etc/sysctl.conf文件,類(lèi)似oracle也需要配置這兩個(gè)文件

2、解壓tar包,進(jìn)入解壓目錄,使用root用戶(hù)執(zhí)行如下,最后的make install命令把軟件安裝到/postgresql/pgsql目錄

./configure --prefix=/postgresql/pgsql

make

make install

3、把軟件安裝目錄/postgresql/pgsql授權(quán)宿主用戶(hù)為postgresql

4、編輯postgresql用戶(hù)的.bash_profile文件,PATH= /postgresql/pgsql/bin :$PATH、LD_LIBRARY_PATH= /postgresql/pgsql /lib

5、初始化數(shù)據(jù)庫(kù),后面兩條命令任意一條都可以

su - postgresql

initdb -D /postgresql/pgsql/data

pg_ctl -D /postgresql/pgsq l/data initdb

6、啟動(dòng)postgresql程序,下面任意一個(gè)都可以,官方文檔建議使用pg_ctl

postgres -D /postgresql/pgsql/data >logfile 2>&1 &

pg_ctl start -D /postgresql/pgsql/data -l logfile

7、查看postgresql的進(jìn)程

[root@zabbixtest1 ~]# ps -ef|grep postgres

postgre+   803     1  0 07:10 pts/0    00:00:00 /postgresql/pgsql/bin/postgres -D /postgresql/pgsql/data

8、連接postgresql數(shù)據(jù)庫(kù),指定連接postgres庫(kù)

psql -l

psql -d postgres

備注 :psql命令不加端口和不加數(shù)據(jù)庫(kù)名,表示默認(rèn)進(jìn)入端口為5432并且數(shù)據(jù)庫(kù)名和初始數(shù)據(jù)庫(kù)initdb時(shí)的用戶(hù)名一樣的數(shù)據(jù)庫(kù),比如初始數(shù)據(jù)庫(kù)initdb時(shí)的用戶(hù)名為A,則默認(rèn)進(jìn)入A庫(kù)。postgresql的默認(rèn)端口是5432,默認(rèn)數(shù)據(jù)庫(kù)是postgres、template0、template1

如果此時(shí)端口不是5432,則會(huì)報(bào)錯(cuò)psql: FATAL:  role "A" does not exist

因?yàn)榘惭b用戶(hù)"A"對(duì)應(yīng)的實(shí)例端口為其他,端口5432數(shù)據(jù)庫(kù)的Owner不是"A"

如果此時(shí)沒(méi)有"A"庫(kù),則會(huì)報(bào)錯(cuò)psql: FATAL:  database "A" does not exist

因?yàn)榘惭b用戶(hù)"A",默認(rèn)進(jìn)入"A"庫(kù),而"A"庫(kù)是不存在的

9、創(chuàng)建一個(gè)名為test的數(shù)據(jù)庫(kù)

createdb test

10、查看數(shù)據(jù)庫(kù)狀態(tài)

pg_ctl status -D /postgresql/pgsql/data

11、關(guān)閉數(shù)據(jù)庫(kù)

pg_ctl stop -D /postgresql/pgsql/data

官方文檔Short Version簡(jiǎn)要步驟

./configure

make

su

make install

adduser postgres

mkdir /usr/local/pgsql/data

chown postgres /usr/local/pgsql/data

su - postgres

/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &

/usr/local/pgsql/bin/createdb test

/usr/local/pgsql/bin/psql test

到此,關(guān)于“PostgreSQL的安裝和啟動(dòng)方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

網(wǎng)站欄目:PostgreSQL的安裝和啟動(dòng)方法-創(chuàng)新互聯(lián)
轉(zhuǎn)載來(lái)源:http://muchs.cn/article38/dpicsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、服務(wù)器托管App開(kāi)發(fā)、外貿(mào)建站、面包屑導(dǎo)航企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷(xiāo)型網(wǎng)站建設(shè)