Saturday, 18 October 2025

Steps to Create and Connect to Azure Database for PostgreSQL

Steps to Create and Connect to Azure Database for PostgreSQL

  1. Create PostgreSQL Database in Azure Portal
    • Go to the Azure Portal.
    • Search for and select Azure Database for PostgreSQL servers.
    • Click Create, then select Flexible Server option.








  2. Get Connection Information
    • In the newly created server’s Overview page, copy the Server name and Username; you will need these to connect.
  3. Connect Using pgAdmin
    • Open pgAdmin.
    • Right-click Servers and select Create > Server.
    • Enter a name, e.g., azure-pg-tt.
    • On the Connection tab, enter the copied hostname and username from the Azure Portal.
    • Click Save to connect.


  4. Explore Created Databases
    • Expand the connected server in pgAdmin. You will see 3 databases pre-created by Azure. Do not delete these.
  5. Create a New Database to Use
    • Right-click Databases under your server, select Create > Database.
    • Name your new database, for example, mypgsqldb.
  6. Run SQL Queries on Your Database
    • Select your new database (mypgsqldb) and click the Query Tool icon in pgAdmin.
    • Run the following SQL commands to create a table, insert records, and query data:

sql

CREATE TABLE EMP(id serial PRIMARY KEY, name VARCHAR(50),  Salary INTEGER);

INSERT INTO EMP(id, name, salary) VALUES (1, 'Jon', 15000);

INSERT INTO EMP(id, name, salary) VALUES (2, 'Doe', 15400);

SELECT * FROM EMP;



You are now connected to the PostgreSQL database on Azure !!!!!!

Create a Free SQL Database in Azure and query using query editor

 


How to Create a Free SQL Database in Azure (with Screenshots)

Getting started with SQL databases in the cloud is easy with Microsoft Azure. Follow the step-by-step tutorial below to create your own free Azure SQL Database and run queries using the Azure Portal.


1. Log in to the Azure Portal

Go to https://portal.azure.com/ and sign in with your Microsoft account. On the homepage, you’ll find options like Create a resource, Azure SQL Database, and more.




2. Create a New SQL Database

Click on Azure SQL Database or use the search bar to find it. Click the Create button to start the creation process.




3. Configure Database Basics

Fill out the basic details:

  • Subscription: Choose your Azure subscription.
  • Resource group: Create a new resource group or select an existing one.
  • Database name: Enter a meaningful name.
  • Server: Click "Create new" to set up a SQL server (see next step).

4. Set Up SQL Database Server

In the server creation form, provide:

  • Server name: A unique name.
  • Location: Select the Azure region.
  • Authentication: Set admin login and password.


5. Configure Networking Options

On the networking screen:

  • Set Allow Azure services and resources to access this server to No.
  • Set Add current client IP address to Yes.​



6. Additional Settings: Add Sample Data

On the Additional settings tab, choose Sample under “Use existing data”. This loads the AdventureWorksLT sample database for learning and testing.​




7. Review and Create

Click Review + create at the bottom and let Azure deploy your database.


8. Query the Database

Once deployed, go back to the list of your SQL databases and select the one you’ve just created.2_Create.jpg​

  • Open Query editor (preview).
  • Log in with the credentials you set for your server.


9. Sample Query and Output

Here’s how the query and results look in the Azure Portal’s Query Editor :​

sql

SELECT * FROM [SalesLT].[Customer]



You’ll see a result table with columns such as CustomerID, NameStyle, Title, and FirstName.


Sample Text

Sample text