Metis is a comprehensive database observability tool. It can track your live database activity, suggest improvements for schema, indexes, queries, configuration, and more. By onboarding your PostgreSQL server with Metis, you get access to live infrastructural metrics (CPU, memory usage) and database metrics (transactions, buffers, caches). Metis can look for anomalies in performance, index usage, or data distribution. See the documentation on how to monitor & troubleshoot your databases.
[.tip-box]This guide is also available as a video.[.tip-box]
StackGres is the full-stack Postgres Platform. Fully open-source software to run your own Postgres-as-a-Service on any cloud or on-prem. StackGres is a project from OnGres, the Postgres laser-focused startup ("OnGres" means "ON postGRES").
StackGres is a Kubernetes Operator for Postgres. It allows you to create production-ready Postgres clusters in seconds. No advanced Postgres expertise is required. You can use the built-in Web Console or the high-level Kubernetes CRDs for CLI and GitOps.
With StackGres, writing a simple YAML manifest (or point-and-click on the Web Console) is all that is needed to create production-ready Postgres clusters including high availability with Patroni, replication, connection pooling, automated backups, monitoring, and centralized logs.
With support for more than 150 Postgres extensions, StackGres is the most extensible Postgres platform available. It also provides support for Babelfish for Postgres (which brings SQL Server compatibility, at the wire protocol level, SQL and T-SQL) and integrations with Citus for sharding Postgres, Timescale for time-series, Supabase and now, FerretDB.
Metis is a powerful observability tool that can track all the aspects of your databases and database servers. It integrates with your database server with the help of an agent that you need to deploy in your cluster so it can monitor the ongoing activity.
Metis is distributed as a Docker container. You can install it in any environment supporting OCI containers, including AWS ECS, Kubernetes, AKS, or GKE. This makes using Metis straightforward and lets you configure everything in seconds.
Metis connects to your database and extracts details of the database activity. This includes metrics around infrastructure (CPU, memory usage, files opened), databases (transactions, caches, temporary files), live queries (and their execution plans), configuration, schema details, index usage, and much more. Metis explains what is happening in your databases. Metis can look for anomalies and detect drifts between environments. Metis can suggest actionable performance improvements and notify you when things degrade.
Setting Up Metis On Top Of StackGres
We’ll need to install the Kubernetes cluster, then install StackGres, then configure the StackGres cluster, and then configure Metis. Instructions below are for Amazon Linux 2 x86_64 but will work the same way on other operating systems like Mac OS and Windows (with slight syntax changes for PowerShell or other shells), and on ARM64 architecture.
Installing Kubernetes With Minikube
Before installing StackGres, you will need a running Kubernetes cluster and the usual command line tools kubectl and Helm. Please refer to the respective installation pages if you don't have these tools. As for Kubernetes, if you don't have one you can try easily with minikube. It can be installed like this:
This should give you a running single-node cluster in seconds (depending on your Internet connection speed). You can install it in other operating systems the way it’s described in the docs.
Keep in mind that minikube uses Docker behind the scenes. It works natively in Linux, and with a virtual machine in MacOS and Windows. Refer to installation instructions for Docker Desktop to learn how to install it on your machine.
You can now create the minikube cluster with:
This should give you the output similar to this:
When you’re done with the examples, you can easily delete the cluster with:
Let’s now install StackGres.
The best way to install StackGres is through the official Helm chart. You can install it in this way:
Follow this page to install Helm on your machine.
For our particular setup, we use the following Helm commands:
To confirm that the operator is running while also waiting for setup to complete, run the following commands:
As you run the first kubectl command, it should wait for the successful deployment, and the second command will list the pods running in the stackgres namespace.
Creating a StackGres Cluster
Here, we'll create an SGCluster configured to fit Metis requirements. We’re going to use some resources created inline. Metis requires the pg_stat_statements extension, a separate user, and permissions to monitor databases.
Let’s create a password for the user that will get initialized based on the SQL command:
Let’s now create a script that will create a database named metis and a user metis:
We can see the script has five parts. First, we create the user with a password and store the password in the Kubernetes secret. Next, we give pg_monitor permissions to the user. Next, we create the database. Then, we let the user connect to the database. Finally, we create the pg_stat_statements extension in the metis database.
We are now ready to create the Postgres cluster:
It should take a few seconds to a few minutes for the cluster to be up and running:
Likewise, a database named metis must exist and be owned by the same user:
We can now add monitoring of the database to Metis. Go to Metis and click Deploy:
Select Postgres and click Next:
Metis instructs us how to configure the user and grant necessary permissions. We already did that. Click Next.
Metis asks for the connection string now:
Let’s extract the server name:
The service name is cluster.stackgres.svc.cluster.local. The final URL should be like this:
Click Next. Finally, click on Helm and copy the script to deploy Metis.
Extend the script with --namespace stackgres and run it. Your API key will be different as its a specific API key to be used with your project:
When you execute the script, you should get the following:
We can verify that it works with:
You can now go to Metis Monitoring and see that the new host has been added:
When you click on the host, you should see the properties and databases:
You can also click on database metis and get all the details:
Notice that many charts are empty as it’s a completely new database.
Monitoring Live Database Activity
Let’s now add some data and run some queries in the database.
We create table orders, insert some data, and then run a query that extracts the rows with some aggregation. This is the output:
You can now go to Metis and check the Table Sizes widget. It shows the orders table:
You can also go to Top Queries widget and notice that new queries are flowing to the database:
Metis captures the live activity of your database and can suggest how to improve things.
Throughout this article, we have explored the process of setting up a Kubernetes cluster, deploying the StackGres operator, and running Metis on top of it. We have covered steps such as creating an SGCluster, and monitoring basic database operations with Metis.
If you're eager to try Metis and experience its capabilities firsthand, we encourage you to try it out in your own Kubernetes environment, through the StackGres operator.
If you encounter any issue or just wish to say "Hi!" and tell us how Metis works on StackGres, you may drop a line at the: