Postgres文件所有者更改造成異常處理 本地一臺(tái)測(cè)試機(jī),被同事一不小將根目錄下所有文件的屬主都改成了root( chown -R root:root /,這是個(gè)坑爹而且危險(xiǎn)的操作),postgres數(shù)據(jù)庫(kù)是用其他用戶安裝的,上面還有其他應(yīng)用,這里簡(jiǎn)單說(shuō)下postgres數(shù)據(jù)庫(kù)的恢復(fù)過(guò)程
Postgres文件所有者更改造成異常處理
本地一臺(tái)測(cè)試機(jī),被同事一不小將根目錄下所有文件的屬主都改成了root( chown -R root:root /,這是個(gè)坑爹而且危險(xiǎn)的操作),postgres數(shù)據(jù)庫(kù)是用其他用戶安裝的,上面還有其他應(yīng)用,這里簡(jiǎn)單說(shuō)下postgres數(shù)據(jù)庫(kù)的恢復(fù)過(guò)程。
1.環(huán)境
OS:CentOS 6.2
DB:postgres 9.2.4
2.異常現(xiàn)象
a.數(shù)據(jù)庫(kù)進(jìn)程沒(méi)了
b.日志情況
[postgresql@localhost pg_log]$ tail -f postgresql-2013-05-06_000000.csv
2013-05-06 17:11:21.923 CST,"test","testdb",664,"172.25.10.1:13906",51876c10.298,3,"idle",2013-05-06 16:38:40 CST,37/0,0,WARNING,57P02,"terminating connection because of crash of another server process","The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.","In a moment you should be able to reconnect to the database and repeat your command.",,,,,,,""
2013-05-06 17:11:21.921 CST,"test","testdb",2633,"172.25.10.88:45681",5187730e.a49,3,"idle",2013-05-06 17:08:30 CST,14/0,0,WARNING,57P02,"terminating connection because of crash of another server process","The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.","In a moment you should be able to reconnect to the database and repeat your command.",,,,,,,""
.....
2013-05-06 17:11:21.926 CST,,,24842,,5162b7b7.610a,8,,2013-04-08 20:27:35 CST,,0,LOG,00000,"all server processes terminated; reinitializing",,,,,,,,,""
2013-05-06 17:11:21.955 CST,,,24842,,5162b7b7.610a,9,,2013-04-08 20:27:35 CST,,0,LOG,42501,"could not open file ""postmaster.pid"": Permission denied",,,,,,,,,""
2013-05-06 17:11:22.011 CST,,,24842,,5162b7b7.610a,10,,2013-04-08 20:27:35 CST,,0,PANIC,42501,"could not open control file ""global/pg_control"": Permission denied",,,,,,,,,""
3.恢復(fù)過(guò)程
a.首先改回用戶權(quán)限
[root@localhost ~]#chown -R postgresql:postgresql /var/postgres
[root@localhost ~]#chown -R postgresql:postgresql /data/pgdata
b.重新啟動(dòng)
[postgresql@localhost pg_log]$ pg_start
server starting
[postgresql@localhost pg_log]$ FATAL: could not open lock file "/tmp/.s.PGSQL.lock": Permission denied
could not open control file ""global/pg_control"": Permission denied
重新啟動(dòng)的時(shí)候發(fā)現(xiàn)數(shù)據(jù)庫(kù)仍然不能起來(lái),但是這里給出了一個(gè)信息,tmp下socket文件權(quán)限不夠
返回到root用戶下授權(quán),再啟動(dòng)
[root@localhost home]#cd /tmp
[root@localhost tmp]#ls -a .s.PGSQL*
.s.PGSQL.5432 .s.PGSQL.5432.lock
[root@localhost tmp]#chown postgresql:postgresql ./.s.PGSQL*
[root@localhost tmp]#su - postgresql
[postgresql@localhost ~]$ pg_start
--還是報(bào)上面的錯(cuò)誤,因?yàn)閟ocket文件是本地通信文件,故先刪除再啟動(dòng)DB,平時(shí)沒(méi)事不要手賤去刪
[root@localhost tmp]#rm -f ./.s.PGSQL*
[postgresql@localhost ~]$ pg_start
server starting
[postgresql@localhost ~]$ LOG: could not bind Unix socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, remove socket file "/tmp/.s.PGSQL.5432" and retry.
WARNING: could not create Unix-domain socket
c.登陸檢查
[postgresql@localhost ~]$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
[postgresql@localhost ~]$ psql -h 192.168.10.38
Password:
psql (9.2.4)
Type "help" for help.
postgres=# \q
檢查了一下,剛才啟動(dòng)的時(shí)候在tmp下面socket文件沒(méi)有生成,導(dǎo)致psql登陸直接報(bào)錯(cuò)。若想psql能直接登陸,再重啟一下DB,socket文件會(huì)隨著服務(wù)器的啟動(dòng)而生成。
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com