若。。。不小心把這個功能指定到資料庫的 Superuser(enterprisedb),把 enterprisedb 鎖住了,然後又已經登出了。。
edb=# alter user enterprisedb account lock; ALTER ROLE edb=# \q -bash-4.2$ -bash-4.2$ psql -U enterprisedb psql.bin: FATAL: role "enterprisedb" is locked -bash-4.2$
又偏偏沒有其他 Superuser 帳號的話,該怎辦。。。
首先,就算變更 $PGDATA/pg_hba.conf ,讓資料庫變成免密碼登入看看
bash-4.2$ sed -e 's/^local.*/local all all trust/g' -i $PGDATA/pg_hba.conf bash-4.2$ pg_ctl reload server signaled -bash-4.2$ bash-4.2$ psql -U enterprisedb psql.bin: FATAL: role "enterprisedb" is locked -bash-4.2$看起來沒有用。。
bash-4.2$ createuser --super rescuesuper createuser: could not connect to database postgres: FATAL: role "enterprisedb" is locked -bash-4.2$結果要用 Superuser 登入。。。
到了這步,大概要登入進行的手段都不行了。。。
剩下的解決方式可能有點小麻煩:需要停止資料庫,再進入所謂的 Single-User Mode。。
步驟如下:
1. 停止資料庫。。。。
bash-4.2$ pg_ctl -D $PGDATA stop waiting for server to shut down........... done server stopped bash-4.2$
2. 進入 single user mode
bash-4.2$ edb-postgres --single -D $PGDATA edb PostgreSQL stand-alone backend 10.7.15 backend>
3. 執行 unlock 的 SQL 之後,再按 Ctrl 與 D 組合鍵離開 Single User Mode
backend> alter user enterprisedb account unlock; backend> Ctrl+D
4. 啟動資料庫,Superuser 就救援回來了
bash-4.2$ pg_ctl -D $PGDATA start waiting for server to start....2019-06-08 02:42:08 UTC LOG: listening on IPv4 address "0.0.0.0", port 5444 2019-06-08 02:42:08 UTC LOG: listening on IPv6 address "::", port 5444 2019-06-08 02:42:08 UTC LOG: listening on Unix socket "/tmp/.s.PGSQL.5444" 2019-06-08 02:42:09 UTC LOG: redirecting log output to logging collector process 2019-06-08 02:42:09 UTC HINT: Future log output will appear in directory "log". done server started bash-4.2$ psql -U enterprisedb Null display is "(NULL)". psql.bin (10.7.15) Type "help" for help. edb=# \q -bash-4.2$
結論:小心執行 SQL。。。。
參考資料:
2.3.5 Unlocking a Locked Account | Database Compatibility for Oracle Developer’s Guide - EDB Postgres Advanced Server 11
Postgresql single mode and recover from transaction wrap around | AI Rumman with the Systems
PostgreSQL negative PID – Luca Ferrari – Open Source advocate, human being
postgresql - How to exit from postgres' single-user mode? - Stack Overflow
PostgreSQL Administrator Account WITH NOLOGIN (recover your role) – Luca Ferrari – Open Source advocate, human being
沒有留言:
張貼留言