Pages - Menu

Showing posts with label postgresql. Show all posts
Showing posts with label postgresql. Show all posts

Monday, January 28, 2013

Testing different database connections

Hello world!

I had to test some database connections from inside my application.

The user fill a form with the required information but before saving it to my PostgreSQL instance I had to check if everything is OK.

I was trying to use my model like this:


And guess what, as expected it replaces my application connection.

The solution is pretty simple, use the adapter class like:


The reason for this code be inside a bedin/rescue is that if anything is wrong with the connection data it will return 500 Internal Server Error

Problem solved.

Wednesday, October 10, 2012

PostgreSQL - Set superuser password

Hi fellas!

To set the superuser password just follow these amazing steps and be happy.

First you log as su:

[daniel@inspiron ~]$ su -
Password:
[root@inspiron ~]# su - postgres
-bash-4.1$ psql
psql (8.4.9)
Type "help" for help.

postgres=# \password postgres
Enter new password:
Enter it again:
postgres=# \q
-bash-4.1$


Second:

Finish


Ohhhh my God! You don't have the su password? Chill out and do this:

$ sudo passwd root


And define your su password

If I am allowed to you give a tip, create a user with the same name as the one you use to log in on your computer, for instance, mine is daniel, so I created a user with login and superuser access like:

CREATE ROLE your_beautiful_name LOGIN SUPERUSER;


Of course you don't have to give it a SUPERUSER permission but if you don't give it a LOGIN, guess what, it won't log in.

To check if everything went ok just:

SELECT rolname FROM pg_roles;


Adios!

Tuesday, October 9, 2012

PostgreSQL - Problem installing gem

Hi fellas!

I was trying for a few days to solve a problem installing pg gem.

The error was about this freaking file: libpq-fe.h

The solution was to uninstall all my postgresql and install these two packages:

$ sudo apt-get install postgresql-9.1
$ sudo apt-get install postgresql-server-dev-9.1


Then you can install your gem with easy.


$ gem install pg


Adios!

Monday, October 1, 2012

PostgreSQL - Install gem

Hi fellas!

Was trying to install PostgreSQL gem and guess what.

Problem!!!

ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
Bla bla bla
...
The solution?

sudo apt-get install libpq-dev

Adios!