How to run production database dump file your local machine:

Prerequisite: You should have installed postgres database

Follow the one of the below links or could do a google for the help on (how to install and setup PostgreSQL on mac machine).

  1. postgres installation via homebrew
  2. install-postgresql-9-on-os-x

Once you have installed postgres and it’s up and running in your local machine,
we are good to go for the next step.

After installation, you should be able to run the utility command createdb
createdb is a wrapper on top of the SQL command create database.

Now Come to the Requirements:
Create a database in the local machine which contains the production data dump
and should be able to run the SQL script on it.

Solution:


# create new database name as production_local_copy

createdb production_local_copy

# import the production dump data to our new database

psql  production_local_copy < path/to/production/dump/dump_prod_db.sql

# run psql cli and connect to production_local_copy db

psql

\c production_local_copy

Now local production DB is ready to run the desired query results.

NOTE: Don’t forget to sanitize the production users data before using it.

For sanitization of production data, generally, we run the update queries on desired tables.
Ex:


UPDATE users SET first_name 'test';
UPDATE users SET email 'test';
UPDATE users SET login 'test';