Create Azure Database for PostgreSQL with Initialization Script
Published Jul 23 2019 02:36 PM 5,132 Views
Microsoft

After you create a new Azure Database for PostgreSQL server, your next steps are to set up your Postgres users, databases, extensions and more. An ARM template can help you automate both the server creation and running a startup script. This is ideal for automation scenarios in which you create one or more servers with a fixed configuration and pre-loaded databases, users, roles etc. We can create a reproducible SQL script that can be run after server creation to initialize the server. This SQL script can contain steps like create database, create users, configure roles, create tables, load data, manage extensions etc.

 

Now, we provide a mechanism to run this initialization SQL script as part of the ARM Template deployment itself : ExampleWithStartupScript

 

 

To add your own init.sql steps, please fork the repository, modify the init.sql file to include your custom steps and then deploy using the following link (Replace <GITHUB_USERNAME> with your github handle) : 

 

https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2F<GITHUB_USERNAME>%2Fazure-postgresql%2Fmaster%2Farm-templates%2FExampleWithStartupScript%2Ftemplate.json

NOTE: After successful deployment, you may either use the Ubuntu VM as a PG client VM or delete it.

 

If you have trouble running the script, please let us know by opening an issue here.

Also, feel free to contribute any updates or bug fixes by creating a pull request.

 

Thank you!

Version history
Last update:
‎Jul 23 2019 02:36 PM
Updated by: