PostgreSQL is a highly reliable, open-source database system that’s widely used for managing data in both small and large applications. Its robust feature set and exceptional performance make it a top choice for developers and businesses around the world.
To ensure smooth and efficient deployment, especially for larger projects, automating the installation and configuration process is key.
That’s where AttuneOps comes in. AttuneOps is an automation tool designed to simplify repetitive tasks like executing scripts on servers, whether local or remote.
In this blog, we’ll guide you step-by-step through automating the installation and setup of PostgreSQL on an Ubuntu 24.04 server using AttuneOps, saving you time and effort while ensuring consistency across your deployments.
Let’s get started!

Before proceeding, ensure you have access to an environment that meets the following requirements:
This section describes the steps to install AttuneOps Community Edition on the automation node:
Note: This section covers the installation of AttuneOps on a Windows PC. For macOS, you can install AttuneOps by double-clicking the DMG file.
This section describes the steps to setup the Target Linux Node before you can proceed with executing the deployment scripts using AttuneOps:
apt install -y openssh-serversystemd service is started and enabled:systemctl start ssh
systemctl enable sshuseradd -m -s /bin/bash autousr
passwd autousrsudo group, this is to allow the user to execute privileged commands:usermod -aG sudo autousrThe Remote node is now ready to receive commands from the AttuneOps Automation Node.
AttuneOps is divided into three workspaces, which define the three steps in setting up your deployment workflow. These can be accessed from the AttuneOps UI by clicking the hamburger menu in the top left.

This will open the menu below:

Where you define your reusable automated workflows.
Components include:
The Plan Workspace is where you plan a job to run a blueprint and which values are connected to the parameters in the blueprint. A single blueprint can be used for many jobs with different values.
Components Include:
The Section below defines steps to be followed in creating an automation blueprint to deploy and Configure a PostgreSQL Server.



The blueprint will be broken down into the steps below:
To create a step:






The scripts for each step are defined below. Repeat the procedure for all the steps listed above and use the scripts below:
#!/bin/bash
apt update -y && apt upgrade -y#!/bin/bash
apt-get install -y wget gnupg2#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status
# Variables
POSTGRES_VERSION="{postgresVersion}"
DB_NAME="{dbName}"
DB_USER="{dbUser}"
DB_PASSWORD="{dbPassword}"
# Add PostgreSQL repository
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt-get update
sudo apt-get install -y postgresql-$POSTGRES_VERSION postgresql-client-$POSTGRES_VERSION
# Configure PostgreSQL to allow access from any host
echo "Configuring PostgreSQL to allow remote access..."
sudo sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/g" /etc/postgresql/$POSTGRES_VERSION/main/postgresql.conf
echo "host all all 0.0.0.0/0 md5" | sudo tee -a /etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf
# Restart PostgreSQL
sudo systemctl restart postgresql
# Create user and database
echo "Creating user and database..."
sudo -u postgres psql <<EOF
CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWORD';
CREATE DATABASE $DB_NAME OWNER $DB_USER;
EOF
echo "Setup complete!"
echo "PostgreSQL user: $DB_USER"#!/bin/bash
sudo -u postgres psql {dbName} <<EOF
-- Drop existing tables if they exist
DROP TABLE IF NOT EXISTS users;
DROP TABLE IF NOT EXISTS orders;
-- Create a table for users
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert sample user data
INSERT INTO users (username, email) VALUES
('john_doe', 'john@example.com'),
('jane_smith', 'jane@example.com'),
('alice_brown', 'alice@example.com');
-- Create a table for orders
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(id) ON DELETE CASCADE,
product_name VARCHAR(100) NOT NULL,
quantity INT NOT NULL CHECK (quantity > 0),
order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert sample order data
INSERT INTO orders (user_id, product_name, quantity) VALUES
(1, 'Laptop', 1),
(1, 'Smartphone', 2),
(2, 'Headphones', 1),
(3, 'Monitor', 1);
-- Query to display all users and their orders
SELECT
u.username,
u.email,
o.product_name,
o.quantity,
o.order_date
FROM
users u
LEFT JOIN
orders o ON u.id = o.user_id;
EOFYou can define parameters for the blueprints from the Parameters option under the Design workspace of your project.

