# How do i execute a script upon database startup

**URL:** <https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036>\
**Category:** Docker Hub\
**Tags:** docker-compose\
**Created:** [March 10, 2023, 3:57pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036 "2023-03-10T15:57:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickn001](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickn001](https://forums.docker.com/u/nickn001)\
**Post date:** [March 10, 2023, 3:57pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/1 "2023-03-10T15:57:28Z")

</div>

I have a requirement of running a software script just after the container is built. Ive tried mounting a new volume and executing it using the whole path but i keep getting the below error.

thank you

```auto
version: '3'
services:
  db:
    image: oracle/oracle19c:new
    environment:
      - ORACLE_SID=ORCLCDB
      - ORACLE_PDB=ORCLPDB1
      - ORACLE_PWD=password123
    ports:
      - 1521:1521
    volumes:
      - oracle:/opt/oracle/oradata
      - ./scripts:/scripts
      - ./software:/software
      - ./scripts/:/opt/oracle/scripts/startup/
    #entrypoint: /scripts/oracle-init.sh
    command: bash -c "/scripts/oracle-init.sh"
    healthcheck:
      test: ["CMD", "/opt/oracle/checkDBStatus.sh"]
      interval: 5s
      #timeout: 10s
      retries: 50
      #start_period: 40s

```

# postbuild.sql in the scripts folder

```auto
alter session set container=ORCLPDB1;
@/software/utPLSQL-develop/utPLSQL-develop/source/install_headless.sql

```

```auto
Session altered.
db_1 |
db_1 | SP2-0310: unable to open file "/software/utPLSQL-develop/utPLSQL-develop/source/install_headless.sql"

```

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [March 10, 2023, 5:05pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/2 "2023-03-10T17:05:41Z")

</div>

Are you aware oracle has a github repo for their [docker-images](https://github.com/oracle/docker-images) that actually helps you to build your image?  
The README.md even covers [Running scripts after setup and on startup](https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md#running-scripts-after-setup-and-on-startup)

---

<div class="post-metadata">

**Author:** ![nickn001](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickn001](https://forums.docker.com/u/nickn001)\
**Post date:** [March 10, 2023, 6:29pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/3 "2023-03-10T18:29:01Z")

</div>

thanks for pointing it out. Ive updated the description with what im trying to achieve but it cant find the path?  
any thoughts pls

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [March 10, 2023, 6:57pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/4 "2023-03-10T18:57:51Z")

</div>

So basically the problem is while executing your postbuild.sql script.

Since you didn’t share any details about your directory structure and the file content, I can only guess that either the file does not exist on that path or the permissions prevent the container process from accessing the file.

---

<div class="post-metadata">

**Author:** ![nickn001](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickn001](https://forums.docker.com/u/nickn001)\
**Post date:** [March 10, 2023, 7:25pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/5 "2023-03-10T19:25:25Z")

</div>

okay, ive managed to attach the software to the volume and it can now be seen.

The problem im now having is that it does not do a complete install [of utlPLSQL [Releases · utPLSQL/utPLSQL · GitHub](https://github.com/utPLSQL/utPLSQL/releases)] when i call the global script "install\_headless.sql - which then calls other referenced scripts and somehow its incomplete when its runs. When i do it manually, it works smoothly.

```auto

1 |
db_1 | Creating utPLSQL user UT3
db_1 | --------------------------------------------------------------
db_1 | Installing utPLSQL v3 framework into UT3 schema
db_1 | --------------------------------------------------------------
db_1 | Switching current schema to UT3
db_1 | --------------------------------------------------------------
db_1 | Installing component UT_DBMS_OUTPUT_CACHE
db_1 | O/S Message: No such file or directory
db_1 |
db_1 |
db_1 | DONE: Executing user defined scripts
db_1 |

```

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [March 10, 2023, 7:43pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/6 "2023-03-10T19:43:16Z")

</div>

> [@nickn001](#):
>
> When i do it manually, it works smoothly.

Manually where? Inside the container? On a oracle database installation on the host?

---

<div class="post-metadata">

**Author:** ![nickn001](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickn001](https://forums.docker.com/u/nickn001)\
**Post date:** [March 12, 2023, 12:36pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/8 "2023-03-12T12:36:57Z")

</div>

Inside the container and calling the same script as sys user

---

<div class="post-metadata">

**Author:** ![nickn001](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickn001](https://forums.docker.com/u/nickn001)\
**Post date:** [March 14, 2023, 10:05am UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/9 "2023-03-14T10:05:24Z")

</div>

any suggestions on how i can tackle this?  
thanks

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [March 14, 2023, 5:45pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/10 "2023-03-14T17:45:49Z")

</div>

I am too far away from oracle databases to know what the problem is or how to tackle it.

Though, we do know that a) executing scripts on database creation is possible (but fails) and b) executing the script manually inside the container works as expected. So you might want to investigate what the entry point script does different in calling the scripts.

---

<div class="post-metadata">

**Author:** ![nickn001](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickn001](https://forums.docker.com/u/nickn001)\
**Post date:** [March 14, 2023, 5:51pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/11 "2023-03-14T17:51:37Z")

</div>

i think the problem is rather general.

Yes if we specify a .sql or .sh , it would work generally But if we specify a path to a parent sql that has sub sql files on the same folder, it does not like it. Error is the same as above.

The error is no Oracle specific but how Docker-compose does not like embedding a path to a bunch of sql files.

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [March 14, 2023, 5:57pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/12 "2023-03-14T17:57:22Z")

</div>

> [@nickn001](#):
>
> The error is no Oracle specific but how Docker-compose does not like embedding a path to a bunch of sql files.

I am going to state the obvious: If you plan to run your scripts inside the container, they need to be configured to use the paths that exist inside the container.

---

<div class="post-metadata">

**Author:** ![nickn001](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickn001](https://forums.docker.com/u/nickn001)\
**Post date:** [March 14, 2023, 6:13pm UTC](https://forums.docker.com/t/how-do-i-execute-a-script-upon-database-startup/135036/13 "2023-03-14T18:13:11Z")

</div>

> [@nickn001](#):
>
> `@/software/utPLSQL-develop/utPLSQL-develop/source/install_headless.sql`

i can confirm the path does exist in the container and i can execute this manually inside the container and “does not fail”  
where as if executed via docker compose the script does not run as expected.

This is how the header script looks like

```auto
@@set_install_params.sql

@@create_utplsql_owner.sql &&ut3_owner &&ut3_password &&ut3_tablespace
@@install.sql &&ut3_owner
@@create_synonyms_and_grants_for_public.sql &&ut3_owner

exit

```
