Installing MIMIC-III in a local Postgres database on Windows
These are relatively brief instructions provided to ease installation of PostgreSQL with MIMIC on a Windows machine. If you feel there are key details missing, please raise an issue with your suggested improvements - we would love to incorporate them!
Note that before proceeding with this guide you will need to:
- Download the MIMIC-III Clinical Database (see here for details on gaining access).
- Extract the MIMIC-III Clinical Database as .csv files somewhere on your local computer.
- Download the PostgreSQL scripts from here - only the files which end in
Install PostgreSQL using the installer linked to here: http://www.postgresql.org/download/windows/
Run through the entire install process - remember your postgres user password as you will need it later.
Run SQL Shell (psql)
Open up the SQL shell program. Log-in as user postgres (and use the password you specified during the install process).
Create the database to hold the data
Run the following commands:
DROP DATABASE IF EXISTS mimic; CREATE DATABASE mimic OWNER postgres;
This creates the database
mimic, owned by user
postgres. Of course you are welcome to change these values if you like - just note that any changes here will require further changes in the subsequent steps.
Next, connect to the
Create the tables on the database
Note that postgres uses the
public schema by default. While it is personal preference, we recommend creating an independent schema to host the data. To do this, create the mimiciii schema:
CREATE SCHEMA mimiciii;
Then, inform postgres that it should by default use the
mimiciii schema. You will need to do this every time you launch psql.
set search_path to mimiciii;
Now run the create tables script (note: this assumes that the create table script is in the current directory - if it is not, see below).
If you get the error
postgres_create_tables.sql: No such file or directory that means that the file
postgres_create_tables.sql is not in your current directory. Specify the path to the file. In my case, I wrote:
If you see a lot of “NOTICE: table does not exist” don’t worry, that’s normal. The script tries to delete the table before it creates it.
Import the data into the tables
Run the following command import the data into these tables:
\set ON_ERROR_STOP 1 \set mimic_data_dir 'D:/mimic/v1_4' \i D:/work/mimic-code/buildmimic/postgres/postgres_load_data.sql
Note I have specified a folder,
'D:/mimic/v1_4'. This folder contains all the CSV files which store MIMIC. This should begin the load process, which takes some time.
After the load finishes, it is recommended to install indexes to improve the speed of queries on the database. These can be installed by running the following:
While you have the option of building constraints (using
postgres_add_constraints.sql) these are mainly used for data integrity checking during the creation of the data - it is not necessary to run this file on your local installation.
Test your build
You should now be able to query MIMIC-III! Try the following simple query:
select icustay_id, intime, outtime from icustays limit 10;
You may also find the introduction to MIMIC-III guide useful. Good luck in your research!