Atatus Database Monitoring offers comprehensive monitoring for your Google Cloud SQL for PostgreSQL instances, providing valuable insights into query performance, query samples, execution plans, connection details, and system statistics.
To enable Database Monitoring, the Agent gathers telemetry by accessing the database as a read-only user. The Atatus Infra Agent runs on a separate host that connects to your Cloud SQL instance via private IP, public IP, or the Cloud SQL Auth Proxy.
- Configure Cloud SQL Database Flags
- Setup Database Access for the Agent
- Configure Atatus Infrastructure Agent
Before You Begin
| Component | Supported Versions / Requirements |
|---|---|
| PostgreSQL | 10, 11, 12, 13, 14, 15, 16, 17, 18 |
| Atatus Infra Agent | 3.4.0 or higher |
Configure Cloud SQL Database Flags
In the Google Cloud Console, open your Cloud SQL instance and edit its Database flags, then restart the instance.
Required:
| Flag | Value |
|---|---|
track_activity_query_size |
4096 |
Recommended (optional):
| Flag | Value |
|---|---|
pg_stat_statements.track |
all |
pg_stat_statements.max |
10000 |
pg_stat_statements.track_utility |
off |
track_io_timing |
on |
Setup Database Access for the Agent
Connect to the postgres database as a superuser. On Cloud SQL, the built-in postgres user (or any user with the cloudsqlsuperuser role) can run the following statements.
psql -h <INSTANCE_IP> -d postgres -U postgres
Create the
atatususer:copyCREATE USER atatus WITH password '<UNIQUEPASSWORD>';Create the
atatusschema and grant monitoring access in every database you want monitored:copyCREATE SCHEMA atatus; GRANT USAGE ON SCHEMA atatus TO atatus; GRANT USAGE ON SCHEMA public TO atatus; GRANT pg_monitor TO atatus; CREATE EXTENSION IF NOT EXISTS pg_stat_statements;Note:To collect data or custom metrics that require querying additional tables, grant the SELECT permission on those tables: GRANT SELECT ON TABLE_NAME TO atatus;.
Create the explain function in every database:
copyCREATE OR REPLACE FUNCTION atatus.explain_statement( l_query TEXT, OUT explain JSON ) RETURNS SETOF JSON AS $$ DECLARE curs REFCURSOR; plan JSON; BEGIN OPEN curs FOR EXECUTE pg_catalog.concat('EXPLAIN (FORMAT JSON) ', l_query); FETCH curs INTO plan; CLOSE curs; RETURN QUERY SELECT plan; END; $$ LANGUAGE 'plpgsql' RETURNS NULL ON NULL INPUT SECURITY DEFINER;
Verify
Confirm the atatus user can connect and read the core tables:
psql -h <INSTANCE_IP> -U atatus postgres -A \
-c "select * from pg_stat_database limit 1;" \
&& echo -e "\e[0;32mPostgres connection - OK\e[0m" \
|| echo -e "\e[0;31mCannot connect to Postgres\e[0m"
psql -h <INSTANCE_IP> -U atatus postgres -A \
-c "select * from pg_stat_activity limit 1;" \
&& echo -e "\e[0;32mPostgres pg_stat_activity read OK\e[0m" \
|| echo -e "\e[0;31mCannot read from pg_stat_activity\e[0m"
psql -h <INSTANCE_IP> -U atatus postgres -A \
-c "select * from pg_stat_statements limit 1;" \
&& echo -e "\e[0;32mPostgres pg_stat_statements read OK\e[0m" \
|| echo -e "\e[0;31mCannot read from pg_stat_statements\e[0m"
Configure Atatus Infrastructure Agent
Install the Atatus Infrastructure agent on a host that can reach your Cloud SQL instance.
Copy the PostgreSQL example configuration file:
copycd /etc/atatus-infra-agent/conf.d/postgresql.d/ sudo cp postgresql.yml.template postgresql.ymlUpdate the PostgreSQL configuration file at
/etc/atatus-infra-agent/conf.d/postgresql.d/postgresql.yml:copymetrics: - hosts: ["<INSTANCE_IP>"] port: 5432 username: atatus password: <UNIQUEPASSWORD> dbm: true logs: - type: logReplace
<INSTANCE_IP>with your Cloud SQL instance's private/public IP, or127.0.0.1if connecting through the Cloud SQL Auth Proxy.Restart the Atatus Infra Agent:
copysudo service atatus-infra-agent restart
Connecting via Cloud SQL Auth Proxy (Optional)
When connecting through the Cloud SQL Auth Proxy, override the reported hostname so metrics are tagged to the underlying instance:
metrics:
- hosts: ["127.0.0.1"]
port: 5432
username: atatus
password: <UNIQUEPASSWORD>
dbm: true
reported_hostname: <CLOUD_SQL_INSTANCE_NAME>
Collecting Schemas (Optional)
metrics:
- hosts:
- "<INSTANCE_IP>"
username: <DB_USERNAME>
password: <DB_PASSWORD>
dbm: true
db_name: <DB_NAME>
dbm_postgresql_options:
collect_database_info:
enabled: true
auto_discovery: true
max_tables: 200
collect_settings:
enabled: true
ignore_patterns:
- '^pg_toast'
- '^pg_stat'
- '^pg_stat_tmp'
- '^pg_locks'
Collecting Custom Metrics (Optional)
metrics:
- hosts:
- "<INSTANCE_IP>"
username: <DB_USERNAME>
password: <DB_PASSWORD>
dbm: true
db_name: <DB_NAME>
dbm_postgresql_options:
additional_metrics_options:
custom_queries:
enabled: true
max_custom_queries: 5
custom_query:
- query: |
SELECT COUNT(*) AS user_count FROM public.users;
columns:
- name: user_count
type: gauge
tags:
- source:custom_user_count
+1-415-800-4104