PostgreSQL and PostGIS installation in Mac OS

PostGIS is spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL.

When I was setting up a Rails project in my local machine it requires PostGIS setup to run the migration. I have gone through their official sites and many other documents to know about the installation process and found out these processes, to reinstall the PostgreSQL if another version of PostgreSQL is installed previously and installing PostGIS in Mac OS.

Remove previous versions of PostgreSQL

brew uninstall --force postgresql

Delete all Files of Postgres

rm -rf /usr/local/var/postgres

Install Postgres with Homebrew

brew install postgres

Install PostGIS with Homebrew

``` shell brew install postgis ```

Start PostgreSQL server

``` shell pg_ctl -D /usr/local/var/postgres start ```

Create Database

``` shell initdb /usr/local/var/postgres ```

If terminal shows an error

``` shell initdb: directory "/usr/local/var/postgres" exists but is not empty If you want to create a new database system, either remove or empty the directory "/usr/local/var/postgres" or run initdb with an argument other than "/usr/local/var/postgres". ```

Remove old database file

rm -r /usr/local/var/postgres

Run the initdb command again

```shell initdb /usr/local/var/postgres ```

Create a new database

``` shell createdb postgis_test ```

Enable PostGIS

``` shell psql postgis_test ```

This command should show the psql command prompt

psql (10.0)

type “help” for help

postgis_test=#

Creating extension for PostGIS.

``` shell CREATE EXTENSION postgis; ``` If everything goes well we should see: ``` shell postgis_test=#CREATE EXTENSION postgis;

CREATE EXTENSION

postgis_test=#


<h4>Check your PostGIS version</h4>
``` shell
SELECT PostGIS_Version();

Hopefully this article will save your time .

Eslint configuration guide for ReactJS project with VSCode.
Prev post

Eslint configuration guide for ReactJS project with VSCode.

Next post

What is web workers & it's implements in JavaScript?

What is web workers & it's implements in JavaScript?