Postgres App



Columnar storage extension for Postgres built as a foreign data wrapper. Reference App for Ad Analytics, using Django CSS 3 6 0 2 Updated Dec 23, 2020. We and third parties use cookies or similar technologies ('Cookies') as described below to collect and process personal data, such as your IP address or browser information.

-->

Azure App Service provides a highly scalable, self-patching web hosting service. This tutorial shows how to create a Ruby app and connect it to a PostgreSQL database. When you're finished, you'll have a Ruby on Rails app running on App Service on Linux.

  1. One of the basic differences between MySQL and PostgreSQL is that PostgreSQL is an ORDBMS (Object Relational Database Management System) while MySQL is a community-driven RDBMS. Another advantage of PostgreSQL over MySQL is that it can support modern applications feature like JSON, XML, etc. While MySQL can only support JSON.
  2. Hasura gives you instant GraphQL APIs on your data sources. Point Hasura to your preferred internal and external data sources, setup relationships and security rules on your data models across sources and get a managed unified GraphQL API to build modern applications, instantly.
  3. When you run apps on Railway, configs are intelligently provided to you based on your project and environment, to any terminal across the globe.

In this tutorial, you learn how to:

  • Create a PostgreSQL database in Azure
  • Connect a Ruby on Rails app to PostgreSQL
  • Deploy the app to Azure
  • Update the data model and redeploy the app
  • Stream diagnostic logs from Azure
  • Manage the app in the Azure portal
Approximate

If you don't have an Azure subscription, create a free account before you begin.

Postgresql client

Prerequisites

To complete this tutorial:

  • Use the Bash environment in Azure Cloud Shell.

  • If you prefer, install the Azure CLI to run CLI reference commands.

    • If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For additional sign-in options, see Sign in with the Azure CLI.

    • When you're prompted, install Azure CLI extensions on first use. For more information about extensions, see Use extensions with the Azure CLI.

    • Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.

Prepare local Postgres

In this step, you create a database in your local Postgres server for your use in this tutorial.

Connect to local Postgres server

Open the terminal window and run psql to connect to your local Postgres server.

If your connection is successful, your Postgres database is running. If not, make sure that your local Postgres database is started by following the steps at Downloads - PostgreSQL Core Distribution.

Type q to exit the Postgres client.

Postgres Append String

Create a Postgres user that can create databases by running the following command, using your signed-in Linux username.

Create a Ruby on Rails app locally

In this step, you get a Ruby on Rails sample application, configure its database connection, and run it locally.

Clone the sample

In the terminal window, cd to a working directory.

Run the following command to clone the sample repository.

cd to your cloned directory. Install the required packages.

Run the sample locally

Run the Rails migrations to create the tables the application needs. To see which tables are created in the migrations, look in the db/migrate directory in the Git repository.

Run the application.

Navigate to http://localhost:3000 in a browser. Add a few tasks in the page.

To stop the Rails server, type Ctrl + C in the terminal.

Create Postgres in Azure

In this step, you create a Postgres database in Azure Database for PostgreSQL. Later, you configure the Ruby on Rails application to connect to this database.

Create a resource group

A resource group is a logical container into which Azure resources, such as web apps, databases, and storage accounts, are deployed and managed. For example, you can choose to delete the entire resource group in one simple step later.

In the Cloud Shell, create a resource group with the az group create command. The following example creates a resource group named myResourceGroup in the West Europe location. To see all supported locations for App Service on Linux in Basic tier, run the az appservice list-locations --sku B1 --linux-workers-enabled command.

You generally create your resource group and the resources in a region near you.

Columns

When the command finishes, a JSON output shows you the resource group properties.

Create Postgres database in Azure

In this section, you create an Azure Database for PostgreSQL server and database. To start, install the db-up extension with the following command:

