PG_AUTOCTL_SHOW_URI(1)

πŸ“¦
version 2.1 Β· 2 versions
, in fedora 43, fedora 44

πŸ’– PG_AUTOCTL SHOW URI β€” bestie edition πŸ’–

okay so this is pg_autoctl show uri, and it lives in the pg_auto_failover manual (section 1, the fancy command section, iykyk). it hands you the Postgres URI you're supposed to use to actually connect to your pg_auto_failover nodes. like, the string. the whole point. πŸŽ€


✨ NAME ✨

pg_autoctl show uri β€” bestie, it shows the postgres uri to use to connect to pg_auto_failover nodes πŸ’…


🌸 SYNOPSIS 🌸

this command outputs the monitor or the coordinator Postgres URI to use from an application 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 actually lives. it defaults to the environment variable PGDATA. and listen, if you wanna connect to a monitor from literally anywhere instead of using the monitor URI that some local Postgres node managed with pg_autoctl is using, that's what --monitor is for. ✨
  • --monitor β€” the Postgres URI used to connect to the monitor. no cap, it must use the autoctl_node username and it must target the pg_auto_failover database name. fun fact bestie: you can also show the Postgres URI from the monitor node itself with the command pg_autoctl show uri. πŸ¦‹

it defaults to the value of the environment variable PG_AUTOCTL_MONITOR.

  • --formation β€” when you pass --formation, it lists the Postgres URIs of all the known formations on the monitor. all of them. every single one. 🌈
  • --json β€” outputs JSON formatted data instead of a table formatted list. it's giving machine-readable, it's giving parseable. πŸ’œ

🧚 ENVIRONMENT 🧚

  • PGDATA β€” the Postgres directory location. use this instead of the --pgdata option, same energy, less typing.
  • PG_AUTOCTL_MONITOR β€” the Postgres URI to connect to the monitor node. use it 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. iconic honestly. 😭

this multi-hosts connection string facility is what lets applications keep using the same stable connection string across server-side failovers. and that, bestie, is exactly why pg_autoctl show uri uses that format. no cap. πŸ’–


πŸ’€ AUTHOR πŸ’€

Microsoft


Copyright (c) Microsoft Corporation. All rights reserved.


and that's the whole page, periodt. this was pg_autoctl show uri from pg_auto_failover version 2.1, dated Jan 18, 2025. go connect to something bestie πŸ«Άβœ¨πŸ’…
πŸ“¦ where this page comes from