The Easy Way to Get Started with PostgreSQL on a Mac: Postgres.app and Induction
Here’s how to get started with PostgreSQL in minutes without having to touch the command line. You’ll need two applications to run and manage PostgreSQL, Postgres.app and Induction. Postgres.app is the equivalent of the MySQL server you get with MAMP and Induction is the equivalent to something like Sequel Pro if you are coming from MySQL.
Up and Running
Once you have those two applications downloaded and installed, here’s what you need to do to get your PostgreSQL server running and be able to use Induction as a GUI to manage your databases.
1. Open Postgres.app
This will start the server and if it’s the first time you’ve run the app, it will automatically create a PostgreSQL user and database named after the user you are logged in as on your system.
2. Configure Induction
Open Induction and you’ll see the login screen. Enter the following information:
- Adapter: Select postgres
- Hostname: Enter 127.0.0.1 (localhost)
- Username: You can use the username Postgres.app created for you (the same name as the user for your system)
- Password: You should be able to leave this blank if you are using the user that Postgres.app created for you
- Database: As of this writing, it says this is optional, which it should be, but I couldn’t connect without specifying the name of a database. You can use the one Postgres.app created for you (should be the same as the username) or create one by hand with as explained later in this post.
That’s it, you should be up and running (told you it was the easy way!), but read on for a couple other tips on working with Postgres.app and Induction.
Note: There are other tools that are more full-featured than Induction, like Navicat, but Induction is the only open source GUI I’ve seen for managing PostgreSQL and it is being developed by Matt Thompson, the creator of Postgres.app, so you can be confident they are going to play nice together.
Setup the Command Line Tools
Lion and Mountain Lion come with an older version of PostgreSQL which includes a psql
command line utility for managing your PostgreSQL on your machine. However, Postgres.app comes with its own psql
utility as well as a slew of other useful binaries that I’m sure you’ll want to have access to at some point if you continue working with PostgreSQL.
To install these tools, just add Postgres.app’s bin
directory to your PATH
. You can do this by adding the following line to your shell’s configuration (.bashrc
or .zshrc
).
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
Then open a fresh terminal session and you should be able to run all of the command line tools directly. This will also allow you to run psql
on its own, without a host, to login to the console. Try it out and make sure it’s working.
Creating Databases
In the current version of Induction (0.1.0) you can’t create databases from the app (I’m assuming you will be able to at some point) so you still need to do that from the command line using psql
. Just connect by running psql
, then create a database with the CREATE DATABASE
command.
CREATE DATABASE database_name;
You can remove a database by using the DROP DATABASE
command:
DROP DATABASE database_name;
If you’re using Rails, you can also use rake db:create
to create your database without using psql
. Just make sure to configure your database.yml
first.
The Future
Postgres.app and Induction are relatively new and look like they are being very actively developed. Keep an eye out for new releases and additional functionality in the near future, especially with Induction since it is still in alpha.
These tools should make getting started with PostgreSQL on a Mac a lot easier and enable a lot of people who rely on GUIs to administer their databases to make the transition from MySQL to PostgreSQL. If you’re trying to decide if PostgreSQL is right for you, just Google around, there are a lot of resources highlighting the differences.
Please let me know if you have questions, comments or corrections on any of this info. I’ll make sure to update this post if these steps change as the apps evolve.
Source: