Академический Документы
Профессиональный Документы
Культура Документы
Azure Database for PostgreSQL is a relational database service in the Microsoft cloud built for developers based on
the community version of open source PostgreSQL database engine. This service is in public preview. Azure
Database for PostgreSQL delivers:
Built-in high availability with no additional cost.
Predictable performance, using inclusive pay-as-you-go pricing.
Scale on the fly within seconds.
Secured to protect sensitive data at-rest and in-motion.
Automatic backups and point-in-time-restore for up to 35 days.
Enterprise-grade security and compliance.
All those capabilities require almost no administration, and all are provided at no additional cost. These capabilities
allow you to focus on rapid application development and accelerating your time to market, rather than allocating
precious time and resources to managing virtual machines and infrastructure. In addition, you can continue to
develop your application with the open source tools and platform of your choice, and deliver with the speed and
efficiency your business demands without having to learn new skills.
This article is an introduction to Azure Database for PostgreSQL core concepts and features related to
performance, scalability, and manageability. See these quickstarts to get you started:
Create an Azure Database for PostgreSQL using Azure portal
Create an Azure Database for PostgreSQL using the Azure CLI
For a set of Azure CLI samples, see:
Azure CLI samples for Azure Database for PostgreSQL
Next steps
See the pricing page for cost comparisons and calculators.
Get started by creating your first Azure Database for PostgreSQL.
Build your first app in Python, PHP, Ruby, C#, Java, Node.js: Connection libraries
Create an Azure Database for PostgreSQL server in
the Azure portal
11/6/2017 • 11 min to read • Edit Online
Azure Database for PostgreSQL is a managed service that you use to run, manage, and scale highly available
PostgreSQL databases in the cloud. This Quickstart shows you how to create an Azure Database for PostgreSQL
server in about five minutes by using the Azure portal.
If you don't have an Azure subscription, create a free Azure account before you begin.
3. Fill out the new server details form with the following information, as shown in the preceding image:
Server admin login mylogin Your own login account to use when
you connect to the server. The
admin login name can't be
azure_superuser,
azure_pg_admin, admin,
administrator, root, guest, or
public. It can't start with pg_.
Location The region closest to your users The location that's closest to your
users.
PostgreSQL version The latest version The latest version, unless you have
specific requirements.
Pricing tier Basic, 50 Compute Units, 50 GB The service tier and performance
level for your new database. Select
Pricing tier. Next, select the Basic
tab. Then select the left end of the
Compute Units slider to adjust the
value to the least amount available
for this Quickstart. To save the
pricing tier selection, select OK. For
more information, see the following
screenshot.
By default, a postgres database is created under your server. The postgres database is a default database
that's meant for use by users, utilities, and third-party applications.
3. Under the Firewall rules heading, in the Rule Name column, select the blank text box to begin creating
the firewall rule.
For this Quickstart, let's allow all IP addresses into the server. Fill in the text box in each column with the
following values:
4. On the upper toolbar of the Connection security page, select Save. Wait until the notification appears
stating that the connection security update has finished successfully before you continue.
NOTE
Connections to your Azure Database for PostgreSQL server communicate over port 5432. If you try to connect
from within a corporate network, outbound traffic over port 5432 might not be allowed by your network's firewall.
If so, you can't connect to your server unless your IT department opens port 5432.
2. Cloud Shell opens in your browser, where you can type Bash shell commands.
3. At the Cloud Shell prompt, connect to a database in your Azure Database for PostgreSQL server by typing
the psql command line.
To connect to an Azure Database for PostgreSQL server with the psql utility, use the following format:
--host Server name The server name value that you used
when you created the Azure
Database for PostgreSQL server
earlier. The example server shown is
mypgserver-
20170401.postgres.database.azur
e.com. Use the fully qualified
domain name
(*.postgres.database.azure.com)
as shown in the example. If you
don't remember your server name,
follow the steps in the previous
section to get the connection
information.
--username Server admin login name The server admin login username
that you supplied when you created
the Azure Database for PostgreSQL
server earlier. If you don't remember
your username, follow the steps in
the previous section to get the
connection information. The format
is username@servername.
After you run the psql command with your own parameter values, you're prompted to enter the server
admin password. This password is the same one that you provided when you created the server.
After you connect, the psql utility displays a postgres prompt where you type sql commands. In the initial
connection output, a warning might appear because the psql in Cloud Shell might be a different version
than the Azure Database for PostgreSQL server version.
Example psql output:
postgres=>
TIP
If the firewall is not configured to allow the IP address of Cloud Shell, the following error occurs:
"psql: FATAL: no pg_hba.conf entry for host "138.91.195.82", user "mylogin", database "postgres", SSL on FATAL:
SSL connection is required. Specify SSL options and retry.
To resolve the error, make sure the server configuration matches the steps in the "Configure a server-level firewall
rule" section of this article.
\c mypgsqldb
6. Type \q , and then select the Enter key to quit psql. You can close Cloud Shell after you're finished.
Now you're connected to the Azure Database for PostgreSQL server, and you created a blank user database.
Continue to the next section to connect by using another common tool, pgAdmin.
Host Name/Address Server name The server name value that you used
when you created the Azure
Database for PostgreSQL server
earlier. Our example server is
mypgserver-
20170401.postgres.database.azur
e.com. Use the fully qualified
domain name
(*.postgres.database.azure.com)
as shown in the example. If you
don't remember your server name,
follow the steps in the previous
section to get the connection
information.
Username Server admin login name The server admin login username
that you supplied when you created
the Azure Database for PostgreSQL
server earlier. If you don't remember
the username, follow the steps in the
previous section to get the
connection information. The format
is username@servername.
Password Your admin password The password you chose when you
created the server earlier in this
Quickstart.
5. Select Save.
6. In the Browser pane on the left, expand the Servers node. Select your server, for example, Azure
PostgreSQL Server. Click to connect to it.
7. Expand the server node, and then expand Databases under it. The list should include your existing
postgres database and any newly created user database, such as mypgsqldb, which was created in the
previous section. Notice that you can create multiple databases per server with Azure Database for
PostgreSQL.
8. Right-click Databases, choose the Create menu, and then select Database.
9. Type a database name of your choice in the Database field, such as mypgsqldb, as shown in the
example.
10. Select the Owner for the database from the list box. Choose your server admin login name, such as the
example, mylogin.
11. Select Save to create a new blank database.
12. In the Browser pane, see the database that you created in the list of databases under your server name.
Clean up resources
You can clean up the resources that you created in the Quickstart in one of two ways. You can delete the Azure
resource group, which includes all the resources in the resource group. If you want to keep the other resources
intact, delete only the single server resource.
TIP
Other Quickstarts in this collection build on this Quickstart. If you plan to continue working with Quickstarts, don't clean
up the resources that you created in this Quickstart. If you don't plan to continue, follow these steps to delete the
resources that were created by this Quickstart in the portal.
To delete the entire resource group, including the newly created server:
1. Locate your resource group in the portal. On the menu on the left, select Resource groups. Then select
the name of your resource group, such as the example, myresourcegroup.
2. On your resource group page, select Delete. Type the name of your resource group, such as the example,
myresourcegroup, in the text box to confirm deletion. Select Delete.
To delete only the newly created server:
1. Locate your server in the portal, if you don't have it open. On the menu on the left, select All resources.
Then search for the server you created.
2. On the Overview page, select Delete.
3. Confirm the server name you want to delete, and view the databases under it that are affected. Type your
server name in the text box, such as the example, mypgserver-20170401. Select Delete.
Next steps
Migrate your database using Export and Import
Create an Azure Database for PostgreSQL using the
Azure CLI
12/7/2017 • 5 min to read • Edit Online
Azure Database for PostgreSQL is a managed service that enables you to run, manage, and scale highly available
PostgreSQL databases in the cloud. The Azure CLI is used to create and manage Azure resources from the
command line or in scripts. This quickstart shows you how to create an Azure Database for PostgreSQL server in
an Azure resource group using the Azure CLI.
If you don't have an Azure subscription, create a free account before you begin.
Click the Cloud Shell button on the menu in the upper right
of the Azure portal.
If you choose to install and use the CLI locally, this article requires that you are running the Azure CLI version 2.0
or later. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI 2.0.
If you are running the CLI locally, you need to log in to your account using the az login command.
az login
If you have multiple subscriptions, choose the appropriate subscription in which the resource should be billed.
Select a specific subscription ID under your account using az account set command.
IMPORTANT
The server admin login and password that you specify here are required to log in to the server and its databases later in
this quick start. Remember or record this information for later use.
By default, postgres database gets created under your server. The postgres database is a default database meant
for use by users, utilities, and third-party applications.
NOTE
Azure PostgreSQL server communicates over port 5432. When connecting from within a corporate network, outbound
traffic over port 5432 may not be allowed by your network's firewall. Have your IT department open port 5432 to connect
to your Azure SQL Database server.
The result is in JSON format. Make a note of the administratorLogin and fullyQualifiedDomainName.
{
"administratorLogin": "mylogin",
"fullyQualifiedDomainName": "mypgserver-20170401.postgres.database.azure.com",
"id": "/subscriptions/00000000-0000-0000-0000-
000000000000/resourceGroups/myresourcegroup/providers/Microsoft.DBforPostgreSQL/servers/mypgserver-20170401",
"location": "westus",
"name": "mypgserver-20170401",
"resourceGroup": "myresourcegroup",
"sku": {
"capacity": 50,
"family": null,
"name": "PGSQLS2M50",
"size": null,
"tier": "Basic"
},
"sslEnforcement": null,
"storageMb": 51200,
"tags": null,
"type": "Microsoft.DBforPostgreSQL/servers",
"userVisibleState": "Ready",
"version": "9.6"
}
For example, the following command connects to the default database called postgres on your
PostgreSQL server mypgserver-20170401.postgres.database.azure.com using access credentials. Enter
the <server_admin_password> you chose when prompted for password.
2. Once you are connected to the server, create a blank database at the prompt.
3. At the prompt, execute the following command to switch connection to the newly created database
mypgsqldb:
\c mypgsqldb
Clean up resources
Clean up all resources you created in the quickstart by deleting the Azure resource group.
TIP
Other quickstarts in this collection build upon this quickstart. If you plan to continue to work with subsequent quickstarts,
do not clean up the resources created in this quickstart. If you do not plan to continue, use the following steps to delete all
resources created by this quickstart in the Azure CLI.
If you would just like to delete the one newly created server, you can run az postgres server delete command.
Next steps
Migrate your database using Export and Import
Azure Database for PostgreSQL: Use Python to
connect and query data
11/6/2017 • 5 min to read • Edit Online
This quickstart demonstrates how to use Python to connect to an Azure Database for PostgreSQL. It also
demonstrates how to use SQL statements to query, insert, update, and delete data in the database from macOS,
Ubuntu Linux, and Windows platforms. The steps in this article assume that you are familiar with developing using
Python and are new to working with Azure Database for PostgreSQL.
Prerequisites
This quickstart uses the resources created in either of these guides as a starting point:
Create DB - Portal
Create DB - CLI
You also need:
python installed
pip package installed (pip is already installed if you're working with Python 2 >=2.7.9 or Python 3 >=3.4
binaries downloaded from python.org.
5. If you forget your server login information, navigate to the Overview page to view the Server admin login
name and, if necessary, reset the password.
NOTE
Starting in Python version 3, you may see the error SyntaxError: Missing parentheses in call to 'print' when
running the following code blocks: If that happens, replace each call to the command print "string" with a function call
using parenthesis, such as print("string") .
cursor = conn.cursor()
# Create table
cursor.execute("CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity INTEGER);")
print "Finished creating table"
# Cleanup
conn.commit()
cursor.close()
conn.close()
Read data
Use the following code to read the data inserted using cursor.execute function with SELECT SQL statement. This
function accepts a query and returns a result set that can be iterated over with the use of cursor.fetchall(). Replace
the host, dbname, user, and password parameters with the values that you specified when you created the server
and database.
import psycopg2
cursor = conn.cursor()
# Cleanup
conn.commit()
cursor.close()
conn.close()
Update data
Use the following code to update the inventory row that you previously inserted using cursor.execute function with
UPDATE SQL statement. Replace the host, dbname, user, and password parameters with the values that you
specified when you created the server and database.
import psycopg2
cursor = conn.cursor()
# Cleanup
conn.commit()
cursor.close()
conn.close()
Delete data
Use the following code to delete an inventory item that you previously inserted using cursor.execute function with
DELETE SQL statement. Replace the host, dbname, user, and password parameters with the values that you
specified when you created the server and database.
import psycopg2
cursor = conn.cursor()
# Cleanup
conn.commit()
cursor.close()
conn.close()
Next steps
Migrate your database using Export and Import
Azure Database for PostgreSQL: Use Node.js to
connect and query data
11/6/2017 • 4 min to read • Edit Online
This quickstart demonstrates how to connect to an Azure Database for PostgreSQL using a Node.js application. It
shows how to use SQL statements to query, insert, update, and delete data in the database. The steps in this article
assume that you are familiar with developing using Node.js, and are new to working with Azure Database for
PostgreSQL.
Prerequisites
This quickstart uses the resources created in either of these guides as a starting point:
Create DB - Portal
Create DB - CLI
You also need to:
Install Node.js
Install pg client
Install pg, which is a PostgreSQL client for Node.js.
To do so, run the node package manager (npm) for JavaScript from your command line to install the pg client.
npm install pg
npm list
const pg = require('pg');
const config = {
host: '<your-db-server-name>.postgres.database.azure.com',
// Do not hard code your username and password.
// Consider using Node environment variables.
user: '<your-db-username>',
password: '<your-password>',
database: '<name-of-database>',
port: 5432,
ssl: true
};
client.connect(err => {
if (err) throw err;
else {
queryDatabase();
}
});
function queryDatabase() {
const query = `
DROP TABLE IF EXISTS inventory;
CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity INTEGER);
INSERT INTO inventory (name, quantity) VALUES ('banana', 150);
INSERT INTO inventory (name, quantity) VALUES ('orange', 154);
INSERT INTO inventory (name, quantity) VALUES ('apple', 100);
`;
client
.query(query)
.then(() => {
console.log('Table created successfully!');
client.end(console.log('Closed client connection'));
})
.catch(err => console.log(err))
.then(() => {
console.log('Finished execution, exiting now');
process.exit();
});
}
Read data
Use the following code to connect and read the data using a SELECT SQL statement. The pg.Client object is used to
interface with the PostgreSQL server. The pg.Client.connect() function is used to establish the connection to the
server. The pg.Client.query() function is used to execute the SQL query against PostgreSQL database.
Replace the host, dbname, user, and password parameters with the values that you specified when you created the
server and database.
const pg = require('pg');
const config = {
host: '<your-db-server-name>.postgres.database.azure.com',
// Do not hard code your username and password.
// Consider using Node environment variables.
user: '<your-db-username>',
password: '<your-password>',
database: '<name-of-database>',
port: 5432,
ssl: true
};
client.connect(err => {
if (err) throw err;
else { queryDatabase(); }
});
function queryDatabase() {
client.query(query)
.then(res => {
const rows = res.rows;
rows.map(row => {
console.log(`Read: ${JSON.stringify(row)}`);
});
process.exit();
})
.catch(err => {
console.log(err);
});
}
Update data
Use the following code to connect and read the data using a UPDATE SQL statement. The pg.Client object is used
to interface with the PostgreSQL server. The pg.Client.connect() function is used to establish the connection to the
server. The pg.Client.query() function is used to execute the SQL query against PostgreSQL database.
Replace the host, dbname, user, and password parameters with the values that you specified when you created the
server and database.
const pg = require('pg');
const config = {
host: '<your-db-server-name>.postgres.database.azure.com',
// Do not hard code your username and password.
// Consider using Node environment variables.
user: '<your-db-username>',
password: '<your-password>',
database: '<name-of-database>',
port: 5432,
ssl: true
};
client.connect(err => {
if (err) throw err;
else {
queryDatabase();
}
});
function queryDatabase() {
const query = `
UPDATE inventory
SET quantity= 1000 WHERE name='banana';
`;
client
.query(query)
.then(result => {
console.log('Update completed');
console.log(`Rows affected: ${result.rowCount}`);
})
.catch(err => {
console.log(err);
throw err;
});
}
Delete data
Use the following code to connect and read the data using a DELETE SQL statement. The pg.Client object is used to
interface with the PostgreSQL server. The pg.Client.connect() function is used to establish the connection to the
server. The pg.Client.query() function is used to execute the SQL query against PostgreSQL database.
Replace the host, dbname, user, and password parameters with the values that you specified when you created the
server and database.
const pg = require('pg');
const config = {
host: '<your-db-server-name>.postgres.database.azure.com',
// Do not hard code your username and password.
// Consider using Node environment variables.
user: '<your-db-username>',
password: '<your-password>',
database: '<name-of-database>',
port: 5432,
ssl: true
};
client.connect(err => {
if (err) {
throw err;
} else {
queryDatabase();
}
});
function queryDatabase() {
const query = `
DELETE FROM inventory
WHERE name = 'apple';
`;
client
.query(query)
.then(result => {
console.log('Delete completed');
console.log(`Rows affected: ${result.rowCount}`);
})
.catch(err => {
console.log(err);
throw err;
});
}
Next steps
Migrate your database using Export and Import
Azure Database for PostgreSQL: Use Java to connect
and query data
11/6/2017 • 7 min to read • Edit Online
This quickstart demonstrates how to connect to an Azure Database for PostgreSQL using a Java application. It
shows how to use SQL statements to query, insert, update, and delete data in the database. The steps in this article
assume that you are familiar with developing using Java, and are new to working with Azure Database for
PostgreSQL.
Prerequisites
This quickstart uses the resources created in either of these guides as a starting point:
Create DB - Portal
Create DB - Azure CLI
You also need to:
Download the PostgreSQL JDBC Driver matching your version of Java and the Java Development Kit.
Include the PostgreSQL JDBC jar file (for example postgresql-42.1.1.jar) in your application classpath. For more
information, see classpath details.
5. If you forget your server login information, navigate to the Overview page to view the Server admin login
name and, if necessary, reset the password.
import java.sql.*;
import java.util.Properties;
// get connection
connection = DriverManager.getConnection(url, properties);
}
catch (SQLException e)
{
throw new SQLException("Failed to create connection to database.", e);
}
if (connection != null)
{
System.out.println("Successfully created connection to database.");
// Create table.
statement.execute("CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity
INTEGER);");
System.out.println("Created table.");
// Insert some data into table.
int nRowsInserted = 0;
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO inventory (name,
quantity) VALUES (?, ?);");
preparedStatement.setString(1, "banana");
preparedStatement.setInt(2, 150);
nRowsInserted += preparedStatement.executeUpdate();
preparedStatement.setString(1, "orange");
preparedStatement.setInt(2, 154);
nRowsInserted += preparedStatement.executeUpdate();
preparedStatement.setString(1, "apple");
preparedStatement.setInt(2, 100);
nRowsInserted += preparedStatement.executeUpdate();
System.out.println(String.format("Inserted %d row(s) of data.", nRowsInserted));
}
catch (SQLException e)
{
throw new SQLException("Encountered an error when executing given sql statement.", e);
}
}
else {
System.out.println("Failed to create connection to database.");
}
System.out.println("Execution finished.");
}
}
Read data
Use the following code to read the data with a SELECT SQL statement. The methods getConnection(),
createStatement(), and executeQuery() are used to connect to the database, create, and run the select statement.
The results are processed using a ResultSet object.
Replace the host, database, user, and password parameters with the values that you specified when you created
your own server and database.
import java.sql.*;
import java.util.Properties;
// get connection
connection = DriverManager.getConnection(url, properties);
}
catch (SQLException e)
{
throw new SQLException("Failed to create connection to database.", e);
}
if (connection != null)
{
System.out.println("Successfully created connection to database.");
Update data
Use the following code to change the data with an UPDATE SQL statement. The methods getConnection(),
prepareStatement(), and executeUpdate() are used to connect to the database, prepare, and run the update
statement.
Replace the host, database, user, and password parameters with the values that you specified when you created
your own server and database.
import java.sql.*;
import java.sql.*;
import java.util.Properties;
// get connection
connection = DriverManager.getConnection(url, properties);
}
catch (SQLException e)
{
throw new SQLException("Failed to create connection to database.", e);
}
if (connection != null)
{
System.out.println("Successfully created connection to database.");
Delete data
Use the following code to remove data with a DELETE SQL statement. The methods getConnection(),
prepareStatement(), and executeUpdate() are used to connect to the database, prepare, and run the delete
statement.
Replace the host, database, user, and password parameters with the values that you specified when you created
your own server and database.
import java.sql.*;
import java.util.Properties;
// get connection
connection = DriverManager.getConnection(url, properties);
}
catch (SQLException e)
{
throw new SQLException("Failed to create connection to database.", e);
}
if (connection != null)
{
System.out.println("Successfully created connection to database.");
Next steps
Migrate your database using Export and Import
Azure Database for PostgreSQL: Use Ruby to connect
and query data
11/6/2017 • 6 min to read • Edit Online
This quickstart demonstrates how to connect to an Azure Database for PostgreSQL using a Ruby application. It
shows how to use SQL statements to query, insert, update, and delete data in the database. The steps in this article
assume that you are familiar with developing using Ruby, and are new to working with Azure Database for
PostgreSQL.
Prerequisites
This quickstart uses the resources created in either of these guides as a starting point:
Create DB - Portal
Create DB - Azure CLI
Install Ruby
Install Ruby on your own machine.
Windows
Download and Install the latest version of Ruby.
On the finish screen of the MSI installer, check the box that says "Run 'ridk install' to install MSYS2 and
development toolchain." Then click Finish to launch the next installer.
The RubyInstaller2 for Windows installer launches. Type 2 to install the MSYS2 repository update. After it
finishes and returns to the installation prompt, close the command window.
Launch a new command prompt (cmd) from the Start menu.
Test the Ruby installation ruby -v to see the version installed.
Test the Gem installation gem -v to see the version installed.
Build the PostgreSQL module for Ruby using Gem by running the command gem install pg .
MacOS
Install Ruby using Homebrew by running the command brew install ruby . For more installation options, see
the Ruby installation documentation
Test the Ruby installation ruby -v to see the version installed.
Test the Gem installation gem -v to see the version installed.
Build the PostgreSQL module for Ruby using Gem by running the command gem install pg .
Linux (Ubuntu)
Install Ruby by running the command sudo apt-get install ruby-full . For more installation options, see the
Ruby installation documentation.
Test the Ruby installation ruby -v to see the version installed.
Install the latest updates for Gem by running the command sudo gem update --system .
Test the Gem installation gem -v to see the version installed.
Install the gcc, make, and other build tools by running the command sudo apt-get install build-essential .
Install the PostgreSQL libraries by running the command sudo apt-get install libpq-dev .
Build the Ruby pg module using Gem by running the command sudo gem install pg .
Run Ruby code
Save the code into a text file with file extension .rb, and save the file into a project folder, such as
C:\rubypostgres\read.rb or /home/username/rubypostgres/read.rb
To run the code, launch the command prompt or bash shell. Change directory into your project folder
cd rubypostgres , then type the command ruby read.rb to run the application.
5. If you forget your server login information, navigate to the Overview page to view the Server admin login
name. If necessary, reset the password.
begin
# Initialize connection variables.
host = String('mypgserver-20170401.postgres.database.azure.com')
database = String('postgres')
user = String('mylogin@mypgserver-20170401')
password = String('<server_admin_password>')
ensure
connection.close if connection
end
Read data
Use the following code to connect and read the data using a SELECT SQL statement.
The code uses a PG::Connection object with constructor new() to connect to Azure Database for PostgreSQL. Then it
calls method exec() to run the SELECT command, keeping the results in a result set. The result set collection is
iterated over using the resultSet.each do loop, keeping the current row values in the row variable. The code
checks for errors using the PG::Error class. Then it calls method close() to close the connection before terminating.
Replace the host , database , user , and password strings with your own values.
require 'pg'
begin
# Initialize connection variables.
host = String('mypgserver-20170401.postgres.database.azure.com')
database = String('postgres')
user = String('mylogin@mypgserver-20170401')
password = String('<server_admin_password>')
ensure
connection.close if connection
end
Update data
Use the following code to connect and update the data using a UPDATE SQL statement.
The code uses a PG::Connection object with constructor new() to connect to Azure Database for PostgreSQL. Then it
calls method exec() to run the UPDATE command. The code checks for errors using the PG::Error class. Then it calls
method close() to close the connection before terminating.
Replace the host , database , user , and password strings with your own values.
require 'pg'
begin
# Initialize connection variables.
host = String('mypgserver-20170401.postgres.database.azure.com')
database = String('postgres')
user = String('mylogin@mypgserver-20170401')
password = String('<server_admin_password>')
ensure
connection.close if connection
end
Delete data
Use the following code to connect and read the data using a DELETE SQL statement.
The code uses a PG::Connection object with constructor new() to connect to Azure Database for PostgreSQL. Then it
calls method exec() to run the UPDATE command. The code checks for errors using the PG::Error class. Then it calls
method close() to close the connection before terminating.
Replace the host , database , user , and password strings with your own values.
require 'pg'
begin
# Initialize connection variables.
host = String('mypgserver-20170401.postgres.database.azure.com')
database = String('postgres')
user = String('mylogin@mypgserver-20170401')
password = String('<server_admin_password>')
ensure
connection.close if connection
end
Next steps
Migrate your database using Export and Import
Azure Database for PostgreSQL: Use PHP to connect
and query data
11/6/2017 • 6 min to read • Edit Online
This quickstart demonstrates how to connect to an Azure Database for PostgreSQL using a PHP application. It
shows how to use SQL statements to query, insert, update, and delete data in the database. The steps in this article
assume that you are familiar with developing using PHP, and are new to working with Azure Database for
PostgreSQL.
Prerequisites
This quickstart uses the resources created in either of these guides as a starting point:
Create DB - Portal
Create DB - Azure CLI
Install PHP
Install PHP on your own server, or create an Azure web app that includes PHP.
Windows
Download PHP 7.1.4 non-thread safe (x64) version
Install PHP and refer to the PHP manual for further configuration
The code uses the pgsql class (ext/php_pgsql.dll) that is included in the PHP installation.
Enabled the pgsql extension by editing the php.ini configuration file, typically located at
C:\Program Files\PHP\v7.1\php.ini . The configuration file should contain a line with the text
extension=php_pgsql.so . If it is not shown, add the text and save the file. If the text is present, but commented
with a semicolon prefix, uncomment the text by removing the semicolon.
Linux (Ubuntu)
Download PHP 7.1.4 non-thread safe (x64) version
Install PHP and refer to the PHP manual for further configuration
The code uses the pgsql class (php_pgsql.so). Install it by running sudo apt-get install php-pgsql .
Enabled the pgsql extension by editing the /etc/php/7.0/mods-available/pgsql.ini configuration file. The
configuration file should contain a line with the text extension=php_pgsql.so . If it is not shown, add the text and
save the file. If the text is present, but commented with a semicolon prefix, uncomment the text by removing the
semicolon.
MacOS
Download PHP 7.1.4 version
Install PHP and refer to the PHP manual for further configuration
5. If you forget your server login information, navigate to the Overview page to view the Server admin login
name and, if necessary, reset the password.
// Create table.
$query = "CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity INTEGER);";
pg_query($connection, $query)
or die("Encountered an error when executing given sql statement: ". pg_last_error(). "<br/>");
print "Finished creating table.<br/>";
$name = '\'orange\'';
$quantity = 154;
$query = "INSERT INTO inventory (name, quantity) VALUES ($name, $quantity);";
pg_query($connection, $query)
or die("Encountered an error when executing given sql statement: ". pg_last_error(). "<br/>");
$name = '\'apple\'';
$quantity = 100;
$query = "INSERT INTO inventory (name, quantity) VALUES ($name, $quantity);";
pg_query($connection, $query)
or die("Encountered an error when executing given sql statement: ". pg_last_error()). "<br/>";
// Closing connection
pg_close($connection);
?>
Read data
Use the following code to connect and read the data using a SELECT SQL statement.
The code call method pg_connect() to connect to Azure Database for PostgreSQL. Then it calls method pg_query()
to run the SELECT command, keeping the results in a result set, and pg_last_error() to check the details if an error
occurred. To read the result set, method pg_fetch_row() is called in a loop, once per row, and the row data is
retrieved in an array $row , with one data value per column in each array position. To free the result set, method
pg_free_result() is called. Then it calls method pg_close() to close the connection.
Replace the $host , $database , $user , and $password parameters with your own values.
<?php
// Initialize connection variables.
$host = "mypgserver-20170401.postgres.database.azure.com";
$database = "mypgsqldb";
$user = "mylogin@mypgserver-20170401";
$password = "<server_admin_password>";
// Free result_set
pg_free_result($result_set);
// Closing connection
pg_close($connection);
?>
Update data
Use the following code to connect and update the data using a UPDATE SQL statement.
The code call method pg_connect() to connect to Azure Database for PostgreSQL. Then it calls method pg_query()
to run a command, and pg_last_error() to check the details if an error occurred. Then it calls method pg_close() to
close the connection.
Replace the $host , $database , $user , and $password parameters with your own values.
<?php
// Initialize connection variables.
$host = "mypgserver-20170401.postgres.database.azure.com";
$database = "mypgsqldb";
$user = "mylogin@mypgserver-20170401";
$password = "<server_admin_password>";
// Closing connection
pg_close($connection);
?>
Delete data
Use the following code to connect and read the data using a DELETE SQL statement.
The code call method pg_connect() to connect to Azure Database for PostgreSQL. Then it calls method pg_query()
to run a command, and pg_last_error() to check the details if an error occurred. Then it calls method pg_close() to
close the connection.
Replace the $host , $database , $user , and $password parameters with your own values.
<?php
// Initialize connection variables.
$host = "mypgserver-20170401.postgres.database.azure.com";
$database = "mypgsqldb";
$user = "mylogin@mypgserver-20170401";
$password = "<server_admin_password>";
// Closing connection
pg_close($connection);
?>
Next steps
Migrate your database using Export and Import
Azure Database for PostgreSQL: Use .NET (C#) to
connect and query data
11/15/2017 • 5 min to read • Edit Online
This quickstart demonstrates how to connect to an Azure Database for PostgreSQL using a C# application. It shows
how to use SQL statements to query, insert, update, and delete data in the database. The steps in this article assume
that you are familiar with developing using C#, and that you are new to working with Azure Database for
PostgreSQL.
Prerequisites
This quickstart uses the resources created in either of these guides as a starting point:
Create DB - Portal
Create DB - CLI
You also need to:
Install the .NET Framework. Follow the steps in the linked article to install .NET specifically for your platform
(Windows, Ubuntu Linux, or macOS).
Install Visual Studio or Visual Studio Code to type and edit code.
Add a reference to the Npgsql Nuget package.
5. If you forget your server login information, navigate to the Overview page to view the Server admin login
name and, if necessary, reset the password.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
namespace Driver
{
public class AzurePostgresCreate
{
// Obtain connection string information from the portal
//
private static string Host = "mypgserver-20170401.postgres.database.azure.com";
private static string User = "mylogin@mypgserver-20170401";
private static string DBname = "mypgsqldb";
private static string Password = "<server_admin_password>";
private static string Port = "5432";
Console.Out.WriteLine("Opening connection");
conn.Open();
command.CommandText = "CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity
INTEGER);";
command.ExecuteNonQuery();
Console.Out.WriteLine("Finished creating table");
command.CommandText =
String.Format(
@"
INSERT INTO inventory (name, quantity) VALUES ({0}, {1});
INSERT INTO inventory (name, quantity) VALUES ({2}, {3});
INSERT INTO inventory (name, quantity) VALUES ({4}, {5});
",
"\'banana\'", 150,
"\'orange\'", 154,
"\'apple\'", 100
);
Read data
Use the following code to connect and read the data using a SELECT SQL statement. The code uses
NpgsqlCommand class with method Open() to establish a connection to PostgreSQL. Then the code uses the
methods CreateCommand() and ExecuteReader() to run the database commands. Next, the code uses Read() to
advance to the record in the results. Finally, the code uses GetInt32() and GetString() to parse the values in the
record.
Replace the Host, DBName, User, and Password parameters with the values that you specified when you created
the server and database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
namespace Driver
{
public class AzurePostgresRead
{
// Obtain connection string information from the portal
//
private static string Host = "mypgserver-20170401.postgres.database.azure.com";
private static string User = "mylogin@mypgserver-20170401";
private static string DBname = "mypgsqldb";
private static string Password = "<server_admin_password>";
private static string Port = "5432";
Console.Out.WriteLine("Opening connection");
conn.Open();
Console.Out.WriteLine("Closing connection");
conn.Close();
Update data
Use the following code to connect and update the data using an UPDATE SQL statement. The code uses
NpgsqlCommand class with method Open() to establish a connection to PostgreSQL. Then, the code uses method
CreateCommand(), sets the CommandText property, and calls the ExecuteNonQuery() method to run the database
commands.
Replace the Host, DBName, User, and Password parameters with the values that you specified when you created
the server and database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
namespace Driver
{
public class AzurePostgresUpdate
{
// Obtain connection string information from the portal
//
private static string Host = "mypgserver-20170401.postgres.database.azure.com";
private static string User = "mylogin@mypgserver-20170401";
private static string DBname = "mypgsqldb";
private static string Password = "<server_admin_password>";
private static string Port = "5432";
Console.Out.WriteLine("Opening connection");
conn.Open();
Console.Out.WriteLine("Closing connection");
conn.Close();
Delete data
Use the following code to connect and delete data using a DELETE SQL statement.
The code uses NpgsqlCommand class with method Open() to establish a connection to the PostgreSQL database.
Then, the code uses the CreateCommand() method, sets the CommandText property, and calls the method
ExecuteNonQuery() to run the database commands.
Replace the Host, DBName, User, and Password parameters with the values that you specified when you created
the server and database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
namespace Driver
{
public class AzurePostgresDelete
{
// Obtain connection string information from the portal
//
private static string Host = "mypgserver-20170401.postgres.database.azure.com";
private static string User = "mylogin@mypgserver-20170401";
private static string DBname = "mypgsqldb";
private static string Password = "<server_admin_password>";
private static string Port = "5432";
Console.Out.WriteLine("Opening connection");
conn.Open();
Console.Out.WriteLine("Closing connection");
conn.Close();
Next steps
Migrate your database using Export and Import
Azure Database for PostgreSQL: Use Go language to
connect and query data
11/6/2017 • 9 min to read • Edit Online
This quickstart demonstrates how to connect to an Azure Database for PostgreSQL using code written in the Go
language (golang). It shows how to use SQL statements to query, insert, update, and delete data in the database.
This article assumes you are familiar with development using Go, but that you are new to working with Azure
Database for PostgreSQL.
Prerequisites
This quickstart uses the resources created in either of these guides as a starting point:
Create DB - Portal
Create DB - Azure CLI
mkdir %USERPROFILE%\go\src\postgresqlgo
cd %USERPROFILE%\go\src\postgresqlgo
set GOPATH=%USERPROFILE%\go
go get github.com/lib/pq
Linux (Ubuntu)
1. Launch the Bash shell.
2. Install Go by running sudo apt-get install golang-go .
3. Make a folder for your project in your home directory, such as mkdir -p ~/go/src/postgresqlgo/ .
4. Change directory into the folder, such as cd ~/go/src/postgresqlgo/ .
5. Set the GOPATH environment variable to point to a valid source directory, such as your current home
directory's go folder. At the bash shell, run export GOPATH=~/go to add the go directory as the GOPATH for the
current shell session.
6. Install the Pure Go Postgres driver (pq) by running the go get github.com/lib/pq command.
In summary, run these bash commands:
sudo apt-get install golang-go
mkdir -p ~/go/src/postgresqlgo/
cd ~/go/src/postgresqlgo/
export GOPATH=~/go/
go get github.com/lib/pq
Apple macOS
1. Download and install Go according to the installation instructions matching your platform.
2. Launch the Bash shell.
3. Make a folder for your project in your home directory, such as mkdir -p ~/go/src/postgresqlgo/ .
4. Change directory into the folder, such as cd ~/go/src/postgresqlgo/ .
5. Set the GOPATH environment variable to point to a valid source directory, such as your current home
directory's go folder. At the bash shell, run export GOPATH=~/go to add the go directory as the GOPATH for the
current shell session.
6. Install the Pure Go Postgres driver (pq) by running the go get github.com/lib/pq command.
In summary, install Go, then run these bash commands:
mkdir -p ~/go/src/postgresqlgo/
cd ~/go/src/postgresqlgo/
export GOPATH=~/go/
go get github.com/lib/pq
5. If you forget your server login information, navigate to the Overview page, and view the Server admin login
name. If necessary, reset the password.
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
)
const (
// Initialize connection constants.
HOST = "mypgserver-20170401.postgres.database.azure.com"
DATABASE = "mypgsqldb"
USER = "mylogin@mypgserver-20170401"
PASSWORD = "<server_admin_password>"
)
func main() {
// Initialize connection string.
var connectionString string = fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=require", HOST,
USER, PASSWORD, DATABASE)
err = db.Ping()
checkError(err)
fmt.Println("Successfully created connection to database")
// Create table.
_, err = db.Exec("CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity INTEGER);")
checkError(err)
fmt.Println("Finished creating table")
Read data
Use the following code to connect and read the data using a SELECT SQL statement.
The code imports three packages: the sql package, the pq package as a driver to communicate with the PostgreSQL
server, and the fmt package for printed input and output on the command line.
The code calls method sql.Open() to connect to Azure Database for PostgreSQL database, and checks the
connection using method db.Ping(). A database handle is used throughout, holding the connection pool for the
database server. The select query is run by calling method db.Query(), and the resulting rows are kept in a variable
of type rows. The code reads the column data values in the current row using method rows.Scan() and loops over
the rows using the iterator rows.Next() until no more rows exist. Each row's column values are printed to the
console out. Each time a custom checkError() method is used to check if an error occurred and panic to exit if an
error does occur.
Replace the HOST , DATABASE , USER , and PASSWORD parameters with your own values.
package main
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
)
const (
// Initialize connection constants.
HOST = "mypgserver-20170401.postgres.database.azure.com"
DATABASE = "mypgsqldb"
USER = "mylogin@mypgserver-20170401"
PASSWORD = "<server_admin_password>"
)
func main() {
err = db.Ping()
checkError(err)
fmt.Println("Successfully created connection to database")
for rows.Next() {
switch err := rows.Scan(&id, &name, &quantity); err {
case sql.ErrNoRows:
fmt.Println("No rows were returned")
case nil:
fmt.Printf("Data row = (%d, %s, %d)\n", id, name, quantity)
default:
checkError(err)
}
}
}
Update data
Use the following code to connect and update the data using an UPDATE SQL statement.
The code imports three packages: the sql package, the pq package as a driver to communicate with the Postgres
server, and the fmt package for printed input and output on the command line.
The code calls method sql.Open() to connect to Azure Database for PostgreSQL database, and checks the
connection using method db.Ping(). A database handle is used throughout, holding the connection pool for the
database server. The code calls the Exec() method to run the SQL statement that updates the table. A custom
checkError() method is used to check if an error occurred and panic to exit if an error does occur.
Replace the HOST , DATABASE , USER , and PASSWORD parameters with your own values.
package main
import (
"database/sql"
_ "github.com/lib/pq"
"fmt"
)
const (
// Initialize connection constants.
HOST = "mypgserver-20170401.postgres.database.azure.com"
DATABASE = "mypgsqldb"
USER = "mylogin@mypgserver-20170401"
PASSWORD = "<server_admin_password>"
)
func main() {
err = db.Ping()
checkError(err)
fmt.Println("Successfully created connection to database")
Delete data
Use the following code to connect and delete the data using a DELETE SQL statement.
The code imports three packages: the sql package, the pq package as a driver to communicate with the Postgres
server, and the fmt package for printed input and output on the command line.
The code calls method sql.Open() to connect to Azure Database for PostgreSQL database, and checks the
connection using method db.Ping(). A database handle is used throughout, holding the connection pool for the
database server. The code calls the Exec() method to run the SQL statement that deletes a row from the table. A
custom checkError() method is used to check if an error occurred and panic to exit if an error does occur.
Replace the HOST , DATABASE , USER , and PASSWORD parameters with your own values.
package main
import (
"database/sql"
_ "github.com/lib/pq"
"fmt"
)
const (
// Initialize connection constants.
HOST = "mypgserver-20170401.postgres.database.azure.com"
DATABASE = "mypgsqldb"
USER = "mylogin@mypgserver-20170401"
PASSWORD = "<server_admin_password>"
)
func main() {
err = db.Ping()
checkError(err)
fmt.Println("Successfully created connection to database")
Next steps
Migrate your database using Export and Import
Design your first Azure Database for PostgreSQL
using the Azure portal
11/6/2017 • 6 min to read • Edit Online
Azure Database for PostgreSQL is a managed service that enables you to run, manage, and scale highly available
PostgreSQL databases in the cloud. Using the Azure portal, you can easily manage your server and design a
database.
In this tutorial, you use the Azure portal to learn how to:
Create an Azure Database for PostgreSQL server
Configure the server firewall
Use psql utility to create a database
Load sample data
Query data
Update data
Restore data
Prerequisites
If you don't have an Azure subscription, create a free account before you begin.
IMPORTANT
The server admin login and password that you specify here are required to log in to the server and its databases later
in this quickstart. Remember or record this information for later use.
4. Click Pricing tier to specify the service tier and performance level for your new database. For this quickstart,
select Basic Tier, 50 Compute Units and 50 GB of included storage.
5. Click Ok.
6. Click Create to provision the server. Provisioning takes a few minutes.
TIP
Check the Pin to dashboard option to allow easy tracking of your deployments.
By default, postgres database gets created under your server. The postgres database is a default database
meant for use by users, utilities, and third-party applications.
4. Click Save and then click the X to close the Connections security page.
NOTE
Azure PostgreSQL server communicates over port 5432. If you are trying to connect from within a corporate
network, outbound traffic over port 5432 may not be allowed by your network's firewall. If so, you cannot connect to
your Azure SQL Database server unless your IT department opens port 5432.
2. The Azure Cloud Shell opens in your browser, enabling you to type bash commands.
3. At the Cloud Shell prompt, connect to your Azure Database for PostgreSQL server using the psql commands.
The following format is used to connect to an Azure Database for PostgreSQL server with the psql utility:
At the prompt, execute the following command to switch connection to the newly created database mypgsqldb.
\c mypgsqldb
You can see the newly created table in the list of tables now by typing:
\dt
INSERT INTO inventory (id, name, quantity) VALUES (1, 'banana', 150);
INSERT INTO inventory (id, name, quantity) VALUES (2, 'orange', 154);
You have now two rows of sample data into the inventory table you created earlier.
You can see the updated values when you retrieve the data.
Restore point: Select a point-in-time that occurs before the server was changed
Target server: Provide a new server name you want to restore to
Location: You cannot select the region, by default it is same as the source server
Pricing tier: You cannot change this value when restoring a server. It is same as the source server.
3. Click OK restore the server to a point-in-time before the table was deleted. Restoring a server to a different
point in time creates a duplicate new server as the original server as of the point in time you specify, provided
that it is within the retention period for your service tier.
Next steps
In this tutorial, you learned how to use the Azure portal and other utilities to:
Create an Azure Database for PostgreSQL server
Configure the server firewall
Use psql utility to create a database
Load sample data
Query data
Update data
Restore data
Next, to learn how to use the Azure CLI to do similar tasks, review this tutorial: Design your first Azure Database for
PostgreSQL using Azure CLI
Design your first Azure Database for PostgreSQL
using Azure CLI
11/28/2017 • 6 min to read • Edit Online
In this tutorial, you use Azure CLI (command-line interface) and other utilities to learn how to:
Create an Azure Database for PostgreSQL server
Configure the server firewall
Use psql utility to create a database
Load sample data
Query data
Update data
Restore data
You may use the Azure Cloud Shell in the browser, or install Azure CLI 2.0 on your own computer to run the
commands in this tutorial.
Click the Cloud Shell button on the menu in the upper right
of the Azure portal.
If you choose to install and use the CLI locally, this topic requires that you are running the Azure CLI version 2.0 or
later. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI 2.0.
If you have multiple subscriptions, choose the appropriate subscription in which the resource exists or is billed for.
Select a specific subscription ID under your account using az account set command.
IMPORTANT
The server admin login and password that you specify here are required to log in to the server and its databases later in this
quick start. Remember or record this information for later use.
By default, postgres database gets created under your server. The postgres database is a default database meant
for use by users, utilities, and third-party applications.
NOTE
Azure PostgreSQL server communicates over port 5432. When connecting from within a corporate network, outbound traffic
over port 5432 may not be allowed by your network's firewall. Have your IT department open port 5432 to connect to your
Azure SQL Database server.
The result is in JSON format. Make a note of the administratorLogin and fullyQualifiedDomainName.
{
"administratorLogin": "mylogin",
"fullyQualifiedDomainName": "mypgserver-20170401.postgres.database.azure.com",
"id": "/subscriptions/00000000-0000-0000-0000-
000000000000/resourceGroups/myresourcegroup/providers/Microsoft.DBforPostgreSQL/servers/mypgserver-20170401",
"location": "westus",
"name": "mypgserver-20170401",
"resourceGroup": "myresourcegroup",
"sku": {
"capacity": 50,
"family": null,
"name": "PGSQLS2M50",
"size": null,
"tier": "Basic"
},
"sslEnforcement": null,
"storageMb": 51200,
"tags": null,
"type": "Microsoft.DBforPostgreSQL/servers",
"userVisibleState": "Ready",
"version": "9.6"
}
For example, the following command connects to the default database called postgres on your PostgreSQL
server mypgserver-20170401.postgres.database.azure.com using access credentials. Enter the
<server_admin_password> you chose when prompted for password.
2. Once you are connected to the server, create a blank database at the prompt:
3. At the prompt, execute the following command to switch connection to the newly created database
mypgsqldb:
\c mypgsqldb
You can see the newly created table in the list of tables now by typing:
\dt
INSERT INTO inventory (id, name, quantity) VALUES (1, 'banana', 150);
INSERT INTO inventory (id, name, quantity) VALUES (2, 'orange', 154);
You have now added two rows of sample data into the table you created earlier.
You can see the updated values when you retrieve the data:
Restoring a server to a point-in-time creates a new server, copied as the original server as of the point in time you
specify. The location and pricing tier values for the restored server are the same as the source server.
The command is synchronous, and will return after the server is restored. Once the restore finishes, locate the new
server that was created. Verify the data was restored as expected.
Next steps
In this tutorial, you learned how to use Azure CLI (command-line interface) and other utilities to:
Create an Azure Database for PostgreSQL server
Configure the server firewall
Use psql utility to create a database
Load sample data
Query data
Update data
Restore data
Next, learn how to use the Azure portal to do similar tasks, review this tutorial: Design your first Azure Database for
PostgreSQL using the Azure portal
1 min to read •
Edit O nline
Azure CLI samples for Azure Database for
PostgreSQL
11/6/2017 • 1 min to read • Edit Online
The following table includes links to sample Azure CLI scripts for Azure Database for PostgreSQL.
Create a server
Create a server and firewall rule Azure CLI script that creates a single Azure Database for
PostgreSQL server and configures a server-level firewall rule.
Scale a server
Scale a server Azure CLI script that scales a single Azure Database for
PostgreSQL server up or down to allow for changing
performance needs.
Azure Database for PostgreSQL Servers
11/28/2017 • 2 min to read • Edit Online
This article provides considerations and guidelines for working with Azure Database for PostgreSQL servers.
Server parameters
The PostgreSQL server parameters determine the configuration of the server. In Azure Database for PostgreSQL
the list of parameters can be viewed and edited via the Azure portal or the Azure CLI.
As a managed service for Postgres, the configurable parameters in Azure Database for PostgreSQL are a subset of
the parameters in a local Postgres instance (For more information on Postgres parameters, see the PostgreSQL
documentation). Your Azure Database for PostgreSQL server is enabled with default values for each parameter on
creation. Parameters that would require a server restart or superuser access for changes to take effect cannot be
configured by the user.
Next steps
For an overview of the service, see Azure Database for PostgreSQL Overview.
For information about specific resource quotas and limitations based on your service tier, see Service tiers.
For information on connecting to the service, see Connection libraries for Azure Database for PostgreSQL.
View and edit server parameters through Azure portal or Azure CLI.
Supported PostgreSQL Database Versions
11/6/2017 • 1 min to read • Edit Online
Microsoft aims to support n-2 versions of the PostgreSQL engine in the Azure Database for PostgreSQL service,
meaning the currently released major version (n) and the two prior major versions (-2).
Azure Database for PostgreSQL currently supports the following versions:
Next steps
For information about the support of different PostgreSQL extensions, see PostgreSQL Extensions
PostgreSQL extensions in Azure Database for
PostgreSQL
11/28/2017 • 2 min to read • Edit Online
PostgreSQL provides the ability to extend the functionality of your database using extensions. Extensions allow for
bundling multiple related SQL objects together in a single package that can be loaded or removed from your
database with a single command. After being loaded in the database, extensions can function as do built-in
features. For more information on PostgreSQL extensions, see Packaging Related Objects into an Extension.
Functions extensions
EXTENSION DESCRIPTION
Language extensions
EXTENSION DESCRIPTION
Miscellaneous extensions
EXTENSION DESCRIPTION
pg_prewarm Provides a way to load relation data into the buffer cache.
PostGIS extensions
EXTENSION DESCRIPTION
Next steps
If you don't see an extension that you'd like to use, let us know. Vote for existing requests or create new feedback
and requests in our Customer feedback forum.
Server Logs in Azure Database for PostgreSQL
10/25/2017 • 1 min to read • Edit Online
Azure Database for PostgreSQL generates query and error logs. However, access to transaction logs is not
supported. Query and error logs can be used to identify, troubleshoot, and repair configuration errors and
suboptimal performance. For more information, see Error Reporting and Logging.
Log retention
You can set the retention period for system logs using the log_retention_period parameter associated with your
server. The unit for this parameter is days. The default value is 3 days. The maximum value is 7 days. Your server
must have enough allocated storage to contain the retained log files. The log files rotate every one hour or 100 MB
size, whichever comes first.
Next steps
To access logs using Azure CLI command-line interface, see Configure and access server logs using Azure CLI.
For more information on server parameters, see Customize server configuration parameters using Azure CLI.
High availability concepts in Azure Database for
PostgreSQL
11/2/2017 • 1 min to read • Edit Online
The Azure Database for PostgreSQL service provides a guaranteed high level of availability. The financially backed
service level agreement (SLA) is 99.99% upon general availability. There is virtually no application down time when
using this service.
High availability
The high availability (HA) model is based on built-in fail-over mechanisms when a node-level interruption occurs. A
node-level interruption could occur because of a hardware failure or in response to a service deployment.
At all times, changes made to an Azure Database for PostgreSQL database server occur in the context of a
transaction. Changes are recorded synchronously in Azure storage when the transaction is committed. If a node-
level interruption occurs, the database server automatically creates a new node and attaches data storage to the
new node. Any active connections are dropped and any inflight transactions are not committed.
Scaling up or down
Similar to the HA model, when an Azure Database for PostgreSQL is scaled up or down, a new server instance with
the specified size is created. The existing data storage is detached from the original instance, and attached to the
new instance.
During the scale operation, an interruption to the database connections occurs. The client applications are
disconnected, and open uncommitted transactions are canceled. Once the client application retries the connection,
or makes a new connection, the gateway directs the connection to the newly sized instance.
Next steps
For an overview of the service, see Azure Database for PostgreSQL Overview
Azure Database for PostgreSQL options and
performance: Understand what’s available in each
pricing tier
11/6/2017 • 6 min to read • Edit Online
When you create an Azure Database for PostgreSQL server, you decide upon three main choices to configure the
resources allocated for that server. These choices impact the performance and scale of the server.
Pricing tier
Compute Units
Storage (GB)
Each pricing tier has a range of performance levels (Compute Units) to choose from, depending on your
workloads requirements. Higher performance levels provide additional resources for your server designed to
deliver higher throughput. You can change the server's performance level within a pricing tier with virtually no
application downtime.
IMPORTANT
While the service is in public preview, there is not a guaranteed Service Level Agreement (SLA).
Within an Azure Database for PostgreSQL server, you can have one or multiple databases. You can opt to create a
single database per server to have the database utilize all the server resources, or create multiple databases to
share the server resources.
Basic Best suited for small workloads that require scalable compute
and storage without IOPS guarantee. Examples include
servers used for development or testing, or small-scale
infrequently used applications.
Standard The go-to option for cloud applications that need IOPS
guarantee with high throughput. Examples include web or
analytical applications.
Premium Best suited for workloads that need low latency for
transactions and IO. Provides the best support for many
concurrent users. Applicable to databases that support
mission critical applications.
The Premium pricing tier is not available in preview.
To decide on a pricing tier, first start by determining if your workload needs an IOPS guarantee. If so, use
Standard pricing tier.
During the preview timeframe, you cannot change pricing tier once the server is created. In the future, it will be
possible to upgrade or downgrade a server from one pricing tier to another tier.
Included storage size 125 GB, 125 GB, 125 GB, 125 GB,
and provisioned IOPS 375 IOPS 375 IOPS 375 IOPS 375 IOPS
PERFORMANCE LEVEL 100 200 400 800
Max server 3,000 IOPS 3,000 IOPS 3,000 IOPS 3,000 IOPS
provisioned IOPS
Max server Fixed 3 IOPS per GB Fixed 3 IOPS per GB Fixed 3 IOPS per GB Fixed 3 IOPS per GB
provisioned IOPS per
GB
* Max server storage size refers to the maximum provisioned storage size for your server.
Storage
The storage configuration defines the amount of storage capacity available to an Azure Database for PostgreSQL
server. The storage used by the service includes the database files, transaction logs, and the PostgreSQL server
logs. Consider the size of storage needed to host your databases and the performance requirements (IOPS) when
selecting the storage configuration.
Some storage capacity is included at a minimum with each pricing tier, noted in the preceding table as "Included
storage size." Additional storage capacity can be added when the server is created, in increments of 125 GB, up to
the maximum allowed storage. The additional storage capacity can be configured independently of the Compute
Units configuration. The price changes based on the amount of storage selected.
The IOPS configuration in each performance level relates to the pricing tier and the storage size chosen. Basic tier
does not provide an IOPS guarantee. Within the Standard pricing tier, the IOPS scale proportionally to maximum
storage size in a fixed 3:1 ratio. The included storage of 125-GB guarantees for 375 provisioned IOPS, each with
an IO size of up to 256 KB. You can choose additional storage up to 1 TB maximum, to guarantee 3,000
provisioned IOPS.
Monitor the Metrics graph in the Azure portal or write Azure CLI commands to measure the consumption of
storage and IOPS. Relevant metrics to monitor are Storage limit, Storage percentage, Storage used, and IO
percentage.
IMPORTANT
While in preview, choose the amount of storage at the time when the server is created. Changing the storage size on an
existing server is not yet supported.
Next steps
For more on Compute Units, see Explaining Compute Units
Learn how to Monitor and scale a single PostgreSQL server using Azure CLI
Explaining Compute Units in Azure Database for
PostgreSQL
10/26/2017 • 2 min to read • Edit Online
This topic explains the concept of Compute Units and what happens when your workload reaches the maximum
level of Compute Units.
IMPORTANT
If you find storage IOPS are not fully utilized to the maximum, consider monitoring the Compute Units utilization as well.
Raising the Compute Units may allow for higher IO throughput by lessening the performance bottleneck due to limited CPU
or memory.
Next steps
For more information on pricing tiers, see Azure Database for PostgreSQL pricing tiers.
Limitations in Azure Database for PostgreSQL
11/28/2017 • 1 min to read • Edit Online
The Azure Database for PostgreSQL service is in public preview. The following sections describe capacity and
functional limits in the database service.
Max connections
Max storage
When too many connections are reached, you may receive the following error:
Next steps
Understand What’s available in each pricing tier
Understand Supported PostgreSQL Database Versions
Review How To Back up and Restore a server in Azure Database for PostgreSQL using the Azure portal
Azure Database for PostgreSQL Server firewall rules
11/6/2017 • 3 min to read • Edit Online
Azure Database for PostgreSQL Server firewall prevents all access to your database server until you specify which
computers have permission. The firewall grants access to the server based on the originating IP address of each
request. To configure your firewall, you create firewall rules that specify ranges of acceptable IP addresses. You can
create firewall rules at the server level.
Firewall rules: These rules enable clients to access your entire Azure Database for PostgreSQL Server, that is, all
the databases within the same logical server. Server-level firewall rules can be configured by using the Azure
portal or using Azure CLI commands. To create server-level firewall rules, you must be the subscription owner or a
subscription contributor.
Firewall overview
All database access to your Azure Database for PostgreSQL server is blocked by the firewall by default. To begin
using your server from another computer, you need to specify one or more server-level firewall rules to enable
access to your server. Use the firewall rules to specify which IP address ranges from the Internet to allow. Access to
the Azure portal website itself is not impacted by the firewall rules. Connection attempts from the Internet and
Azure must first pass through the firewall before they can reach your PostgreSQL Database, as shown in the
following diagram:
Dynamic IP address: If you have an Internet connection with dynamic IP addressing and you are having
trouble getting through the firewall, you could try one of the following solutions:
Ask your Internet Service Provider (ISP) for the IP address range assigned to your client computers that
access the Azure Database for PostgreSQL Server, and then add the IP address range as a firewall rule.
Get static IP addressing instead for your client computers, and then add the static IP address as a firewall
rule.
Next steps
For articles on creating server-level firewall rules, see:
Create and manage Azure Database for PostgreSQL firewall rules using the Azure portal.
Create and manage Azure Database for PostgreSQL firewall rules using Azure CLI.
Configure SSL connectivity in Azure Database for
PostgreSQL
11/1/2017 • 5 min to read • Edit Online
Azure Database for PostgreSQL prefers connecting your client applications to the PostgreSQL service using Secure
Sockets Layer (SSL). Enforcing SSL connections between your database server and your client applications helps
protect against "man in the middle" attacks by encrypting the data stream between the server and your
application.
By default, the PostgreSQL database service is configured to require SSL connection. Optionally, you can disable
requiring SSL to connect to your database service if your client application does not support SSL connectivity.
You can confirm the setting by viewing the Overview page to see the SSL enforce status indicator.
Using Azure CLI
You can enable or disable the ssl-enforcement parameter using Enabled or Disabled values respectively in
Azure CLI.
az postgres server update --resource-group myresourcegroup --name mypgserver-20170401 --ssl-enforcement
Enabled
wget http://www.openssl.org/source/openssl-1.1.0e.tar.gz
Enter the directory where the files were extracted. By default, it should be as follows.
cd openssl-1.1.0e
Configure OpenSSL by executing the following command. If you want the files in a folder different than
/usr/local/openssl, make sure to change the following as appropriate.
Now that OpenSSL is configured properly, you need to compile it to convert your certificate. To compile, run the
following command:
make
Once compilation is complete, you're ready to install OpenSSL as an executable by running the following
command:
make install
To confirm that you've successfully installed OpenSSL on your system, run the following command and check to
make sure you get the same output.
/usr/local/openssl/bin/openssl version
For Windows
Installing OpenSSL on a Windows PC can be done in the following ways:
1. (Recommended) Using the built-in Bash for Windows functionality in Window 10 and above, OpenSSL is
installed by default. Instructions on how to enable Bash for Windows functionality in Windows 10 can be found
here.
2. Through downloading a Win32/64 application provided by the community. While the OpenSSL Software
Foundation does not provide or endorse any specific Windows installers, they provide a list of available
installers here.
Decode your certificate file
The downloaded Root CA file is in encrypted format. Use OpenSSL to decode the certificate file. To do so, run this
OpenSSL command:
NOTE
Currently, there is a known issue if you use "sslmode=verify-full" in your connection to the service, the connection will fail
with the following error: server certificate for "<region>.control.database.windows.net" (and 7 other names) does not
match host name "<servername>.postgres.database.azure.com". If "sslmode=verify-full" is required, please use the server
naming convention <servername>.database.windows.net as the host name in your connection string. We plan to
remove this limitation in the future. Connections using other SSL modes should continue to use the preferred host naming
convention <servername>.postgres.database.azure.com.
postgres=>
Next steps
Review various application connectivity options following Connection libraries for Azure Database for PostgreSQL.
Monitoring in Azure Database for PostgreSQL
10/24/2017 • 1 min to read • Edit Online
Monitoring data about your servers helps you troubleshoot and optimize for your workload. Azure Database for
PostgreSQL provides various metrics that give insight into the behavior of the resources supporting the
PostgreSQL server.
Metrics
All Azure metrics have a one-minute frequency, and each metric provides 30 days of history.
You can configure alerts on the metrics. For step by step guidance, see How to set up alerts.
Other tasks include setting up automated actions, performing advanced analytics, and archiving history. For more
information, see the Azure Metrics Overview.
List of metrics
These metrics are available for Azure Database for PostgreSQL:
NOTE
Compute Unit is composed of Memory and CPU. The Compute Unit percentage is max(memory%, cpu%). Examine the
memory and cpu charts to pinpoint which is contributing to Compute Unit percentage changes. For more information, see
compute units.
Next steps
For step by step guidance, see How to set up alerts.
For more information on how to access and export metrics using the Azure portal, REST API, or CLI, see the
Azure Metrics Overview.
Connection libraries for Azure Database for
PostgreSQL
11/6/2017 • 1 min to read • Edit Online
This article lists libraries and drivers that developers can use to develop applications to connect to and query
Azure Database for PostgreSQL.
Client interfaces
Most language client libraries used to connect to PostgreSQL server are external projects and are distributed
independently. The libraries listed are supported on the Windows, Linux, and Mac platforms, for connecting to
Azure Database for PostgreSQL. Several quickstart examples are listed in the Next steps section.
Next steps
Read these quickstarts on how to connect to and query Azure Database for PostgreSQL by using your language of
choice:
Python | Node.JS | Java | Ruby | PHP | .NET (C#) | Go
Create and manage Azure Database for PostgreSQL
firewall rules using the Azure portal
11/28/2017 • 2 min to read • Edit Online
Server-level firewall rules enable administrators to access an Azure Database for PostgreSQL Server from a
specified IP address or range of IP addresses.
Prerequisites
To step through this how-to guide, you need:
A server Create an Azure Database for PostgreSQL
2. Select Add My IP on the toolbar. This action automatically creates a firewall rule with the public IP address
of your computer, as perceived by the Azure system.
3. Verify your IP address before saving the configuration. In some situations, the IP address observed by Azure
portal differs from the IP address used when accessing the internet and Azure servers. Therefore, you may
need to change the Start IP and End IP to make the rule function as expected. Use a search engine or other
online tool to check your own IP address (for example, Bing search "what is my IP").
4. Add additional address ranges. In the firewall rules for the Azure Database for PostgreSQL, you can specify a
single IP address, or a range of addresses. If you want to limit the rule to a single IP address, type the same
address in the field for Start IP and End IP. Opening the firewall enables administrators, users, and
applications to log in to any database on the PostgreSQL server to which they have valid credentials.
5. Click Save on the toolbar to save this server-level firewall rule. Wait for the confirmation that the update to
the firewall rules was successful.
Next steps
Similarly, you can script to Create and manage Azure Database for PostgreSQL firewall rules using Azure CLI.
For help in connecting to an Azure Database for PostgreSQL server, see Connection libraries for Azure Database
for PostgreSQL.
Create and manage Azure Database for PostgreSQL
firewall rules using Azure CLI
11/28/2017 • 2 min to read • Edit Online
Server-level firewall rules enable administrators to manage access to an Azure Database for PostgreSQL Server
from a specific IP address or range of IP addresses. Using convenient Azure CLI commands, you can create, update,
delete, list, and show firewall rules to manage your server. For an overview of Azure Database for PostgreSQL
firewall rules, see Azure Database for PostgreSQL Server firewall rules
Prerequisites
To step through this how-to guide, you need:
An Azure Database for PostgreSQL server and database.
Install Azure CLI 2.0 command-line utility or use the Azure Cloud Shell in the browser.
The output lists the firewall rules, if any, by default in JSON format. You may use the switch --output table for a
more readable table format as the output.
To allow access to a singular IP address, provide the same address in the --start-ip-address and
--end-ip-address , as in this example.
az postgres server firewall-rule create --resource-group myresourcegroup
--server mypgserver-20170401 --name "AllowSingleIpAddress" --start-ip-address 13.83.152.1 --end-ip-address
13.83.152.1
Upon success, the command output lists the details of the firewall rule you have created, by default in JSON
format. If there is a failure, the output shows an error message instead.
Upon success, the command output lists the details of the firewall rule you have updated, by default in JSON
format. If there is a failure, the output shows an error message instead.
NOTE
If the firewall rule does not exist, it gets created by the update command.
Upon success, the command output lists the details of the firewall rule you have specified, by default in JSON
format. If there is a failure, the output shows an error message instead.
Upon success, there is no output. Upon failure, the error message text is returned.
Next steps
Similarly, you can use a web browser to Create and manage Azure Database for PostgreSQL firewall rules
using the Azure portal.
Understand more about Azure Database for PostgreSQL Server firewall rules.
For help in connecting to an Azure Database for PostgreSQL server, see Connection libraries for Azure
Database for PostgreSQL.
How to backup and restore a server in Azure
Database for PostgreSQL using the Azure portal
11/6/2017 • 1 min to read • Edit Online
3. On the toolbar of the server's overview page, click Restore. The Restore page opens.
4. Fill out the Restore form with the required information:
Restore point: Select a point-in-time that occurs before the server was changed.
Target server: Provide a new server name you want to restore to.
Location: You cannot select the region. By default it is same as the source server.
Pricing tier: You cannot change this value when restoring a server. It is same as the source server.
5. Click OK to restore the server to restore to a point in time.
6. Once the restore finishes, locate the new server that is created to verify the data was restored as expected.
Next steps
Connection libraries for Azure Database for PostgreSQL
How to backup and restore a server in Azure
Database for PostgreSQL by using the Azure CLI
11/28/2017 • 2 min to read • Edit Online
Use Azure Database for PostgreSQL to restore a server database to an earlier date that spans from 7 to 35 days.
Prerequisites
To complete this how-to guide, you need:
An Azure Database for PostgreSQL server and database
Click the Cloud Shell button on the menu in the upper right
of the Azure portal.
IMPORTANT
If you install and use the Azure CLI locally, this how-to guide requires that you use Azure CLI version 2.0 or later. To confirm
the version, at the Azure CLI command prompt, enter az --version . To install or upgrade, see Install Azure CLI 2.0.
When you restore a server to an earlier point in time, a new server is created. The original server and its databases
from the specified point in time are copied to the new server.
The location and pricing tier values for the restored server remain the same as the original server.
The az postgres server restore command is synchronous. After the server is restored, you can use it again to
repeat the process for a different point in time.
After the restore process finishes, locate the new server and verify that the data is restored as expected.
Next steps
Connection libraries for Azure Database for PostgreSQL
Migrate your PostgreSQL database using dump and
restore
11/6/2017 • 1 min to read • Edit Online
You can use pg_dump to extract a PostgreSQL database into a dump file and pg_restore to restore the PostgreSQL
database from an archive file created by pg_dump.
Prerequisites
To step through this how-to guide, you need:
An Azure Database for PostgreSQL server with firewall rules to allow access and database under it.
pg_dump and pg_restore command-line utilities installed
Follow these steps to dump and restore your PostgreSQL database:
Create a dump file using pg_dump that contains the data to be loaded
To back up an existing PostgreSQL database on-premises or in a VM, run the following command:
For example, if you have a local server and a database called testdb in it
Restore the data into the target Azure Database for PostrgeSQL using
pg_restore
Once you have created the target database, you can use the pg_restore command and the -d, --dbname parameter
to restore the data into the target database from the dump file.
In this example, restore the data from the dump file testdb.dump into the database mypgsqldb on target server
mypgserver-20170401.postgres.database.azure.com.
Next steps
To migrate a PostgreSQL database using export and import, see Migrate your PostgreSQL database using
export and import
Migrate your PostgreSQL database using export
and import
11/6/2017 • 1 min to read • Edit Online
You can use pg_dump to extract a PostgreSQL database into a script file and psql to import the data into the
target database from that file.
Prerequisites
To step through this how-to guide, you need:
An Azure Database for PostgreSQL server with firewall rules to allow access and database under it.
pg_dump command-line utility installed
psql command-line utility installed
Follow these steps to export and import your PostgreSQL database.
Create a script file using pg_dump that contains the data to be loaded
To export your existing PostgreSQL database on-premises or in a VM to a sql script file, run the following
command in your existing environment:
For example, if you have a local server and a database called testdb in it:
This example uses psql utility and a script file named testdb.sql from previous step to import data into the
database mypgsqldb on the target server mypgserver-20170401.postgres.database.azure.com.
Next steps
To migrate a PostgreSQL database using dump and restore, see Migrate your PostgreSQL database using
dump and restore
Configure server parameters in Azure portal
11/9/2017 • 1 min to read • Edit Online
You can list, show, and update configuration parameters for an Azure Database for PostgreSQL server through the
Azure portal.
Prerequisites
To step through this how-to guide you need:
Azure Database for PostgreSQL server
4. Select the drop down button to see the possible values for enumerated-type parameters like
client_min_messages.
5. Select or hover over the i (information) button to see the range of possible values for numeric parameters
like cpu_index_tuple_cost.
6. If needed, use the search box to narrow down to a specific parameter. The search is on the name and
description of the parameters.
7. Change the parameter values you would like to adjust. All changes you make in a session are highlighted in
purple. Once you have changed the values, you can select Save. Or you can Discard your changes.
8. If you have saved new values for the parameters, you can always revert everything back to the default
values by selecting Reset all to default.
Next steps
Learn about:
Overview of server parameters in Azure Database for PostgreSQL
Configuring parameters using the Azure CLI
Customize server configuration parameters using
Azure CLI
11/28/2017 • 1 min to read • Edit Online
You can list, show, and update configuration parameters for an Azure PostgreSQL server using the Command Line
Interface (Azure CLI). A subset of engine configurations is exposed at server-level and can be modified.
Prerequisites
To step through this how-to guide, you need:
Create an Azure Database for PostgreSQL server and database by following Create an Azure Database for
PostgreSQL
Install Azure CLI 2.0 command-line interface on your machine or use the Azure Cloud Shell in the Azure portal
using your browser.
If you want to reset the value of a configuration parameter, you simply choose to leave out the optional --value
parameter, and the service applies the default value. In above example, it would look like:
This command resets the log_min_messages configuration to the default value WARNING. For more
information on server configuration and permissible values, see PostgreSQL documentation on Server
Configuration.
Next steps
To configure and access server logs, see Server Logs in Azure Database for PostgreSQL
Configure and access server logs in the Azure portal
11/7/2017 • 1 min to read • Edit Online
You can configure, list, and download the Azure Database for PostgreSQL server logs from the Azure portal.
Prerequisites
To step through this how-to guide, you need:
Azure Database for PostgreSQL server
Configure logging
Configure access to the query logs and error logs.
1. Sign in to the Azure portal.
2. Select your Azure Database for PostgreSQL server.
3. Under the Monitoring section in the sidebar, select Server Logs.
4. Select the heading Click here to enable logs and configure log parameters to see the server
parameters.
5. Select the Show more expander to see an extended list of available parameters.
For more information on the definitions of parameters, see the PostgreSQL documentation on Error
Reporting and Logging.
6. Change the parameters that you need to adjust. All changes you make in this session are highlighted in
purple.
Once you have changed the parameters, you can click Save. Or you can Discard your changes.
7. Return to the list of logs by clicking the close button (X icon) on the Server Parameters page.
4. If needed, use the search box to quickly narrow down to a specific log based on date/time. The search is on
the name of the log.
5. Download individual log files using the download button (down arrow icon) next to each log file in the table
row as shown:
Next steps
See Access Server Logs in CLI to learn how to download logs programmatically.
Learn more about Server Logs in Azure DB for PostgreSQL.
For more information about the parameter definitions and PostgreSQL logging, see the PosgreSQL
documentation on Error Reporting and Logging.
Configure and access server logs using Azure CLI
11/28/2017 • 1 min to read • Edit Online
You can download the PostgreSQL server error logs using the Command Line Interface (Azure CLI). However,
access to transaction logs is not supported.
Prerequisites
To step through this how-to guide, you need:
An Azure Database for PostgreSQL server
Install Azure CLI 2.0 command-line utility or use the Azure Cloud Shell in the browser.
Next steps
To learn more about server logs, see Server Logs in Azure Database for PostgreSQL
For more information on server parameters, see Customize server configuration parameters using Azure CLI
Use the Azure portal to set up alerts on metrics for
Azure Database for PostgreSQL
10/24/2017 • 2 min to read • Edit Online
This article shows you how to set up Azure Database for PostgreSQL alerts using the Azure portal. You can receive
an alert based on monitoring metrics for your Azure services.
The alert triggers when the value of a specified metric crosses a threshold you assign. The alert triggers both when
the condition is first met, and then afterwards when that condition is no longer being met.
You can configure an alert to do the following actions when it triggers:
Send email notifications to the service administrator and co-administrators.
Send email to additional emails that you specify.
Call a webhook.
You can configure and get information about alert rules using:
Azure portal
PowerShell
Command-line interface (CLI)
Azure Monitor REST API
Name Provide a name for the alert rule. This value is sent in the
alert notification email.
Resource group This field is prepopulated with the resource group of your
Azure Database for PostgreSQL.
Metric Select the metric that you want to issue an alert for. For
example, Storage percentage.
Period The period of time that the metric rule must be satisfied
before the alert triggers. For example, Over the last 30
minutes.
Based on the example, the alert looks for Storage percentage above 85% over a 30-minute period. That
alert triggers when the average Storage percentage has been above 85% for 30 minutes. Once the first
trigger occurs, it triggers again when the average Storage percentage is below 85% over 30 minutes.
5. Choose the notification method you want for the alert rule.
Check Email owners, contributors, and readers option if you want the subscription administrators and
co-administrators to be emailed when the alert fires.
If you want additional emails to receive a notification when the alert fires, add them in the Additional
administrator email(s) field. Separate multiple emails with semi-colons -
email@contoso.com;email2@contoso.com
Optionally, provide a valid URI in the Webhook field if you want it called when the alert fires.
6. Select OK to create the alert.
Within a few minutes, the alert is active and triggers as previously described.
Next steps
Learn more about configuring webhooks in alerts.
Get an overview of metrics collection to make sure your service is available and responsive.
Azure Database for PostgreSQL videos
12/1/2017 • 1 min to read • Edit Online
Azure Database for PostgreSQL and Azure Database for MySQL bring together community edition database
engines and capabilities of a fully managed service—so you can focus on your apps instead of having to manage a
database. Tune in to get a quick overview of the advantages of using the service, and see some of the capabilities in
action.
Deep dive on managed service capabilities for MySQL and PostgreSQL
Azure Database for PostgreSQL and Azure Database for MySQL bring together community edition database
engines and the capabilities of a fully managed service. Tune in to get a deep dive on how these services work—
how we ensure high availability and fast scaling (within seconds), so you can meet your customers’ needs. You'll
also learn about some of the underlying investments in security and worldwide availability.
Develop an intelligent analytics app with PostgreSQL
Azure Database for PostgreSQL brings together community edition database engine and capabilities of a fully
managed service—so you can focus on your apps instead of having to manage a database. Tune in to see in action
how easy it is to create new experiences like adding Cognitive Services to your apps by virtue of being on Azure.
How to get started with the new Azure Database for PostgreSQL service
In this video from the 2017 Microsoft //Build conference, learn from two early adopting customers how they've
used Azure Database for PostgreSQL service to innovate faster. Learn how they migrated to the service, and discuss
next steps in their application development. The video walks through some of the key service features and
discusses how you as a developer can migrate your existing applications or develop new applications that use this
managed PostgreSQL service in Azure.