CentOS7下PostgreSQL搭建與配置


root用戶下:

安裝

yum install postgresql-server

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

postgresql-setup initdb

設(shè)置開(kāi)機(jī)啟動(dòng)

systemctl enable postgresql.service

啟動(dòng)服務(wù)

systemctl start postgresql.service

切換用戶

su - postgres

postgres用戶下:

登錄postgresql控制臺(tái)

psql

PostgreSQL控制臺(tái)下:

為postgres用戶設(shè)置密碼

\password postgres;

輸入新密碼 YOUR_OWN_PWD

創(chuàng)建數(shù)據(jù)庫(kù)用戶test

CREATE USER test WITH PASSWORD 'YOUR_OWN_PWD';

創(chuàng)建數(shù)據(jù)庫(kù)TestCaseRepo

CREATE DATABASE TestCaseRepo OWNER test;

將TestCaseRepo數(shù)據(jù)庫(kù)的所有權(quán)限賦予test

GRANT ALL PRIVILEGES ON DATABASE TestCaseRepo to test;

退出psql控制臺(tái)

\q

回到root用戶:

修改/var/lib/pgsql/data/pg_hba.conf部分內(nèi)容,添加信任的連接ip

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             192.168.2.1/24          trust

設(shè)置允許通過(guò)ip地址連接,修改/var/lib/pgsql/data/postgresql.conf部分內(nèi)容

listen_addresses = '*'

重啟服務(wù),使配置生效

systemctl restart postgresql.service

登錄數(shù)據(jù)庫(kù)(數(shù)據(jù)庫(kù)名稱(chēng)需要小寫(xiě))

psql -U test -d testcaserepo -h 127.0.0.1 -p 5432
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容