Deploy PostgreSQL on Northflank | Deploy Databases On Northflank | Databases And Persistence | Northflank Application docs
v1

Databases And Persistence / Deploy Databases On Northflank /

Deploy PostgreSQL on Northflank

This guide explains how to quickly and easily deploy and use PostgreSQL on Northflank.

Available versionsDescriptionBackupsTLS
15, 14, 13, 12, 11PostgreSQL is a free and open-source relational database management system. High availability with PatroniNative or diskYes

Deploy PostgreSQL

  1. Click here to create an addon , or choose addon from the create new menu in the top right corner of the dashboard
  2. Select PostgreSQL and enter a name

  3. Choose a version or leave as default (most recent version)

  4. Choose whether to deploy with TLS. This can be changed later.

  5. Choose whether to make the database publicly accessible. This will give your addon a URL and make it available online. TLS must be enabled to select this.

  6. If you have secret groups in your project, choose ones to link to the addon so that the database can be used in services and jobs that inherit variables from the secret group. To link the database to a secret group:

    • Show secret groups and configure the secret groups you wish to use
    • Select suggested secrets from the database to link, or select all
    • Set any required aliases for specific secrets to make them accessible by that name within your application
  7. Select the required resources for your database. You can scale the database after creation, but available storage and replicas cannot be decreased once increased.

  8. Create addon and PostgreSQL will begin provisioning, this may take a few minutes.

Connect to PostgreSQL

You can manually copy the connection secrets for your PostgreSQL database from the connection details page into runtime variables or build arguments of your workloads on Northflank.

However, it is much easier to link your database's connection details to a new or existing secret group.

The necessary secrets to connect your workload will vary depending on the application in your workload.

Some clients may use a connection string , while some clients may not support the connection string URI format.

The connection string takes the format postgresql://[username:password@][host][:port][/database][...options]. The POSTGRES_URI and JDBC_POSTGRES_URI (for Java applications using JDBC) connection strings will be automatically configured for your database.

You can supply connections details and secrets such as host, username, password, and port to your workload if your application is configured to use these instead of a connection string.

Available ports

Internal portExternal portProtocolURI prefix
5432Dynamically generatedPostgreSQLpostgresql://

If you create more than one replica, read replicas will have the read prefixes in place of the primary prefix for the primary replica.

Automatically inherit database connection details into your workload

  1. Create a new secret group of runtime variables to connect in the running workload
  2. Show addons and configure your addon with either the POSTGRES_URI or JDBC_POSTGRES_URI connection string, or select connection details and secrets
  3. Set the aliases required in your workload to access the secrets
  4. Enable apply secrets to specific services/jobs and select the workloads you want to access the database
  5. Create secret group
  6. Go to one of the workloads that inherits from the group and check the environment page, you should see the inherited variables from the secret group

The connection string or secrets will now be available in your workload under the configured aliases, and your application will be able to connect to the database using them.

Access PostgreSQL

You can access your PostgreSQL addon using the relevant connection string, or by using the HOST, PORT, USERNAME and PASSWORD secrets found in the connection details page of the addon.

You can connect using the psql interactive terminal , or via a GUI such as pgAdmin .

Secure local access

To forward your PostgreSQL database for local access using the Northflank CLI, copy and execute the forward addon command from the local access section of the overview.

You can then use the connection details to access your PostgreSQL deployment in your local development environment.

External access

To access your PostgreSQL database externally, ensure deploy with TLS and publicly accessible are enabled on the settings page under networking. External connection strings will appear in the addon's connection details page, and the host will now resolve externally.

Administration

You can connect to your PostgreSQL database as administrator using the connection strings that end in _ADMIN, or log in using ADMIN_USERNAME and ADMIN_PASSWORD. You should only use this account for necessary maintenance, and otherwise access the database using the standard user credentials.

PostgreSQL specifications

Connection limits

The maximum concurrent connections allowed on a PostgreSQL is 750. You can add connection poolers on the resources page if you need to manage high numbers of connections.

Extensions

The PostgreSQL addon offers a number of available extensions which include:

  • PostGIS
  • earthdistance
  • timescaledb
  • vector
  • pg_stat_statements
  • pg_cron

For a complete list connect to your PostgreSQL addon and run SELECT pg_available_extensions();.

You can install an extension by running the CREATE EXTENSION <extension-name>; SQL command on your addon.

© 2024 Northflank Ltd. All rights reserved.