解除安裝安裝postgres資料庫

2021-09-26 07:58:05 字數 2718 閱讀 7781

一、postgres的解除安裝

a.centos系統

1.檢視版本號和系統類別:cat /etc/redhat-realease;

2.如果是redhat:(yum install)

a、yum 刪除軟體包:

yum remove postgresql* 或者 rpm -qa | grep postgresql 然後再一一刪除

b、刪除相關目錄檔案:

rm -rf /var/lib/pgsql

rm -rf /usr/pgsql*

c、刪除pg相關使用者組/使用者

userdel -r postgres

groupdel postgres

b.ubuntu

a、如果在執行,預設的5432埠就能被監聽到,請執行 sudo service postgresql stop 暫停服務。在命令列輸入

sudo apt-get --purge remove postgresql

b、刪除postgresql安裝包,安裝刪除後還有刪除對應的配置

sudo rm -r /etc/postgresql/

sudo rm -r /etc/postgresql-common/

sudo rm -r /var/lib/postgresql/

c、刪除pg相關使用者組/使用者

sudo userdel -r postgres

sudo groupdel postgres

二、centos7.0下postgres資料庫的安裝

a、安裝資料庫版本包

yum install -y

yum install -y postgresql10-server postgresql10-contrib

b、初始化

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

c、配置遠端訪問(注意配置檔案中不能允許出現tab符)

vi /var/lib/pgsql/10/data/postgresql.conf 

如果想對所有ip開放,則將listen_addresses = 'localhost』改為listen_addresses = '*'即可,如果想僅對部分ip開放,多個ip之間用,(逗號+空格)隔開

d、配置賬戶訪問許可權

vi /var/lib/pgsql/10/data/pg_hba.conf

最後一項method解析如下:

trust 任何連線都允許,不需要密碼

reject 拒絕符合條件(前面幾個條件)的請求

md5 接收乙個md5加密過的密碼

password 接收乙個密碼來登陸,只在可信的網路使用這種方式

gss 使用gssapi認證,只在tcp/ip連線可用

sspi 只在windows可用的一種方式

krb5 不常用,只在tcp/ip可用

ident 使用作業系統使用者名稱認證,驗證它是否符合請求的的資料庫使用者名稱

ldap 使用ldap伺服器認證

cert 使用ssl客戶端認證

pam 使用作業系統的pam模組服務

# ipv4 local connections: host all all 127.0.0.1/32 trust

host all all      0.0.0.0/0(需要連線的伺服器ip) trust

e、設定開機啟動

systemctl enable postgresql-10

systemctl daemon-reload 載入配置

f、啟動資料庫

systemctl start postgresql-10

三、安裝後使用設定

adduser dbuser (新增使用者dbuser )

su - postgres (切換使用者)

psql (進入資料庫)

alter user postgres with encrypted password 『abc123』; (修改postgres 的密碼)

create user dbuser with password 『password』;(新增dbuser 的密碼)

create database exampledb owner dbuser; (創資料庫exampledb 並指定所有者為dbuser)

grant all privileges on database exampledb to dbuser;將exampledb資料庫的所有許可權都賦予dbuser,否則dbuser只能登入控制台,沒有任何資料庫操作許可權。

\q (退出)

psql -u dbuser -d exampledb -h 127.0.0.1 -p 5432 (連線進入資料庫 initdb --help 可以看到初始化資料庫的幫助資訊)

開啟防火牆

firewall-cmd --query-port=3306/tcp 查詢埠是否開放

firewall-cmd --permanent --add-port=3306/tcp 開放埠

firewall-cmd --permanent --remove-port=3306/tcp 關閉埠

service firewalld restart //重啟防火牆

debian下安裝Postgres資料庫

2.這些包安裝完成後,postgres就算安裝完成了,接下來就是通過安裝時預設建立的postgres使用者來建立的資料庫使用者名稱,root使用者是不能用來登入資料庫的。1 先通過root使用者在debian環境下建立乙個使用者用於登入系統,如testroot adduser testroot 然後...

centOS下安裝postgres資料庫

需在root使用者許可權下安裝 yum install yum install postgresql11 yum install postgresql11 server 初始化資料庫,並使其自啟動服務 usr pgsql 11 bin postgresql 11 setup initdb syste...

postgres模板資料庫

create database 實際上是通過拷貝乙個現有的資料庫進行工作的。預設時,它拷貝名為 template1 的標準系統資料庫。所以該資料庫是建立新資料庫的 模板 如果你給 template1 增加物件,這些物件將被拷貝到隨後建立的使用者資料庫中。這樣的行為允許節點對資料庫中的標準套件進行修改...