Parameters allow you to plug in custom values to your blueprints and steps. To create a parameter, click Parameters and then Create Parameters. The parameters defined for this project are:
| Parameter | Type | Script Reference |
|---|---|---|
| Automation User | Linux/Unix Credential | automationuser |
| Database Node | Linux/Unix Node | databaseNode |
| DB_NAME | Text | dbName |
| DB_PASSWORD | Text | dbPassword |
| DB_USER | Text | dbUser |
| POSTGRES_VERSION | Text | postgresVersion |
These values are referenced from the steps using the substitution: {scriptReference}.
To define values for your parameters, click Values from the Plan workspace.

You will have the option to define values for the Parameters:

Specifically for the credentials and nodes, you have to specify the values as below:
Node
| Type | Linux/Unix Node |
| Name | Specify a Unique Name |
| SSH Port | Your SSH Port or 22 if Default |
| IP Address | Your Target IP |
| Hostname | Your Node Hostname |
| Domain Name | Your Node Domain |
Credential
| Type | Linux/Unix Credential |
| Name | Name of the Credential e.g. Automation User |
| User | Your remote Automation Username |
| Sudo to | root |
| Password | Click and Set the Password |
You can plan a job to run a blueprint from this workspace.
Click Plan Trees, then click Create Tree, and specify a plan tree name, for example, Database Deploy Plan.

Once the plan tree is created, click on it to select it, then click the three-dot menu and Create a Plan, providing a name for the plan.
From the Blueprints pane, once you select the plan, you can map projects and blueprints to the plan.

From the Inputs pane of the plan, you can map the input values to the parameters.

Once this step is done, you can proceed to run the job from the Run workspace.

Click on the Run/Debug Job option, and you will find a list of plans you created. Upon clicking one of them, you can launch the job as specified by the blueprint by clicking the Play button for the plan or clicking the Play button for each task.

The steps will proceed to execute, updating the system, downloading packages, installing/configuring PostgreSQL, and setting up the database structures before finally loading the sample data.
As the script executes, AttuneOps will output debug, informational, and error logs for each step on its main pane.

If all steps are executed without errors, the job will be marked as a success, and you can validate the installation.
If the job was successful, you can test the deployment by connecting to and querying the database via:
For this example, we will use the CLI.
sudo su - postgrespsql orders. You should get a prompt like the one below:
select orders.product_name,orders.quantity,orders.order_date,users.username,users.email,users.created_at from orders inner join users on orders.user_id = users.id;
If you can get results, you can validate that the installation and configuration were executed correctly.
AttuneOps is a solution for IT automation and orchestration that streamlines repetitive tasks like installing and configuring databases. AttuneOps for PostgreSQL makes PostgreSQL installation a reliable, consistent, and fault-free process. AttuneOps substitutes manual environment configurations with predefined workflows, eliminating the potential for human errors and saving time, especially in enterprise environments.
No. AttuneOps is easy to use, with graphical workflows and pre-configured automation steps. Even a minimal user of the Linux command line can successfully deploy PostgreSQL. More advanced users, nonetheless, are also able to customise workflows to meet their infrastructure needs. This compromise makes AttuneOps accessible to both beginners and experts.
Yes. AttuneOps excels in multi-server orchestration. AttuneOps is able to deploy PostgreSQL simultaneously on different servers with consistent configuration and faster deployment. This is especially helpful for companies that handle clusters, high-availability configurations, or large deployments.
Not at all. AttuneOps does have PostgreSQL automation, but the strength is far broader than the database. It is capable of taking on operating system setup, middleware deployment, patching, compliance audits, and a whole lot more. PostgreSQL automation is only one of the multiple ways that AttuneOps reduces complexity and speeds up delivery.
Manual bash scripts require deep knowledge, ongoing maintenance, and debugging per environment. They are also prone to human error and not centrally controlled. AttuneOps removes these constraints by being able to provide reusable, tried automation blueprints that are version-controllable, auditable, and easily distributable across teams. Such a systematic process increases reliability, accelerates deployment, and reduces long-term maintenance costs compared to ad-hoc scripting.
By now, you should have a clear understanding of how to automate the PostgreSQL installation process with AttuneOps. With tools like reusable blueprints, dynamic parameters, and scheduling, you can simplify and standardise your database deployments.
This method not only improves efficiency but also ensures consistency, making managing PostgreSQL across multiple servers a breeze. Here’s to smoother, faster deployments!
Comments