I am doing some maintenance work for a postgres database, and one particular table has two status columns that I want to convert into one bitmask column. This database uses a lot of different stored procedures for data manipulation that are sadly not covered by unit tests.
Is there a way to tell whether this table is being used inside queries by any stored procedures? Well, aside from manually going through each procedure’s body using the \df+ switch inside psql.
Sadly, there isn’t. The body of a plpgsql function is just a string that is saved and executed upon call. When you create a function only superficial syntax checks are run on it.
Sometimes this is a blessing. Other times, it’s a curse.
What I do in such a case: dump the schema and search the dump with vim (or grep or the tool of your choice).
If all your functions reside in a particular schema (same word, different meaning!), add:
-n $SCHEMA