Create the Postgres database in Azure with the az postgres up command, as shown in the following example. Replace <postgresql-name> with a unique name (the server endpoint is https://<postgresql-name>.postgres.database.azure.com). For <admin-username> and <admin-password>, specify credentials to create an administrator user for this Postgres server.

This command may take a while because it's doing the following:

  • Creates a resource group called myResourceGroup, if it doesn't exist. Every Azure resource needs to be in one of these. --resource-group is optional.
  • Creates a Postgres server with the administrative user.
  • Creates a sampledb database.
  • Allows access from your local IP address.
  • Allows access from Azure services.
  • Create a database user with access to the sampledb database.

You can do all the steps separately with other az postgres commands and psql, but az postgres up does all of them in one step for you.

When the command finishes, find the output lines that being with Ran Database Query:. They show the database user that's created for you, with the username root and password Sampledb1. You'll use them later to connect your app to the database.

Tip

--location <location-name>, can be set to any one of the Azure regions. You can get the regions available to your subscription with the az account list-locations command. For production apps, put your database and your app in the same location.

Connect app to Azure Postgres

In this step, you connect the Ruby on Rails application to the Postgres database you created in Azure Database for PostgreSQL.

Configure the database connection

In the repository, open config/database.yml. At the bottom of the file, replace the production variables with the following code.

Save the changes.

Test the application locally

Back in the local terminal, set the following environment variables:

Run Rails database migrations with the production values you just configured to create the tables in your Postgres database in Azure Database for PostgreSQL.

Postgres apple silicon

When running in the production environment, the Rails application needs precompiled assets. Generate the required assets with the following command:

The Rails production environment also uses secrets to manage security. Generate a secret key.

Save the secret key to the respective variables used by the Rails production environment. For convenience, you use the same key for both variables.

Enable the Rails production environment to serve JavaScript and CSS files.

Run the sample application in the production environment.

Navigate to http://localhost:3000. If the page loads without errors, the Ruby on Rails application is connecting to the Postgres database in Azure.

Add a few tasks in the page.

To stop the Rails server, type Ctrl + C in the terminal.

Commit your changes

Run the following Git commands to commit your changes:

Your app is ready to be deployed.

Deploy to Azure

In this step, you deploy the Postgres-connected Rails application to Azure App Service.

Configure a deployment user

FTP and local Git can deploy to an Azure web app by using a deployment user. Once you configure your deployment user, you can use it for all your Azure deployments. Your account-level deployment username and password are different from your Azure subscription credentials.

To configure the deployment user, run the az webapp deployment user set command in Azure Cloud Shell. Replace <username> and <password> with a deployment user username and password.

  • The username must be unique within Azure, and for local Git pushes, must not contain the ‘@’ symbol.
  • The password must be at least eight characters long, with two of the following three elements: letters, numbers, and symbols.

The JSON output shows the password as null. If you get a 'Conflict'. Details: 409 error, change the username. If you get a 'Bad Request'. Details: 400 error, use a stronger password.

Postgres App Binaries Not Found

Record your username and password to use to deploy your web apps.

Create an App Service plan

A resource group is a logical container into which Azure resources, such as web apps, databases, and storage accounts, are deployed and managed. For example, you can choose to delete the entire resource group in one simple step later.

In the Cloud Shell, create a resource group with the az group create command. The following example creates a resource group named myResourceGroup in the West Europe location. To see all supported locations for App Service on Linux in Basic tier, run the az appservice list-locations --sku B1 --linux-workers-enabled command.

You generally create your resource group and the resources in a region near you.

When the command finishes, a JSON output shows you the resource group properties.

Create a web app

Create a web app in the myAppServicePlan App Service plan.

In the Cloud Shell, you can use the az webapp create command. In the following example, replace <app-name> with a globally unique app name (valid characters are a-z, 0-9, and -). The runtime is set to RUBY|2.6.2. To see all supported runtimes, run az webapp list-runtimes --linux.

When the web app has been created, the Azure CLI shows output similar to the following example:

You’ve created an empty new web app, with git deployment enabled.

Note

The URL of the Git remote is shown in the deploymentLocalGitUrl property, with the format https://<username>@<app-name>.scm.azurewebsites.net/<app-name>.git. Save this URL as you need it later.

Configure database settings

In App Service, you set environment variables as app settings by using the az webapp config appsettings set command in the Cloud Shell.

Postgres App

The following Cloud Shell command configures the app settings DB_HOST, DB_DATABASE, DB_USERNAME, and DB_PASSWORD. Replace the placeholders <appname> and <postgres-server-name>.

Configure Rails environment variables

In the local terminal, generate a new secret for the Rails production environment in Azure.

Configure the variables required by Rails production environment.

In the following Cloud Shell command, replace the two <output-of-rails-secret> placeholders with the new secret key you generated in the local terminal.

ASSETS_PRECOMPILE='true' tells the default Ruby container to precompile assets at each Git deployment. For more information, see Precompile assets and Serve static assets.

Push to Azure from Git

In the local terminal, add an Azure remote to your local Git repository.

Push to the Azure remote to deploy the Ruby on Rails application. You are prompted for the password you supplied earlier as part of the creation of the deployment user.

During deployment, Azure App Service communicates its progress with Git.

Browse to the Azure app

Browse to http://<app-name>.azurewebsites.net and add a few tasks to the list.

Install Postgres Mac

Congratulations, you're running as Overview page. Here, you can perform basic management tasks like stop, start, restart, browse, and delete.

The left menu provides pages for configuring your app.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, delete the resource group by running the following command in the Cloud Shell:

This command may take a minute to run.

Next steps

In this tutorial, you learned how to:

  • Create a Postgres database in Azure
  • Connect a Ruby on Rails app to Postgres
  • Deploy the app to Azure
  • Update the data model and redeploy the app
  • Stream diagnostic logs from Azure
  • Manage the app in the Azure portal

Advance to the next tutorial to learn how to map a custom DNS name to your app.

Postgres App Mac

Or, check out other resources: