-
-
Notifications
You must be signed in to change notification settings - Fork 26
Common problems and its solutions
This error is really common among others. It often happens to appear just after you began to migrate the database -or create them- [rake db:create db:migrate, for example] , or when you are trying to set-up the server for tests [rails server]. There are many "things" that could potentially cause this type of error, we will try to cover the common ones here:
-
- An installation of postgresql that went bad.
-
- An installation of postgresql that went well, but is un-expectedly misconfigurated.
It is often resolved by un-installing postgresql and re-installing it. This problem is usually caused by having an old installed version, or, a corrupted one. For Ubuntu users, by terminal, the "recipe" should be:
-
- Un-install postgresql: sudo apt-get remove postgresql. If you happen to have trouble with dependency, you will need to remove any program that depends on postgresql, and then, remove it.
-
- Re-install postgresql: sudo apt-get install postgresql. After installing, just to check it is well installed, in case it didn't, start the postgresql service (sudo service postgresql start) , and go to /var/run and check if the directory postgresql exists. If it exists, it all went correct.
This situation is rare, but it also causes trouble. While you should think that, after a fresh and successful installation, your postgresql is set to work, you may need to check its configuration. There are cases which have the listen_address not set, or set wrongly. To see if that's the real cause, go to the installation directory of postgresql (in Ubuntu it should be /etc/postgresql/(your installed postgresql version)/main) and open postgresql.conf. This file, among other things, allow us to modify certain connection settings. The one that cares us the most is the listen_address. This setting will define which IPs the server will answer on. If it appears to be commented, un-comment it.
#listen_address = "localhost". Should be: listen_address = "localhost".
If it happens to be set to "localhost", set it to " * ", where the " * " means that the server will answer on any given IP. It should be:
listen_address = " * "
Another useful file is pg_hba.conf. Since we are not going deep in its use, which you can read here, the things you should check is that in the IPv4 local connections you should have:
host all all 127.0.0.1/32 md5
Since this file is read and write protected, you can edit it by running this command line: sudo gedit pg_hba.conf.
While this error may have a quick solution by creating the role mumuki in the database, in this case we will treat the problem where the role postgres doesn't exist.
It is known to be caused for having different "versions" of postgresql installed on top of the postgresql itself. For example: postgres-xc, postgres-xc-common or postgres-xl. Having this versions mixed generates trouble to locate the correct configuration files for the service, or just locating the missing role. The solution to this problem is:
-
- Un-install postgres-xl. In case you have it installed
-
- Un-install postgres-xc-common. In case you have it installed
-
- Un-install postgres-xc. In case you have it installed
-
- Un-install postgresql.
-
- Install postgresql. Probably it will install the latest version, which is good!
-
- Enter the postgres role: sudo su postgres
-
- Enter psql: psql
-
- Create the user mumuki with password mumuki: create role mumuki with createdb login password 'mumuki';
-
- Exit the psql and postgres role: CTRL + D
-
- Run the migrations: rake db:create db:migrate
-
- Run the server: rails server (just to test the app)
Note: The server could be hosted in localhost:3000 instead of localhost:5432, which is not a problem.