title: How to create a postgres database in the azure pipeline?
body: <p>I am using the windows-latest host agent in my azure pipeline to build and package my maven spring boot Java project. As pare of the Maven buil it runs the tests against a postgres db that is contained on the window host agent. However, how can create a database in the postgres server?</p>
  <p>I am able to connect to the db by specifing the spring datasource URL, username and password as system properties, that works fine (else an error is shown in the console log that it is unable to connect).</p>
  <p>I can use the file schema.sql that contains SQL to perform db initialization that is run by Spring during startup of the app. However, Postgres doesn't have default &quot;creat db if not exists&quot;.
  As such that I tried to use psql to create the db in a script. I found the following command on SO to create the db and tried to run that in a script:</p>
  <pre><code>        - script: |
              &quot;C:\Program Files\PostgreSQL\13\bin\psql&quot; -c &quot;CREATE DATABASE default&quot; &quot;user=postgres dbname=postgres password=root&quot;
            displayName: Creating DB
  </code></pre>
  <p>However, it results in the following error in the console log:</p>
  <pre><code>ERROR:  syntax error at or near &quot;default&quot;
  LINE 1: CREATE DATABASE default
                          ^
  ##[error]Cmd.exe exited with code '1'.
  Finishing: Creating DB
  </code></pre>
  <p>Please some advise on the creation of the db ? And the above error?</p>
  <p>The maven task:</p>
  <pre><code>        - task: Maven@3
            name: maven_package
            displayName: Maven package
            inputs:
                goals: &quot;package&quot;
                mavenPomFile: &quot;backend/pom.xml&quot;
                options: '--settings backend/.mvn/settings.xml -DmygetUsername=$(mygetUsername) -DmygetPassword=$(mygetPassword) -Dspring.datasource.url=jdbc:postgresql://localhost:5432/default  -Dspring.datasource.username=postgres -Dspring.datasource.password=root'
                mavenOptions: &quot;-Xmx3072m $(MAVEN_OPTS)&quot;
                javaHomeOption: &quot;JDKVersion&quot;
                jdkVersionOption: &quot;1.13&quot;
                mavenAuthenticateFeed: true
  </code></pre>