Skip to content

Instantly share code, notes, and snippets.

@scootcho
Created March 11, 2014 08:52
Show Gist options
  • Save scootcho/9481892 to your computer and use it in GitHub Desktop.
Save scootcho/9481892 to your computer and use it in GitHub Desktop.
To install Postgres (linux):
1. Open your terminal and type sudo apt-get install postgresql
2. After installing postgres, you might like to install pgAdmin III. It is a nice GUI to have, especially for beginners. To do this, in terminal type ```sudo apt-get install pgadmin3
3. To start off, we need to change the PostgreSQL postgres user password; we will not be able to access the server otherwise. As the “postgres” Linux user, we will execute the psql command. In terminal, type sudo -u postgres psql postgres
4. Set a password for the "postgres" database role using the command: \password postgres
and give your password when prompted. The password text will be hidden from the console for security purposes.
Type Control+D to exit the posgreSQL prompt.
5. To create the first database, which we will call "odin", simply type:
sudo -u postgres createdb odin
6. For ""Postgresql 9.1""+ install the adminpack "extension":
sudo -u postgres psql
CREATE EXTENSION adminpack;
7. Open up pgAdmin III (app menu->development->pgAdmin III)
8. Open file->add server and populate the following as field:data
Name: localhost
Host: localhost
Port: 5432
Service: <leave blank>
Maintenance DB: postgres
Username: <whatever>
Password: <whatever>
Store Password: yes
and click "OK".
9. You should see a new server populated in the side panel of the pgadmin window.
10. Expand (+) the server and you will see the database you created with a red X next to it. Double click to connect the database.
11. You now have postgresql set up with a GUI frontend for management, if you so desire. It is much easier for a newcomer to user pgadmin III than to try and figure out all the terminal commands.
12. Edit your /config/database.yml with the correct database information you set up in the prior steps. It will then connect to the database you created and rake db:migrate will now properly function.
---
On nitrous:
1. In the console type:
parts install postgresql
2. Now that it's installed, we start it using:
parts start postgresql
3. Now that postgres is started, we want to create a new username and database:
createuser --createdb --superuser -Uaction YOUR_USERNAME
psql -c "create database YOUR_DATABASE_NAME owner YOUR_USERNAME encoding 'UTF8' TEMPLATE template0;"
4. Now that you have the new database created, simply edit your config/database.yml file:
development:
adapter: postgresql
encoding: unicode
database: <YOUR_DB_NAME>
pool: 5
host: localhost
username: <YOUR_USER_NAME>
password: <YOUR_PASSWORD_(IF_ANY)>
That's it! You're all set up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment