0

I am trying to clone a schema in my remotely hosted Postgres 15 database, without affecting the original schema. I decided to do this in the method outlined here in the most-upvoted answer, i.e. using pg_dump to get a plain text file backup, "hacking" the dump to find and replace all references to old_schema with new_schema (because I cannot afford to take the master schema off the grid and I have hard-coded schema-qualified names in functions), and then restoring using psql.

The issue is that when I try to restore, I get this:

ERROR: syntax error at or near "psql".

I'm restoring using the PSQL shell on a Mac and after logging into my database, attempted to run these commands. All resulted in the same error, pointing to the start of the command as incorrect. What is the incorrect syntax in my commands? I also tried using a backslash at the start and omitting the psql part, neither of those worked either.

psql my_db -f '/path/to/file.pgsql';

psql my_db -f /path/to/file.pgsql;

psql -U username -d dbname < /path/to/file.sql;

psql -U username -d dbname < '/path/to/file.sql';

mustaccio
  • 25,896
  • 22
  • 57
  • 72
  • 1
    psql is not a psql meta-command; you should run what you've tried to run from the OS shell command line. – mustaccio May 23 '23 at 20:23
  • @mustaccio I tried that too, the error was "zsh: command not found: psql". – user274130 May 24 '23 at 13:56
  • I'm confused; you said you were "using the PSQL shell on a Mac", now you say it does not exist. You may want to copy-paste your complete shell session for clarity. – mustaccio May 24 '23 at 14:08
  • I have the PSQL application but Terminal isn't recognizing it. I'm looking at this thread and trying to figure out which solution I need to take: https://stackoverflow.com/questions/36155219/psql-command-not-found-mac – user274130 May 24 '23 at 14:29

0 Answers0