Steps to Create and Connect to Azure Database for PostgreSQL
- 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.
- Get
Connection Information
- In
the newly created server’s Overview page, copy the Server name
and Username; you will need these to connect.
- 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.
- Explore
Created Databases
- Expand
the connected server in pgAdmin. You will see 3 databases pre-created by
Azure. Do not delete these.
- Create
a New Database to Use
- Right-click
Databases under your server, select Create > Database.
- Name
your new database, for example, mypgsqldb.
- 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 !!!!!!