Centos7 postgresql安裝全過程


安裝
安裝 存儲庫RPM

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
安裝客戶端軟件包

yum install postgresql10

安裝服務器包

yum install postgresql10-server
只下載 不安裝

yum install --downloadonly --downloaddir=/root/ postgresql10 postgresql10-server
--downloadonly #只下載
--downloaddir=/root/ #rpm的下載保存地址
安裝

yum install ./*.rpm
初始化數據庫並啟用自動啟動

# 初始化數據庫
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10

配置用戶名密碼+遠程登錄
允許遠程登錄

# 編輯配置文件 listen_address=’localhost’ 改為 "*",去掉注釋
vim /var/lib/pgsql/10/data/postgresql.conf


# 修改
vim /var/lib/pgsql/10/data/pg_hba.conf
# 添加 24是子網掩碼 password ,將127 也改為password
host all all 192.168.56.0/24 password


#重啟服務
systemctl restart postgresql-10

從系統中進入數據庫進行操作:

su postgres
psql -U postgres # 登錄命令 會進入postgres用戶的控制台
# psql -U postgres # 再次執行 進入數據庫
\c postgres # \c 數據庫 ,選擇一個數據庫進入

\l 是查看有哪些數據庫

創建用戶名和密碼

create user username with login password 'password';
# 如,用戶名sun,密碼123456
create user sun with login password '123456';

# 創建數據庫 dbname,dbname小寫
CREATE DATABASE dbname;

# 給用戶權限, 給用戶某個schema的所有權限,如果有
grant all on all tables in schema postgres to sun;


data目錄遷移
https://blog.csdn.net/wk1134314305/article/details/79054248


免責聲明!

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



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