I run a daily backup of my database using pg_dump and pg_restore that recently stopped working after I pushed an update.
I have a function validate_id
that's a Case/When
statement just as a quick check for some the data that has integrity issues. Looks something like this:
CREATE OR REPLACE FUNCTION validate_id(
_string text,
_type type
) RETURNS boolean AS
$$
SELECT
CASE WHEN (stuff) THEN TRUE
WHEN (other stuff) THEN TRUE
When (more stuff) THEN raise_err('Not an accepted type, the accepted types are: x y z')
ELSE FALSE
$$
LANGUAGE SQL;
Since I added this function, when I dump using this command:
pg_dump -U postgres -h ipaddress -p 5432 -w -F t databaseName > backupsfolder/databaseName.tar
When I use this command:
pg_restore -U postgres -h localhost -p 5432 -d postgres -C "backupsfolder/databaseName.tar"
As of two days ago, this now throws an error:
pg_restore: error: could not execute query: ERROR: function raise_err(unknown) does not exist
I'm pretty lost on what to do. I think what might be going on is that it's trying to restore this function before it restores the raise_err
function. Which I thought was built-in to postgres (I can SELECT raise_err('Hello, World');
). Is this possible? Is it my CASE
statement because I need to return only Booleans? All of the permissions seem correct and restoring with previous backups works fine.
psql
, and do\df+ raise_err
. That is not a standard function so far as I know. You should not need another function to raise an error since you can just doraise error
– Mike Organeksql
or does it have to beplpgsql
? – HelpMeExitVim\df+ raise_err
does...return the function. It's not something I ever remember explicitly creating but I mean, stuff happens. – HelpMeExitVimlanguage sql
will not support it, and that probably explains why you wrote it as a function. Also, it israise exception
, notraise error
as I erroneously said in my earlier comment. It looks like this sometimes happens: stackoverflow.com/q/30707533/13808319 – Mike Organeklanguage sql
function confounded the algo's trying to find dependencies during pg_backup. – Mike Organek