Skip to content

Commit 0cdb1bc

Browse files
committed
[DBM] Add datadog.column_stats() function to Postgres setup docs
Add the column_stats() SECURITY DEFINER function to all 8 Postgres DBM setup guides (selfhosted, RDS, Aurora, Azure, GCP Cloud SQL, AlloyDB, Heroku, Supabase). This function enables the Agent to collect column statistics from pg_stats for Database Monitoring.
1 parent 5aeedd5 commit 0cdb1bc

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed

content/en/database_monitoring/setup_postgres/alloydb.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ RETURNS NULL ON NULL INPUT
107107
SECURITY DEFINER;
108108
```
109109

110+
Create the function **in every database** to enable the Agent to collect column statistics.
111+
112+
```SQL
113+
CREATE OR REPLACE FUNCTION datadog.column_stats() RETURNS TABLE (
114+
schemaname name, tablename name, attname name,
115+
n_distinct real, avg_width integer, null_frac real
116+
) AS
117+
$$
118+
SELECT schemaname, tablename, attname, n_distinct, avg_width, null_frac
119+
FROM pg_stats;
120+
$$
121+
LANGUAGE sql
122+
SECURITY DEFINER;
123+
```
124+
110125
### Securely store your password
111126
{{% dbm-secret %}}
112127

content/en/database_monitoring/setup_postgres/aurora.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ RETURNS NULL ON NULL INPUT
142142
SECURITY DEFINER;
143143
```
144144

145+
Create the function **in every database** to enable the Agent to collect column statistics.
146+
147+
```SQL
148+
CREATE OR REPLACE FUNCTION datadog.column_stats() RETURNS TABLE (
149+
schemaname name, tablename name, attname name,
150+
n_distinct real, avg_width integer, null_frac real
151+
) AS
152+
$$
153+
SELECT schemaname, tablename, attname, n_distinct, avg_width, null_frac
154+
FROM pg_stats;
155+
$$
156+
LANGUAGE sql
157+
SECURITY DEFINER;
158+
```
159+
145160
### Securely store your password
146161
{{% dbm-secret %}}
147162

content/en/database_monitoring/setup_postgres/azure.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,21 @@ RETURNS NULL ON NULL INPUT
190190
SECURITY DEFINER;
191191
```
192192

193+
Create the function **in every database** to enable the Agent to collect column statistics.
194+
195+
```SQL
196+
CREATE OR REPLACE FUNCTION datadog.column_stats() RETURNS TABLE (
197+
schemaname name, tablename name, attname name,
198+
n_distinct real, avg_width integer, null_frac real
199+
) AS
200+
$$
201+
SELECT schemaname, tablename, attname, n_distinct, avg_width, null_frac
202+
FROM pg_stats;
203+
$$
204+
LANGUAGE sql
205+
SECURITY DEFINER;
206+
```
207+
193208
### Securely store your password
194209
{{% dbm-secret %}}
195210

content/en/database_monitoring/setup_postgres/gcsql.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ RETURNS NULL ON NULL INPUT
106106
SECURITY DEFINER;
107107
```
108108

109+
Create the function **in every database** to enable the Agent to collect column statistics.
110+
111+
```SQL
112+
CREATE OR REPLACE FUNCTION datadog.column_stats() RETURNS TABLE (
113+
schemaname name, tablename name, attname name,
114+
n_distinct real, avg_width integer, null_frac real
115+
) AS
116+
$$
117+
SELECT schemaname, tablename, attname, n_distinct, avg_width, null_frac
118+
FROM pg_stats;
119+
$$
120+
LANGUAGE sql
121+
SECURITY DEFINER;
122+
```
123+
109124
### Securely store your password
110125
{{% dbm-secret %}}
111126

content/en/database_monitoring/setup_postgres/heroku.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ RETURNS NULL ON NULL INPUT
7373
SECURITY DEFINER;
7474
```
7575

76+
Create the function **in every database** to enable the Agent to collect column statistics.
77+
78+
```SQL
79+
CREATE OR REPLACE FUNCTION datadog.column_stats() RETURNS TABLE (
80+
schemaname name, tablename name, attname name,
81+
n_distinct real, avg_width integer, null_frac real
82+
) AS
83+
$$
84+
SELECT schemaname, tablename, attname, n_distinct, avg_width, null_frac
85+
FROM pg_stats;
86+
$$
87+
LANGUAGE sql
88+
SECURITY DEFINER;
89+
```
90+
7691
## Configuring the Postgres integration
7792

7893
Next, configure the Datadog agent to enable the Postgres integration, using one of the following two options.

content/en/database_monitoring/setup_postgres/rds/_index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ RETURNS NULL ON NULL INPUT
202202
SECURITY DEFINER;
203203
```
204204

205+
Create the function **in every database** to enable the Agent to collect column statistics.
206+
207+
```SQL
208+
CREATE OR REPLACE FUNCTION datadog.column_stats() RETURNS TABLE (
209+
schemaname name, tablename name, attname name,
210+
n_distinct real, avg_width integer, null_frac real
211+
) AS
212+
$$
213+
SELECT schemaname, tablename, attname, n_distinct, avg_width, null_frac
214+
FROM pg_stats;
215+
$$
216+
LANGUAGE sql
217+
SECURITY DEFINER;
218+
```
219+
205220
### Securely store your password
206221
{{% dbm-secret %}}
207222

content/en/database_monitoring/setup_postgres/selfhosted.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ RETURNS NULL ON NULL INPUT
165165
SECURITY DEFINER;
166166
```
167167

168+
Create the function **in every database** to enable the Agent to collect column statistics.
169+
170+
```SQL
171+
CREATE OR REPLACE FUNCTION datadog.column_stats() RETURNS TABLE (
172+
schemaname name, tablename name, attname name,
173+
n_distinct real, avg_width integer, null_frac real
174+
) AS
175+
$$
176+
SELECT schemaname, tablename, attname, n_distinct, avg_width, null_frac
177+
FROM pg_stats;
178+
$$
179+
LANGUAGE sql
180+
SECURITY DEFINER;
181+
```
182+
168183
### Securely store your password
169184
{{% dbm-secret %}}
170185

content/en/database_monitoring/setup_postgres/supabase.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ RETURNS NULL ON NULL INPUT
114114
SECURITY DEFINER;
115115
```
116116

117+
Create the function **in every database** to enable the Agent to collect column statistics.
118+
119+
```SQL
120+
CREATE OR REPLACE FUNCTION datadog.column_stats() RETURNS TABLE (
121+
schemaname name, tablename name, attname name,
122+
n_distinct real, avg_width integer, null_frac real
123+
) AS
124+
$$
125+
SELECT schemaname, tablename, attname, n_distinct, avg_width, null_frac
126+
FROM pg_stats;
127+
$$
128+
LANGUAGE sql
129+
SECURITY DEFINER;
130+
```
131+
117132
### Securely store your password
118133

119134
{{% dbm-secret %}}

0 commit comments

Comments
 (0)