PGsql 基本用戶權限操作


Ⅰ. 安裝與初始賬戶密碼修改

1. 安裝

sudo apt-get install postgresql-9.4

2. 管理員身份打開pg

sudo -u postgres psql

 sudo -u postgres 表示以postgres 用戶身份登錄

PostgreSQL數據默認會創建一個postgres的數據庫用戶作為數據庫的管理員,密碼隨機;

3.  修改密碼

ALTER USER postgres WITH PASSWORD '123456'; 

 

Ⅱ. 修改指定用戶指定權限

alter user postgres superuser createrole createdb replication;

注意:如果出現 FATAL: role '...' is not permitted to log in.  的錯誤

alter user postgres superuser createrole createdb replication login;

在授權后面加入login 即可;

 

Ⅲ. 數據庫更改屬於postgres用戶

postgres=# alter database database_name OWNER TO new_user;

 

IV. 修改PostgresSQL數據庫配置實現遠程訪問

vi /etc/postgresql/9.4/main/postgresql.conf

1.監聽任何地址訪問,修改連接權限

#listen_addresses = 'localhost'      改為 listen_addresses = '*'

2.啟用密碼驗證

#password_encryption = on 改為 password_encryption = on
vi /etc/postgresql/9.4/main/pg_hba.conf

在文檔末尾加上以下內容

host all all 0.0.0.0 0.0.0.0 md5

6、重啟服務

/etc/init.d/postgresql restart

7、5432端口的防火牆設置 ( Iptable版)

5432為postgreSQL默認的端口

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM