1

I have some shell and java jar files that need to be executed on a database from the command prompt.

1 Answer 1

2

In order to perform SQL queries on a Postgres database, you'll need to log in. The simplest way to execute raw PL/pgSQL (which includes SQL syntax) is by using the psql binary:

psql -U <db_username> -d <db_name> < <raw_PL/pgSQL_file>

If the bash is raw SQL / PL/pgSQL, you can give it directly to the psql command. If it's a script that connects to a database (which it probably is), you'll need to either 1) modify it to connect to your database, or 2) delete everything but the SQL / PL/pgSQL that needs to be run, then pass it to the psql command.

As for the jar, I can't say. It's compiled java code--who knows what database it's trying to connect to (maybe it requires you to pass the database name and the user to log in as?).

EDIT: All of these methods require a database password (if your database has one set up, which I would hope it would).

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry—meant “PL/pgSQL”

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.