{"id":20643869,"url":"https://github.com/adjust/postgresql_exporter","last_synced_at":"2025-04-16T02:06:11.574Z","repository":{"id":57619420,"uuid":"181687105","full_name":"adjust/postgresql_exporter","owner":"adjust","description":null,"archived":false,"fork":false,"pushed_at":"2019-08-12T09:39:37.000Z","size":782,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-29T03:51:23.487Z","etag":null,"topics":["metrics","postgresql","prometheus","prometheus-exporter"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adjust.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-16T12:41:53.000Z","updated_at":"2024-08-20T11:56:18.000Z","dependencies_parsed_at":"2022-09-16T19:21:15.215Z","dependency_job_id":null,"html_url":"https://github.com/adjust/postgresql_exporter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpostgresql_exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpostgresql_exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpostgresql_exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpostgresql_exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adjust","download_url":"https://codeload.github.com/adjust/postgresql_exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249183102,"owners_count":21226141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["metrics","postgresql","prometheus","prometheus-exporter"],"created_at":"2024-11-16T16:14:10.099Z","updated_at":"2025-04-16T02:06:11.541Z","avatar_url":"https://github.com/adjust.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostgreSQL Metrics Exporter\n\nPrometheus exporter for PostgreSQL metrics.\u003cbr\u003e\n\n## Features\n\n- Use of multiple connections while fetching metrics\n- Statement timeouts to cancel long-running queries\n- Version-specific queries in the config file\n- Connection labels\n- No hard-coded metrics\n\n## Getting and running\n\nGet:\n```\n    go get -u github.com/adjust/postgresql_exporter\n```\n\nRun:\n```\n    postgresql_exporter --config {path to the config file}\n```\n\n\n## Config file\n```\n{connection name}: \n    host: {host}\n    port: {port}\n    user: {username}\n    dbname: {db name}\n    sslmode: {ssl mode}\n    workers: {number of parallel connections to use}\n    statementTimeout: {pg statement_timeout value for each connection}\n    isNotPg: {true if the destination side is not postgresql (e.g. pgbouncer/odyssey)}\n    labels:\n        {labels added to each metric in the \"queryFiles\"}\n    queryFiles: \n        {use metric queries from files}\n```\n\nsample:\n```\ntest:\n    host: localhost\n    port: 5432\n    user: postgres\n    dbname: test\n    sslmode: disable\n    workers: 5\n    statementTimeout: \"3s\"\n    labels:\n        production: true\n    queryFiles:\n        - \"basic.yaml\"\n        - \"pertable.yaml\"\n```\n\n## Query file\n\nsample:\nfirst query will be using for postgresql \u003e=10\nthe second query will be using for postgresql \u003e=9.4 but \u003c10 \n```\npg_slots:\n    query:\n        10-: \u003e-\n            select\n            slot_name,\n            slot_type,\n            active,\n            case when not pg_is_in_recovery() then pg_current_wal_lsn() - restart_lsn end as current_lag_bytes\n            from pg_replication_slots s\n            order by s.slot_name\n        9.4-10: \u003e-\n            select\n            slot_name,\n            slot_type,\n            active,\n            case when not pg_is_in_recovery() then pg_current_xlog_location() - restart_lsn end as current_lag_bytes\n            from pg_replication_slots s\n            order by s.slot_name\n    metrics:\n        - slot_name:\n            usage: \"LABEL\"\n            description: \"Slot name\"\n        - slot_type:\n            usage: \"LABEL\"\n            description: \"Slot type\"\n        - active:\n            usage: \"LABEL\"\n            description: \"Is slot active\"\n        - current_lag_bytes:\n            usage: \"GAUGE\"\n            description: \"Lag in bytes\"\n```\n\nquery will be used for all the postgresql versions:\n```\nrelation_total_size:\n    query: \u003e-\n        select\n            n.nspname as schemaname,\n            c.relname,\n            pg_total_relation_size(c.oid) as inclusive_bytes,\n            pg_relation_size(c.oid) as exclusive_bytes\n        from pg_class c\n        join pg_namespace n on c.relnamespace = n.oid\n        where relkind = 'r'\n        and n.nspname not in ('pg_toast', 'pg_catalog', 'information_schema')\n    metrics:\n        - schemaname:\n            usage: \"LABEL\"\n            description: \"Schema of relation\"\n        - relname:\n            usage: \"LABEL\"\n            description: \"Name of relation\"\n        - inclusive_bytes:\n            usage: \"GAUGE\"\n            description: \"Size of table, including indexes and toast\"\n        - exclusive_bytes:\n            usage: \"GAUGE\"\n            description: \"Size of table, excluding indexes and toast\"\n```\n\n\nif you need to get metric names and values from the columns,\nspecify them in the \"nameColumn\" and \"valueColumn\" accordingly:\n```\npg_settings:\n    query:\n        8.0-9.5: \u003e-\n            select\n                name,\n                case setting when 'off' then 0 when 'on' then 1 else setting::numeric end as setting\n            from pg_settings\n            where vartype IN ('bool', 'integer', 'real')\n        9.5-: \u003e-\n            select\n                name,\n                case setting when 'off' then 0 when 'on' then 1 else setting::numeric end as setting,\n                pending_restart\n            from pg_settings\n            where vartype IN ('bool', 'integer', 'real')\n    nameColumn: \"name\"\n    valueColumn: \"setting\"\n    metrics:\n        - pending_restart:\n            usage: \"LABEL\"\n            description: \"if the value has been changed in the configuration file but needs a restart\"\n        - allow_system_table_mods:\n            usage: \"GAUGE\"\n            description: \"Allows modifications of the structure of system tables\"\n        - archive_timeout:\n            usage: \"GAUGE\"\n            description: \"Forces a switch to the next WAL file if a new file has not been started within N seconds\"\n...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadjust%2Fpostgresql_exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadjust%2Fpostgresql_exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadjust%2Fpostgresql_exporter/lists"}