Centos6.9安裝postgresql12

1.Setup

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql12-contrib postgresql12-server -y
service postgresql-12 initdb 
service postgresql-12 start
su - postgres
psql
ALTER USER postgres WITH PASSWORD '密碼';
\q

2.Create User

CREATE USER pguser WITH PASSWORD '123456';

3.Create Database

CREATE DATABASE test OWNER pguser;  
GRANT ALL PRIVILEGES ON DATABASE test to pguser;  授權給pguser

4.Login
此時登錄出錯:

 $ psql -U pguser - d test 
 psql: FATAL:  Peer authentication failed for user "pguser"
 設置本地用戶登錄

```bash
su
gedit  /var/lib/pgsql/12/data/pg_hba.conf


# “local” is for Unix domain socket connections only
local all all peer
改爲
# “local” is for Unix domain socket connections only
local all all md5
類似的其他改爲:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
然後重啓postgresql
sudo service postgresql-9.3 restart
則可以使用ip登錄
psql -U pguser -d test -h 127.0.0.1
然後重啓postgresql

sudo service postgresql-12 restart

設置遠程連接

sudo vi /var/lib/pgsql/12/data/postgresql.conf

定位到#listen_addresses=’localhost’。PostgreSQL安裝完成後,默認是隻接受來在本機localhost的連接請 求。
將行開頭都#去掉,將行內容修改爲listen_addresses=’*'來允許數據庫服務器監聽來自任何主機的連接請求
/var/lib/pgsql/12/data/pg_hba.conf 添加一行
host all all 0.0.0.0/0 md5

sudo service postgresql-12 restart
psql -U pguser - d test
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章