If both approaches do theoretically the same configuration and obviously at a first glance the first approach is simpler than the latter due the amount of lines.
Question
When would be mandatory use the manually configure the Apt repository approach?
I read the PostgreSQL Apt Repository wiki page page but there is no an explicit explanation about when the manual (long) approach would be mandatory over the former.
@Manuel_Jordan
The first method is a script. If you do not trust the script, you may wish to do it by the second long method, where you can see each command.
I suspected the script just did the same thing as the manual steps. I asked Copilot and it agreed with me.
Great instinct, Pat—and yes, you’re spot on. The apt.postgresql.org.sh script is essentially a convenience wrapper that automates the manual steps for configuring the PostgreSQL Apt repository. Here’s a breakdown of what it actually does:
What the Script Does (Under the Hood)
It performs the following tasks:
Installs prerequisites: Ensures curl, ca-certificates, and postgresql-common are present.
Imports the signing key: Downloads the PostgreSQL GPG key and places it in the expected location.
Detects your distro codename: Reads from /etc/os-release to determine $VERSION_CODENAME (e.g., jammy, noble, etc.).
Creates the repo file: Writes the correct deb line to /etc/apt/sources.list.d/pgdg.list with the signed-by directive.
Updates package lists: Runs apt update so the system recognizes the new repo.
Why You Might Still Use the Manual Method
Even though the script replicates the manual steps, there are cases where you’d want—or need—to do it manually:
Script fails due to missing dependencies or misidentifies the codename.
You want to audit or customize the repository setup (e.g., add deb-src, change key location, or use a proxy).
You’re working in a minimal or locked-down environment (e.g., Docker base image, CI/CD pipeline, or air-gapped server).
You need reproducibility in provisioning scripts and want to avoid relying on external scripts.
So yes, the script is a shortcut—but the manual method gives you full control and transparency. If you’re building containers or provisioning VMs, manual setup might be the safer bet.
Want to peek at the actual contents of the script and compare line-by-line? I can walk you through it.
The first method is a script. If you do not trust the script, you may wish to do it by the second long method, where you can see each command
I am fine with the script because it is available by the official source. Therefore it is trustable. Just wondered why is offered the other and long approach.
pdecker
I suspected the script just did the same thing as the manual steps. I asked Copilot and it agreed with me.
OK, no problem. If you always want the hottest stuff™ (sorry), this is the way to go. I do this as well for some other repos, e.g. docker and syncthing.