Creating PostgreSQL Database (OS X)

First we need to install PostgreSQL. You can do it in many ways, but in this example I’m using Homebrew:

brew install postgres

Creating a new PostgreSQL database

For creating a new database we just need to run the createdb command:

createdb --encoding=<encoding> --locale=<locale> --template=<template> <dbname>

What are these options?

–encoding: specifies the character encoding scheme to be used in this database.

–locale: Sets the locale settings LC_COLLATE and LC_CTYPE for the database. We can use the following command in the console in order to see the available ones:

locale -a

–template: Specifies the template database from which to build this database. You should use “template0” whenever the collation is different than the one defined by default in your OS. Otherwise we will get an error when trying to create a new db. If you want to know your current collation just run the following command:

locale

Try it!

A real life example, creating the Database Shopping:

createdb --encoding=UTF8 --locale=en_US.UTF-8 --template=template0 Shopping

Leave a Reply

Your email address will not be published. Required fields are marked *