# How can execute a SQL script in Postgres on multiple database

**URL:** <https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965>\
**Category:** Community Answers\
**Created:** [June 14, 2022, 1:49pm UTC](https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965 "2022-06-14T13:49:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![daulat01](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@daulat01](https://forum.liquibase.org/u/daulat01)\
**Post date:** [June 14, 2022, 1:49pm UTC](https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965/1 "2022-06-14T13:49:27Z")

</div>

Hello Team,

I am new to the Liquibase. Hence, I need your suggestions and help on the following.  
I want to use the SQL format to interact with PostgreSQL server /databases.  
I am able to execute my sql script with single database successfully but I want to know how I can execute the same SQL script for multiple databases on the same server (Liquibase and Postgres is on the same machine).

Also, How we can interact to multiple Postgres servers incase liquibase is on different server/standalone machine.

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [June 14, 2022, 4:42pm UTC](https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965/2 "2022-06-14T16:42:24Z")

</div>

Hello,

The only thing that needs to change to deploy your liquibase changelogs to mulitple databases is the database jdbc string (and possibly the credentials). You will run a Liquibase “update” for each different database, changing the URL (jdbc string) between each execution.

Liquibase does not need to be installed on the database server, it just needs to be able to reach the database server (no firewall blocks).

---

<div class="post-metadata">

**Author:** ![daulat01](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@daulat01](https://forum.liquibase.org/u/daulat01)\
**Post date:** [June 15, 2022, 5:50pm UTC](https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965/3 "2022-06-15T17:50:15Z")

</div>

Thanks for your prompt reply. I have deployed the changes to more than one database using below

liquibase --changelog-file=changelog5.sql --url=jdbc:postgresql://localhost:5432/test1 update  
liquibase --changelog-file=changelog5.sql --url=jdbc:postgresql://localhost:5432/test2 update

liquibase --changeLogFile=changelog.sql --username=postgres --password=Postgres10 --classpath=/home/ec2-user/liquibase/internal/lib/postgresql.jar --url=jdbc:postgresql://localhost:5432/test1 update

But facing an issue while making changes to remote host. Could you please suggest on this ?  
Remote host:

liquibase --changelog-file=changelog5.sql --url=jdbc:postgresql://18.104.102.25:5432/test\_db2 update

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [June 15, 2022, 6:59pm UTC](https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965/4 "2022-06-15T18:59:48Z")

</div>

What is the issue? unless you have a liquibase.properties file that contains the username and password, you also need to provide those when using the CLI.

---

<div class="post-metadata">

**Author:** ![daulat01](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@daulat01](https://forum.liquibase.org/u/daulat01)\
**Post date:** [June 16, 2022, 10:46am UTC](https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965/5 "2022-06-16T10:46:09Z")

</div>

I am getting below error message.

[ec2-user@ip-172-31-32-99 ~]$ liquibase --changelog-file=changelog5.sql --username=postgres --password=Postgres10 --url=jdbc:postgresql://18.104.102.25:5432/test\_db2 update

Error:  
Unexpected error running Liquibase: Connection could not be created to jdbc:postgresql://18.104.102.25:5432/test\_db2 with driver org.postgresql.Driver. The connection attempt failed.

For more information, please use the --log-level flag

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [June 16, 2022, 4:07pm UTC](https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965/6 "2022-06-16T16:07:28Z")

</div>

ok, that’s not really a Liquibase error. Are you able to connect to the database using psql?

---

<div class="post-metadata">

**Author:** ![daulat01](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@daulat01](https://forum.liquibase.org/u/daulat01)\
**Post date:** [June 23, 2022, 7:00pm UTC](https://forum.liquibase.org/t/how-can-execute-a-sql-script-in-postgres-on-multiple-database/6965/7 "2022-06-23T19:00:26Z")

</div>

Thanks. It is resolved after opening the port (added port in security group on AWS) between servers.
