Deleted PostgreSQL user from mac, how to restore?

烂漫一生 提交于 2021-02-04 14:12:43

问题


I did something really stupid. I was running a postgreSQL on my mac, with a few databases in it.

Recently I noticed a new user called PostgreSQL was added at my login screen, and I didn't find a better idea to remove this user.

Now, my pgAdminIII doesn't connect to the server anymore, giving this error when I try to connect:

Server doesn't listen The server doesn't accept connections: the connection library reports could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (fe80::1) and accepting TCP/IP connections on port 5432?

How can I restore my connection? Hopefully without fully re-installing my postgres??

Thanks a lot :)


回答1:


You must create a new user (it should not have admin rights) with the shortname "postgres" in the admin console, and make sure it has the exact same user ID as the original "postgres" user did.

If you aren't sure what the old user ID was, you can find out by looking at the PostgreSQL directory:

ls -ldn /path/to/data/directory

(The data directory location depends on the PostgreSQL version you installed, and how you installed it).

If you cannot specify the user ID during user creation on Mac OS X, you will instead need to create the user, then reset ownership of the data directory to the newly created user:

sudo chown -R postgres:postgres /path/to/data/directory



回答2:


I use PostgreSQL for linux, but I suposse that in mac OSX will be the same. You can create an admin user from the system command line (without using psql) with the createuser external program, typing in the prompt of a OS terminal.



来源:https://stackoverflow.com/questions/22405576/deleted-postgresql-user-from-mac-how-to-restore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!