PG_AUTOCTL SHOW URI(1)

✨ PG_AUTOCTL SHOW URI ✨

okay bestie, welcome to pg_autoctl show uri β€” one of the pg_auto_failover girlies πŸ’–


🌸 NAME 🌸

pg_autoctl show uri β€” pg_autoctl show uri

pg_autoctl show uri β€” show the postgres uri you use to connect to pg_auto_failover nodes 🫢


πŸŽ€ SYNOPSIS πŸŽ€

so like, this command spits out the monitor URI or the coordinator Postgres URI that your app should use to connect to Postgres:

usage: pg_autoctl show uri  [ --pgdata --monitor --formation --json ]

  --pgdata      path to data directory
  --monitor     monitor uri
  --formation   show the coordinator uri of given formation
  --json        output data in the JSON format

πŸ’… OPTIONS πŸ’…

  • --pgdata β€” where the Postgres node that's being managed locally lives. Defaults to the environment variable PGDATA. and like, use --monitor when you wanna connect to a monitor from literally anywhere, instead of the monitor URI that a local Postgres node managed with pg_autoctl is using. ✨
  • --monitor β€” the Postgres URI used to connect to the monitor. it MUST use the autoctl_node username and target the pg_auto_failover database name, no cap. also you can show the Postgres URI from the monitor node itself with pg_autoctl show uri. it defaults to the value of the environment variable PG_AUTOCTL_MONITOR. πŸ‘‘
  • --formation β€” when --formation is used, it lists the Postgres URIs of all known formations on the monitor. the way it just... hands you every formation 😭
  • --json β€” output JSON formatted data instead of a table formatted list. for the girlies who pipe things into jq πŸ¦‹

🌈 ENVIRONMENT 🌈

  • PGDATA β€” Postgres directory location. can be used instead of the --pgdata option.
  • PG_AUTOCTL_MONITOR β€” Postgres URI to connect to the monitor node, can be used instead of the --monitor option.
  • XDG_CONFIG_HOME β€” the pg_autoctl command stores its configuration files in the standard place XDG_CONFIG_HOME. See the XDG Base Directory Specification.
  • XDG_DATA_HOME β€” the pg_autoctl command stores its internal states files in the standard place XDG_DATA_HOME, which defaults to ~/.local/share. See the XDG Base Directory Specification.

πŸ“ EXAMPLES πŸ“

$ pg_autoctl show uri
        Type |    Name | Connection String
-------------+---------+-------------------------------
     monitor | monitor | postgres://autoctl_node@localhost:5500/pg_auto_failover
   formation | default | postgres://localhost:5502,localhost:5503,localhost:5501/demo?target_session_attrs=read-write&sslmode=prefer
$ pg_autoctl show uri --formation monitor
postgres://autoctl_node@localhost:5500/pg_auto_failover
$ pg_autoctl show uri --formation default
postgres://localhost:5503,localhost:5502,localhost:5501/demo?target_session_attrs=read-write&sslmode=prefer
$ pg_autoctl show uri --json
[
 {
     "uri": "postgres://autoctl_node@localhost:5500/pg_auto_failover",
     "name": "monitor",
     "type": "monitor"
 },
 {
     "uri": "postgres://localhost:5503,localhost:5502,localhost:5501/demo?target_session_attrs=read-write&sslmode=prefer",
     "name": "default",
     "type": "formation"
 }
]

🧚 MULTI-HOSTS POSTGRES CONNECTION STRINGS 🧚

PostgreSQL since version 10 includes support for multiple hosts in its connection driver libpq, with the special target_session_attrs connection property. πŸ”₯

this multi-hosts connection string facility lets applications keep using the same stable connection string across server-side failovers. that's literally why pg_autoctl show uri uses that format. main character behavior fr fr πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Microsoft


Copyright (c) Microsoft Corporation. All rights reserved.


and that's the whole page bestie, slay πŸ’…βœ¨

pg_auto_failover β€” version 2.2, dated Apr 07, 2025 πŸŽ€πŸ«Ά bye ily, go show some uris πŸ’–

πŸ“¦ where this page comes from