Home
%3CLINGO-SUB%20id%3D%22lingo-sub-753040%22%20slang%3D%22en-US%22%3ECreate%20Azure%20Database%20for%20PostgreSQL%20with%20Initialization%20Script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-753040%22%20slang%3D%22en-US%22%3E%3CP%3EAfter%20you%20create%20a%20new%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fservices%2Fpostgresql%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Database%20for%20PostgreSQL%20server%3C%2FA%3E%2C%20your%20next%20steps%20are%20to%20set%20up%20your%20Postgres%20users%2C%20databases%2C%20extensions%20and%20more.%20An%20ARM%20template%20can%20help%20you%20automate%20both%20the%20server%20creation%20and%20running%20a%20startup%20script.%20This%20is%20ideal%20for%20automation%20scenarios%20in%20which%20you%20create%20one%20or%20more%20servers%20with%20a%20fixed%20configuration%20and%20pre-loaded%20databases%2C%20users%2C%20roles%20etc.%20We%20can%20create%20a%20reproducible%20SQL%20script%20that%20can%20be%20run%20after%20server%20creation%20to%20initialize%20the%20server.%20This%20SQL%20script%20can%20contain%20steps%20like%20create%20database%2C%20create%20users%2C%20configure%20roles%2C%20create%20tables%2C%20load%20data%2C%20manage%20extensions%20etc.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20we%20provide%20a%20mechanism%20to%20run%20this%20initialization%20SQL%20script%20as%20part%20of%20the%20ARM%20Template%20deployment%20itself%20%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-postgresql%2Ftree%2Fmaster%2Farm-templates%2FExampleWithStartupScript%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EExampleWithStartupScript%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%2F%23create%2FMicrosoft.Template%2Furi%2Fhttps%253A%252F%252Fraw.githubusercontent.com%252FAzure%252Fazure-postgresql%252Fmaster%252Farm-templates%252FExampleWithStartupScript%252Ftemplate.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20%3CIMG%20src%3D%22http%3A%2F%2Fazuredeploy.net%2Fdeploybutton.png%22%20border%3D%220%22%20%2F%3E%20%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20add%20your%20own%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-postgresql%2Fblob%2Fmaster%2Farm-templates%2FExampleWithStartupScript%2Finit.sql%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Einit.sql%3C%2FA%3Esteps%2C%20please%20%3CA%20href%3D%22https%3A%2F%2Fhelp.github.com%2Fen%2Farticles%2Ffork-a-repo%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Efork%3C%2FA%3Ethe%20repository%2C%20modify%20the%20init.sql%20file%20to%20include%20your%20custom%20steps%20and%20then%20deploy%20using%20the%20following%20link%20(Replace%20%3CSTRONG%3E%3CGITHUB_USERNAME%3E%3C%2FGITHUB_USERNAME%3E%3C%2FSTRONG%3Ewith%20your%20github%20handle)%20%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3Ehttps%3A%2F%2Fportal.azure.com%2F%23create%2FMicrosoft.Template%2Furi%2Fhttps%253A%252F%252Fraw.githubusercontent.com%252F%26lt%3BGITHUB_USERNAME%26gt%3B%252Fazure-postgresql%252Fmaster%252Farm-templates%252FExampleWithStartupScript%252Ftemplate.json%3C%2FPRE%3E%0A%3CP%3E%3CSTRONG%3ENOTE%3A%3C%2FSTRONG%3EAfter%20successful%20deployment%2C%20you%20may%20either%20use%20the%20Ubuntu%20VM%20as%20a%20PG%20client%20VM%20or%20delete%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20trouble%20running%20the%20script%2C%20please%20let%20us%20know%20by%20opening%20an%20issue%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-postgresql%2Fissues%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere.%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EAlso%2C%20feel%20free%20to%20contribute%20any%20updates%20or%20bug%20fixes%20by%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-postgresql%2Fpulls%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecreating%20a%20pull%20request%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-753040%22%20slang%3D%22en-US%22%3E%3CP%3ECreate%20Azure%20Database%20for%20PostgreSQL%20with%20Initialization%20Script%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20600px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F118085i29BA4C3A757E0103%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22pg.png%22%20title%3D%22pg.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-753040%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Einit%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epostgresql%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EScript%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
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!