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:
Connect to your PostgreSQL server as an administrative user:
psql -U postgres -h localhostCreate a dedicated read-only user for Grafana:
CREATE USER grafanareader WITH PASSWORD 'password';Grant the user access to the schema and read access to the tables you want to visualize. Replace
schemaandtablewith your own names:GRANT USAGE ON SCHEMA schema TO grafanareader; GRANT SELECT ON schema.table TO grafanareader;Exit the PostgreSQL client:
\qTest the new user’s connection:
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.