I achived that wrote (located in the directory where my script is)
::someguy@host::$sudo -u user psql -d my_database -a -f file.sql
where -u user
is the role who owns the database where I want to execute the script then the psql
connects to the psql
console after that -d my_database
loads me in mydatabase
finally -a -f file.sql
where -a
echo all input from the script and -f
execute commands from file.sql
into mydatabase
, then exit.
I'm using: psql (PostgreSQL) 10.12 on (Ubuntu 10.12-0ubuntu0.18.04.1)