{"id":20632481,"url":"https://github.com/citusdata/nationwide-hands-on-session","last_synced_at":"2026-03-19T16:50:58.835Z","repository":{"id":149340003,"uuid":"210651162","full_name":"citusdata/Nationwide-Hands-On-Session","owner":"citusdata","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-24T17:20:18.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-08-01T16:03:05.537Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/citusdata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-24T16:39:46.000Z","updated_at":"2020-02-19T18:30:50.000Z","dependencies_parsed_at":"2023-09-03T16:47:32.175Z","dependency_job_id":null,"html_url":"https://github.com/citusdata/Nationwide-Hands-On-Session","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/citusdata/Nationwide-Hands-On-Session","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citusdata%2FNationwide-Hands-On-Session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citusdata%2FNationwide-Hands-On-Session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citusdata%2FNationwide-Hands-On-Session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citusdata%2FNationwide-Hands-On-Session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/citusdata","download_url":"https://codeload.github.com/citusdata/Nationwide-Hands-On-Session/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citusdata%2FNationwide-Hands-On-Session/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29211127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T22:22:11.602Z","status":"ssl_error","status_checked_at":"2026-02-07T22:22:10.684Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T14:16:20.034Z","updated_at":"2026-02-07T22:31:09.395Z","avatar_url":"https://github.com/citusdata.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Design an Azure Database for PostgreSQL - Single Server using the Azure portal\n\nAzure 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.\n\nIn this tutorial, you use the Azure portal to learn how to:\n\u003e \n\u003e * Create an Azure Database for PostgreSQL server\n\u003e * Configure the server firewall\n\u003e * Use [**psql**](https://www.postgresql.org/docs/9.6/static/app-psql.html) utility to create a database\n\u003e * Load sample data\n\u003e * Query data\n\u003e * Update data\n\u003e * Restore data\n\n## Prerequisites\nIf you don't have an Azure subscription, create a [free](https://azure.microsoft.com/free/) account before you begin.\n\n## Create an Azure Database for PostgreSQL\n\nAn Azure Database for PostgreSQL server is created with a defined set of [compute and storage resources](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/concepts-compute-unit-and-storage.md). The server is created within an [Azure resource group](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/azure-resource-manager/resource-group-overview.md).\n\nFollow these steps to create an Azure Database for PostgreSQL server:\n1. Click **Create a resource**  in the upper left-hand corner of the Azure portal.\n2. Select **Databases** from the **New** page, and select **Azure Database for PostgreSQL** from the **Databases** page.\n   ![Azure Database for PostgreSQL - Create the database](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/1-create-database.png)\n\n3. Select the **Single server** deployment option.\n\n   ![Select Azure Database for PostgreSQL - Single server deployment option](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/select-deployment-option.png)\n\n4. Fill out the **Basics** form with the following information:\n\n    ![Create a server](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/create-basics.png)\n\n    Setting|Suggested Value|Description\n    ---|---|---\n    Subscription|Your subscription name|The  Azure subscription that you want to use for your server. If you have multiple subscriptions, choose the subscription in which you're billed for the resource.\n    Resource group|*myresourcegroup*| A new resource group name or an existing one from your subscription.\n    Server name |*mydemoserver*|A unique name that identifies your Azure Database for PostgreSQL server. The domain name *postgres.database.azure.com* is appended to the server name you provide. The server can contain only lowercase letters, numbers, and the hyphen (-) character. It must contain at least 3 through 63 characters.\n    Data source | *None* | Select *None* to create a new server from scratch. (You would select *Backup* if you were creating a server from a geo-backup of an existing Azure Database for PostgreSQL server).\n    Admin username |*myadmin*| 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_**.\n    Password |Your password| A new password for the server admin account. It must contain between 8 and 128 characters. Your password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers (0 through 9), and non-alphanumeric characters (!, $, #, %, etc.).\n    Location|The region closest to your users| The location that is closest to your users.\n    Version|The latest major version| The latest PostgreSQL major version, unless you have specific requirements otherwise.\n    Compute + storage | **General Purpose**, **Gen 5**, **2 vCores**, **5 GB**, **7 days**, **Geographically Redundant** | The compute, storage, and backup configurations for your new server. Select **Configure server**. Next, select the **General Purpose** tab. *Gen 5*, *4 vCores*, *100 GB*, and *7 days* are the default values for **Compute Generation**, **vCore**, **Storage**, and **Backup Retention Period**. You can leave those sliders as is or adjust them. To enable your server backups in geo-redundant storage select **Geographically Redundant** from the **Backup Redundancy Options**. To save this pricing tier selection, select **OK**. The next screenshot captures these selections.\n\n   \u003e [!NOTE]\n   \u003e Consider using the Basic pricing tier if light compute and I/O are adequate for your workload. Note that servers created in the Basic pricing tier cannot later be scaled to General Purpose or Memory Optimized. See the [pricing page](https://azure.microsoft.com/pricing/details/postgresql/) for more information.\n   \u003e \n\n    ![The \"Pricing tier\" pane](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/quickstart-create-database-portal/2-pricing-tier.png)\n\n    \u003e [!TIP]\n    \u003e With **auto-growth** enabled your server increases storage when you are approaching the allocated limit, without impacting your workload.\n\n5. Select **Review + create** to review your selections. Select **Create** to provision the server. This operation may take a few minutes.\n\n6. On the toolbar, select the **Notifications** icon (a bell) to monitor the deployment process. Once the deployment is done, you can select **Pin to dashboard**, which creates a tile for this server on your Azure portal dashboard as a shortcut to the server's **Overview** page. Selecting **Go to resource** opens the server's **Overview** page.\n\n    ![The \"Notifications\" pane](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/quickstart-create-database-portal/3-notifications.png)\n   \n   By default, a **postgres** database is created under your server. The [postgres](https://www.postgresql.org/docs/9.6/static/app-initdb.html) database is a default database that's meant for use by users, utilities, and third-party applications. (The other default database is **azure_maintenance**. Its function is to separate the managed service processes from user actions. You cannot access this database.)\n\n\n## Configure a server-level firewall rule\n\nThe Azure Database for PostgreSQL service uses a firewall at the server-level. By default, this firewall prevents all external applications and tools from connecting to the server and any databases on the server unless a firewall rule is created to open the firewall for a specific IP address range. \n\n1. After the deployment completes, click **All Resources** from the left-hand menu and type in the name **mydemoserver** to search for your newly created server. Click the server name listed in the search result. The **Overview** page for your server opens and provides options for further configuration.\n\n   ![Azure Database for PostgreSQL - Search for server](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/4-locate.png)\n\n2. In the server page, select **Connection security**. \n\n3. Click in the text box under **Rule Name,** and add a new firewall rule to specify the IP range for connectivity. Enter your IP range. Click **Save**.\n\n   ![Azure Database for PostgreSQL - Create Firewall Rule](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/5-firewall-2.png)\n\n4. Click **Save** and then click the **X** to close the **Connections security** page.\n\n   \u003e [!NOTE]\n   \u003e 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.\n   \u003e\n\n## Get the connection information\n\nWhen you created the Azure Database for PostgreSQL server, the default **postgres** database was also created. To connect to your database server, you need to provide host information and access credentials.\n\n1. From the left-hand menu in the Azure portal, click **All resources** and search for the server you just created.\n\n   ![Azure Database for PostgreSQL - Search for server](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/4-locate.png)\n\n2. Click the server name **mydemoserver**.\n\n3. Select the server's **Overview** page. Make a note of the **Server name** and **Server admin login name**.\n\n   ![Azure Database for PostgreSQL - Server Admin Login](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/6-server-name.png)\n\n\n## Connect to PostgreSQL database using psql\nIf your client computer has PostgreSQL installed, you can use a local instance of [psql](https://www.postgresql.org/docs/9.6/static/app-psql.html), or the Azure Cloud Console to connect to an Azure PostgreSQL server. Let's now use the psql command-line utility to connect to the Azure Database for PostgreSQL server.\n\n1. Run the following psql command to connect to an Azure Database for PostgreSQL database:\n   ```\n   psql --host=\u003cservername\u003e --port=\u003cport\u003e --username=\u003cuser@servername\u003e --dbname=\u003cdbname\u003e\n   ```\n\n   For example, the following command connects to the default database called **postgres** on your PostgreSQL server **mydemoserver.postgres.database.azure.com** using access credentials. Enter the `\u003cserver_admin_password\u003e` you chose when prompted for password.\n  \n   ```\n   psql --host=mydemoserver.postgres.database.azure.com --port=5432 --username=myadmin@mydemoserver --dbname=postgres\n   ```\n\n   \u003e [!TIP]\n   \u003e If you prefer to use a URL path to connect to Postgres, URL encode the @ sign in the username with `%40`. For example the connection string for psql would be,\n   \u003e ```\n   \u003e psql postgresql://myadmin%40mydemoserver@mydemoserver.postgres.database.azure.com:5432/postgres\n   \u003e ```\n\n2. Once you are connected to the server, create a blank database at the prompt:\n   ```sql\n   CREATE DATABASE mypgsqldb;\n   ```\n\n3. At the prompt, execute the following command to switch connection to the newly created database **mypgsqldb**:\n   ```sql\n   \\c mypgsqldb\n   ```\n\n## Create tables in the database\nNow that you know how to connect to the Azure Database for PostgreSQL, you can complete some basic tasks:\n\nFirst, create a table and load it with some data. Let's create a table that tracks inventory information using this SQL code:\n```sql\nCREATE TABLE inventory (\n\tid serial PRIMARY KEY, \n\tname VARCHAR(50), \n\tquantity INTEGER\n);\n```\n\nYou can see the newly created table in the list of tables now by typing:\n```sql\n\\dt\n```\n\n## Load data into the tables\nNow that you have a table, insert some data into it. At the open command prompt window, run the following query to insert some rows of data.\n```sql\nINSERT INTO inventory (id, name, quantity) VALUES (1, 'banana', 150); \nINSERT INTO inventory (id, name, quantity) VALUES (2, 'orange', 154);\n```\n\nYou have now two rows of sample data into the inventory table you created earlier.\n\n## Query and update the data in the tables\nExecute the following query to retrieve information from the inventory database table. \n```sql\nSELECT * FROM inventory;\n```\n\nYou can also update the data in the table.\n```sql\nUPDATE inventory SET quantity = 200 WHERE name = 'banana';\n```\n\nYou can see the updated values when you retrieve the data.\n```sql\nSELECT * FROM inventory;\n```\n\n## Create data from web urls\n\nThe data model we're going to work with is simple: user and event data from GitHub. Events include fork creation, git commits related to an organization, and more.\n\nOnce you've connected via psql, let's create our tables. In the psql console run:\n\n```sql\nCREATE TABLE github_events\n(\n    event_id bigint,\n    event_type text,\n    event_public boolean,\n    repo_id bigint,\n    payload jsonb,\n    repo jsonb,\n    user_id bigint,\n    org jsonb,\n    created_at timestamp\n);\n\nCREATE TABLE github_users\n(\n    user_id bigint,\n    url text,\n    login text,\n    avatar_url text,\n    gravatar_id text,\n    display_login text\n);\n```\n\nThe `payload` field of `github_events` has a JSONB datatype. JSONB is the JSON datatype in binary form in Postgres. The datatype makes it easy to store a flexible schema in a single column.\n\nPostgres can create a `GIN` index on this type, which will index every key and value within it. With an  index, it becomes fast and easy to query the payload with various conditions. Let's go ahead and create a couple of indexes before we load our data. In psql:\n\n```sql\nCREATE INDEX event_type_index ON github_events (event_type);\nCREATE INDEX payload_index ON github_events USING GIN (payload jsonb_path_ops);\n```\n\nWe're ready to load data. In psql still, shell out to download the files:\n\n```sql\n\\! curl -O https://examples.citusdata.com/users.csv\n\\! curl -O https://examples.citusdata.com/events.csv\n```\n\nNext, load the data from the files into the tables:\n\n```sql\nSET CLIENT_ENCODING TO 'utf8';\n\n\\copy github_events from 'events.csv' WITH CSV\n\\copy github_users from 'users.csv' WITH CSV\n```\n\n## Run queries\n\nNow it's time for the fun part, actually running some queries. Let's start with a simple `count (*)` to see how much data we loaded:\n\n```sql\nSELECT count(*) from github_events;\n```\n\nThat worked nicely. We'll come back to that sort of aggregation in a bit, but for now let’s look at a few other queries. Within the JSONB `payload` column there's a good bit of data, but it varies based on event type. `PushEvent` events contain a size that includes the number of distinct commits for the push. We can use it to find the total number of commits per hour:\n\n```sql\nSELECT date_trunc('hour', created_at) AS hour,\n       sum((payload-\u003e\u003e'distinct_size')::int) AS num_commits\nFROM github_events\nWHERE event_type = 'PushEvent'\nGROUP BY hour\nORDER BY hour;\n```\n\nLet's find the users who created the greatest number of repositories. This query involved joining events and the users table on the user_id column.\n\n```sql\nSELECT gu.login, count(*)\n  FROM github_events ge\n  JOIN github_users gu\n    ON ge.user_id = gu.user_id\n WHERE ge.event_type = 'CreateEvent'\n   AND ge.payload @\u003e '{\"ref_type\": \"repository\"}'\n GROUP BY gu.login\n ORDER BY count(*) DESC;\n```\n\n## Restore data to a previous point in time\nImagine you have accidentally deleted these tables. This situation is something you cannot easily recover from. Azure Database for PostgreSQL allows you to go back to any point-in-time for which your server has backups (determined by the backup retention period you configured) and restore this point-in-time to a new server. You can use this new server to recover your deleted data. The following steps restore the **mydemoserver** server to a point before the inventory table was added.\n\n1. On the Azure Database for PostgreSQL **Overview** page for your server, click **Restore** on the toolbar. The **Restore** page opens.\n\n   ![Azure portal - Restore form options](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/9-azure-portal-restore.png)\n\n2. Fill out the **Restore** form with the required information:\n\n   ![Azure portal - Restore form options](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/media/tutorial-design-database-using-azure-portal/10-azure-portal-restore.png)\n\n   - **Restore point**: Select a point-in-time that occurs before the server was changed\n   - **Target server**: Provide a new server name you want to restore to\n   - **Location**: You cannot select the region, by default it is same as the source server\n   - **Pricing tier**: You cannot change this value when restoring a server. It is same as the source server. \n3. Click **OK** to [restore the server to a point-in-time](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/howto-restore-server-portal.md) 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 [pricing tier](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/concepts-pricing-tiers.md).\n\n## Next steps\nIn this tutorial, you learned how to use the Azure portal and other utilities to:\n\u003e [!div class=\"checklist\"]\n\u003e * Create an Azure Database for PostgreSQL server\n\u003e * Configure the server firewall\n\u003e * Use [**psql**](https://www.postgresql.org/docs/9.6/static/app-psql.html) utility to create a database\n\u003e * Load sample data\n\u003e * Query data\n\u003e * Update data\n\u003e * Restore data\n\nNext, to learn how to use the Azure CLI to do similar tasks, review this tutorial: \n[Design your first Azure Database for PostgreSQL using Azure CLI](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/postgresql/tutorial-design-database-using-azure-cli.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcitusdata%2Fnationwide-hands-on-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcitusdata%2Fnationwide-hands-on-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcitusdata%2Fnationwide-hands-on-session/lists"}