---
title: "Prepare PostgreSQL database configuration | Grafana Labs"
description: "Learn how to create a read-only user in PostgreSQL and prepare the database connection details."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Prepare PostgreSQL database configuration

In this milestone, you prepare the PostgreSQL configuration required for monitoring. This includes creating a dedicated read-only user for Grafana and gathering the connection details you’ll need later.

Grafana doesn’t validate the safety of queries, so a user with broad privileges could run harmful SQL such as `DROP TABLE`. Creating a dedicated user with only `SELECT` permissions on the schemas and tables you need follows security best practices and limits risk.

**Prerequisites**:

- Check that your PostgreSQL server is up and running.
- Make sure your firewall allows connections to the PostgreSQL server (the default port is `5432`).

To prepare your PostgreSQL database configuration, complete the following steps:

1. Connect to your PostgreSQL server as an administrative user:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   psql -U postgres -h localhost
   ```
2. Create a dedicated read-only user for Grafana:
   
   SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```sql
   CREATE USER grafanareader WITH PASSWORD 'password';
   ```
3. Grant the user access to the schema and read access to the tables you want to visualize. Replace `schema` and `table` with your own names:
   
   SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```sql
   GRANT USAGE ON SCHEMA schema TO grafanareader;
   GRANT SELECT ON schema.table TO grafanareader;
   ```
4. Exit the PostgreSQL client:
   
   SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```sql
   \q
   ```
5. Test the new user’s connection:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   psql -U grafanareader -h localhost -d your_database -c "SELECT version();"
   ```

In the next milestone, you’ll add the PostgreSQL data source to your Grafana Cloud instance.

* * *

### More to explore (optional)

- [Configure the PostgreSQL data source](/docs/grafana/latest/datasources/postgres/configure/)
- [Data source plugins for Grafana](/grafana/plugins/data-source-plugins/)
