Arch Linux PostreSQL Installation

This last weekend at a friends house I got tired of my desktop wallpaper and decided to migrate distro’s from my default, Debian, to Arch Linux. I’m now setting up my rails development environment. I prefer PostgreSql for my database.

To get the gem ‘pg’ running in my application I need a working instance of Postgres.

$ pacman -s postgresql

This installed postgresql-9.3.5-1 and postgresql-libs-9.3

Become the postgres user

$ su - postgres

Initialize the DB cluster

$ initdb --locale en_US.UTF-8 -E UTF-8 -D '/var/lib/postgres/data'
$ systemctl start posgresql

When I ran the above, I received a notice that I required polkit. I resolved this by running

$ pacman -S polkit

I then had to reboot and retry starting the postgresql service

Create a postgres user for my app

$ createuser --interactive
$ Enter name of role: <user>
$ Shall new role be superuser?: n
$ Shall new user create db?: n
$ Shall new user create roles?: n

I created a super user role with the same name as my linux user

Create a database

$ createdb <database-name>

Add a new linux user with same name as created role

$ sudo useradd -m -s /bin/zsh <user>
$ sudo passwd <user>

Access the database through the REPL as postgres user

$ psql -d <database-name>

Create user in database [Don’t forget the ‘;’ terminator]

=# CREATE USER talon WITH PASSWORD 'mypassword';
=# CREATE DATABASE <database-name>;
=# GRANT ALL PRIVILEGES ON DATABASE <database-name> to <user>;

And then there was a running postgres database!

Published: September 03 2014

blog comments powered by Disqus