Path

Learn how to create a read-only user in PostgreSQL and prepare the database connection details.

Estimated time: 2 min

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
    psql -U postgres -h localhost
  2. Create a dedicated read-only user for Grafana:

    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
    GRANT USAGE ON SCHEMA schema TO grafanareader;
    GRANT SELECT ON schema.table TO grafanareader;
  4. Exit the PostgreSQL client:

    SQL
    \q
  5. Test the new user’s connection:

    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)