mimic-code icon indicating copy to clipboard operation
mimic-code copied to clipboard

Add indexes to improve performance: ERROR: relation "admissions" does not exist

Open HelloAnneKim opened this issue 9 years ago • 9 comments

I'm adding indexes/indices to improve performance. I used psql 'dbname=mimic user=mimic options=--search_path=mimiciii' -f postgres_add_indexes.sql while I was in the working directory buildmimic/postgres , I got the error:

psql:postgres_add_indexes.sql:19: NOTICE: index "admissions_idx01" does not exist, skipping DROP INDEX psql:postgres_add_indexes.sql:21: ERROR: relation "admissions" does not exist

How should I troubleshoot?

HelloAnneKim avatar Jul 06 '17 19:07 HelloAnneKim

Further, when I try to skip this step and actually query mimic with psql 'dbname=mimic user=mimic options=--search_path=mimiciii' and then alter superuser and mimic=> select count(subject_id) \n mimic-> from mimiciii.patients; I get the following error: ERROR: permission denied for schema mimiciii

HelloAnneKim avatar Jul 06 '17 19:07 HelloAnneKim

Your first error looks like an issue regarding the schema. That is you may have built the tables on a different schema. Double check to confirm that you've built all the tables on the mimiciii schema.

The second issue implies you're using a user with insufficient privileges. You need to grant access to the schema to whatever user you are querying with, e.g. GRANT USAGE ON SCHEMA mimiciii TO <username_here>;

alistairewj avatar Jul 09 '17 03:07 alistairewj

How do I double check if the tables are built? Also, how can I check what my local sql environment's <username> is?

HelloAnneKim avatar Jul 10 '17 12:07 HelloAnneKim

By default you will have the SQL user postgres. Past that, it depends on how you built the database (the scripts make a user called mimic_user I believe). Once you are in psql, you can run a few commands:

\l - list databases \dn - list schemas under a database \dt - list tables under schema that's currently looked for in the search_path

You can change the search_path using the command set search_path to <schema>;

Users are done entirely independent from this and can be checked using \du

You might find a tutorial on postgres useful, e.g. https://www.tutorialspoint.com/postgresql/postgresql_schema.htm

alistairewj avatar Jul 11 '17 05:07 alistairewj

Thank you. The postgres information was very helpful, but I'm still getting errors

                                        List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 annekim   | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 mimic     |                                                            | {}

mimic=> GRANT USAGE ON SCHEMA mimiciii TO annekim;
ERROR:  permission denied for schema mimiciii
mimic=> GRANT USAGE ON SCHEMA mimiciii TO mimic;
ERROR:  permission denied for schema mimiciii

HelloAnneKim avatar Jul 11 '17 14:07 HelloAnneKim

My guess is you are logged in as user mimic who doesn't have permission to grant privileges. Try logging in as annekim as follows: psql -U annekim -d mimic. See how that works!

alistairewj avatar Jul 12 '17 02:07 alistairewj

@tompollard helped me out by granting superuser privileges to the mimic user and I believe we also changed something about the schema. Thanks!

HelloAnneKim avatar Jul 12 '17 20:07 HelloAnneKim

Thanks @herroannekim. @alistairewj it seems there may be something up with the build scripts and/or the tutorials, so I'll leave this issue open.

tompollard avatar Jul 12 '17 23:07 tompollard

I tidied up the build scripts. I rebuilt the database successfully on my Ubuntu machine last night so hopefully this issue is resolved. Also tidied up the readme a bit.

alistairewj avatar Jul 26 '17 16:07 alistairewj