欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

忘記PostgreSQL賬號(hào)密碼如何解決-創(chuàng)新互聯(lián)

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)忘記PostgreSQL賬號(hào)密碼如何解決,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

華龍網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)公司成立與2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)公司。

1:定位pg_hba.conf文件位置

首先找到pg_hba.conf文件的位置,具體有下面這些方法:

方法1:locate定位pg_hba.conf文件的位置

$ locate pg_hba.conf
/usr/pgsql-9.5/share/pg_hba.conf.sample
/var/lib/pgsql/9.5/data/pg_hba.conf

方法2:find命令查找。

$ find / -name "pg_hba.conf" 2>%1 | grep -v "Permission denied"
/var/lib/pgsql/9.5/data/pg_hba.conf

2:修改pg_hba.conf配置文件

修改pg_hba.conf前好做一個(gè)備份,這是一個(gè)良好的習(xí)慣,避免回滾的時(shí)候,你能輕松回撤所有操作。

#cp /var/lib/pgsql/9.5/data/pg_hba.conf /var/lib/pgsql/9.5/data/pg_hba.conf.20210125

在pg_hba.conf中找到類似下面這樣的地方:

# TYPE DATABASE USER ADDRESS  METHOD
 
# "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
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres  peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128  ident
 
# Allow access from all host to connect to this UAT server
host all all 0.0.0.0/0 md5

關(guān)于修改pg_hba.conf,如果你打算以socket方式在本機(jī)登錄數(shù)據(jù)庫,那么只需修改local這條記錄,將pg_hba.conf中的這個(gè)選項(xiàng)的的值從md5修改為trust

修改前
# "local" is for Unix domain socket connections only
local all all   md5
 
修改后
# "local" is for Unix domain socket connections only
local all all   trust

trust表示允許可信的本地連接。此時(shí)連接數(shù)據(jù)庫不用輸入密碼。

小知識(shí):

TYPE表示主機(jī)類型,它的取值有下面這些:

local :表示是unix-domain的socket連接

host :表示TCP/IP socket

hostssl: 表示SSL加密的TCP/IP socket

如果你打算以TCP/IP方式訪問數(shù)據(jù)庫,即psql -h227.0.0.1 -Upostgres這樣的方式,那么必須修改host的配置。具體如下所示:

修改前:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
 
 
修改后:
# IPv4 local connections:
host all all 127.0.0.1/32 trust

3: 重啟PostgreSQL服務(wù)

重啟PostgreSQL服務(wù)的方法很多,這里不做過多介紹,選擇你常用的方式即可。

# service postgresql-9.5 stop
Redirecting to /bin/systemctl stop postgresql-9.5.service
# service postgresql-9.5 start
Redirecting to /bin/systemctl start postgresql-9.5.service
# service postgresql-9.5 status
Redirecting to /bin/systemctl status postgresql-9.5.service

4:重置賬號(hào)postgres的密碼

使用psql無密碼登錄,修改用戶postgres的密碼

alter user postgres with password '新的密碼';

方式1:


#psql -U postgres

方式2:


#psql

關(guān)于兩者,如果ssh是用postgres用戶連接服務(wù)器的話,那么直接psql即可,如果是root用戶連接服務(wù)器的話,必須用psql -U postgres

-bash-4.2$ psql
psql (9.5.6)
Type "help" for help.
 
postgres=# alter user postgres with password 'xxxxxxxx';
ALTER ROLE

5:恢復(fù)pg_hba.conf配置文件的修改

6:重啟PostgreSQL服務(wù)

上述就是小編為大家分享的忘記PostgreSQL賬號(hào)密碼如何解決了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站標(biāo)題:忘記PostgreSQL賬號(hào)密碼如何解決-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://chinadenli.net/article46/desdeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、品牌網(wǎng)站制作、動(dòng)態(tài)網(wǎng)站靜態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化